where is the root directory?
where is the root directory?
Where is the root directory on FAT12 diskette and how can I read it with int 13h.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:where is the root directory?
it starts after the FAT copies ... so you just have to find out where these one ends (BPB.reserved_sectors + BPB.numfat * BPB.numfatsectors is your logical sector nr that you will have to convert into cylinder - head - sector ).
oh, and just in case, BPB is the parameter block that a good BIOS-aware floppy (and thus a DOS-formatted one too should always have B)
oh, and just in case, BPB is the parameter block that a good BIOS-aware floppy (and thus a DOS-formatted one too should always have B)
Re:where is the root directory?
;************************************************************************
;* Convert the LBA sector address into CHS scheme so int 13h can use it *
;* HPC = Number of heads/cylinder *
;* SPT = sectors/track *
;* Sector = (LBA mod SPT) + 1 *
;* Head = (LBA / SPT) mod HPC *
;* Cylinder = (LBA / SPT) / HPC *
;************************************************************************
XOR DX, DX
DIV WORD [BPB_SecPerTrk]
INC DX
MOV CL, DL
XOR DX, DX
DIV WORD [BPB_NumHeads]
MOV CH, AL
MOV DH, DL
Assumes AX contains the LBA sector you want to convert. Leaves CL=Sector, CH=Cylinder, DH=Head, it's that way to make it easier to use int 13h. Based on someone's recent post you may want to change those XOR DX, DX lines to MOV DX, BYTE 0, but I think it is clearer without mixing 16 and 8bit values.
Curufir
*That's based on someone else's work (I visited many, many sites about fat12, conversion and all things disks, so I can't remember whose the original was), but it is a fairly standard algorithm*
;* Convert the LBA sector address into CHS scheme so int 13h can use it *
;* HPC = Number of heads/cylinder *
;* SPT = sectors/track *
;* Sector = (LBA mod SPT) + 1 *
;* Head = (LBA / SPT) mod HPC *
;* Cylinder = (LBA / SPT) / HPC *
;************************************************************************
XOR DX, DX
DIV WORD [BPB_SecPerTrk]
INC DX
MOV CL, DL
XOR DX, DX
DIV WORD [BPB_NumHeads]
MOV CH, AL
MOV DH, DL
Assumes AX contains the LBA sector you want to convert. Leaves CL=Sector, CH=Cylinder, DH=Head, it's that way to make it easier to use int 13h. Based on someone's recent post you may want to change those XOR DX, DX lines to MOV DX, BYTE 0, but I think it is clearer without mixing 16 and 8bit values.
Curufir
*That's based on someone else's work (I visited many, many sites about fat12, conversion and all things disks, so I can't remember whose the original was), but it is a fairly standard algorithm*
Re:where is the root directory?
it starts after the FAT copies ... so you just have to find out where these one ends (BPB.reserved_sectors + BPB.numfat * BPB.numfatsectors is your logical sector nr that you will have to convert into cylinder - head - sector ).
I use standard FAT 12 Boot loader
OEM_ID db "CHAOS-OS"
BytesPerSector dw 0x0200
SectorsPerCluster db 0x01
ReservedSectors dw 0x0001
TotalFATs db 0x02
MaxRootEntries dw 0x00E0
TotalSectorsSmall dw 0x0B40
MediaDescriptor db 0xF0
SectorsPerFAT dw 0x0009
SectorsPerTrack dw 0x0012
NumHeads dw 0x0002
HiddenSectors dd 0x00000000
TotalSectorsLarge dd 0x00000000
DriveNumber db 0x00
Flags db 0x00
Signature db 0x29
VolumeID dd 0xFFFFFFFF
VolumeLabel db "CHAOS BOOT"
SystemID db "FAT12 "
in this code where is the numfatsectors, numfat, reserved_sectors
I use standard FAT 12 Boot loader
OEM_ID db "CHAOS-OS"
BytesPerSector dw 0x0200
SectorsPerCluster db 0x01
ReservedSectors dw 0x0001
TotalFATs db 0x02
MaxRootEntries dw 0x00E0
TotalSectorsSmall dw 0x0B40
MediaDescriptor db 0xF0
SectorsPerFAT dw 0x0009
SectorsPerTrack dw 0x0012
NumHeads dw 0x0002
HiddenSectors dd 0x00000000
TotalSectorsLarge dd 0x00000000
DriveNumber db 0x00
Flags db 0x00
Signature db 0x29
VolumeID dd 0xFFFFFFFF
VolumeLabel db "CHAOS BOOT"
SystemID db "FAT12 "
in this code where is the numfatsectors, numfat, reserved_sectors
Re:where is the root directory?
Not too keen to engage brain today huh ;Dfcatak wrote: it starts after the FAT copies ... so you just have to find out where these one ends (BPB.reserved_sectors + BPB.numfat * BPB.numfatsectors is your logical sector nr that you will have to convert into cylinder - head - sector ).
I use standard FAT 12 Boot loader
OEM_ID db "CHAOS-OS"
BytesPerSector dw 0x0200
SectorsPerCluster db 0x01
ReservedSectors dw 0x0001
TotalFATs db 0x02
MaxRootEntries dw 0x00E0
TotalSectorsSmall dw 0x0B40
MediaDescriptor db 0xF0
SectorsPerFAT dw 0x0009
SectorsPerTrack dw 0x0012
NumHeads dw 0x0002
HiddenSectors dd 0x00000000
TotalSectorsLarge dd 0x00000000
DriveNumber db 0x00
Flags db 0x00
Signature db 0x29
VolumeID dd 0xFFFFFFFF
VolumeLabel db "CHAOS BOOT"
SystemID db "FAT12 "
in this code where is the numfatsectors, numfat, reserved_sectors
numfatsectors=SectorsPerFat
numfat=TotalFats
reserved_sectors=(*drumroll*)ReservedSectors.
Seeing as you have 2 Fats on a fat12 disk (TotalFats), and they are consecutive on the disk, the data section of the disk (Ie the start of the root directory) begins at:
reserved_sectors + numfat*numfatsectors (In your notation)
In real terms for fat12 this is:
1 + 2*9=19 sectors into the disk.
Curufir
*It really would be easier if everyone stuck to the MS names for the BPB*