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是超級用戶。
APUE2 第四章
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
Linux基本操作命令
wbzjacky
2019-02-24 13:12:38
真實的模擬***綜合實驗
wbzjacky
2019-02-24 13:12:37
三層交換機的HSRP、vlan、端口聚合
wbzjacky
2019-02-24 13:12:37
HSRP和二層交換機的端口聚合、vlan
wbzjacky
2019-02-24 13:12:37
如果同事暗中傷害你,應該怎麼辦?
這個饅頭有餡
2019-02-24 13:59:08
職場中,抱怨越多的員工,越被領導瞧不起!
這個饅頭有餡
2019-02-24 13:59:08
老程序員被裁,應屆生卻能月薪 1.3 萬?這你能忍?
前端高達
2019-02-24 13:48:04
遇到到處蹭吃卻從不請客吃飯的主怎麼辦?
樑軍年
2019-02-24 13:26:35
高標準機房綜合配線安裝
wbzjacky
2019-02-24 13:12:38
IPsec ***實驗
wbzjacky
2019-02-24 13:12:37
CISCO路由AAA的Easy ***
wbzjacky
2019-02-24 13:12:37
CISCO訪問控制列表 企業網絡管理的必殺技
wbzjacky
2019-02-24 13:12:37