-
Notifications
You must be signed in to change notification settings - Fork 2.1k
pkg/fatfs: fatfs_vfs: wire up format() #14430
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
Conversation
bc5ead1
to
82ffbea
Compare
82ffbea
to
3aafdd9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, two remarks inline
0ec13cb
to
0d27ad2
Compare
0d27ad2
to
2c5969f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested with an sdcard on the nucleo-f401re. Works as advertised!
fatfs_desc_t *fs_desc = mountp->private_data; | ||
char volume_str[TEST_FATFS_MAX_VOL_STR_LEN]; | ||
|
||
BYTE *work = malloc(FF_MAX_SS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need malloc
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FF_MAX_SS
is 512 byte so I'd rather not put it on the stack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general (or maybe my strict?) expectation of RIOT functions without any admonitions is that they don't use the heap, are reentrant / thread safe, and don't overexert the stack. This can't hold that, so we should put a warning around the general vfs_format function. So what'd that best be?
-
"Not thread safe! Do not call this concurrently on different (let alone the same) file system.": Similar to the warning already on vfs_iterate_mounts; would give license to use a static buffer.
Advantages: Consistent with other vfs functions; memory limitations are visible (with
nm
showing the culprit) at build time if no heap allocation is used. -
"On some file systems (currently \ref FatFS), this may resort to dynamic memory allocation, and return -ENOMEM if insufficient memory is available." This would justify the current behavior.
Advantage: Works well on otherwise idle systems even with little memory.
-
"Beware that some file systems (currently \ref FatFS) have extensive stack requirements when running this". Very vague, and has bad error behavior.
Based on this, I'm softly leaning toward a const allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about making it configurable? Allowing a static buffer to be provided, otherwise allocating one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added CONFIG_FATFS_FORMAT_ALLOC_STATIC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a good enough compromise @bergzand? (I would personally prefer that the default be avoiding malloc though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After letting this brew for a year I think I'm fine with anything as long as it is documented so the user doesn't run into unexpected troubles. Having it configurable seems like a perfect solution to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think now that the warning I sketched above is superfluous as mountpoint-related vfs stuff is behind a mutex anyway (but please verify, I'm on mobile and can't easily read long code here)
[edit because for some reason I can't reply to this particular comment:]
The warning should still be there, for vfs_format
only blocks the mount mutex briefly, and releases it for the formatting operation.
Not thread safe! Do not call this concurrently on different (let alone the same) file system. (For example, FatFS uses static buffers during formatting in some configurations.)
c29cb67
to
29efe9e
Compare
So what's the verdict on this one? |
3778aae
to
f7e5181
Compare
Can't do the full review right now, but seeing #17653 I noticed that (especially in combination) much of the unsightliness of the native/fatfs README can go away (because now fatfs can be formatted just like any other FS) -- to the point where after the two, the section could be gone completely (because all that's left is switching around the FS, and that should be obvious) |
pkg/fatfs/Makefile.dep
Outdated
@@ -1,5 +1,9 @@ | |||
USEMODULE += fatfs_diskio_mtd | |||
USEMODULE += mtd | |||
|
|||
ifneq (,$(filter vfs_auto_format,$(USEMODULE))) | |||
USEMODULE += fatfs_vfs_format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might suffice as d default module (maybe the FAT isn't automounted)
fatfs_desc_t *fs_desc = mountp->private_data; | ||
char volume_str[TEST_FATFS_MAX_VOL_STR_LEN]; | ||
|
||
BYTE *work = malloc(FF_MAX_SS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think now that the warning I sketched above is superfluous as mountpoint-related vfs stuff is behind a mutex anyway (but please verify, I'm on mobile and can't easily read long code here)
[edit because for some reason I can't reply to this particular comment:]
The warning should still be there, for vfs_format
only blocks the mount mutex briefly, and releases it for the formatting operation.
Not thread safe! Do not call this concurrently on different (let alone the same) file system. (For example, FatFS uses static buffers during formatting in some configurations.)
Thanks. Please squash and rebase onto current master, which will enable the changes that I think are suitable in examples/filesystem/REAMDE mergable (probably best fit in a separate commit, but if you prefer squash them right in):
|
FAT now behaves just like all other FSs and does not need special treatment.
7470ce7
to
70d9856
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is ready to be merged. Thank you!
Thank you for pushing this forward! |
Contribution description
This hooks up
vfs_format
tof_mkfs()
.fatfs also provides a
f_fdisk()
function to create a partition table, but this doesn't seem to be necessary.Since pulling in the format logic adds 3.5k
.text
and will not be needed on many applications, it is added as afatfs_vfs_format
pseudo-module.Testing procedure
tests/pkg_fatfs_vfs
will now format the storage before testing, so beware 😉This is consistent with the other file-system tests though.
Issues/PRs references