(First timer here) FDISK: Getting into the nitty-gritty

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
Licca
Posts: 2
Joined: Fri May 03, 2024 2:07 pm

(First timer here) FDISK: Getting into the nitty-gritty

Post by Licca »

I'll preface this with a bit so y'all know that while I'm a bit of a n00b in the OS department, I've been programming for a while - mainly on emulators. Been coding in C for almost 25 years now - and been learning x86 ASM recently. I've made a few attempts at rewriting DOS that went down in smoke, but I've got a few pieces of those projects. And then IBM and Microsoft dropped PC DOS/MS-DOS 4.0 on us recently :mrgreen:

I was looking at some of the pieces we've got that aren't likely to need too much updating, and decided FDISK could use a nicer interface, but couldn't really get too deep into the weeds because the code's partially algolized (anyone who's seen the original code to the Bourne Shell will know what I mean). I almost think it'll be easier to just gut the thing and start fresh.

And this is where I'm deep in the weeds. I know a bit of the basics, and keep RBIL open most times (remember, 8088 target here in C/ASM) so at the high level I'm fine. It's when I get down to stuff like enumerating hard drives and handling MBR that I'm lost, and not really finding the info I need (if I just need to RTFW - read the f'n wiki - it's possible I just haven't found the right page yet!)

(For what it's worth, I'll be using the same license that the existing code has, and I _can_ avail myself of the existing code, inasfar as it's part of 4.0 and therefore legitimate.)
Octocontrabass
Member
Member
Posts: 5418
Joined: Mon Mar 25, 2013 7:01 pm

Re: (First timer here) FDISK: Getting into the nitty-gritty

Post by Octocontrabass »

I don't know how (or if!) DOS enumerates hard drives, so I can't help you very much there, but Wikipedia has a surprisingly thorough description of MBR partition tables.
nullplan
Member
Member
Posts: 1733
Joined: Wed Aug 30, 2017 8:24 am

Re: (First timer here) FDISK: Getting into the nitty-gritty

Post by nullplan »

According to the source code of FreeDOS I've just read, KERNEL.SYS will enumerate all hard disks the BIOS knows using function 8 of interrupt 0x13 to get the number of hard disks, then read the partition table off of each of them, then assign drive letters by the Windows 2000 algorithm (which essentially means all partitions found in this way get the next available letter starting from C. Floppy drives are assigned after, starting from A, and then CD-ROM drives are assigned starting from D). All of this happens in ReadAllPartitionTables() in initdisk.c, which is executed during boot.

So that seems to be the answer to OP's question: Function 8 of interrupt 0x13.
Carpe diem!
Licca
Posts: 2
Joined: Fri May 03, 2024 2:07 pm

Re: (First timer here) FDISK: Getting into the nitty-gritty

Post by Licca »

nullplan wrote:According to the source code of FreeDOS I've just read, KERNEL.SYS will enumerate all hard disks the BIOS knows using function 8 of interrupt 0x13 to get the number of hard disks, then read the partition table off of each of them, then assign drive letters by the Windows 2000 algorithm (which essentially means all partitions found in this way get the next available letter starting from C. Floppy drives are assigned after, starting from A, and then CD-ROM drives are assigned starting from D). All of this happens in ReadAllPartitionTables() in initdisk.c, which is executed during boot.

So that seems to be the answer to OP's question: Function 8 of interrupt 0x13.
Most likely, PC DOS uses the same algorithm...
Post Reply