Skip to content

Commit

Permalink
More fixes in fat1X_mkfs
Browse files Browse the repository at this point in the history
- CHS are now explicitly set in partutils.py for some well-known 3.5 inch floppy disks, fixing format capabilities in mkfat.py
- less assumptions about heads and sectors per track in mkfat.py
  • Loading branch information
maxpat78 committed Apr 24, 2023
1 parent fd711f3 commit c3ab613
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
19 changes: 12 additions & 7 deletions FATtools/mkfat.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ def fat12_mkfs(stream, size, sector=512, params={}):
boot.chPhysDriveNumber = 0
boot.uchSignature = 0x29
boot.wBootSignature = 0xAA55
boot.wSectorsPerTrack = 18 # CAVE! This is true with floppies, not little HDDs (20MB, 120MB etc.)
#~ boot.wHeads = 2
boot.wHeads = partutils.size2chs(size,1)[1] # not used with LBA
c,h,s = partutils.size2chs(size,1)
if DEBUG&1: log("fat12_mkfs C=%d, H=%d, S=%d", c, h, s)
boot.wSectorsPerTrack = s
boot.wHeads = h # not used with LBA

boot.pack()
#~ print boot
Expand Down Expand Up @@ -277,8 +278,10 @@ def fat16_mkfs(stream, size, sector=512, params={}):
boot.chPhysDriveNumber = 0x80
boot.uchSignature = 0x29
boot.wBootSignature = 0xAA55
boot.wSectorsPerTrack = 63 # not used w/o disk geometry!
boot.wHeads = partutils.size2chs(size,1)[1] # not used with LBA
c,h,s = partutils.size2chs(size,1)
if DEBUG&1: log("fat16_mkfs C=%d, H=%d, S=%d", c, h, s)
boot.wSectorsPerTrack = s
boot.wHeads = h # not used with LBA

boot.pack()
#~ print boot
Expand Down Expand Up @@ -448,8 +451,10 @@ def fat32_mkfs(stream, size, sector=512, params={}):
boot.chPhysDriveNumber = 0x80
boot.chExtBootSignature = 0x29
boot.wBootSignature = 0xAA55
boot.wSectorsPerTrack = 63 # not used w/o disk geometry!
boot.wHeads = partutils.size2chs(size,1)[1] # not used with LBA
c,h,s = partutils.size2chs(size,1)
if DEBUG&1: log("fat32_mkfs C=%d, H=%d, S=%d", c, h, s)
boot.wSectorsPerTrack = s
boot.wHeads = h # not used with LBA

fsi = fat32_fsinfo(offset=sector)
fsi.sSignature1 = b'RRaA'
Expand Down
22 changes: 21 additions & 1 deletion FATtools/partutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,27 @@ def lba2chs(lba, hpc=0):

def size2chs(n, getgeometry=0):
lba = n//512
for hpc in (2,16,32,64,128,255): # 2 is typical for 720K DS/DD and 1.44M DS/HD floppies

# Avoid computations with some well-known IBM PC floppy formats
# Look at: https://en.wikipedia.org/wiki/List_of_floppy_disk_formats#Logical_formats
if lba == 640:
return (80, 1, 8) # 3.5in DS/DD 320KB
elif lba == 720:
return (80, 1, 9) # 3.5in DS/DD 360KB
elif lba == 1280:
return (80, 2, 8) # 3.5in DS/DD 640KB
elif lba == 1440:
return (80, 2, 9) # 3.5in DS/DD 720KB
elif lba == 2880:
return (80, 2, 18) # 3.5in DS/HD 1440KB
elif lba == 3360:
return (80, 2, 21) # 3.5in DS/HD 1680KB (MS-DMF)
elif lba == 3440:
return (82, 2, 21) # 3.5in DS/HD 1720KB
elif lba == 5760:
return (80, 2, 36) # 3.5in DS/XD 2880KB

for hpc in (2,16,32,64,128,255):
c,h,s = lba2chs(lba,hpc)
if c < 1024: break
if DEBUG&1: log("size2chs: calculated Heads Per Cylinder: %d", hpc)
Expand Down
2 changes: 1 addition & 1 deletion FATtools/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.11'
__version__ = '1.0.12'

0 comments on commit c3ab613

Please sign in to comment.