Page 1 of 1

Find all stage2 clusters

Posted: Tue Feb 01, 2011 6:41 pm
by afdgdhfrtewdszs
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.

Re: Find all stage2 clusters

Posted: Tue Feb 01, 2011 10:17 pm
by Hoozim
It is fragmented. That is the point of the FAT table. To find the fragments.

Re: Find all stage2 clusters

Posted: Wed Feb 02, 2011 11:39 am
by afdgdhfrtewdszs
I know that, what i don't know how to find the next cluster without checking the entry.

Re: Find all stage2 clusters

Posted: Wed Feb 02, 2011 6:41 pm
by Andyhhp
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