使用stat(2) - 获取Inode编号和硬链接计数

Nat*_*ate 1 c

我在获取此信息时遇到问题.我不知道如何访问它.我目前的代码片段如下所示.随意批评那里已经存在的问题.谢谢.

DIR *directory;
struct dirent *fileEntry; 

directory = opendir(argv[1]);
if(directory != NULL)
 {
  while((fileEntry = readdir(directory)) != NULL)
   {
    int i = 0;
    char *filename[];
    filename[i] = fileEntry -> d_name; // Get filename
    // Get inode here
    // Get hard link count here
    i++; 
   }
  }
Run Code Online (Sandbox Code Playgroud)

shi*_*kou 6

你有没有检查过联机帮助页? http://linux.die.net/man/2/stat 您应该可以通过以下方式访问它们:

fileEntry->st_ino; /* inode number */
fileEntry->st_nlink;  /* number of hard links */
Run Code Online (Sandbox Code Playgroud)