Struct stat { Mode_t st_mode;/* file type & mode (permissions )*/ Ino_t st_ino;/* I-node number (serial number )*/ Dev_t st_dev;/* Device number (File System )*/ Dev_t st_rdev;/* Device number for special files */ Nlink_t st_nlink;/* Number of links */ Uid_t st_uid;/* User ID of owner */ Gid_t st_gid;/* Group ID of owner */ Off_t st_size;/* size in bytes, for regular files */ Time_t st_atime;/* time of last access */ Time_t st_mtime;/* time of last modification */ Time_t st_ctime;/* time of last File status change */ Blksize_t st_blksize;/* Best I/O BLOCK SIZE */ Blkcnt_t st_blocks;/* Number of disk blocks allocated */ };
2. Each process has six user IDs:
real user id real group ID |
who we really are |
valid tive user id valid tive group ID Supplementary group IDs |
used for file access permission checks |
saved set-user-id saved set-group-id |
saved by exec functions, which is a copy of valid user ID and valid group ID. |
|
3. File Access Permissions
S_irusr |
User-read |
S_iwusr |
User-write |
S_ixusr |
User-Execute |
S_irgrp |
Group-read |
S_iwgrp |
Group-write |
S_ixgrp |
Group-Execute |
S_iroth |
Other-read |
S_iwoth |
Other-write |
S_ixoth |
Other-Execute |
|
When accessing related files, we must have the running permission for all the folders on the path. If we have the read permission, we can open the file in read-only mode,
If you have the write permission, you can open the file as a write. To create or delete a file under a directory, you must have the write and run permissions on the directory.
4. Access check
Int access (const char * pathname, int mode );
5. Sticky Bit
By setting stick bit, after the file is run for the first time, the text content is copied to the swap area, and the next time can be quickly run.
6. File System
Because each I-node is numbered inside the same file system, ln (1) cannot be linked in different file systems.
In the same file system, MV and RM operations do not need to carry data.
Each cylinder group can be expressed as follows:
Open the file. If the link count of the file is 0, delete the file.
Each inode contains the following information:
File type, File Permission, file size, file Data Pointer
Most of the information in stat is stored in inode.
7. Links
Hard links all point to the same I-node
Symbolic Links are implemented by storing the directed path name, which can be cross-file systems and direct to directories.
Function |
Does not follow symbolic link |
Follows symbolic link |
Access |
|
• |
Chdir |
|
• |
Chmod |
|
• |
Chown |
• |
• |
Creat |
|
• |
Exec |
|
• |
Lchown |
• |
|
Link |
|
• |
Lstat |
• |
|
Open |
|
• |
Opendir |
|
• |
Pathconf |
|
• |
Readlink |
• |
|
Remove |
• |
|
Rename |
• |
|
Stat |
|
• |
Truncate |
|
• |
Unlink |
• |
|
|
8. File time:
Field |
Description |
Example |
Ls(1) Option |
St_atime |
Last-access time of file data |
Read |
-U |
St_mtime |
Last-modification time of file data |
Write |
Default |
St_ctime |
Last-Change Time of I-node status |
Chmod, chown |
-C |
|
You can use the following functions to modify access time and modification time:
Int utime (const char * pathname, const struct utimbuf * times );
|