Page 1 of 1
ext2 read Block Group Descriptor
Posted: Wed Oct 01, 2014 8:22 am
by onlshk
Hello,
i have a disk which created with:
Code: Select all
dd if=/dev/zero of=zerOS.img bs=1048576 count=10
(echo "n"; echo "p"; echo ""; echo ""; echo ""; echo "w") | sudo fdisk -u -C10 -S63 -H16 zerOS.img
sudo rm -rf /mnt
sudo mkdir -p /mnt/fcd
sudo losetup /dev/loop0 zerOS.img
sudo mke2fs -b1024 /dev/loop0
sudo mount -t ext2 /dev/loop0 /mnt/fcd
sudo dd if=loader.bin of=zerOS.img count=1 conv=notrunc
sudo dd if=stage1.bin of=zerOS.img count=1 conv=notrunc seek=1
sudo cp kernel.bin /mnt/fcd
sleep 0.1
sudo umount /mnt/fcd
sudo losetup -d /dev/loop0
I copied bootloader and kernel.bin there. Now i want to load kernel.bin. But before i must to find it's inode. First of all i need to load 2 inode for root directory. Trying to load block group descriptor from block group descriptor table, it is: 2 sectors (al), 0 cylinder (ch), 5 sector (cl), 0 head (dh) and buffer bx. After i read it, i get 'Number of directories in group' from this descriptor with
, but everytime i'm getting 2 in ax, event i put 5 files/dirs there.
And i can't undersratnd, why it everytime shows 2. or i built image in wrong way or i'm reading it wrong way.
Re: ext2 read Block Group Descriptor
Posted: Wed Oct 01, 2014 8:49 am
by Combuster
Code: Select all
# create partition table with one partition
(echo "n"; echo "p"; echo ""; echo ""; echo ""; echo "w") | sudo fdisk -u -C10 -S63 -H16 zerOS.img
# use entire disk
sudo losetup /dev/loop0 zerOS.img
# destroy the partition table and use the entire disk as ext2
sudo mke2fs -b1024 /dev/loop0
# ...
# profit
Re: ext2 read Block Group Descriptor
Posted: Wed Oct 01, 2014 11:34 am
by onlshk
Combuster wrote:Code: Select all
# create partition table with one partition
(echo "n"; echo "p"; echo ""; echo ""; echo ""; echo "w") | sudo fdisk -u -C10 -S63 -H16 zerOS.img
# use entire disk
sudo losetup /dev/loop0 zerOS.img
# destroy the partition table and use the entire disk as ext2
sudo mke2fs -b1024 /dev/loop0
# ...
# profit
hmm... So how can i make this in right way?
Re: ext2 read Block Group Descriptor
Posted: Wed Oct 01, 2014 11:50 am
by jnc100
In addition to what Combuster posted above, you can quite easily tell whether its a problem with creating the image or reading the image in your OS by examining the image file with a hex editor and seeing if what you expect to be in a certain place is actually there.
Furthermore, I'd recommend against having your ext2 driver work with CHS addressing - have it use LBA instead and then either use the extended read BIOS functions or convert to CHS somewhere in your block layer.
Regards,
John.
Re: ext2 read Block Group Descriptor
Posted: Thu Oct 02, 2014 7:55 am
by onlshk
# create partition table with one partition
(echo "n"; echo "p"; echo ""; echo ""; echo ""; echo "w") | sudo fdisk -u -C10 -S63 -H16 zerOS.img
Am i right that this partition will start from 2048?
I created partition and write bootloader to disk with:
Code: Select all
dd if=/dev/zero of=zerOS.img bs=1048576 count=10
sudo losetup /dev/loop0 zerOS.img
(echo "n"; echo "p"; echo ""; echo ""; echo ""; echo "w") | sudo fdisk -u -C10 -S63 -H16 zerOS.img
sudo fdisk -u -C10 -S63 -H16 zerOS.img
# write bootloader
sudo dd if=loader.bin of=zerOS.img count=1 bs=512 conv=notrunc
sudo dd if=stage1.bin of=zerOS.img count=1 bs=512 conv=notrunc seek=1
sudo losetup -d /dev/loop0
Now i set up another loop device and mounted ext2 with offset:
Code: Select all
sudo losetup -o 1048576 /dev/loop1 zerOS.img
# 1024 block size
sudo mke2fs -b1024 /dev/loop1
sudo mount -t ext2 /dev/loop1 /mnt/fcd
# copy kernel
sudo cp kernel.bin /mnt/fcd
sudo umount /mnt/fcd
sudo losetup -d /dev/loop1
Now bootloader works, but now i can't read superblock. What's wrong here?
Re: ext2 read Block Group Descriptor
Posted: Thu Oct 02, 2014 9:17 am
by Combuster
Which superblocks were you unable to find? The Ext2 one or the partition table one?
I also wouldn't normally trust a power of two in partition table offsets.
Re: ext2 read Block Group Descriptor
Posted: Thu Oct 02, 2014 11:23 am
by onlshk
previously i read superblock at sector 3 with:
Code: Select all
mov ah, 0x02
mov al, 1
mov cx, 0x0003
xor dh, dh
mov bx, buffer
int 0x13
Now i can't understand where to read it.