Ext2 implementation problem [SOLVED]
Posted: Wed Jul 01, 2009 5:07 am
Hello,
I am currently trying to implement ext2 in my OS. I made an image of an ext2 hdd and made up some directories and put random files in them. Now, before I put bad code in my kernel, I made a small program that is supposed to run through the whole filesystem, to fully understand the filesystem.
But I have a problem : here is my filesystem
/dir1/
/dir1/file1
/dir1/file2
/dir1/sub1/
/dir1/sub1/file1
/dir2/.hidden_file
/dir2/symlink1
Now I run my test program on that image, and here is my output:
1264 inodes per block
Listing /
-> . : name_len = 1, type = 2, inode = 2, next = 12
-> .. : name_len = 2, type = 2, inode = 2, next = 32
-> dir1 : name_len = 4, type = 2, inode = 1265, next = 12
-------> . : name_len = 1, type = 2, inode = 1265, next = 12
-------> .. : name_len = 2, type = 2, inode = 2, next = 12
-------> file1 : name_len = 5, type = 1, inode = 1268, rec_len = 13
-------> file2 : name_len = 5, type = 1, inode = 1269, rec_len = 13
-------> sub : name_len = 3, type = 2, inode = 12, next = 952
-> dir2 : name_len = 4, type = 2, inode = 1266, next = 968
As you can see, the superblock tells me that there are 1264 inodes per group. But when I read the inode of dir1/, I see inode 1265. I thought that it might mean that the content of dir1 has been put in the second block group. So I made some division/modulo, and succeeded in reading the content of dir1/, its inode being indeed the 1st of the second group. But now I can't see why dir2/ is not shown, even if I read the group2 / inode 2 (which is actually group[1], inode[1] of course).
It seems I have the same problem for reading dir1/sub/, located at inode 12... But is it inode 12 of the 1st group ? Or the 2nd one ? If it is the 12th of the second one, does it mean that directories can contain inodes pointers that point to an other group's inodes, but only if this group is after the current one ? This seems quite strange to me, isn't it ? In other words, How is this cross-group reference thing working ?
Thanks for any help,
Lionel
Edit: made the hierarchy clearer
Edit2 : Fixed, thanks a lot James.
I am currently trying to implement ext2 in my OS. I made an image of an ext2 hdd and made up some directories and put random files in them. Now, before I put bad code in my kernel, I made a small program that is supposed to run through the whole filesystem, to fully understand the filesystem.
But I have a problem : here is my filesystem
/dir1/
/dir1/file1
/dir1/file2
/dir1/sub1/
/dir1/sub1/file1
/dir2/.hidden_file
/dir2/symlink1
Now I run my test program on that image, and here is my output:
1264 inodes per block
Listing /
-> . : name_len = 1, type = 2, inode = 2, next = 12
-> .. : name_len = 2, type = 2, inode = 2, next = 32
-> dir1 : name_len = 4, type = 2, inode = 1265, next = 12
-------> . : name_len = 1, type = 2, inode = 1265, next = 12
-------> .. : name_len = 2, type = 2, inode = 2, next = 12
-------> file1 : name_len = 5, type = 1, inode = 1268, rec_len = 13
-------> file2 : name_len = 5, type = 1, inode = 1269, rec_len = 13
-------> sub : name_len = 3, type = 2, inode = 12, next = 952
-> dir2 : name_len = 4, type = 2, inode = 1266, next = 968
As you can see, the superblock tells me that there are 1264 inodes per group. But when I read the inode of dir1/, I see inode 1265. I thought that it might mean that the content of dir1 has been put in the second block group. So I made some division/modulo, and succeeded in reading the content of dir1/, its inode being indeed the 1st of the second group. But now I can't see why dir2/ is not shown, even if I read the group2 / inode 2 (which is actually group[1], inode[1] of course).
It seems I have the same problem for reading dir1/sub/, located at inode 12... But is it inode 12 of the 1st group ? Or the 2nd one ? If it is the 12th of the second one, does it mean that directories can contain inodes pointers that point to an other group's inodes, but only if this group is after the current one ? This seems quite strange to me, isn't it ? In other words, How is this cross-group reference thing working ?
Thanks for any help,
Lionel
Edit: made the hierarchy clearer
Edit2 : Fixed, thanks a lot James.