inodes

Jim Webb jrw at hropus.UUCP
Mon Oct 20 02:19:42 AEST 1986


> 	                        Is there any way to "get" an i-node into a C 
> program, the way getpwent gets passwd entries ?  Do I really have to
> open the device file and look for the i-list ?  

The stat(2) call yields a lot of info in the inode, but if you are
looking for block info, reading the inode is the only means of getting
it.  There is not a getinode() function, but it would be a very simple
function to write.

Under System V, the physical disk slice looks like this:

   block 0       block 1     block 2 ....       
+------------+------------+---------------------------+---------------
|  BOOT BLK  | SUPER BLK  | INODES....                |  DATA BLOCKS
+------------+------------+---------------------------+---------------

So, to grab the inode, all one has to do is to lseek past the
boot and super- blocks, and then, using the inode number, lseek into
the ilist and read out the inode:

		#include <sys/types.h>
		#include <sys/ino.h>
		#include <fcntl.h>

		int fd;
		ino_t inum;
		struct dinode ibuf;

		fd=open("/dev/rdsk/0s0",O_RDONLY);
		lseek(fd,1024+inum*sizeof(struct dinode),0);
		read(fd,ibuf,sizeof(struct dinode));

Then you can look at any of the inode info via ibuf.
-- 
Jim Webb             "Out of phase--get help"          ...!ihnp4!hropus!jrw
		"Use the Force, Read the Source"



More information about the Comp.unix mailing list