OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Feb 01, 2023 1:04 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: What do i need to do to find file on fat12 in bootsect
PostPosted: Tue Nov 22, 2022 6:58 pm 
Offline

Joined: Tue Nov 22, 2022 6:55 pm
Posts: 1
What do i need to do to find a file with a specified name on a fat12 partitioned disk in the boot sector


Top
 Profile  
 
 Post subject: Re: What do i need to do to find file on fat12 in bootsect
PostPosted: Sun Nov 27, 2022 8:07 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 4509
Read the root directory into memory and search for the file with the correct name. If you want to load that file, follow the cluster chain in the FAT.

Microsoft published a specification for FAT12 (and FAT16 and FAT32) as part of the EFI specification. Here's a copy of that specification converted to PDF. You can download the original Word document directly from Microsoft.

I've written code to load a file from a FAT12 partition on a hard disk. You can find it here if you're interested. (I've made a few updates recently that haven't yet made it onto Github... nothing important, though; just changing the load address.)


Top
 Profile  
 
 Post subject: Re: What do i need to do to find file on fat12 in bootsect
PostPosted: Tue Nov 29, 2022 8:15 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 2954
I don't think that is possible within the limited space of the boot sector. You need to load a second stage loader (from fixed sectors) in the boot sector, and then load the file in the second stage loader.


Top
 Profile  
 
 Post subject: Re: What do i need to do to find file on fat12 in bootsect
PostPosted: Tue Nov 29, 2022 9:30 am 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1047
rdos wrote:
I don't think that is possible within the limited space of the boot sector.

Sure it is! See http://www.brokenthorn.com/Resources/OSDev6.html

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: What do i need to do to find file on fat12 in bootsect
PostPosted: Tue Nov 29, 2022 9:53 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 2954
nexos wrote:
rdos wrote:
I don't think that is possible within the limited space of the boot sector.

Sure it is! See http://www.brokenthorn.com/Resources/OSDev6.html


OK, it might be possible but it is still not a good idea. By keeping stage2 in the root directory you risk it getting deleted or corrupted, so a better idea is to place it in reserved sectors directly after the boot sector. Additionally, you might decide to format your boot partition as FAT32, EXT or NTFS, and then you need a new boot sector to load the second stage, and it might not be possible to handle reading the root directory of EXT or NTFS from the boot sector.


Top
 Profile  
 
 Post subject: Re: What do i need to do to find file on fat12 in bootsect
PostPosted: Tue Nov 29, 2022 11:37 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 4509
rdos wrote:
By keeping stage2 in the root directory you risk it getting deleted or corrupted,

Everything is in the root directory! By that logic, you shouldn't store any part of your OS as files on the disk because that risks it getting deleted or corrupted.

rdos wrote:
it might not be possible to handle reading the root directory of EXT or NTFS from the boot sector.

That's why EXT2 and NTFS have more than one sector for the boot "sector".


Top
 Profile  
 
 Post subject: Re: What do i need to do to find file on fat12 in bootsect
PostPosted: Tue Nov 29, 2022 1:01 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1420
rdos wrote:
it might not be possible to handle reading the root directory of EXT or NTFS from the boot sector.

That's why EXT2 and NTFS have more than one sector for the boot "sector".[/quote]
Well, you say that, but my previous attempt to write a real-mode ext2 file loader finally clocked in at 2048 bytes. Unfortunately, ext2 only gives me 1024 bytes of space (irrespective of block size, by the way).

However, those 1024 bytes are enough to load i-node 5 (which is the ext2 reserved i-node for the boot loader). So if I had gone that route, I would have had routines to load sectors in the first 512 bytes, routines to load i-nodes in the second 512 bytes, then skip 1024 bytes for superblock and block group descriptors, then routines to traverse directories in however much memory was needed.

But I never finished it. My main goal was to only use the first 1024 bytes. But it seems like that is just not enough space for
  • enabling A20-gate
  • testing if the CPU is acceptable
  • loading second bootloader block and superblock
  • traversing directories to find a programmable path name
  • finally loading that one to the 1MB line
  • mapping it as an ELF file
  • doing the rest of stuff my kernel needs
  • and finally transitioning to 64-bit mode

_________________
Carpe diem!


Top
 Profile  
 
 Post subject: Re: What do i need to do to find file on fat12 in bootsect
PostPosted: Tue Nov 29, 2022 1:30 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 4509
nullplan wrote:
But it seems like that is just not enough space for
  • enabling A20-gate
  • testing if the CPU is acceptable
  • loading second bootloader block and superblock
  • traversing directories to find a programmable path name
  • finally loading that one to the 1MB line
  • mapping it as an ELF file
  • doing the rest of stuff my kernel needs
  • and finally transitioning to 64-bit mode

I don't think anyone is suggesting that you do all of those things within the EXT2 boot block; just finding and loading the second stage is enough.


Top
 Profile  
 
 Post subject: Re: What do i need to do to find file on fat12 in bootsect
PostPosted: Tue Nov 29, 2022 2:28 pm 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 2954
Octocontrabass wrote:
rdos wrote:
By keeping stage2 in the root directory you risk it getting deleted or corrupted,

Everything is in the root directory! By that logic, you shouldn't store any part of your OS as files on the disk because that risks it getting deleted or corrupted.


Not in my design. I can have several bootable images in the root directory, and if one is deleted or corrupt I can always boot the other. That's why I call the second one for "safe". However, the second stage loader only exists in a single instance, and it is never modified, so it's better placed in reserved sectors.

For UEFI boot, things are a bit more safe since the loaders & images are on it's own UEFI system partition.


Top
 Profile  
 
 Post subject: Re: What do i need to do to find file on fat12 in bootsect
PostPosted: Tue Nov 29, 2022 2:46 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 4509
You can have a separate boot partition on legacy BIOS too.


Top
 Profile  
 
 Post subject: Re: What do i need to do to find file on fat12 in bootsect
PostPosted: Fri Dec 23, 2022 2:49 pm 
Offline
Member
Member
User avatar

Joined: Sun Aug 25, 2013 5:47 pm
Posts: 86
Location: Nebraska, USA
Late to the party, but here is also a fat32 implementation which loads a file in the "stage1": https://bitbucket.org/AlexOSAdventurer/alo_chainloader/src/master/src/boot_stage1/ . This is if you're wanting something that will work with a large fat system. I heavily commented it to death too so it should be straightforward to understand the process.

_________________
"Procrastination is the art of keeping up with yesterday."


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group