473,385 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,385 developers and data experts.

Understanding Ext-2 file system:chapter 2

ashitpro
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
  1.  
  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>
  10.  
  11.     int main()
  12.     {
  13.         char *buff = (char *)malloc(sizeof(struct ext2_group_desc));
  14.  
  15.         struct ext2_group_desc * gdesc = (struct ext2_group_desc *)malloc(sizeof(struct ext2_group_desc));
  16.  
  17.         //open any partition for testing,must be ext2/ext3.
  18.         int fd = open("/dev/hda3",O_RDONLY);
  19.  
  20.         //skip the boot block and super block
  21.         lseek(fd,4096,SEEK_CUR);
  22.  
  23.         //read the raw data from disk to buff
  24.         read(fd,buff,sizeof(struct ext2_group_desc));
  25.  
  26.         //copy buffer to gdesc, you can use casting or union for this.
  27.         memcpy((void *)gdesc,(void *)buff,sizeof(struct ext2_group_desc));
  28.  
  29.         //At this position you can be assured that you read group descriptor successfully.            
  30.         close(fd);    
  31.  
  32.         return 0;
  33.     }
  34.  
  35.  
Feb 20 '08 #1
0 5983

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

Similar topics

1
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 COS_species table....the information in it cannot...
43
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 much of the same functionality through their own...
19
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 the cost per gallon and use a switch statement to...
3
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 about the method table. Is it an C array named...
3
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 Copy-Constructor ), where he explains that how to return big...
5
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 thing, these are just 2 different names for the...
263
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 programming, with a bias towards graphics. It...
139
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
3
numberwhun
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 am self-learning the Python language. I am in...
5
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. See this URL for details: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.