FAT12 Structure: Need Help With Strings

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
tagar
Posts: 4
Joined: Fri Nov 07, 2014 11:31 pm

FAT12 Structure: Need Help With Strings

Post by tagar »

Hi everyone! I'm trying to make a FAT12 bootloader. It will be loaded in the first 512 bytes sector on media, so i want it to load a file from disk.

I need a help with this code. Strings. I saw many examples of fat12 bootloaders.
Why strings in this code were padded with spaces? :?:

Code: Select all

   
        BS_OEMName      db      'KOLIBRI '      ; db 8
        BPB_BytsPerSec  dw      512             ; bytes per sector
        BPB_SecPerClus  db      1               ; sectors per cluster
        BPB_RsvdSecCnt  dw      1               ; number of reserver sectors
        BPB_NumFATs     db      2               ; count of FAT data structures
        BPB_RootEntCnt  dw      224             ; count of 32-byte dir. entries (224*32 = 14 sectors)
        BPB_TotSec16    dw      2880            ; count of sectors on the volume (2880 for 1.44 mbytes disk)
        BPB_Media       db      0f0h            ; f0 - used for removable media
        BPB_FATSz16     dw      9               ; count of sectors by one copy of FAT
        BPB_SecPerTrk   dw      18              ; sectors per track
        BPB_NumHeads    dw      2               ; number of heads
        BPB_HiddSec     dd      0               ; count of hidden sectors
        BPB_TotSec32    dd      0               ; count of sectors on the volume (if > 65535)
        BS_DrvNum       db      0               ; int 13h drive number
        BS_Reserved     db      0               ; reserved
        BS_BootSig      db      29h             ; Extended boot signature
        BS_VolID        dd      0               ; Volume serial number
        BS_VolLab       db      'KOLIBRI    '   ; Volume label (db 11)
        BS_FilSysType   db      'FAT12   '      ; file system type (db 8)
In my code i just made this:
Now strings looks like this, so, is this correct?

Code: Select all

BS_OEMName						db 13, 10, 'PROTOVISION$'

BPB_BytesPerSector				dw 512
BPB_SectorsPerCluster			db 1
BPB_ReservedSectors				dw 1

BPB_DataStructures				db 2
BPB_RootEntries					dw 224
BPB_TotalSectors16				dw 2880

BPB_MediaType					db 0f0h
BPB_SectorsPerDataStructure		dw 9
BPB_SectorsPerTrack				dw 18

BPB_Heads						dw 2
BPB_HiddenSectors				dd 0
BPB_TotalSectors32				dd 0

BS_DriveNumber					db 0
BS_Reserved						db 0
BS_BootSignature				db 29h

BS_VolumeID						dd 0
BS_VolumeLabel					db 13, 10, 'PROTOVISION$'
BS_FileSystemType				db 13, 10, 'FAT12$' 
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: FAT12 Structure: Need Help With Strings

Post by b.zaar »

You might want to read up about the BPB structure on a FAT formatted disk.
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
tagar
Posts: 4
Joined: Fri Nov 07, 2014 11:31 pm

Re: FAT12 Structure: Need Help With Strings

Post by tagar »

No, i need to know, why all strings is padded by spaces.

I want to just make it null-terminated.
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: FAT12 Structure: Need Help With Strings

Post by b.zaar »

Space padding is just the way it works, the official format doesn't require space padding but I'm pretty sure your oem string is too long.

There was something about older DOS versions only recognizing certain oem strings and these all used spaces.
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: FAT12 Structure: Need Help With Strings

Post by iansjack »

The string elements of the structure are of fixed length. For example, if OEMname was only 2 characters how would the driver know where to find BytesPerSec? It would have to do a lot of calculations to locate each entry in the structure; having them at fixed positions is far simpler. Conventionally you pad unused characters in the string with space characters.

It would have been possible to design FAT to use zero-terminated strings, but that would have made life more complicated for the driver. If you really want to use zero-terminated strings I guess you could, but you'll have work out the location of every element in the structure when you want to access them. And remember to convert the strings from/to the fixed-length form when you access them on the disk.
tagar
Posts: 4
Joined: Fri Nov 07, 2014 11:31 pm

Re: FAT12 Structure: Need Help With Strings

Post by tagar »

If my OEMName string be longer than 8 bytes, will be it readed by Fat12 Driver?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: FAT12 Structure: Need Help With Strings

Post by Brendan »

Hi,
tagar wrote:If my OEMName string be longer than 8 bytes, will be it readed by Fat12 Driver?
If you try to put more than 8 characters into a fixed size field that's only capable of storing 8 characters; then you'll screw up the offsets of everything else in BPB.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: FAT12 Structure: Need Help With Strings

Post by Gigasoft »

If my OEMName string be longer than 8 bytes, will be it readed by Fat12 Driver?
Willfully ignoring the replies given is not going to change the answer.

With a string of the wrong length, every field that comes after it is displaced and your structure is no longer a valid BPB, and will not be recognized by any existing operating system.
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: FAT12 Structure: Need Help With Strings

Post by iansjack »

tagar wrote:If my OEMName string be longer than 8 bytes, will be it readed by Fat12 Driver?
Let's save everyone a lot of time. Just try it and see what happens.
tagar
Posts: 4
Joined: Fri Nov 07, 2014 11:31 pm

Re: FAT12 Structure: Need Help With Strings

Post by tagar »

Okay, i read FATGEN. OEMName must be 8 characters long, FileSystemType - 8, VolumeLabel - 11.

Thank you!
Post Reply