自举块:引导程序。node
超级块: 记录整个文件系统相关的信息的地方,它记录的信息主要有:block与inode的总量、使用量、剩余量,文件系统的挂载时间,最近一次写入数据的时间等。网络
i节点图:标记那些inode 是否为已使用socket
块位图:标记那些block 是否为已使用测试
i节点(表):i节点存放文件有关的全部信息:文件类型、文件访问权限位、文件长度和指向文件数据块的指针、文件名、i节点编号.ui
数据块:存放文件内容。操作系统
特色 :unix
unix系统以inode号来操做系统。inode号对应的数据存了文件名、权限、增改查时etc指针
文件名只是方便人类操做,整数操做比字符快rest
操做code
访问 /etc/passwd 文件:
先经过 / 的inode号获取 / 信息。经过权限验证后,从对应的block中访问 文件名列表,找到 /etc
先经过 /etc 的inode号获取 /etc 信息。经过权限验证后,从对应的block中访问 文件名列表,找到 /etc/passwd
先经过 /etc/passwd 的inode号获取 /etc/passwd 信息。经过权限验证后,从对应的block中获得文件信息
修改文件名:直接替换inode中的文件名信息
同一个文件系统中移动文件。建立一个新的inode节点,将旧的inode节点删除。
方法名 | 做用 | 成功 | 失败 |
---|---|---|---|
stat | 返回文件信息 | 0 | -1 |
access和faccessat | 返回文件访问权限 | 0 | -1 |
umask | 屏蔽进程的文件模式的权限 | 返回以前的文件模式建立的屏蔽字 | |
chmode、fchmode、fchmodat | 变动文件的权限 | 0 | -1 |
link、linkat | 建立链接 | 0 | -1 |
unlink、unlinkat | 删除一个文件链接。若是链接为0,则文件删除 | 0 | -1 |
remove | 删除一个文件链接。若是链接为0,则文件删除 | 0 | -1 |
rename、renameat | 重命名 | 0 | -1 |
symlink、symlinkat | 建立符号连接 | 0 | -1 |
readlink、readlinkat | 读取符号连接 | 0 | -1 |
futimens、utimensat 和 utimes | 修改文件时间 | 0 | -1 |
mkdir、mkdirat | 建立目录 | 0 | -1 |
rmdir | 删除目录 | 0 | -1 |
chdir、fchdir | 打开工做目录 | 0 | -1 |
getcwd | 打开工做目录 | 0 | NULL |
#include <sys/stat.h> inct stat(const char *restrict pathname,struct stat *restrict buf); int fstat(int fd,struct stat *buf); int lstat(const char *restrict pathname, struct stat *restrict buf); int fstat(int fd, const char *restrict pathname, struct stat restrict buf, int flag); --'成功:0;出错:-1'
参数:
struct stat { mode_t st_mode; '文件类型' ino_t st_ino; 'i-node 数数量' dev_t st_dev; 'device 数量' dev_t st_rdev; '特殊文件的 device 数量' nlink_t st_nlink; 'link文件的数量' uid_t st_uid; 'user ID' gid_t st_gid; 'group ID' off_t st_size; '普通文件的字节大小' struct timespec st_atime; '最近被访问时间' struct timespec st_mtime; '最近被修改时间' struct timespec st_ctime; '被建立时间' blksize_t st_blksize; 'I/O 的块大小' blkcnt_t st_blocks; '磁盘分配的块大小' }
文件类型
st_mode 的类型 # include<sys/stat.h>
宏 | 说明 |
---|---|
文件类 | |
S_ISREG() | 不一样文件 |
S_ISDIR() | 目录文件 |
S_ISCHR() | 字符特殊文件 |
S_ISBLK() | 块特殊文件 |
S_ISFIFO() | 管道或FIFO |
S_ISLNK() | 符号连接 |
S_ISSOCK() | 套接字 |
IPC类 | |
S_TYPEISMQ() | 消息队列 |
S_TYPEISSEM() | 信号量 |
S_TYPEISSHM() | 共享存储对象 |
#include <unistd.h> int access(const char *pathname, int mode); '绝对路径' int faccessat(int fd, const char *pathname, int mode ,int flag); '相对fd的路径' -- '成功:0;出错:-1'
参数
mode | 说明 |
---|---|
R_OK | 测试读权限 |
W_OK | 测试写权限 |
X_OK | 测试执行权限 |
#incLude <sys/stat.h> mode_t umask(mode_t cmask); --- '返回以前的文件模式建立的屏蔽字'
#include <sys/stat.h> int chmod(const char *pathname ,mode_t mode ); int fchmod(int fd, mode_t mode); int fchmodat(int fd, const char *pathname, mode_t mode, int flag); --- '成功:0;失败-1'
参数
mode | 说明 |
---|---|
S_ISUID | 执行时设置用户ID |
S_ISGID | 执行时设置组ID |
S_ISXID | 保存正文(粘着位) |
S_IRWXU | 用户(全部者)读、写和执行 |
S_IRUSR | 用户(全部者)读 |
S_IWUSR | 用户(全部者)写 |
S_IXUSR | 用户(全部者)执行 |
S_IRWXG | 组读、写和执行 |
S_IRGRP | 组读 |
S_IWGRP | 组写 |
S_IXGRP | 组执行 |
S_IRWXO | 其它读、写和执行 |
S_IROTH | 其它读 |
S_IWOTH | 其它写 |
S_IXOTH | 其它执行 |
#incldue <unistd.h> ' 建立链接' int link(const char *existingpath , const char *newpath) ; int linkat(int efd, const char *existingpath, int nfd, const char *newpath , int flag ); -- '成功:0;出错:-1' '删除一个链接' int unlink(const char *pathname); int unlinkat(int fd , const char *pathname ,int flag); -- '成功:0;失败:-1' '删除' #include <stdio.h> int remove(const char *pathname); '成功:0;失败:-1'
#incldue <unistd.h> int rename(const char *oldname , const char *newname) ; int renameat(int oldfd , const char *oldname, int newfd, const char *newname); -- '成功:0;出错:-1'
#incldue <unistd.h> int symlink(const char *oldname , const char *newname) ; int symlinkat(int oldfd , const char *oldname, int newfd, const char *newname); -- '成功:0;出错:-1'
#incldue <unistd.h> ssize_t readlink(const char *restrict pathname , char *restrict buf , size_t bufsize ) ; ssize_t readlinkat(int fd , const char *restrict pathname , char *restrcit buf newfd, size_t bufsize ); -- '成功:返回读取的字节数;出错:-1'
#incldue <sys/stat.h> ssize_t futimens(int fd , const struct timespec time[2] ) ; ssize_t utimensat(int fd ,const char *path , const struct timespec time[2] ,int flag ) ; -- '成功:0;出错:-1' #include <sys/time.h> int utimes(const char *pathname, const struct timeval time[2]); -- '成功:0;出错:-1'
#incldue <sys/stat.h> int mkdir(const char *pathname,mode_t mode); int mkdirat(int fd , const char *pathname,mode_t mode); -- '成功:0;出错:-1'
#incldue <sys/stat.h> int rmdir(const char *pathname,mode_t mode); -- '成功:0;出错:-1'
#incldue <dirent.h> DIR *opendir(const char *pahtname); DIR *fopendir(int fd); -- '成功:返回指针;出错:NULL' struct dirent *readdir(DIR *dp); -- '成功:返回指针;若在目录尾或出错:NULL' void rewinddir(DIR *dp); void closedir(DIR *dp); -- '成功:0;出错:-1' long telldir(DIR *dp); -- '返回:与dp关联的目录中的当前位置' void seekdir(DIR *dp , long ioc); -- '成功:0;出错:-1'
#incldue <unistd.h> int *chdir(const char *pahtname); int fchdir(int fd); -- '成功:0;出错:-1' char *getcwd(char *buf, size_t size); -- '成功:返回buf;出错:NULL'