konniskatt wrote:
Well, my real question is, how I can read/write FAT16 hard drives, get metadata (ex. last time modified, etc)
I already read the OSDev wiki, which gives to you a good introduction, but not how implement it, and well, I have no idea how to do what I want
First, you need to read data from the disk. This means reading sectors into memory. Second, depending what sector you've just read, interpret it accoringly. With FAT you'll have the following structures:
1. BPB (describes the whole file system, like cluster size, root directory position etc. This is always in the first sector of the volume)
2. directory entries (filenames and starting clusters, this stores the metadata you asked for)
3. FAT table (data is stored in a linked list, but the "next" pointers are gathered together, that's what this table is about)
Quote:
(I can't find it in internet).
There are plenty of examples. Try the keywords "fat16 boot sector asm" in google.
For example here's alexfru's FAT16 reader in assembly:
https://github.com/alexfru/BootProg/blob/master/boot16.asmIf you prefer C, here's my example code, which can read FAT16/FAT32. It was written for RPi3, but the code is architecture independent, just replace "sd_readblock()" with the aforementioned INT13H call:
https://github.com/bztsrc/raspi3-tutorial/blob/master/0D_readfile/fat.cWriting a file on a FAT file system is very similar, but you'll need a "find_free_cluster()" function, which is searching the FAT looking for a free entry. Then:
1. find a free cluster, that would be the "starting cluster"
2. write data to disk with INT13H at cluster (use sector_per_cluster and other fields in BPB to calculate LBA)
3. if you have no more data to write, go to step 7
4. find a free cluster
5. save that new cluster number into the FAT at position fat[cluster]
6. go to step 2
7. write EOF marker into the FAT at fat[cluster]
8. write directory entry with the file name, file size, "starting cluster" and other info
Cheers,
bzt