pkg/fatfs: Refactor path handling, minor fixes#8615
pkg/fatfs: Refactor path handling, minor fixes#8615jnohlgard merged 6 commits intoRIOT-OS:masterfrom
Conversation
There was a problem hiding this comment.
Increase FATFS_MAX_VOL_STR_LEN a tiny bit to avoid any possible overflows, fixes a compilation warning/error in GCC 7 about a truncated format string (-Wformat-truncation)
somehow I culdn't reproduce that (using gcc 7.3) and I don't see how 4 is too short for a string like '9:/\0'
sys/include/fs/fatfs.h
Outdated
|
|
||
| /** | ||
| * info of a single opened file | ||
| * @brief info of a single opened file |
There was a problem hiding this comment.
while at it, this could be changed to "FatFs file instance descriptor" for consistency with the above
No, but "10:/\0" is too long. |
one could argue that its unlikely to have >9 fat volumes on a riot device, but who knows... But even then, why 6 and not 5?
With current master I only get the -Wformat-truncation error when reducing FATFS_MAX_VOL_STR_LEN to 3 (while 4 works just fine for me). Thats why I wondered if it's needed at all. |
|
I see this with |
|
the only relevant diff to my setup seems to be the newlib version: Installed toolchain versions
----------------------------
native gcc: gcc (GCC) 7.3.0
msp430-gcc: msp430-gcc (mspgcc_20120406) 4.6.3 20120301 (mspgcc LTS 20120406 unpatched)
avr-gcc: avr-gcc (GCC) 7.3.0
arm-none-eabi-gcc: arm-none-eabi-gcc (Arch Repository) 7.3.0
mips-mti-elf-gcc: mips-mti-elf-gcc (Codescape GNU Tools 2016.05-03 for MIPS MTI Bare Metal) 4.9.2
clang: clang version 5.0.1 (tags/RELEASE_501/final)
arm-none-eabi-newlib: "3.0.0"
mips-mti-elf-newlib: "2.1.0"
avr-libc: "2.0.0" ("20150208")
cppcheck: Cppcheck 1.82
coccinelle: spatch version 1.0.6 compiled with OCaml version 4.05.0
git: git version 2.16.2
|
|
#8614 is merged, so |
|
@basilfx thanks |
Prevents compile time warnings about truncation of the format string for fs_idx > 9
390a901 to
4f5961f
Compare
4f5961f to
0bc2c1b
Compare
|
Rebased, squashed minor editorial doxygen comment fix into the other doxygen commit. |
cladmi
left a comment
There was a problem hiding this comment.
Looks ok, just some questions inline.
I did not tested for the moment.
|
|
||
| char volume_str[FATFS_MAX_VOL_STR_LEN]; | ||
| snprintf(volume_str, sizeof(volume_str), "%d:/", fs_desc->vol_idx); | ||
| _build_abs_path(fs_desc, ""); |
There was a problem hiding this comment.
In this one, you replaced the volume_str by using fs->abs_path_str_buff is it ok to use this one ? Just asking I do not know whet it should be used for.
There was a problem hiding this comment.
fs->abs_path_str_buff is used as a string buffer for building the absolute paths for the library calls in other parts of the VFS wrapper. Since it is already allocated inside the struct, I didn't see any point in adding another string buffer on the stack, even if it is only a few bytes long.
There was a problem hiding this comment.
Ok, from the type definition, it looks like it should be used for this anyway.
| _build_abs_path(fs_desc, from_path); | ||
|
|
||
| snprintf(fatfs_abs_path_to, sizeof(fatfs_abs_path_to), "%d:/%s", | ||
| snprintf(fatfs_abs_path_to, sizeof(fatfs_abs_path_to), "%u:/%s", |
There was a problem hiding this comment.
This format string is duplicated with _build_abs_path. Would it make sense to put the format string in a shared define to remove the magic value in the middle of the functions?
There was a problem hiding this comment.
I guess it could be macroed, but I don't think it is necessary with only two occurrences. Before this PR, the format string was duplicated in all functions.
|
Tested with
|
cladmi
left a comment
There was a problem hiding this comment.
ACK, tested only on native.
| _build_abs_path(fs_desc, from_path); | ||
|
|
||
| snprintf(fatfs_abs_path_to, sizeof(fatfs_abs_path_to), "%d:/%s", | ||
| snprintf(fatfs_abs_path_to, sizeof(fatfs_abs_path_to), "%u:/%s", |
|
|
||
| char volume_str[FATFS_MAX_VOL_STR_LEN]; | ||
| snprintf(volume_str, sizeof(volume_str), "%d:/", fs_desc->vol_idx); | ||
| _build_abs_path(fs_desc, ""); |
There was a problem hiding this comment.
Ok, from the type definition, it looks like it should be used for this anyway.
|
I will test on |
|
Hmm, mulle does not have any @MichelRottleuthner do you have some hardware to test ? |
There was a problem hiding this comment.
No mulle here, but ran tests/pkg_fatfs_vfs and tests/pkg_fatfs with an SD-card on remote-revb both working fine -> another ACK from my side. Thanks for improving the code @gebart!
|
Thanks for reviewing! |
Contribution description
_build_abs_pathfor better maintainabilityFATFS_DIR_SIZE,FATFS_FILE_SIZEFATFS_MAX_VOL_STR_LENa tiny bit to avoid any possible overflows, fixes a compilation warning/error in GCC 7 about a truncated format string (-Wformat-truncation)Issues/PRs references
depends on #8614
contains fix for #8265