mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: superblock & inode's
       [not found]       ` <17127.14026.575904.182205@cerise.gclements.plus.com>
@ 2005-07-27 18:53         ` Nanakos Chrysostomos
  0 siblings, 0 replies; only message in thread
From: Nanakos Chrysostomos @ 2005-07-27 18:53 UTC (permalink / raw)
  To: Glynn Clements; +Cc: nanakos, linux-c-programming

I looked the sources and the programs use the libext2fs library.I found it
in the sources but it is loss of time reading it just to understand and
retrieve some simple things.So i finally did this below,but i am stack
only in one thing.How to parse the information for a data block that
contains the info for the dir's & files , e.g / directory.Please check the
code below.
The data block allocates 8 blocks ( in my machine 4096 bytes ),the data
are struct ext2_dir_entry_2 structures.But the name lenght isn't always
the same so i cant parse it just knowing the sizeof the structure.Maybe an
iteration with llseek will help.Can someone help me with this algorithm???
Have you got sth to propose????


#include <ext2fs/ext2_fs.h>
#include <fcntl.h>
#include <math.h>


int main()
{
	int fd,of;
	char buf[8*4096];
	int count=0;
	struct ext2_super_block s;
	struct ext2_group_desc g;
	struct ext2_inode i;
	struct ext2_dir_entry_2 dir;
	int block_size,is=0,dir_entry_size;

	fd = open("/dev/hdb2",O_RDONLY);

	lseek(fd,1024L,0);

	read(fd,&s,sizeof(s));

	printf("%d inodes (%d free)\n",s.s_inodes_count,s.s_free_inodes_count);
	printf("%d blocks (%d free)\n",s.s_blocks_count,s.s_free_blocks_count);


	block_size = s.s_log_block_size;

	block_size = pow(2,block_size)*1024;

	printf("Block size: %d\n",block_size);

	printf("Volume name: %s\n",s.s_volume_name);
	printf("Inode size : %d\n",s.s_inode_size);


	lseek(fd,4096L,0);

	read(fd,&g,sizeof(g));

	printf("Inodes Table Block:%d\n",g.bg_inode_table);


	lseek(fd,4*4096L+128L,0); /*inode 2 */

	read(fd,&i,sizeof(i));


	printf("Pointer to data block:%d\n",i.i_block[0]);
	printf("Data blocks occupied:%d\n",i.i_blocks);


	dir_entry_size = sizeof(dir);

	printf("%d\n",dir_entry_size);

	/* Read data block and retrieve directory & file information */
	lseek(fd,i.i_block[0]*4096L,0);
	is += read(fd,&dir,12);
	printf("name:%s inode:%d name_len:%d rec_len:%d
file_type:%d\n",dir.name,dir.inode,dir.name_len,dir.rec_len,dir.file_type);


	is += read(fd,&dir,19);
	printf("name:%s inode:%d name_len:%d rec_len:%d
file_type:%d\n",dir.name,dir.inode,dir.name_len,dir.rec_len,dir.file_type);

	is += read(fd,&dir,12);
	printf("name:%s inode:%d name_len:%d rec_len:%d
file_type:%d\n",dir.name,dir.inode,dir.name_len,dir.rec_len,dir.file_type);

	close(fd);

	return 0;
}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-07-27 18:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <Pine.LNX.4.61.0507250842380.3913@praktifix.dwd.de>
     [not found] ` <17125.51475.763052.283552@cerise.gclements.plus.com>
     [not found]   ` <Pine.LNX.4.61.0507260638110.22613@praktifix.dwd.de>
     [not found]     ` <40710.62.1.10.61.1122396787.squirrel@webmail.wired-net.gr>
     [not found]       ` <17127.14026.575904.182205@cerise.gclements.plus.com>
2005-07-27 18:53         ` superblock & inode's Nanakos Chrysostomos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®