VFS FatFS: mkdir with trailing slash fails when it should succeed
On CPython and unix uPy, os.mkdir('directory/') makes the requested directory. But on bare metal ports using VFS with FatFS it fails with ENOENT because of the trailing slash. I'd say this should be fixed. (And in fact CPy and unix uPy allow any number of trailing slashes).
vfs_fat/fsusermount: mkfs, mount, umount inconsistencies.
While writing the tests for fsusermount, I notices some oddities with the vfs_* functions that I'd like to mention.
- Fsusermount mkfs:
uos.vfs_mkfs(bdev, "/ramdisk")
takes a blockdevice and a path, the latter is not necessary but required. Comparing this to:
uos.VfsFat.mkfs(bdev)
which writes the filesystem and nothing else, as the function name suggests. Defined as a CONST_FUN_OBJ_1 in vfs_fat.c (#L55)
- We have 3 ways of unmounting the device:
uos.vfs_umount("/ramdisk") # by calling umount
uos.vfs_mount(None, "/ramdisk") # by mounting None
uos.vfs_mkfs(None, "/ramdisk") # why?
While first 2 calls are logical, the last call is a side effect from having the same underlying call to fatfs_mount_mkfs(). We duplicate the umount functionality in fsusermount.c (L#54, #L166)
Mkfs thus also can take a readonly=True parameter, which will obviously fail.
- In vfs_fat.c both
fat_vfs_make_new()andfat_vfs_mkfs()call the internal functionfatfs_mount_mkfs(), instead offatfs_mount()andfatfs_mkfs()respectively, which should be internal to fsusermount.
What I would like to propose is:
-
Have the mkfs take a block device only, it should not be concerned with mount path at this stage.
-
Umount functionality should belong to it's
fatfs_umount()on L#166 only, and not be repeated infatfs_mount_mkfs(). Mounting a None case can then make a call to umount instead of being duplicated, but I don't see a good reason for such call in favour of regular umount. Readonly=True argument should be relevant to mounting only. -
Just like we have a new "_internal" function for removing files/dirs,
fatfs_mount_mkfs()should be renamed and not called directly by VfsFat. Mounting and mkfs will use the internal function as they do at the moment.
This is just my observations, please share your thoughts and counter-arguments!