c - 在C中打印 inode 号

标签 c inode

如何获取文本文件的 inode 编号列表?在C中

int main(int argc, char *argv[])
{

    FILE *pFile;
    pFile=fopen("file.txt", "r");
       .
       .
       .
       .
    fclose(pFile);

  system("pause");
  return 0;
}

我不知道如何获取inode。

由某人代码添加?

最佳答案

正确吗?

int main (int argc, char *argv[])
{
    struct stat fileStat;
    int fd=0;
    FILE *filename = "infile.txt";

    if ( ( fd = open (filename , O_RDONLY) ) == -1){
        perror ( "open " );
        system("pause");
        exit (1) ;
    }

    if(fstat(fd, &fileStat)<0) return 1;

    printf("Information for %s\n",filename);
    printf("---------------------------\n");
    printf("File Size: \t\t%d bytes\n",fileStat.st_size);
    printf("Number of Links: \t%d\n",fileStat.st_nlink);
    printf("File inode: \t\t%d\n",fileStat.st_ino);

    system("pause");
    return 0;
}

关于c - 在C中打印 inode 号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39791426/

相关文章:

c - 暂停线程?

c++ - Visual Studio 中的 OpenCL - 我们可以编译一个 exe 来使用所有可能的 CPU OpenCL 可以获得所有 OpenCL 支持平台吗?

excel - 使用数据库时如何使用 Anylogic 对象 (INode) 作为类型

cocoa - 如何确定Cocoa中两个路径是同一个文件的硬链接(hard link)?

c - 从内核空间的 inode 读取原始字节

c - 静态变量和静态内存分配之间的区别?

c - 对 VeriFone 库的内存可用调用

c - malloc 的包装会起作用吗?

amazon-web-services - 增加 AWS EBS 上的 inode 数量

c - 统计信息未显示正确的 inode 号