1.stat , fstat , lstat
int stat( const char * restrict pathname , struct stat * restrict buf ) ;
int fstat ( int filedes , struct stat* restrict buf ) ;
int lstat ( const char * restrict pathname , struct stat * restrict buf ) ;
以上三个函数均可以获取文件的相关信息,以stat的结构返回。其中,stat使用文件名进行获取,而且会跟踪链接,而lstat会显示链接文件的信息,不会跟踪。而fstat则是通过已经打开的文件描述符来获得相关的文件信息。
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.每个进程都有六个相关的用户ID值 :
real user ID real group ID
|
who we really are
|
effective user ID effective group ID supplementary group IDs
|
used for file access permission checks
|
saved set-user-ID saved set-group-ID
|
saved by exec functions,是effective user ID和effective group ID的复制。
|
|
3.文件访问权限
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
|
|
在访问相关的文件时,我们必须对于该路径上的所有的文件夹拥有运行权限。如果我们拥有read的权限,则可以以只读形式打开文件,
如果 拥有write权限,则可以以写的形式打开文件。要在一个目录下新建或者删除文件,我们必须对该目录拥有写与运行权限。
4.访问检查
int access( const char * pathname , int mode ) ;
5.sticky bit
通过设定stick bit,在该文件第一次被运行后,text的内容被复制到交换区,下一次可以快速地运行。
6.文件系统

因为每个i-node都是要同一个文件系统内部进行编号的,所以ln(1)无法在不同的文件系统中进行链接操作。
而在同一个文件系统中时,mv与rm操作都不需要搬运数据。
对于每个cylinder group,可以表示成以下形式:
打开该文件,如果该文件的link count为0,则为将该文件删除。
每个inode都会包含如下信息:
文件类型,文件权限,文件大小, 文件数据的指针
stat中的信息大部分都是保存在inode之中。
7.链接
硬链接,均指向同一个i-node
符号链接,通过存储指向的路径名实现,可以实现跨文件系统与指向目录。
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.文件时间:
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
|
|
access time 与modification time 均可以使用下面的函数进行修改:
int utime( const char * pathname , const struct utimbuf * times ) ;
|
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述