Write A Program in Python / C++ To Read & Display The i-Node Information For A Given Text or Image file.
============ Python Program ============
import os,sys print 'Enter file name' name=raw_input() fd=os.open(name,os.O_RDWR) info=os.fstat(fd) print "File Information is as follows:" print "File inode number:",info.st_ino print "Device number:",info.st_dev print "Number of link:",info.st_nlink print "UID of the file:%d" %info.st_uid print "GID of the file:%d" %info.st_gid print "Size:",info.st_size print "Access time:",info.st_atime print "Modify time:",info.st_mtime print "Change time:",info.st_ctime print "Protection:",info.st_mode print "Number of blocks allocated:",info.st_blocks print "Size of blocks:",info.st_blksize os.close(fd)
============ OUTPUT ============
hnpandya@localhost ~]$ python inode.py Enter file name inode.py File Information is as follows: File inode number: 431632 Device number: 64769 Number of link: 1 UID of the file:1000 GID of the file:1000 Size: 604 Access time: 1413137831.37 Modify time: 1413068044.91 Change time: 1413137821.02 Protection: 33270 Number of blocks allocated: 8 Size of blocks: 4096
============ C++ Program ============
include iostream include fstream // Write As #include < > include sys/stat.h using namespace std; class osd1 { private: char filename[20],data[20]; struct stat buf; public: void get_filename(); void creat_file(); void display_data(); //void write_data(); }; void osd1::get_filename() { cout<<"\n\n Enter the file name.."; cin>>filename; } void osd1::creat_file() { ofstream write(filename); if(write.is_open()) { cout<<"\n\nFile "<write.close(); } else { cout<<"\n\n File does not created.."; } } void osd1::display_data() { cout<<"\n\n FILE DETAILS.."; cout<<"\n File name is:-"< stat(filename,&buf); cout<<"\n INODE NO:-"< cout<<"\n Size:-"< cout<<"\n Contents of file are:-"<} /*void osd1::write_data() { ifstream write(data); if(write.is_open()) { cout<<"\n\nEnter the data.."; cin>>data; write.close(); } else { cout<<"\n\n File is closed.."; } }*/ int main() { osd1 o; o.get_filename(); o.creat_file(); //o.write_data(); o.display_data(); return 0; }
============ OUTPUT =============
[hnpandya@localhost ~]$ g++ inode.cpp [hnpandya@localhost ~]$ ./a.out Enter the file name..inodefile File inodefile created.. FILE DETAILS.. File name is:-inodefile INODE NO:-432085 Size:-0 Contents of file are:- [hnpandya@localhost ~]$
** Note : OSD Program..
Write A Program in Python / C++ To Read & Display The i-Node Information For A Given Text or Image file.
Reviewed by Hardik Pandya
on
12:06:00 AM
Rating:
Or you can use C++ program for inode:
ReplyDelete#include
#include
using namespace std;
class inodetest
{
public:
struct stat s;
char str[100];
void accept()
{
cout<<"Enter the file name";
cin>>str;
cout<<"File name accepted!";
}
void display()
{
int d=stat(str,&s); //function defined
cout<<"\n\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()
{
inodetest i1;
i1.accept();
i1.display();
}
Thanks Saurabh, I'll Update It to post. :)
DeleteHere are other Pl Programs, If You Have More Easy, Working/Error Free programs For Pl1, Pl2, Pl3 From Pune University , Mail Me Compressed zip/rar To hardik.imfrosty.com
man, cant copy any of your code
ReplyDeleteSorry Bro, But other bloggers steals my content so I had to disable Copy/Paste, I don't have any issue if you want to copy only program, you can right click on code and Inspect element and copy HTML code. Now, Paste code to HTML EditorBlue area to get original program as it is shown above.
Deletehow to execute the program.Is it just a normal execution in terminal or any other steps to be performed
ReplyDeleteSave Program file with inode.cpp or inode.py and then execute with terminal, and yes you need to have python and cpp already installed in linux os.. execute them as shown above in post respectively.
Delete