Find all stage2 clusters

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
afdgdhfrtewdszs
Posts:18
Joined:Tue Feb 01, 2011 6:25 pm
Find all stage2 clusters

Post by afdgdhfrtewdszs » Tue Feb 01, 2011 6:41 pm

In tutorial 6 i can't understand the piece of code where we load file stage2 into memory.First of all how do we check if the next cluster to read is contiguous to the current one? In other words how do we know that the next contiguous cluster is the one we want to read and load?


code:
mov WORD [cluster], dx ; store new cluster
cmp dx, 0x0FF0 ; test for end of file
jb LOAD_IMAGE ; we are not done yet--go to next cluster

We just check for end-of-file, not where the next cluster to read is.
I don't understand this because i think that a file located at FAT is not at contiguous clusters but is fragmented.

Thanks in advance.

Hoozim
Posts:34
Joined:Sun Nov 21, 2010 6:40 pm

Re: Find all stage2 clusters

Post by Hoozim » Tue Feb 01, 2011 10:17 pm

It is fragmented. That is the point of the FAT table. To find the fragments.

afdgdhfrtewdszs
Posts:18
Joined:Tue Feb 01, 2011 6:25 pm

Re: Find all stage2 clusters

Post by afdgdhfrtewdszs » Wed Feb 02, 2011 11:39 am

I know that, what i don't know how to find the next cluster without checking the entry.

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: Find all stage2 clusters

Post by Andyhhp » Wed Feb 02, 2011 6:41 pm

The FAT is a table pointing to the next cluster.

An overview is like this:

Read the root directory, find a file which has a pointer to the first cluster.
Load the referenced cluster
Look up the entry for that cluster in the FAT.
This is either EOF or the next cluster in the file.
Loop until EOF

The thing to note is that the 1st entry in the FAT is the next cluster for whichever file contains the 1st cluster.

~Andrew
Image

Post Reply