访问权限和文件模式 ◆文件潜在的用户分为3种类型 >文件所有者 同组用户 >其他用户 ☆访问权限:读、写、执行 >每类用户都有这三种权限 ◆文件的访问权限使用9个不同的b来表示 ◆此外还有三种附加标记 >suid、sgid、 sticky ce and 2021/2/9 嵌入式系统实验室 Linux Os analysis 13184 EM目 EDDED SYSTEM LA口RAT口RY
2021/2/9 Linux OS analysis 13/84 访问权限和文件模式 ❖文件潜在的用户分为3种类型 ➢文件所有者 ➢同组用户 ➢其他用户 ❖访问权限:读、写、执行 ➢每类用户都有这三种权限 ❖文件的访问权限使用9个不同的bit来表示 ❖此外还有三种附加标记 ➢suid、sgid、sticky
关于suid、sgid、 sticky 今Suid 执行某个可执行文件的时候,进程通常具有进程拥有 者的UID,但是若可执行文件设置了SUID标记,则进 程将拥有文件所有者的UID ●危险:若文件所有者是root? 8 sgid 类似,进程的GID将不是进程拥有者的GID,而是文 件所有者所在组的GID Sticky 告诉内核,就算一个程序运行结束了,也暂时将程序 保留在内存中 2021/2/9 嵌入式系统实验室 Linux Os analysis 14184 EM目 EDDED SYSTEM LA口RAT口RY
2021/2/9 Linux OS analysis 14/84 关于suid、sgid、sticky ❖Suid ➢执行某个可执行文件的时候,进程通常具有进程拥有 者的UID,但是若可执行文件设置了SUID标记,则进 程将拥有文件所有者的UID ⚫危险:若文件所有者是root? ❖Sgid ➢类似,进程的GID将不是进程拥有者的GID,而是文 件所有者所在组的GID ❖Sticky ➢告诉内核,就算一个程序运行结束了,也暂时将程序 保留在内存中
◆在一个文件被创建的时候: 个文件的属主UID就是创建这个文件的进程的UID 个文件的属主GD可能是 ●创建这个文件的进程的GID 若文件的父目录设置了SGD标记,则该文件将继承父目录 的GD 2021/2/9 Linux Os analysis 15184 嵌入式系统实验室 EM目 EDDED SYSTEM LA口RAT口RY
2021/2/9 Linux OS analysis 15/84 ❖在一个文件被创建的时候: ➢一个文件的属主UID就是创建这个文件的进程的UID ➢一个文件的属主GID可能是 ⚫创建这个文件的进程的GID ⚫若文件的父目录设置了SGID标记,则该文件将继承父目录 的GID
文件操作的系统调用 令创建删除# nclude <sys/types. h ◆打开关闭 include <sys/stat. h> #include <fcntlh> 读/写 int open( const char' pathname, int flags) ◆定位 int open(const char * pathname, int flags, mode t mode) int creat(const char*pathname, mode t mode) 令更名 #include <unistd.h> ssize t write(int fd, const void *buf, size t count) int unlink(const char pathname #include <sys/types.h> include <unistd.h> off t Iseek(int fildes, off t offset, int whence) #include <stdio. h> 2021/2/9 int rename(const char *oldpath, const char newpath)
2021/2/9 Linux OS analysis 16/84 文件操作的系统调用 ❖创建/删除 ❖打开/关闭 ❖读/写 ❖定位 ❖更名 #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int open(const char *pathname, int flags); int open(const char *pathname, int flags, mode_t mode); int creat(const char *pathname, mode_t mode); #include <unistd.h> ssize_t write(int fd, const void *buf, size_t count); int unlink(const char *pathname); #include <sys/types.h> #include <unistd.h> off_t lseek(int fildes, off_t offset, int whence); #include <stdio.h> int rename(const char *oldpath, const char *newpath);
提纲 ◆虚拟文件系统VFS的作用 ☆VFS的数据结构 文件系统类型 文件系统安装 冷路径名查找8 ☆VFS系统调用的实现 ◆文件加锁 2021/2/9 嵌入式系统实验室 Linux Os analysis 18184 EM目 EDDED SYSTEM LA口RAT口RY
2021/2/9 Linux OS analysis 18/84 提纲 ❖虚拟文件系统VFS的作用 ❖VFS的数据结构 ❖文件系统类型 ❖文件系统安装 ❖路径名查找 ❖VFS系统调用的实现 ❖文件加锁