|
我通过如下方式取得了/分区的supper_block及group_desc 块的内容,结果显示好奇怪啊!
open /dev/hda3!
inode_per_group is 16096
s_inodes_count is 595552
s_free_inodes_count is 386527
s_free_blocks_count is 221056
block size is 4096 byte
blocks_count is 1188810
first_data_block is 0
blocks_per_group is 32768
total group is 37
inode_per_block is 32
inode_bit_blocks is 503
volume name is /
bg_block_bitmap is 2
bg_inode_bitmap is 3
bg_inode_table is 4
bg_free_blocks_count is 0
bg_free_inodes_count is 10424
group_count=0
bg_block_bitmap is 32770
bg_inode_bitmap is 32771
bg_inode_table is 32772
bg_free_blocks_count is 2
bg_free_inodes_count is 10449
group_count=1
bg_block_bitmap is 65536 //????
bg_inode_bitmap is 65537 //????
bg_inode_table is 65540
bg_free_blocks_count is 0
bg_free_inodes_count is 10443
group_count=2
bg_block_bitmap is 98306
bg_inode_bitmap is 98307
bg_inode_table is 98308
bg_free_blocks_count is 0
bg_free_inodes_count is 10438
group_count=3
bg_block_bitmap is 131072 //????
bg_inode_bitmap is 131073 //????
bg_inode_table is 131076
bg_free_blocks_count is 0
bg_free_inodes_count is 8243
group_count=4
.......
打问号的地方感觉不对呀?每个组的第一个应该是supper_block,然后是group_desc,然后才是block_bitmap和inode_bitmap,为什么在这里显示的会有这种奇怪的情况呢?
我的读取程序如下,感觉没有问题?
FILE *fp; /*定义文件指针*/
char info[1024];
if((fp=fopen("/dev/hda2","rb"))==NULL){
printf("open /dev/hda2 failure!\n");
exit(1);
}else
printf("open /dev/hda2!\n");
fseek(fp,1024,0);
fread(info,sizeof(s_block),1,fp);
p_block=info;
//超级块的内容分解
printf("inode_per_group is %d \n",p_block->s_inodes_per_group);
printf("s_inodes_count is %d \n",p_block->s_inodes_count);
printf("s_free_inodes_count is %d \n",p_block->s_free_inodes_count);
printf("s_free_blocks_count is %d \n",p_block->s_free_blocks_count);
printf("block size is %d byte\n",1<<(p_block->s_log_block_size+10));//一个数据块的大小
printf("blocks_count is %d \n",p_block->s_blocks_count);//分区总块数
printf("first_data_block is %d \n",p_block->s_first_data_block);//第一个数据块号
printf("blocks_per_group is %d \n",p_block->s_blocks_per_group);//每个块组的块数
printf("total group is %d \n",(p_block->s_blocks_count-p_block->s_first_data_block-1)/p_block->s_blocks_per_group+1);//这个分区的块组数
//每个块可以存放的索引节点数
unsigned long inode_per_block=(1<<(p_block->s_log_block_size+10))/128;
printf("inode_per_block is %d \n",inode_per_block);
//索引节点表占用空间的计算
printf("inode_bit_blocks is %d \n",p_block->s_inodes_per_group/inode_per_block);
printf("volume name is %s \n",p_block->s_volume_name);//卷标名
printf("last mounted directory is %s \n",p_block->s_last_mounted);
char info1[2048];
fseek(fp,4096,0);
fread(info1,2048,1,fp);
int group_count;
for(group_count=0;group_count<37;group_count++)
{
p_dec=info1+group_count*32;
//块描述结构的内容分解
printf("bg_block_bitmap is %d \n",p_dec->bg_block_bitmap);//节点总数
printf("bg_inode_bitmap is %d \n",p_dec->bg_inode_bitmap);
printf("bg_inode_table is %d \n",p_dec->bg_inode_table);
printf("bg_free_blocks_count is %d \n",p_dec->bg_free_blocks_count);
printf("bg_free_inodes_count is %d \n",p_dec->bg_free_inodes_count);
printf("group_count=%d \n",group_count);
} |
|