← index #2929Issue #2556
Off-topic · high · value 1.960
QUERY · ISSUE

VFS FatFS: mkdir with trailing slash fails when it should succeed

openby dpgeorgeopened 2017-03-03updated 2017-03-08

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).

CANDIDATE · ISSUE

vfs_fat/fsusermount: mkfs, mount, umount inconsistencies.

closedby hosakaopened 2016-10-24updated 2017-01-27

While writing the tests for fsusermount, I notices some oddities with the vfs_* functions that I'd like to mention.

  1. 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)

  1. 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.

  1. In vfs_fat.c both fat_vfs_make_new() and fat_vfs_mkfs() call the internal function fatfs_mount_mkfs(), instead of fatfs_mount() and fatfs_mkfs() respectively, which should be internal to fsusermount.

What I would like to propose is:

  1. Have the mkfs take a block device only, it should not be concerned with mount path at this stage.

  2. Umount functionality should belong to it's fatfs_umount() on L#166 only, and not be repeated in fatfs_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.

  3. 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!

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied