A program in Python/C++ to read display the i-node information for a given text file, image file.

inode.cpp



1:  #include"iostream"  
2:  #include"stdio.h"  
3:  #include"stdlib.h"  
4:  #include"sys/types.h"  
5:  #include"sys/stat.h"  
6:  #include"time.h"  
7:  using namespace std;  
8:  int main()  
9:  {  
10:    int m;  
11:    struct stat var;  
12:    char fname[50];  
13:    cout<<"\nEnter file name: ";  
14:    cin>>fname;  
15:    stat(fname, &var);  
16:    cout<<"\nFile name you entered is: "<<fname<<endl;  
17:    cout<<"\n*****************************************************\n";  
18:    cout<<"  INODE STRUCTURE FOR GIVEN FILE\n";  
19:    cout<<"*******************************************************\n";  
20:    cout<<"\n1. Size of file is: "<<var.st_size;  
21:    cout<<"\n2. inode no. is: "<<var.st_ino;  
22:    cout<<"\n3. Device id of file is: "<<var.st_dev;  
23:    cout<<"\n4. Time of last access: "<<ctime(&var.st_atime);  
24:    cout<<"\n5. Time of last modification: "<<ctime(&var.st_mtime);  
25:    cout<<"\n6. Time of last status change: "<<ctime(&var.st_ctime);  
26:    cout<<"\n7. No. of links to file: : "<<var.st_nlink;  
27:    cout<<"\n8. User ID of owner of file: "<<var.st_uid;  
28:    cout<<"\n9. No. of IO blocks allocated to file: "<<var.st_blksize;  
29:    m=var.st_mode;  
30:    cout<<"\n10. type of file: ";  
31:    if(S_ISREG(m))  
32:      cout<<"regular file\n";  
33:    else if(S_ISDIR(m))  
34:      cout<<"directory\n";  
35:    cout<<"\n11. Access permissions of file: ";  
36:    if(S_ISDIR(m))  
37:      cout<<"d";  
38:    else  
39:      cout<<"-";  
40:    if(S_IRUSR & m)  
41:      cout<<"r";  
42:    else  
43:      cout<<"-";  
44:    if(S_IWUSR & m)  
45:      cout<<"w";  
46:    else  
47:      cout<<"-";    
48:    if(S_IXUSR & m)  
49:      cout<<"x";  
50:    else  
51:      cout<<"-";  
52:    if(S_IRGRP & m)  
53:      cout<<"r";  
54:    else  
55:      cout<<"-";  
56:    if(S_IWGRP & m)  
57:      cout<<"w";  
58:    else  
59:      cout<<"-";  
60:    if(S_IXGRP & m)  
61:      cout<<"x";  
62:    else  
63:      cout<<"-";  
64:    if(S_IROTH & m)  
65:      cout<<"r";  
66:    else  
67:      cout<<"-";  
68:    if(S_IWOTH & m)  
69:      cout<<"w";  
70:    else  
71:      cout<<"-";  
72:    if(S_IXOTH & m)  
73:      cout<<"x";  
74:    else  
75:      cout<<"-"<<endl;  
76:    return 0;  
77:  }  

Post a Comment

Previous Post Next Post