getting 2nd cluster No.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

getting 2nd cluster No.

Post by ggodw000 »

Jump starting my os design project this week after long pause. Took me a whole day to re-familiarize.
Looks like I need to take the mini-fat32 driver more seriously and need to come up with several api-s.

I am almost certain on this: to read the next (2nd cluster No.) after obtaining first one from boot sector of volume, you basically offset into by 1st cluster No and read the 4 bytes for fat32 right?

here is the pseudo plan for load file from fat32 volume:
function load_file (in cluster_no_1st, in memDest)
----currCluster = cluster_no_1st
----start loop
--------read cluster currCluster into memDest
--------memDest+=ClusterSize
--------find next cluster No. (get it from fat32 table) - offset into curCluster in FAT and read the 4 bytes, that is your next cluster) -> nextCluster
--------currCluster = nextCluster
--------terminate and exit loop if currCluster is empty, bad or EOF.
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: getting 2nd cluster No.

Post by BrightLight »

It looks correct. What exactly is your question?
You know your OS is advanced when you stop using the Intel programming guide as a reference.
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: getting 2nd cluster No.

Post by ggodw000 »

i was not sure my assumption was right regarding how to read second cluster and so on.
I had to boot to efi shell and dblk to search through a bunch of blocks and deciphering those hex-s to verify my assumption was right.
it was grueling task.
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
User avatar
zaval
Member
Member
Posts: 659
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: getting 2nd cluster No.

Post by zaval »

FAT documentation. it exists, it is small and it's a very easy reading. try it.)
PS.
after obtaining first one from boot sector of volume,
You take 1st cluster number of an entity from DIR_FstClusLO and DIR_FstClusHI fields of a directory entry. The only 1st cluster number in the BPB is the root dir's 1st cluster, on FAT32. And on FAT32, significant bytes are 28 not 32.
Looks like I need to take the mini-fat32 driver more seriously
yup, you do. :)
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: getting 2nd cluster No.

Post by ggodw000 »

is it good approach to load all of FAT to memory? I initially thinking to load just 1 sector worth of FAT (128 entries) into memory at a time but it has too much complicacy:
if FAT pointer falls outside the current sectors and have to do a mathematical calculation to get which sector to load etc.,
Instead I just declared 64KB area for entire FAT assuming this is the limit (current size I see is much less than that).
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: getting 2nd cluster No.

Post by ggodw000 »

zaval wrote:FAT documentation. it exists, it is small and it's a very easy reading. try it.)
PS.
after obtaining first one from boot sector of volume,
You take 1st cluster number of an entity from DIR_FstClusLO and DIR_FstClusHI fields of a directory entry. The only 1st cluster number in the BPB is the root dir's 1st cluster, on FAT32. And on FAT32, significant bytes are 28 not 32.
Looks like I need to take the mini-fat32 driver more seriously
yup, you do. :)
Yes i got it from directory entry. Initially (or probably just set it as permanent limitation), I am going to design such that only can work with directory entries in the root folder, but even though it was quite a bit, reading all these BPB-s and root dir entries and having to shuffle those numbers between CPU registers! I decided to use memory variables freely otherwise it is just too much!
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
User avatar
jojo
Member
Member
Posts: 138
Joined: Mon Apr 18, 2016 9:50 am
Libera.chat IRC: jojo
Location: New York New York

Re: getting 2nd cluster No.

Post by jojo »

I decided to use memory variables
I mean... that's kind of the point of memory.
Post Reply