flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Understanding FAT16 Sub-Directories. (This is BS btw) |
Author |
|
sid123 07 Mar 2014, 15:46
Hi,
After implementing a simple FAT16 Read FS driver (which only supports the root directory) I've planned to extend it further . Well, the next is possibly implementing directories. From what the FAT Documentation says: sid123 randomly understanding FAT Doc wrote:
I understand till here. But there are 2 main doubts I have: 1. Is the cluster the LBA address of that entry? For example a root directory's LBA address is calculated by BytesPerSector * SectorsPerFAT * Number of FATs + BytesPerSector * NumberofReserved Sectors, I use this address while browsing the root directory. However, does the cluster point to the LBA address of that sub-directory? Or do I need to calculate something more? If so, what is it? Also, I've seen that a Cluster is (in FAT16) is a WORD but a LBA address is a DWORD, how's it possible? In simple words can I use the cluster as an LBA address of the sub-directory, like I use it with the root directory? 2. How do I find the address of the Parent Directory, some sources say that the '..' points to a parent directory? What do they mean by that? I've seen some copyright and legal issues with LFN, what's it btw? EDIT: Got the second point, the '..' is a name given to a entry in a sub directory whose cluster points to the cluster of the parent directory Thanks, -sid123 _________________ "Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X XD |
|||
07 Mar 2014, 15:46 |
|
sid123 08 Mar 2014, 01:18
Okay, wrote some code btw
Code: ;; Change to a Directory. ;; IN : ESI - Name of Directory ;; OUT: CF on Ok, or current_directory.offset set to the new ;; directory chdir: pushad clc mov eax, esi ;; Convert it to FAT16 Directory filename call dir_convert mov esi, eax xor eax, eax ;; Query for existence of directory ;; and it's starting cluster call entry_exists ;; Good it exists jc .ok ;; Maybe not, clear carry and bailout clc popad ret .ok: ;; AX contains starting cluster, now we need to calculate ;; the first sector of the cluster ;; Subtract 2 from ;; ax sub ax, 2 ;; Save ECX push ecx xor ecx, ecx mov cl, byte [BPB.fat_16_sectors_per_cluster] ;; EAX now holds starting sector of cluster imul cx ;; Add Data Start region to the ;; Formula: ;; DataRegion + ((N - 2) * SectorsPerCluster) add eax, [BPB.data_start] ;; Cool now, EAX contains the starting sector ;; of the sub-directory ;; Update Values. mov dword [current_directory.offset], eax ;; Reload ECX pop ecx ;; Reload All registers popad ;; Set Carry Sucessful stc ;; Return ret Is it correct? It's supposed to find a root directory, get it's cluster, and then compute the 1st sector of the sub-directory's cluster. _________________ "Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X XD |
|||
08 Mar 2014, 01:18 |
|
sid123 08 Mar 2014, 03:01
WORKS WORKS WORKS!
I solved my problem myself. So just to tell more OSDevers about directories here you go: 1. In you file_exists/load_file/write_file NEVER use the root directory offset, IMO on HDD Initialization calculate the root directory offset and store it in a global variable. 2. Next create a DWORD called current_directory.offset (Choose your own name), and on HDD Initialization set this to the root directory offset. THIS is the variable you will use in your FAT Functions. 3. Make sure you have an entry_exists function (Not tough to implement. And it should return the cluster in AX, Hint: In a FAT Root Directory entry, the 15th byte points to the start of the cluster) 4. Use the above function to compute the offset of the sub directory and set the current directory offset respectively. 5. Done. My goals for 0.1 are almost over. I will be pushing it on github soon. These were the goals: 1. Simple PS/2 Keyboard Driver - Done 2. A simple shell - Done 3. FAT16 Read FS + Directory Support. Done 4. Homemade C Library - scanf remaining rest all printf, strlen, malloc etc. are implemented. 5. Simple API for apps - Done (chdir, file_load, file_query, printc, prints, pci read, pci write etc.) Well my goal for 0.2 is basically a FASM port. The only functions missing are: file_write file_create lseek - No idea why fasm needs it. Btw does fasm need malloc when running under ring 0, my apps run under ring 0 there is no need for memory allocation, fasm can use as much memory as it wants. |
|||
08 Mar 2014, 03:01 |
|
DOS386 08 Mar 2014, 08:05
> lseek - No idea why fasm needs it.
RTFS. Maybe GetFileSizeEx would be sufficient (you have to know the file size BEFORE you load it). > I've seen some copyright and legal issues with LFN, what's it btw? YES ... the NTLFN "technology" is most likely patented. > should return the cluster in AX Good ... you'll need EAX or DX:AX for FAT28 and RAX for some other filesystems |
|||
08 Mar 2014, 08:05 |
|
Dex4u 28 Apr 2014, 16:44
Hi sorry about the delay, been away.
Here's is the fat16 driver code, to DexOS.
|
|||||||||||
28 Apr 2014, 16:44 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.