Page 1 of 1

How can winxp load its ntfs driver from an ntfs filesystem?

Posted: Mon Sep 24, 2007 11:37 am
by kirsis
Hi, everybody,

Got a bit of a mental block here, hope somebody can point me the right way. Here's what I'm thinking:

WinXP needs a driver to use an NTFS file system.

The driver is an external file (ntfs.sys, I believe).

If WinXP is on an ntfs partition, then how can it load the driver (which needs to be found in the filesystem if it's to be loaded) in the first place? It seems to me it would need to load the ntfs driver before it could actually find and load the ntfs driver?

And if it has inbuilt NTFS capabilities, then why bother with a driver at all?

I started thinking about this while fleshing out a design for an OS I'd like to make. The idea was that filesystem support could be loaded through external modules only (nothing hardcoded in the kernel). The kernel would detect all logical storage devices, query the registered filesystem drivers to see which one can handle each device, and use the drivers to access the storage devices in an abstracted manner.

That lead me to the problem - can't load any filesystem modules without accessing the filesystem first. Then I thought of windows ...

Perhaps a custom bootloader can be made to detect the filesystem and load the first driver into memory for the kernel but that would render the whole idea useless.

So, how does Windows does this? Anybody know?

Posted: Mon Sep 24, 2007 12:09 pm
by kataklinger
Ntldr starts the appropriate minifile system drivers; these are built into Ntldr to find and load Windows NT from different file system formats (FAT, NTFS).
http://en.wikipedia.org/wiki/Windows_NT_startup_process

Posted: Mon Sep 24, 2007 12:30 pm
by Jeffrey
kirsis,

The solution is quite simple actually. How about have something that supports the ntfs filesystem load everything needed to get the system up and running.

When a partition is made bootable at format, the utility provides a bootsector capable of reading an NTFS parition, as it is done during Windows installation. The same goes for when you format to other filesystems; generally each bootsector is specific to a target filesystem format. This is due to the limited amount of space available to the bootsectors code, well of course, unless the bootsector code supports spanning multiple sectors.

So here is an overview of how it is achieved.
1) Bootsector from HD is executed, which support NTFS.
2) Bootsector loads NTLDR from an NTFS partition and passes execution to it.
3) NTLDR then determines what filesystem it is being loaded from, which in our case is NTFS, and then continues loading Windows as usual.

Nothing special here.

Posted: Mon Sep 24, 2007 12:32 pm
by Craze Frog
A way to do this is to only support filesystems as loadable modules (as you want) and have the bootloader load an "initial ramdisk" with the filesystem and disk drivers.

See: http://en.wikipedia.org/wiki/Initrd

Posted: Mon Sep 24, 2007 1:36 pm
by Dex
There is a big differance, from loading file X from say ntfs and a full capable ntfs driver. You could for example load file X from a ntfs partion in about 30 lines of asm code.

Posted: Mon Sep 24, 2007 3:53 pm
by kirsis
Craze Frog wrote:A way to do this is to only support filesystems as loadable modules (as you want) and have the bootloader load an "initial ramdisk" with the filesystem and disk drivers.

See: http://en.wikipedia.org/wiki/Initrd
Thanks for the pointer, I'll look into this. Looks like what I was after :)
Dex wrote:There is a big differance, from loading file X from say ntfs and a full capable ntfs driver. You could for example load file X from a ntfs partion in about 30 lines of asm code.
Thanks for the info, I was under the impression that at least a complete read-only driver was required to load a file.
Jeffrey wrote:The solution is quite simple actually. How about have something that supports the ntfs filesystem load everything needed to get the system up and running.

When a partition is made bootable at format, the utility provides a bootsector capable of reading an NTFS parition, as it is done during Windows installation. The same goes for when you format to other filesystems; generally each bootsector is specific to a target filesystem format. This is due to the limited amount of space available to the bootsectors code, well of course, unless the bootsector code supports spanning multiple sectors.

So here is an overview of how it is achieved.
1) Bootsector from HD is executed, which support NTFS.
2) Bootsector loads NTLDR from an NTFS partition and passes execution to it.
3) NTLDR then determines what filesystem it is being loaded from, which in our case is NTFS, and then continues loading Windows as usual.

Nothing special here.
I wasn't aware that loading a simple file is relatively simple and does not require a fleshed out filesystem driver (as Dex pointed out), so I didn't see the benefit in making a boot loader that contains all the required code to access the filesystem. Might as well put it in the kernel in that case and not bother with modularity.

All in all, thanks for your answers, gonna go read up on initial ramdisks :)

Posted: Tue Sep 25, 2007 5:57 am
by JamesM
The hardest part about writing a FS or FS driver is space management and reclaimation, which happens when you delete/insert/write to files. So reading is the only operation where there's not much work involved.

Posted: Tue Sep 25, 2007 9:50 am
by JAAman
also, it doesnt even need full read functionality:
iirc, the NTFS bootloader can only load NTLDR if its the first entry in the MFT, and (iirc) only if the first MFT is valid, and i believe there are a few other restrictions also