2016-09-30 2 views
0

텍스트 파일의 inode 번호 목록을 얻는 방법은 무엇입니까? C에서C의 Inode 번호 인쇄

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

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

    system("pause"); 
    return 0; 
} 

나는 inode를 얻는 방법을 모른다.

누군가 코드에 의해 추가 되었습니까?

+0

http://stackoverflow.com/questions/22575727/printing-info-of-a-file-director-inode –

+0

M.S 차우 : 정보를 보여이있는 파일을 지정하는 방법 ?? 내 파일의 이름을 file.txt로 지정하십시오. – Henrix

답변

0

맞습니까?

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; 
} 
0

희망이 있습니다.

#include <stdio.h> 
#include <sys/stat.h> 
#include <fcntl.h> 
#include <stdlib.h> 
int main (int argc, char *argv[]) 
{ 
     struct stat fileStat; 
     int fd=0; 
     FILE *filename = "file1.txt"; 

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

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

     printf("File inode: %d\n",fileStat.st_ino); 

     return 0; 
}