访问权限和文件模式 ?文件潜在的用户分为3种类型 >文件所有者 >同组用户 >其他用户 必访问权限:读、写、执行 >每类用户都有这三种权限 文件的访问权限使用9个不同的t来表示 冬此外还有三种附加标记 >suid、sgid、sticky ce and Techno 嵌入式系统实验室 2023/7/14 Linux OS analysis 13/84 EMBEDDED SYSTEM LABORATORY SUZHOU INSTITUTE FON ADVANCED STUDY OF USTC
2023/7/14 Linux OS analysis 13/84 访问权限和文件模式 ❖文件潜在的用户分为3种类型 ➢文件所有者 ➢同组用户 ➢其他用户 ❖访问权限:读、写、执行 ➢每类用户都有这三种权限 ❖文件的访问权限使用9个不同的bit来表示 ❖此外还有三种附加标记 ➢suid、sgid、sticky
关于suid、sgid、sticky 必Suid >执行某个可执行文件的时候,进程通常具有进程拥有 者的UID,但是若可执行文件设置了SUID标记,则进 程将拥有文件所有者的UID ●危险:若文件所有者是root? Sgid 58 >类似,进程的GD将不是进程拥有者的GD,而是文 件所有者所在组的GD Sticky > 告诉内核,就算一个程序运行结束了,也暂时将程序 保留在内存中 ence and 嵌入式系统实验室 2023/7/14 Linux OS analysis 14/84 EMBEDDED SYSTEM LABORATORY SUZHOU INSTITUTE FON ADVANCED STUDY OF USTC
2023/7/14 Linux OS analysis 14/84 关于suid、sgid、sticky ❖Suid ➢执行某个可执行文件的时候,进程通常具有进程拥有 者的UID,但是若可执行文件设置了SUID标记,则进 程将拥有文件所有者的UID ⚫危险:若文件所有者是root? ❖Sgid ➢类似,进程的GID将不是进程拥有者的GID,而是文 件所有者所在组的GID ❖Sticky ➢告诉内核,就算一个程序运行结束了,也暂时将程序 保留在内存中
在一个文件被创建的时候: >一个文件的属主UID就是创建这个文件的进程的UID >一个文件的属主GD可能是 ●1 创建这个文件的进程的GD ●若文件的父目录设置了SGD标记,则该文件将继承父目录 的GD ersitv of Science and Technoloo 嵌入式系统实验室 2023/7/14 Linux OS analysis 15/84 EMBEDDED SYSTEM LABORATORY SUZHOU INSTITUTE FON ADVANCED STUDY OF USTC
2023/7/14 Linux OS analysis 15/84 ❖在一个文件被创建的时候: ➢一个文件的属主UID就是创建这个文件的进程的UID ➢一个文件的属主GID可能是 ⚫创建这个文件的进程的GID ⚫若文件的父目录设置了SGID标记,则该文件将继承父目录 的GID
文件操作的系统调用 创建/删除 #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 twrite(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> 2023/7/14 int rename(const char *oldpath,const char *newpath);
2023/7/14 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);
Linux的虚拟文件系统 中国科学技术大学计算机系 陈香兰(0512-87161312) xlanchen@ustc.edu.cn 助教:裴建国、冯晓静 Autumn 2008 嵌入式系统实验室 EMBEDDED SYSTEM LABORATORY SUZHOU INSTITUTE FOR ADVANCED STUDY OF USTC
Linux的虚拟文件系统 中国科学技术大学计算机系 陈香兰(0512-87161312) xlanchen@ustc.edu.cn 助教:裴建国、冯晓静 Autumn 2008