Page 1 of 1

Ext2 root node's data

Posted: Sun Mar 03, 2013 9:48 am
by nickie
Hello ppl,
I had a break from os dev(or I shoud call it bootloader dev :P) since I couldn't implement my bootloader last time.
Now I'm here and I've got a linux distro. I'm amazed how easer and faster is to get things done here. (Bye virtualbox, hello qemu and free mount)
Ok back to the business.
Now I achived it(after 3 days of non stop debugging lol... I need a break), however I can't understand something.
http://wiki.osdev.org/Ext2#Directory_Entry
Currently my algorithm iterates and search for a something called "boot.bin". However I can't find out where is the next entry.
I found that if there is nothing in the spot I'm currently reading then I need to add "Entry Size" to my iterator(pointer), however if it is a real file(like boot.bin) then I need to add 8 + name len. Is there another way to find how much I need to add?
Currently I've got something like that:

Load the directory entries block into memory at address 0x07C0:1200
Set iterator i to 0x1200
repeat:
call Compare ; address 'boot.bin', size 8 <-> address i+8, size BYTE[i+6]
cmp ax, 01h ; I use ax as a flag , 01h means that strigns are equal
je done
i += WORD[i+4] ; I can't understand what shoud I do in this step. It seems to work in some cases only.
jmp repeat
done:
;load the node data and jump over it

So how much shoud I jump on the step? And if there are different cases, then how shoud I find out what to do?
Thank you.

Re: Ext2 root node's data

Posted: Sun Mar 03, 2013 10:20 am
by jnc100
You always skip on by the 16 bit value located 4 bytes from the beginning of the current entry. Don't use the name length to determine how much to skip. Note that the last entry in the block will have an entry size that fills the entire block, therefore you keep reading until you've reached the end of the block (in your case loop while i < (1200 + block_size)). Then if there are more blocks which make up the directory you have to load up the next block and parse it etc.

If that doesn't work there's probably an error elsewhere in your code. Either single step through with a debugger seeing what the value of 'i' and '[i + 4]' is at each iteration or load up an image of the filesystem in a hex editor and work through your algorithm with a piece of paper.

Regards,
John.

Re: Ext2 root node's data

Posted: Sun Mar 03, 2013 11:18 am
by nickie
I was just analyzing what is happening in this reply when it hit me in the head. LOL
I got it what is happening. I shoud jump by entry size. The last entry size is that large because it need to fill the entire block after it.
Sometimes it help only when you just try to explain to someone the situation.. Thank you John.