【发布时间】:2019-06-13 07:12:21
【问题描述】:
$ stat Cargo.toml
16777220 9094681422 -rw-r--r-- 1 tonytonyjan staff 0 109 "Jan 19 10:05:13 2019" "Dec 31 17:52:29 2018" "Dec 31 17:52:29 2018" "Dec 14 16:32:26 2018" 4096 8 0 Cargo.toml
man stat不解释但提到输出是lstat得到的:
显示的信息是通过使用给定参数调用 lstat(2) 并评估返回的结构来获得的。
man lstat 之后,它给出了一个看起来像我正在寻找的 C 结构:
The buf argument is a pointer to a stat structure as defined by <sys/stat.h> and into which information is placed concerning the file. When the macro
_DARWIN_FEATURE_64_BIT_INODE is not defined (see below for more information about this macro), the stat structure is defined as:
struct stat { /* when _DARWIN_FEATURE_64_BIT_INODE is NOT defined */
dev_t st_dev; /* device inode resides on */
ino_t st_ino; /* inode's number */
mode_t st_mode; /* inode protection mode */
nlink_t st_nlink; /* number of hard links to the file */
uid_t st_uid; /* user-id of owner */
gid_t st_gid; /* group-id of owner */
dev_t st_rdev; /* device type, for special file inode */
struct timespec st_atimespec; /* time of last access */
struct timespec st_mtimespec; /* time of last data modification */
struct timespec st_ctimespec; /* time of last file status change */
off_t st_size; /* file size, in bytes */
quad_t st_blocks; /* blocks allocated for file */
u_long st_blksize;/* optimal file sys I/O ops blocksize */
u_long st_flags; /* user defined flags for file */
u_long st_gen; /* file generation number */
};
很遗憾,我仍然无法将每个字段映射到stat 的输出,例如:
$ stat Cargo.toml
16777220 9094681422 -rw-r--r-- 1 tonytonyjan staff 0 109 "Jan 19 10:05:13 2019" "Dec 31 17:52:29 2018" "Dec 31 17:52:29 2018" "Dec 14 16:32:26 2018" 4096 8 0 Cargo.toml
- 16777220 - 设备 inode 驻留在
- 9094681422 - 索引节点
- -rw-r--r-- - 保护模式
- 1 - 硬链接数
- tonytonyjan - 用户
- 员工 - 组
- 0 - 不确定。是设备类型吗?
- 109 - 尺寸
- “2019 年 1 月 19 日 10:05:13” - 最后访问
- “2018 年 12 月 31 日 17:52:29” - 最后修改
- “2018 年 12 月 31 日 17:52:29” - 最后文件状态更改
- “Dec 14 16:32:26 2018” - 应该只有 3 个时间戳,这是什么?
- 4096 - 文件大小(以字节为单位)
- 8 - 为文件分配的块
- 0 - 最佳文件系统 I/O 操作块大小?用户定义的标志?还是文件代号?
- Cargo.toml - 文件名
我的问题:
- 第一个
0是否代表st_rdev? -
st_dev和st_rdev有什么区别? - 秒
0代表什么? - 很多我没有找到正确的
man页面(既没有man stat也没有man lstat)。是否有任何官方文档详细解释每个stat字段?我在哪里可以找到它?
【问题讨论】:
-
这不是一个真正的编程问题,因此不适合 Stack Overflow。另一个 Stack Exchange 站点会更好。也就是说,试试
-s选项。 ;) -
unix.stackexchange.com 是这个问题的更好论坛。
标签: macos file unix stat manpage