#include <dirent.h> struct dirent { ino_t d_ino; /* Inode number */ off_t d_off; /* Not an offset; see below */ unsigned short d_reclen; /* Length of this record */ unsigned char d_type; /* Type of file; not supported by all filesystem types */ char d_name[256]; /* Null-terminated filename */ };
用於存儲文件狀態的數據結構---struct statnode
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> int stat(const char *path, struct stat *buf); 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 of 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; /* total size, in bytes */ blksize_t st_blksize; /* blocksize for file system I/O */ blkcnt_t st_blocks; /* number of 512B blocks allocated */ time_t st_atime; /* time of last access */ time_t st_mtime; /* time of last modification */ time_t st_ctime; /* time of last status change */ };
用於存儲用戶信息的數據結構---struct passwdshell
#include < sys / types.h > #include < pwd.h > struct passwd * getpwnam(const char * name ); //經過用戶名獲取用戶信息 struct passwd * getpwuid(uid_t uid ); //經過用戶ID獲取用戶信息 struct passwd { char *pw_name; /* username */ char *pw_passwd; /* user password */ uid_t pw_uid; /* user ID */ gid_t pw_gid; /* group ID */ char *pw_gecos; /* user information */ char *pw_dir; /* home directory */ char *pw_shell; /* shell program */ }
用於存儲用戶組信息的數據結構---struct group數據結構
#include <sys/types.h> #include <grp.h> struct group *getgrnam(const char *name); //經過用戶組名來獲取用戶組信息 struct group *getgrgid(gid_t gid); //經過用戶組ID來獲取用戶組信息 struct group { char *gr_name; /* group name */ char *gr_passwd; /* group password */ gid_t gr_gid; /* group ID */ char **gr_mem; /* group members */ };
三個文件特殊屬性:函數
SUID:通常做用於二進制文件上;執行者將暫時擁有文件擁有者的全部權限ui
SGID:對於二進制文件來講,SGID做用同SUID,使得執行者暫時擁有文件所屬用戶組的全部權限;對於目錄來講,在該目錄下建立的文件屬組於目錄屬組相同this
SBIT:僅對目錄有效,使得該目錄下建立的文件僅有文件擁有者和root可刪除,其餘用戶不可刪除該目錄下的文件code