473,837 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Understanding Ext-2 file system:chapter 2

542 Recognized Expert Contributor
As per the last discussion(chap ter 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_co unt: 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_des c" 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 6031

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 COS_species table....the information in it cannot be changed. Everything in this database is pretty much centered around the speciesID. We also want other species that are no included in the COS_Species table. Specifically....we want to be able to handle multi species which would contain many...
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 libraries. I'm not sure if that's a good thing or not. AFAIK, most of Qt is compatable with the Standard Library. That is, QLT can interoperate with STL, and you can convert back and forth between std::string and Qt::QString, etc. Are there any...
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 pull a value based on the price per gallon. For example if the price of fuel is 2.44 per gallon and the enter that they get 5.9 miles per gallon the cost of that mile is $.41. Then based on the cost per gallon of 2.44 we might pay them another...
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 "PyMethodDef"? Now, onto my questions about the arguments: I see that even when the Python function we are supplying takes no arguments, (the argument flag is METH_NOARGS), that we still pass the
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 objects / values from functions and the issues involved therein specifically w.r.t. reentrency. He explains that because of reentrency, the object to be returned can't be located down in the stack (down in relative here, which means that stack...
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 same thing. ?
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 includes mathematical routines from the basics up, including floating point arithmetic, compression techniques, including the GIF and JPEG file formats, hashing, red black trees, 3D and 3D graphics, colour spaces, machine learning with neural...
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 am self-learning the Python language. I am in Chapter 4 and reading about "Getting Object References with getattr". First, it say in there that, "you can get a reference to a function without knowing its name until run−time, by using the getattr function". That is the first thing that is a...
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: http://knking.com/books/c2/ I don't think I'm alone among c.l.c. participants in recommending this book (based upon the very good first edition).
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.