FATFS: Write volume label to the BPB too
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 https://github.com/dosemu2/fdpp/pull/202. Part of a fix for [https://github.com/FDOS/label/issues/17]
This commit is contained in:
parent
63c2e621ca
commit
106d4cd73b
@ -486,6 +486,7 @@ extern request /* I/O Request packets */
|
||||
/* dsk.c */
|
||||
COUNT ASMCFUNC FAR blk_driver(rqptr rp);
|
||||
ddt * getddt(int dev);
|
||||
COUNT writelabelBPB(char drive, const char *name);
|
||||
|
||||
/* error.c */
|
||||
COUNT char_error(request * rq, struct dhdr FAR * lpDevice);
|
||||
|
35
kernel/dsk.c
35
kernel/dsk.c
@ -97,6 +97,40 @@ ddt *getddt(int dev)
|
||||
return &(((ddt *) Dyn.Buffer)[dev]);
|
||||
}
|
||||
|
||||
STATIC WORD getbpb(ddt *pddt);
|
||||
STATIC WORD RWzero(ddt *pddt, UWORD mode);
|
||||
|
||||
COUNT writelabelBPB(char drive, const char *name)
|
||||
{
|
||||
ddt *pddt = getddt(drive - 'A');
|
||||
struct FS_info *fs;
|
||||
int offset;
|
||||
int ret;
|
||||
|
||||
ret = getbpb(pddt);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
if (DiskTransferBuffer[0x26] == 0x29 &&
|
||||
pddt->ddt_bpb.bpb_nfsect != 0) // BPB v4.1
|
||||
offset = 0x27;
|
||||
else if (DiskTransferBuffer[0x42] == 0x29 &&
|
||||
pddt->ddt_bpb.bpb_nfsect == 0) // BPB v7 long
|
||||
offset = 0x43;
|
||||
else
|
||||
return -1;
|
||||
|
||||
/* store volume name */
|
||||
fs = (struct FS_info *)&DiskTransferBuffer[offset];
|
||||
memcpy(&fs->volume[0], name, 11);
|
||||
|
||||
ret = RWzero(pddt, LBA_WRITE);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC VOID tmark(ddt *pddt)
|
||||
{
|
||||
pddt->ddt_fh.ddt_lasttime = ReadPCClock();
|
||||
@ -122,7 +156,6 @@ STATIC dsk_proc mediachk, bldbpb, blockio, IoctlQueblk,
|
||||
Genblkdev, Getlogdev, Setlogdev, blk_Open, blk_Close,
|
||||
blk_Media, blk_noerr, blk_nondr, blk_error;
|
||||
|
||||
STATIC WORD getbpb(ddt * pddt);
|
||||
#ifdef PROTO
|
||||
STATIC WORD dskerr(COUNT);
|
||||
#else
|
||||
|
@ -148,6 +148,7 @@ int dos_open(char *path, unsigned flags, unsigned attrib, int fd)
|
||||
return ret;
|
||||
status = S_CREATED;
|
||||
|
||||
writelabelBPB(path[0], path + 3);
|
||||
goto doit;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user