472,330 Members | 1,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 472,330 developers and data experts.

Understanding Ext-2 file system:chapter 2

542 Expert 512MB
As per the last discussion(chapter 1), here we'll try to read the group descriptor.
First of all we'll try to understand what is group descriptor.
AS we know, superblock and group descriptor table are duplicated in each block group.
Group descriptor table is an array of group desciptors
Each block group has it's own group descriptor. And it is stored in group discriptor table in sequential manner.
In other word each block group has all group descriptors, as descriptor table is copied in each block group.
That means if we are looking at block group 3, then we can find it's group descriptor at 3 position in descriptor table.
In this article we'll retrieve the first group descriptor structure from table. So without any doubt it will represent the first block group.

Let's see what information can single group descriptor contain:

bg_block_bitmap: Block number of block bitmap
bg_inode_bitmap: Block number of inode bitmap
bg_inode_table: Block number of first inode table block
bg_free_blocks_count: Number of free blocks in the group
bg_free_inodes_count: Number of free inodes in the group
bg_used_dirs_count: Number of directories in the group
bg_pad: Alignment to word
bg_reserved: Nulls to pad out 24 bytes

Group descriptor is represented in linux kernel as "ext2_group_desc" structure.
Abouve fields belongs to same structure.

As we can see from above information, It will give us all information for it's block group.

Lets see how we can code to retrive the group descriptor structure.

Very first block is boot block:1024 B
Later resides superblock
We are assuming that block size is 4096.
After 4096 B group descriptor table can be find out.
So we will open any ext2 partition and seek 4096 bytes, read the first group descriptor.

Expand|Select|Wrap|Line Numbers
  2.     #include<linux/ext2_fs.h>
  3.     #include<sys/types.h>
  4.     #include<sys/stat.h>
  5.     #include<stdio.h>
  6.     #include<unistd.h>
  7.     #include<fcntl.h>
  8.     #include<stdlib.h>
  9.     #include<string.h>
  11.     int main()
  12.     {
  13.         char *buff = (char *)malloc(sizeof(struct ext2_group_desc));
  15.         struct ext2_group_desc * gdesc = (struct ext2_group_desc *)malloc(sizeof(struct ext2_group_desc));
  17.         //open any partition for testing,must be ext2/ext3.
  18.         int fd = open("/dev/hda3",O_RDONLY);
  20.         //skip the boot block and super block
  21.         lseek(fd,4096,SEEK_CUR);
  23.         //read the raw data from disk to buff
  24.         read(fd,buff,sizeof(struct ext2_group_desc));
  26.         //copy buffer to gdesc, you can use casting or union for this.
  27.         memcpy((void *)gdesc,(void *)buff,sizeof(struct ext2_group_desc));
  29.         //At this position you can be assured that you read group descriptor successfully.            
  30.         close(fd);    
  32.         return 0;
  33.     }
Feb 20 '08 #1
0 5818

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Member | last post by:
I have a situation that some of you may be of help. I will name the tables specifically so you can understand what I am talking about. I have a...
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide...
by: rdavis7408 | last post by:
Hello, I have four textboxes that the user enters the price per gallon paid at the pump, the mileage per gallon and I would like to then calculate...
by: Redefined Horizons | last post by:
I'm trying to understand the argument flags that are used in the method table of an extension module written in C. First let me ask this question...
by: Divick | last post by:
I was reading this section in Bruce Eckel's book which talks about passing and returning large objects ( Chapter 11: References & the...
by: arnuld | last post by:
this is from mentioned section. i did not understand some things here: it means "flushing the buffer" and "writing to output device" are SAME...
by: Malcolm McLean | last post by:
The webpages for my new book are now up and running. The book, Basic Algorithms, describes many of the fundamental algorithms used in practical...
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
by: numberwhun | last post by:
Hello everyone! I am presently going through the "Dive Into Python" tutorial which I obtained from their website. No, this is not for any class, I...
by: Bob Nelson | last post by:
Right next to K&R2 on my bookshelf is _C Programming: A Modern Approach_ by Professor K.N. King. The second edition of this book is now available....
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.