#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;
}
stを使用してstruct statを取得する場合、st_inoはls -iのiノード番号と同じです。st_inoと混同されていますか?
1305609
[[email protected] chapter-four]$ ls -i
1305607 a.txt 1305606 fstatat.bin 1305609 fstatat.c 1305605 tmp.txt
BUF iの関数FSTATを使用している場合、st_inoのは常にこれが起こる理由4195126.
誰も教えてもらえますか?
あなたがコメントアウトされている 'open'呼び出しが間違っています。 2番目のパラメータは文字列ではなく適切なフラグでなければなりません。また、 'fstat'の使い方を示す完全なコードを投稿してください。 – davmac