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

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem reading group descriptor

ashitpro
542 Expert 512MB
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;
}
Feb 1 '08 #1
3 1994
weaknessforcats
9,208 Expert Mod 8TB
read(fd,buff,block_size); //read superblock,we read one block here
Shouldn't you be reading the boot block size??
Expand|Select|Wrap|Line Numbers
  1. read(fd,buff,boot_block_size); //read superblock,we read one block here
  2.  
Feb 1 '08 #2
ashitpro
542 Expert 512MB
Shouldn't you be reading the boot block size??
Expand|Select|Wrap|Line Numbers
  1. read(fd,buff,boot_block_size); //read superblock,we read one block here
  2.  
Boot block is always 1024 bytes(This is fixed). And rest of the blocks are of size 4096 bytes(this number may vary).
Thats why I am reading block_size here..
And in reality we should not care about size. Because size of group descriptor structure is not greater that 1024.
So further memcpy must work..But it's not working
Feb 1 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
Then I have no idea. Pehaps another kindly soul can step in here.
Feb 2 '08 #4

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

Similar topics

3
by: Jonas | last post by:
Hi, I'm writing a small chat client to learn some python and networking. No problem with the network stuff tho, the problem is when the user should be able to interact and type messages to send....
1
by: Hao Xu | last post by:
Hi everyone! I found that if you want to write to the memory got by mmap(), you have to get the file descriptor for mmap() in O_RDWR mode. If you got the file descriptor in O_WRONLY mode, then...
3
by: collinm | last post by:
hi i send a command to a led display, the led display is suppose to return me some character i write a string on a serial port void ledDisplayExist() { char msg={'\0', '\0', '\0', '\0',...
7
by: DBMS_Plumber | last post by:
Having a hard time with a UDF. Wonder if folk might care to take a look and tell me what's up. All of this kicked off from trying to build a set of C++ iostream derived classes that can make...
0
by: The Frog | last post by:
Hello Everyone, I have been asked to try and create a single SQL query to retrieve product information from a database. The way that data is arranged is that in some tables there are user...
1
by: Pathik | last post by:
Hi All, I have to get the values of "reading" and "value" elements of context Person/Category/Group/ser.These values must be on condition based,means I have to get the values of "reading" and...
3
by: Eric Mahurin | last post by:
Is there a standard way to get a descriptor object for an arbitrary object attribute - independent of whether it uses the descriptor/ property protocol or not. I want some kind of...
0
by: =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki | last post by:
How many times is map file faster than reading of file by next of file descriptor and when both times are so aqual one? Thanks in advance.
2
by: shahiz | last post by:
basically im having null pointer exception //read an inputstream is = new DataInputStream(new FileInputStream("test.mpg")); loadBytes(is); //pass it as a datasource for the player public...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.