nathanhi / pyfatfs

Python based FAT12/FAT16/FAT32 implementation with VFAT support
https://pypi.org/project/pyfatfs/
MIT License
29 stars 14 forks source link

PyFat.mkfs() - volume label does not appear to be applied #18

Closed dseeley closed 2 years ago

dseeley commented 2 years ago

Attempting to create a volume using the new mkfs() function:

temp_file = open(file="test_mkfs.fat12", mode="w+")
temp_pyfat = PyFat()
temp_pyfat.mkfs(filename=temp_file.name, fat_type=PyFat.FAT_TYPE_FAT12, label="TSTLABEL", size=(1024 * 256))

It appears that on mounting, the volume label is not set:

$ sudo losetup /dev/loop0 ./test_mkfs.fat12
$ lsblk -o name,label,size,uuid
NAME   LABEL  SIZE UUID
loop0         256K 5444-8E7B

I get the same results with FAT16/32

A similarly created file using mkfs yields a label:

$ mkfs.fat -C -F12 -n "TSTLABEL" test_mkfs.fat12 256
$ sudo losetup /dev/loop0 ./test_mkfs.fat12
$ lsblk -o name,label,size,uuid
NAME   LABEL     SIZE UUID
loop0  TSTLABEL  256K A562-5D4B
nathanhi commented 2 years ago

Seems like the special volume label file is actually required in some cases (and you just discovered one of them :tada:). I was under the impression that the special file is optional - at least with FAT16/32 I cannot remember that fsck ever complained about it. file and fatcat seem to work just fine without it, but lsblk/Linux is a bit more picky. :slightly_smiling_face:

image

As a workaround you can add a new FATDirectoryEntry to the root directory with the FATDirectoryEntry.ATTR_VOLUME_ID set as an attribute. I'll need to investigate under which circumstances the special file is actually required first.