Simple FAT12 Problem

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
Mr. L

Simple FAT12 Problem

Post by Mr. L »

Hi,
I need to know where the BIOS Parameter Block is on a floppy.
I've added a BPB to the bootsector before the boot-code, like this:

Code: Select all

[bits 16]
[org 0x7c00]

jmp main

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;   B I O S   P A R A M E T E R   B L O C K
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

   OEM_ID            db    "12345678"      ; The OEM ID (Who formatted the disk?)
   BytesPerSector      dw    0x0200         ; 512 bytes per sectors
   SectorsPerCluster   db    0x01         ; 1 sector per cluster
   ReservedSectors      dw    0x0001         ; 1 reserved sector (boot sector)   
   TotalFATs         db    0x02         ; 2 copies of the FAT
   MaxRootEntries      dw    0x00E0         ; Up to 224 entries in the root dir
   TotalSectorsSmall   dw    0x0B40         ; 18 * 80 * 2 = 2880 sectors
   MediaDescriptor      db    0xF0         ; 0xF0 = 3.5", 2-sided, 18-sectors per track
   SectorsPerFAT      dw    0x0009         ; 9 sectors per FAT
   SectorsPerTrack      dw    0x0012         ; 18 sectors per track
   NumHeads         dw    0x0002         ; 2 heads (disk sides)
   HiddenSectors      dd    0x00000000      ; No hidden sectors
   TotalSectorsLarge   dd    0x00000000      ; Sectors fit in TotalSectorsSmall so this is 0
   DriveNumber         db    0x00         ; The drive number is saved here.
   Flags            db    0x00         ; Flags
   Signature         db    0x29         ; Signature of 0x29
   VolumeID         dd    0xDEAD0539      ; Random volume ID
   VolumeLabel         db    "BOOT DISK  "   ; The volume label
   SystemID         db    "FAT12   "      ; The file system ID (FAT12)



main:
   ; Disable interrupts
   cli

   ; Set up segment registers
   xor ax, ax
   mov ds, ax
   mov es, ax
   mov fs, ax
   mov gs, ax
   
   ; Set up stack   
   mov ss, ax
   mov sp, 0xFFFF

   ; Enable interrupts
   sti
   


times 510-($-$$) db 0
dw 0xAA55
I then use partcopy to copy it to the first sector (boot sector).
The BPB in the code shows that the volume label is "BOOT DISK", but when I go to explorer (Windows ME) is shows no volume label >:(
I've also tried formating the a floopy in Win ME and placing my code (with BPB) in the floppy. Then I go to a Hex editor and find that the BPB in my code is at 0x0000 and the BPB that Win ME on the floppy is at 0x2600 ???

Can someone pls tell me how to format a floppy with FAT12 in Windows ME or what format Win ME uses when it formats a floppy (because all it says is "FAT").
I also need to know how to access the BPB.

Thanks in advance.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Simple FAT12 Problem

Post by Candy »

If it does recognise it but without volume label, you've succeeded.

WinME etc. can use a volume label "file" that's just a normal file, but which can have a long file name. Try that.
IRBMe

Re:Simple FAT12 Problem

Post by IRBMe »

Indeed. There is usually a special directory entry in the root directory (near the beginning usually, so that DOS can read it) for the volume label. You can find it by examining the attributes of the directory entries in the root directory. If a directory contains the volume label, then the "v" attribute will be set.

Code: Select all

Attribute byte:

Bits      7 - 6 5 4 3 2 1 0
Meaning  Unused A D V S H R
IRBMe

Re:Simple FAT12 Problem

Post by IRBMe »

Ah! I wondered why that code of yours looks famiilar. Looks like It's from my boot loader. hehe.
smiddy

Re:Simple FAT12 Problem

Post by smiddy »

The only thing I see possibly wrong is that SystemID is only 7 bytes long. Since it is only 7 bytes long whenever the OS goes to look at the the File System Type it sees "FAT12 " + 0xFA at the end, which isn't FAT12 alone.

Here I've edited so you can cut and paste it:

Code: Select all

[bits 16]
[org 0x7c00]

jmp main

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;   B I O S  P A R A M E T E R  B L O C K
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

   OEM_ID               db    "12345678"        ; The OEM ID (Who formatted the disk?)
   BytesPerSector       dw    0x0200            ; 512 bytes per sectors
   SectorsPerCluster    db    0x01              ; 1 sector per cluster
   ReservedSectors      dw    0x0001            ; 1 reserved sector (boot sector)   
   TotalFATs            db    0x02              ; 2 copies of the FAT
   MaxRootEntries       dw    0x00E0            ; Up to 224 entries in the root dir
   TotalSectorsSmall    dw    0x0B40            ; 18 * 80 * 2 = 2880 sectors
   MediaDescriptor      db    0xF0              ; 0xF0 = 3.5", 2-sided, 18-sectors per track
   SectorsPerFAT        dw    0x0009            ; 9 sectors per FAT
   SectorsPerTrack      dw    0x0012            ; 18 sectors per track
   NumHeads             dw    0x0002            ; 2 heads (disk sides)
   HiddenSectors        dd    0x00000000        ; No hidden sectors
   TotalSectorsLarge    dd    0x00000000        ; Sectors fit in TotalSectorsSmall so this is 0
   DriveNumber          db    0x00              ; The drive number is saved here.
   Flags                db    0x00              ; Flags
   Signature            db    0x29              ; Signature of 0x29
   VolumeID             dd    0xDEAD0539        ; Random volume ID
   VolumeLabel          db    "BOOT DISK  "     ; The volume label
   SystemID             db    "FAT12   "        ; The file system ID (FAT12)



main:
   
   cli              ; Disable interrupts

   xor ax, ax       ; Set up segment registers
   mov ds, ax
   mov es, ax
   mov fs, ax
   mov gs, ax
   
   mov ss, ax       ; Set up stack
   mov sp, 0xFFFF
   
   sti              ; Enable interrupts

times 510-($-$$)        db 0
                        dw 0xAA55
This is what I get with a DIR under Windows XP. This should be the same for Windows ME.

Code: Select all

 Volume in drive A has no label.
 Volume Serial Number is DEAD-0539

 Directory of A:\

File Not Found
I hope that helps you...
Mr. L

Re:Simple FAT12 Problem

Post by Mr. L »

Thanks guys ;D I can't express my gratitude enough. Thank you. All is working :)

However, I have two more realtively silly questions :-[.

How do I find the root directory? Is it in the sector directly after the boot sector?

Since the 16 bit "jmp main" is before the BPB, does the OS skip over the first 16 bits or does the first instruction ("jmp main") cut into the OEM ID parameter?

BTW,
Ah! I wondered why that code of yours looks famiilar. Looks like It's from my boot loader. hehe.
LOL...I learn from the best. excellent tutorial. ;D
Mr. L

Re:Simple FAT12 Problem

Post by Mr. L »

Err...I just realised the simple answers to the questions I asked in my previous post. So, I would like to draw this thread to a close. Thanks to everyone that helped.
Post Reply