-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FATFS: Add special case for label creation #202
Conversation
I thought it about time that I addressed the FAT label issue FDOS/label#17 on FDPP. Currently the kernel sees identically named volume labels and files/directories as in conflict. MS-DOS 6.22 and DR-DOS 7.01 allow them to coexist. I added some tests to my topic branch dosemu2/dosemu2@ff58161 to show the problem. Currently (without this patch): So you can see that at the very least the current behaviour is asymmetric based on creation order. Now for a discussion about the patch. I've created a special case that only comes into play if we have the volid set, are in the root directory and are doing file create/truncate. This seems to work quite nicely, however there's a strange behaviour with the status = find_fname(path, D_VOLID, fnp);
if ((status == SUCCESS) && (fnp->f_dir.dir_attrib & D_VOLID)) { I thought that by specifying the D_VOLID attribute I'd only be finding the volume names. However it seems that plain files are also found, which I why I added the additional check Thoughts? |
if find_fname() finds both and you Or alternatively maybe you can use |
Yes, that's a very good point! As I note in cases 3 and 4 above the duplicate filename (file/directory) with label problem already exists, but only in the case that the vol was set first and the file/directory added afterwards. I can imagine that any search with
Mmm, I was afraid you'd say that. I suppose I'll need to find all its callers, then I'll know what to check afterwards.
I think I will have to do that in addition to what I have here because there's already the case in the wild of BPB volname and root directory volid file contents getting out of sync. This is what MS-DOS 6.22 does to avoid that problem. |
Maybe because no one creates |
It seems findfile/next returning other files with VOLID bit set was DOS 2 behaviour, with 3 and later it only returns the label. I've added some code to do this. The tests all pass now. I now need to think about setting the volume name in BPB too. Have you any thoughts on how best to do this cleanly? |
What will this give us? |
Ensure that disk utilities like FDISK/format will report the same name that a user set and that reports like this one https://gitlab.com/FreeDOS/issue-reporting/-/issues/31 won't occur. |
I really don't know how that should |
Looks like here Lines 682 to 711 in fbd9ee2
|
Serial number?? |
Yes serial number is the adjacent field in the bpb. This code shows me how to get the bpb (location can vary if FAT32), test for proper bpb version, set the field to be changed (in my case will be volume name), and write it back to disk.
MS-DOS 6.22 sets bpb->volume_name within the kernel at the same time as writing the file with volid set. I want to avoid changing all the userspace tools. |
Sounds like a plan actually.
Which means that all we need is to "abuse" |
This seems to work. |
Ok I thought you can use fn 0x46, |
Do you know if there's an easy way to wrap a partition table around disk image file? I want to do this:
Now run test I specifically don't want to have to use root privilege for something like kpartx |
I can think of partitioning the hd image |
Oh, try fuseloop tool - seems to be |
Thanks, I'll give them both a try. |
I have now successfully tested these patches with FAT12, FAT16 and FAT32 filesystems. |
Don't apply yet, as I need to consider the unlikely but valid case where bpb is v7 and fs is not fat32. It says "A common misconception is that this BPB is exclusive to 32-bit FAT. It is not. Just as there was no reason that the version 4.0 BPB could not be used for 12-bit FAT, there is no reason that the version 7.0 BPB cannot be used for filesystem formats other than 32-bit FAT. " |
mtools just had this edge case fixed. The truth is that the word (16-bit) "sectors per FAT" field being zero indicates using both the larger EBPB and FAT32. It doesn't really matter how many clusters there are, you can create a FAT32 file system with less than 64 Ki clusters. That seems to be what most drivers, including Microsoft's, actually do. |
Quoting from the mailing list for mtools: https://lists.gnu.org/archive/html/info-mtools/2022-09/msg00003.html
|
This seems wrong. If you have a FAT32 EBPB then the byte at offset 26h is part of the ebpbSectorsPerFATLarge field, for which 29h would be a valid value. You should check bpbSectorsPerFAT == 0 to determine whether to use the EBPB or BPB new fields. |
If the BPB is either v4.1 or v7 long, then its volume label field should be written. Note: This site https://jdebp.uk/FGA/bios-parameter-block.html suggests that it is perfectly valid to have a v7 long BPB with a FAT12 or FAT16 filesystem, although more usually it's used for FAT32. However I can't see any confirmation of this elsewhere, haven't seen an example of this in the wild, and have no means of generating a test article. More importantly since we are writing to the filesystem, it's important to not have any false positives or we could cause corruption. So for now this combination, should it exist, will not be updated. See the discussion here dosemu2#202.
If the BPB is either v4.1 or v7 long, then its volume label field should be written. Note: This site https://jdebp.uk/FGA/bios-parameter-block.html suggests that it is perfectly valid to have a v7 long BPB with a FAT12 or FAT16 filesystem, although more usually it's used for FAT32. However I can't see any confirmation of this elsewhere, haven't seen an example of this in the wild, and have no means of generating a test article. More importantly since we are writing to the filesystem, it's important to not have any false positives or we could cause corruption. So for now this combination, should it exist, will not be updated. See the discussion here dosemu2#202.
If the BPB is either v4.1 or v7 long, then its volume label field should be written. Note: This site https://jdebp.uk/FGA/bios-parameter-block.html suggests that it is perfectly valid to have a v7 long BPB with a FAT12 or FAT16 filesystem, although more usually it's used for FAT32. However I can't see any confirmation of this elsewhere, haven't seen an example of this in the wild, and have no means of generating a test article. More importantly since we are writing to the filesystem, it's important to not have any false positives or we could cause corruption. So for now this combination, should it exist, will not be updated. See the discussion here dosemu2#202.
If the BPB is either v4.1 or v7 long, then its volume label field should be written. Note: This site https://jdebp.uk/FGA/bios-parameter-block.html suggests that it is perfectly valid to have a v7 long BPB with a FAT12 or FAT16 filesystem, although more usually it's used for FAT32. However I can't see any confirmation of this elsewhere, haven't seen an example of this in the wild, and have no means of generating a test article. More importantly since we are writing to the filesystem, it's important to not have any false positives or we could cause corruption. So for now this combination, should it exist, will not be updated. See the discussion here dosemu2#202.
So back on this now. I wrote an additional test for LFNs (andrewbird/dosemu2@6ce3be8) , and my current code fails it. When creating a new volume label, I need to scan the root directory to ensure that there is not already a label. I use |
There was probably a brackets error in |
If the BPB is either v4.1 or v7 long, then its volume label field should be written. Note: This site https://jdebp.uk/FGA/bios-parameter-block.html suggests that it is perfectly valid to have a v7 long BPB with a FAT12 or FAT16 filesystem, although more usually it's used for FAT32. However I can't see any confirmation of this elsewhere, haven't seen an example of this in the wild, and have no means of generating a test article. More importantly since we are writing to the filesystem, it's important to not have any false positives or we could cause corruption. So for now this combination, should it exist, will not be updated. See the discussion here dosemu2#202.
Thanks, but it didn't fix my issue here.
So would you expect that specifying |
Yes, I think so. |
I don't think so, but I'll have to instrument the code a little to be sure. |
Sorry, my mistake in rebasing the December label test code onto current devel without reviewing. I had already set a volume label in the common code that makes the image, and this test didn't delete it first! |
Mmm, a comment from my test case!
|
I think findfirst/findnext types of calls should never return LFN entries on an LFN-aware kernel (MS-DOS v7 compatibility). I don't know any reason that |
I don't think it does, it was just a |
Mine, not @ecm-pushbx 's |
Correct, sorry for confusion! |
So what's the status of this? |
OK, thanks. |
In EDR-DOS you can (probably) FCB open or FCB create a label, but DOS will immediately close the FCB before the control flow returns from the int 21h: https://hg.pushbx.org/ecm/edrdos/file/b390f7f10fd0/drdos/fcbs.a86#l217 So no seeking or writing to it is possible. |
Opening draft PR so we can discuss things