【发布时间】:2016-09-05 05:31:09
【问题描述】:
#include "stdio.h"
#include <sys/stat.h>
int
main(int argc, char *argv[]) {
struct stat buf;
//int fd = open("./fstatat.c", "r");
//int fd2 = fstatat(fd, "a.txt", &buf, 0);
//printf("%d\n", buf.st_ino);
stat("./fstatat.c", &buf);
printf("%d\n", buf.st_ino);
return 0;
}
如果我使用函数 stat 得到一个 struct stat,st_ino 与 ls -i 的 i-node 编号相同。
1305609
[inmove@localhost chapter-four]$ ls -i
1305607 a.txt 1305606 fstatat.bin 1305609 fstatat.c 1305605 tmp.txt
如果我使用函数 fstat,则 st_ino 始终是 4195126。
谁能告诉我为什么会这样?
【问题讨论】:
-
你注释掉的
open调用是错误的;第二个参数应该是合适的标志,而不是字符串。另外,请发布完整的代码,展示您如何使用fstat。