APUE2 第四章

1.三個函數
     #inlcude <sys/stat.h>
      int stat(const char *restrict pathname, struct stat *restrict buf);
      int fstat(int filedes, struct stat *buf);
      int lstat(const char *restrict pathname, struct stat *restrict buf);
      stat 和 fstat 完全相同,除了前者使用路徑名,而後者使用文件描述符。
      lstat 和 stat唯一區別是,在操作文件的符號連接時,前者取得的是符號連接本身的信息。

2. stat結構
      struct stat {
           dev_t    st_dev;        /* ID of device containing file */
           ino_t      st_ino;         /* inode number */
           mode_t  st_mode;   /* protection */
           nlink_t    st_nlink;     /* number off hard links */
           uid_t       st_uid;       /* user ID of owner */
           gid_t       st_gid;       /* group ID of owner */
           dev_t    st_rdev;      /* device ID (if special file) */
           off_t       st_size;     /* size in bytes, for regular files */
           time_t    st_atime; /* time of last acess */
           time_t    st_mtime; /* time of last modification */
           time_t    st_ctime;  /* time of last stat change */
           blksize_t  st_blksize;  /* best IO block size */
           blkcnt_t   st_blocks;  /* number of disk blocks allocated */
      }

3. 文件類型
     1) regular file :     S_ISREG()
     2) directory file:     S_ISDIR()
     3) block special file:     S_ISBLK()
     4) character special file:   S_ISCHR()
     5) FIFO:          S_ISFIFO()
     6) socket:       S_ISSOCK()
     7) symbolic link:     S_ISSOCK()

4. 訪問許可
     S_IRUSR
     S_IWUSR
     S_IXUSR
     S_IRGRP
     S_IWGRP
     S_IXGRP
     S_IROTH
     S_IWOTH
     S_IXOTH
     目錄必須有執行權限才能操作目錄下的文件。

5. 新建文件ID
    用戶ID設置成有效用戶ID, 組ID可選: 有效用戶ID或者所在目錄ID




6. access 函數
      int access(const char *pathname, int mode);
        R_OK,  W_OK, X_OK, F_OK

7, umask 函數
        mode_t umask(mode_t cmask);
        改變進程文件創建掩碼, 並返未改變前文件創建掩碼。

8. chmod 和 fchmod函數
        改變文件權限, 爲了改變權限,進程有效用戶ID必須等於文件ower ID或者,有效用戶ID是超級用戶。





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章