Problem Statement:
Write a program in Python/C++ to read display the i-node information for a given text file, image file.
Write a program in Python/C++ to read display the i-node information for a given text file, image file.
PROGRAM
#include <iostream>
#include <sys/stat.h>
using namespace std;
class inode
{
struct stat s;
char str[1000];
public:
void accept()
{
cout<<"Enter the path of the
file:\t";
cin>>str;
}
void information()
{
int
d=stat(str,&s);
}
void disp()
{
cout<<"\nThe inode details of
the file:\n";
cout<<"\n\t 1)Device ID: "<<s.st_dev;
cout<<"\n\t 2)File Serial No:
"<<s.st_ino;
cout<<"\n\t 3)Mode : "<<s.st_mode;
cout<<"\n\t 4)No of Hard Links:
"<<s.st_nlink;
cout<<"\n\t 5)User ID: "<<s.st_uid;
cout<<"\n\t 6)Group ID: "<<s.st_gid;
cout<<"\n\t 7)Size: "<<s.st_size;
cout<<"\n\t 8)Time of last
access: "<<s.st_atime;
cout<<"\n\t 9)Time of last data
modification: "<<s.st_mtime;
cout<<"\n\t 10)Time of last
status change: "<<s.st_ctime;
cout<<"\n\t 11)I/O block size:
"<<s.st_blksize;
cout<<"\n\t 12)No of blocks
allocated: "<<s.st_blocks<<endl;
}
};
int main()
{
inode node;
node.accept();
node.information();
node.disp();
return 0;
}
OUTPUT
[dbsl@localhost
~]$ g++ A4_inode.cpp
[dbsl@localhost
~]$ ./a.out
Enter path: /home/dbsl/A4_inode.cpp
Filename : /home/dbsl/A4_inode.cpp
Device id : 2058
Inode number : 526528
Device id (if the file is character or
block special) : 0
File size :2132
Block size : 4096
Number of blocks allocated for this file :
8
Last access time : 1406093149 s
Modified time : 1405655410 s
Number of hard links : 1
User name : dbsl
User id : 1000
Group name : dbsl
Group id : 1000
Mode : -rw-r--r--
mode doesnt come
ReplyDeleteI apologise for the late reply.
ReplyDeleteThe mode is getting displayed. Try running the program again. It maybe getting displayed in the form of numbers as shown in the output below:
The inode details of the file:
1)Device ID: 16777220
2)File Serial No: 39102707
3)Mode : 33184
4)No of Hard Links: 1
5)User ID: 501
6)Group ID: 20
7)Size: 504429
8)Time of last access: 1447781726
9)Time of last data modification: 1443965057
10)Time of last status change: 1447781726
11)I/O block size: 4096
12)No of blocks allocated: 992
Tell me how it works out!
Very nice site I get my ans very easily..
ReplyDeleteThanks! Kindly share this blog with other people in need.
Deletei want explaination of whole programme. can i get it?
ReplyDelete