Hi All,
I am working on ext3 file system.
I am trying to read group descriptor from disk.
I am able to read the superblock structure successfully.
But I am not getting successful to get the group descriptor. Here is my code. Please check out what is missing.
#include<linux/ext3_fs.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<stdlib.h>
#include<string.h>
#define block_size 4096
#define boot_block_size 1024
int main()
{
char *buff = (char *)malloc(block_size);
struct ext3_super_block * sblock = (struct ext3_super_block *)malloc(sizeof(struct ext3_super_block));
struct ext3_group_desc * gdesc = (struct ext3_group_desc *)malloc(sizeof(struct ext3_group_desc));
int fd = open("/dev/hda3",O_RDONLY);
lseek(fd,boot_block_size,SEEK_CUR); //skip the boot block
read(fd,buff,block_size); //read superblock,we read one block here
memcpy((void *)sblock,(void *)buff,sizeof(struct ext3_super_block));
//read the next block..assuming this will contain group dsc for this block
read(fd,buff,block_size); //read first group desc struct.
memcpy((void *)gdesc,(void *)buff,sizeof(struct ext3_group_desc));
//try to print some field inside structure..
printf("\nbg_inode_table:%u",gdesc->bg_inode_table);
close(fd);
return 0;
}