Second stage bootloader filename doesn't work with lowercase
-
- Posts: 20
- Joined: Wed Jan 29, 2014 11:57 am
Second stage bootloader filename doesn't work with lowercase
I am referring to BrokenThorn's tutorial on OS development and am currently at the chapter on writing the first stage bootloader and loading the second stage.
I wrote the whole code and ran into crashes on running it using qemu. After some debugging, I found out that the problem was with the name of the second stage bootloader, which I'm reading by looping through the root directory entries.
If I use the filename for the second stage as INITKRNL.BIN, everything works fine. But if I use initkrnl.bin (thus the difference being only in the case of the name), it crashes.
I also printed the name being read from the root directory. For the upper case name, it reads INITKRNL.BIN only. For the lower case name, it reads some letters of the name and some random characters.
Why does the case of the file name matter, and what is the reason for this difference ?
Note : I'm using Ubuntu 13.04 as my development environment. I format the floppy image with the VFAT file system using mkfs.vfat.
I wrote the whole code and ran into crashes on running it using qemu. After some debugging, I found out that the problem was with the name of the second stage bootloader, which I'm reading by looping through the root directory entries.
If I use the filename for the second stage as INITKRNL.BIN, everything works fine. But if I use initkrnl.bin (thus the difference being only in the case of the name), it crashes.
I also printed the name being read from the root directory. For the upper case name, it reads INITKRNL.BIN only. For the lower case name, it reads some letters of the name and some random characters.
Why does the case of the file name matter, and what is the reason for this difference ?
Note : I'm using Ubuntu 13.04 as my development environment. I format the floppy image with the VFAT file system using mkfs.vfat.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Second stage bootloader filename doesn't work with lower
FAT has a fair share of legacy. Real file names are always in uppercase 8.3 format, and it would actually be stored as "INITKRNLBIN" (without the period). After a file you can add a legible filename according to the LFN scheme, but it's not mandatory. Since it's also more complicated, you won't see that feature used in bootloaders, which revert to the simple name.
So if you use a filename that doesn't fit the simple scheme, the fat driver will make something up for you that only superfluously resembles the name you think you gave it.
So if you use a filename that doesn't fit the simple scheme, the fat driver will make something up for you that only superfluously resembles the name you think you gave it.
- Owen
- Member
- Posts: 1700
- Joined: Fri Jun 13, 2008 3:21 pm
- Location: Cambridge, United Kingdom
- Contact:
Re: Second stage bootloader filename doesn't work with lower
I'll also add:
FAT mandates upper case short file names, so for the name "initkrnl.bin" the short name would have to be "INITKRNLBIN".
However, Linux wants to preserve case, so it stores "initkrnl.bin" as a long name (Windows will do the same).
The difference arises because of patents. Microsoft have a patent covering storing of both short and long names. Pretty much every FAT driver can cope with files which don't have a valid short name (and they must support files which only have a short name), so Linux works around this patent by not storing a short name when it stores a long name, which it will do whenever the short name cannot represent the chosen name.
(There is a flag somewhere to turn on storing both names. If you are outside the US, the patent does not apply to you and you can turn on this flag if you wish)
FAT mandates upper case short file names, so for the name "initkrnl.bin" the short name would have to be "INITKRNLBIN".
However, Linux wants to preserve case, so it stores "initkrnl.bin" as a long name (Windows will do the same).
The difference arises because of patents. Microsoft have a patent covering storing of both short and long names. Pretty much every FAT driver can cope with files which don't have a valid short name (and they must support files which only have a short name), so Linux works around this patent by not storing a short name when it stores a long name, which it will do whenever the short name cannot represent the chosen name.
(There is a flag somewhere to turn on storing both names. If you are outside the US, the patent does not apply to you and you can turn on this flag if you wish)
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Second stage bootloader filename doesn't work with lower
I thought the patent in question expired somewhere last year...
-
- Member
- Posts: 5604
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Second stage bootloader filename doesn't work with lower
Windows NT and upwards will use two extra bits somewhere in the directory entry to represent the case of a short file name, and only write a long file name if the case can't be represented in those two bits. Linux, by default, will not.
Mounting your disk image with the option "shortname=winnt" should cause the same short name to be written for both "INITKRNL.BIN" and "initkrnl.bin" (and also "initkrnl.BIN" and "INITKRNL.bin").
Mounting your disk image with the option "shortname=winnt" should cause the same short name to be written for both "INITKRNL.BIN" and "initkrnl.bin" (and also "initkrnl.BIN" and "INITKRNL.bin").
- wichtounet
- Member
- Posts: 90
- Joined: Fri Nov 01, 2013 4:05 pm
- Location: Fribourg, Switzerland
- Contact:
Re: Second stage bootloader filename doesn't work with lower
If I'm not mistaken, there are still two years before the end of this damn patent... (http://www.google.com/patents/US5758352)Combuster wrote:I thought the patent in question expired somewhere last year...
Thor Operating System: C++ 64 bits OS: https://github.com/wichtounet/thor-os
Good osdeving!
Good osdeving!
-
- Posts: 20
- Joined: Wed Jan 29, 2014 11:57 am
Re: Second stage bootloader filename doesn't work with lower
Thank you for all the quick replies.
But I think I am even more confused now.
The name I am using is exactly 8.3 characters. So shouldn't it be stored that way ? Where does the long/short name come into play here, and why does simply changing the case make it work ?
Is it something to do with using Linux?
If someone could explain what value is written and why, it would be very helpful.
But I think I am even more confused now.
The name I am using is exactly 8.3 characters. So shouldn't it be stored that way ? Where does the long/short name come into play here, and why does simply changing the case make it work ?
Is it something to do with using Linux?
If someone could explain what value is written and why, it would be very helpful.
- Owen
- Member
- Posts: 1700
- Joined: Fri Jun 13, 2008 3:21 pm
- Location: Cambridge, United Kingdom
- Contact:
Re: Second stage bootloader filename doesn't work with lower
Owen wrote:FAT mandates upper case short file names, so for the name "initkrnl.bin" the short name would have to be "INITKRNLBIN".
Re: Second stage bootloader filename doesn't work with lower
maybe if i repeat...shahsunny712 wrote:Thank you for all the quick replies.
But I think I am even more confused now.
The name I am using is exactly 8.3 characters. So shouldn't it be stored that way ? Where does the long/short name come into play here, and why does simply changing the case make it work ?
Is it something to do with using Linux?
If someone could explain what value is written and why, it would be very helpful.
IT IS NOT POSSIBLE TO USE LOWER CASE FILENAMES IN FAT
if you create a filename using lower case letters, you will then instead of having the filename in lower case letters, a filename will be created using random numbers and letters (in SOME cases portions of the filename might be the same changed to all caps, but that cannot be relied on)
-
- Member
- Posts: 5604
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Second stage bootloader filename doesn't work with lower
FAT stores short file names as all-uppercase, but it has some extra data to specify when the name or extension should be lowercase. Windows NT uses that extra data, so that "initkrnl.bin" and "INITKRNL.BIN" will both be written as "INITKRNLBIN", and the only difference between the two will be the extra data.shahsunny712 wrote:The name I am using is exactly 8.3 characters. So shouldn't it be stored that way ? Where does the long/short name come into play here, and why does simply changing the case make it work ?
Is it something to do with using Linux?
Linux, on the other hand, will only allow you to store an all-uppercase file name as a short file name. This means "INITKRNL.BIN" will end up as "INITKRNLBIN", but "initkrnl.bin" will use a long file name instead. The short file name cannot be blank, which is why Linux writes the random characters.
You can make Linux do the same thing as Windows NT by mounting your filesystem with the "shortname=winnt" option.
Tell that to Windows NT.JAAman wrote:IT IS NOT POSSIBLE TO USE LOWER CASE FILENAMES IN FAT
-
- Posts: 20
- Joined: Wed Jan 29, 2014 11:57 am
Re: Second stage bootloader filename doesn't work with lower
Thanks for your replies guys.
Okay, so here's what I gather:
FAT stores short file names in only upper case. For lower case, you need a long file name which specifies the case. In Windows NT, this is read to determine the case. If I do want to have a lower case support, I would have to store a long file name and read off the extra data.
Linux stores only upper case names as a short name. Others end up as long names, and the short name is given random characters.
Assuming this is right(please correct me if I am wrong), questions:
- Why can't Linux also use a long file name and write the upper case version in the short name value (why does FAT have to be different for Windows and Linux, assuming thats a valid question), and use the extra data to store the case (like in NT) ?
- How can I get the name with the correct case in Linux ?
Okay, so here's what I gather:
FAT stores short file names in only upper case. For lower case, you need a long file name which specifies the case. In Windows NT, this is read to determine the case. If I do want to have a lower case support, I would have to store a long file name and read off the extra data.
Linux stores only upper case names as a short name. Others end up as long names, and the short name is given random characters.
Assuming this is right(please correct me if I am wrong), questions:
- Why can't Linux also use a long file name and write the upper case version in the short name value (why does FAT have to be different for Windows and Linux, assuming thats a valid question), and use the extra data to store the case (like in NT) ?
- How can I get the name with the correct case in Linux ?
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Second stage bootloader filename doesn't work with lower
shahsunny712 wrote:- Why can't Linux also use a long file name and write the upper case version in the short name value (why does FAT have to be different for Windows and Linux, assuming thats a valid question), and use the extra data to store the case (like in NT) ?
Owen wrote:The difference arises because of patents. (...)
shahsunny712 wrote:- How can I get the name with the correct case in Linux ?
The fact that I could answer both with quotes from this very thread is a really bad indication of your reading skills. Please, take some effort to read things through instead of blindly asking.Octocontrabass wrote:You can make Linux do the same thing as Windows NT by mounting your filesystem with the "shortname=winnt" option.