#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