[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: [linux-india-programmers] Inode



Hello all,
	I can't figure out how I got on this mailing list. Anyway,
I have an interesting and fast solution to your inode-file problem.
Prerequsites:
	1. you must know the file system structure.
		( i will assume that you are working with ext2fs)

The solution :
1. Access the raw disk "/dev/hda1 ...."
2. Implement your own version of fs/ext2/inode/"read_inode"
3. Determine the group descriptor of your inode.
4. Implement the algorithm in "fs/ext2/super.c" to read the group
   descriptor.
5. Read the inode.
6. finally, read the blocks.

The above solution is the fastest and as always is the case the most
inflexible. The implementation is not as difficult as it seems. 
Please tell me if you try out the above method. Good luck.
							murali.

:> 
:>  I have an seemly off-topic question, but any Gurus please enlighten me.
:> 
:>  I know only the inode number of a file. Is there anyway i can fetch
:>  the contents of the file( preferably through a C program) . Assume
:>  the access permissions are OK with the file.
:> 
:>  I'd be grateful for any pointers .
:
:Sudhir Parasuram forced the electrons to say:
:> 
:> The easiest way wud b to :- 
:> 
:> Use find with "-inum" option as follows:
:> 
:> find <dir> -inum -exec cat {} \;
:> 
:> It shudn't be extremely difficult to simulate find (though it might take
:> some time). 
:> 
:
:In a shell script, find is fine. But in a C program, implementing find will be
:faster than using find in the program. I suggest you go to the beginning of
:the directory tree from where you want to search from (the syscall chdir()),
:use opendir() and readdir() recursively, and use stat() on all the entries in
:the directory. Compare stat_buf.st_ino with the inode number you have. Then
:fopen() the file and do whatever you want with it. Don't forget to closedir()
:the directory.
:
:This is going to be a nice exercise in recursive programming using C.
:
:The required headers are sys/types.h, sys/stat.h, dirent.h and stdio.h and
:possibly other headers.
:
:Please followup to linux-india-programmers, as I feel this is more on topic
:there. I have crossposted this reply there.
:

- --------------------------------------------------------------------
For more information on Linux in India visit http://www.linux-india.org/
Linux India is NOT a forum for Microsoft/India/Pakistan/US/UK bashing.
Flame baits will not be tolerated.  If you can appreciate satire read
http://www.templetons.com/brad/emily.html

------------------------------