Fat12 Disk Image Tool

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
essial
Member
Member
Posts: 26
Joined: Sat Mar 01, 2008 10:23 pm

Fat12 Disk Image Tool

Post by essial »

I don't know if it would help anyone, but I needed to create FAT12 disk images for my OS project, and decided to write a Python3.0 (NOT Python2.6) class that makes this easy. The disk image was tested with MSDOS 6.22 and works correctly.

Here's example code (the code I was using to test the class):

Code: Select all

builder = Fat12Builder("Fat12BootDisk.dsk", "temp/Fat12BootSector.bin")
from fat12builder import *
builder.AddFile("media/README.TXT", 0)
builder.AddFile("media/ED.EXE", 0)
builder.AddFile("media/HELLO.TXT", 0)
builder.AddFile("media/EDIT.COM", 0)
builder.AddFile("media/LICENSE.TXT", 0)
builder.AddFile("media/CHANGES.TXT", 0)
builder.DeleteFile("README.TXT")
builder.DeleteFile("media/EDIT.COM")
builder.AddFile("media/EDIT.COM", 0)
builder.AddFile("media/README.TXT", 0)
builder.CloseDisk()
In the constructor, you can specify the disk image file, and the boot sector binary. The 3-byte JMP code is added automatically, so your boot sector simply needs to ORG at 0x7C3E. The boot sector also doesn't have to be padded out with TIMES, and you don't need to add the boot signature (it does this for you, if you specify the boot binary). If you don't want to inject boot code, just pass "" for the boot sector binary and it will make a non bootable disk.

The ", 0" is for the file attribute, which can be any combination of the following (replace "builder" with your object of course):

Code: Select all

builder.ATTR_READ_ONLY
builder.ATTR_HIDDEN
builder.ATTR_SYSTEM
builder.ATTR_VOLUME_ID
builder.ATTR_ARCHIVE
There are several properties that I default in for my OS that you may want to set yourself as well (again replace "builder" with your own object):

Code: Select all

builder.OEMName          (defaults to "JFOS". Maximum of 8 characters. less chars are padded with spaces, more are truncated)
builder.VolumeID         (any 32-bit number, defaults to 0xB007DA7A)
builder.BootLabel        (defaults to "JFOSBOOTDSK", same rules as OEMName except that this field is 11 characters)
builder.RootEntriesCount (defaults to 224, this field basically determines the maximum number of file entries allowed)
builder.NumberOfFATs     (defaults to 2, this field specifies how many copies of FAT are on the disk. 2 is default because most
                          disks have 2 FATs)
It doesn't support directories or timestamps because I don't see a reason for it to do so as Fat12 disks are generally only for boot loading stuff now (either real floppy or for emulation mode on a CD) and those features only complicates things.

I plan on getting a solid, well commented boot loader and second stage bootloader COM file written soon, which I'll release, along with this utility as a full bootloader example.

Let me know what you guys think!
Attachments
fat12builder.zip
(2.86 KiB) Downloaded 93 times
essial
Member
Member
Posts: 26
Joined: Sat Mar 01, 2008 10:23 pm

Re: Fat12 Disk Image Tool

Post by essial »

Whoops, it helps to not forcefully set the disk image name. The attachment in the original post has been replaced with the fixed version, and my sample code has been updated as well.
Post Reply