From b4a97db94822a5614e28641e57aeda95952370c8 Mon Sep 17 00:00:00 2001 From: uyjulian Date: Fri, 19 Aug 2022 23:10:56 -0500 Subject: [PATCH 1/2] bdmfs_fatfs: Copy unmodified filename into modified buffer --- iop/fs/bdmfs_fatfs/src/fs_driver.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/iop/fs/bdmfs_fatfs/src/fs_driver.c b/iop/fs/bdmfs_fatfs/src/fs_driver.c index d73a6340bb3..025472a8fc1 100644 --- a/iop/fs/bdmfs_fatfs/src/fs_driver.c +++ b/iop/fs/bdmfs_fatfs/src/fs_driver.c @@ -34,16 +34,26 @@ fatfs_fs_driver_mount_info fs_driver_mount_info[FF_VOLUMES]; // Macros for defining the modified path on stack. #define FATFS_FS_DRIVER_NAME_ALLOC_ON_STACK_DEFINITIONS(varname) \ - int strlen_##varname; \ - char *modified_##varname; + const char *modified_##varname; #define FATFS_FS_DRIVER_NAME_ALLOC_ON_STACK_IMPLEMENTATION(varname, fd) \ - strlen_##varname = strlen(varname); \ - modified_##varname = __builtin_alloca(3 + strlen_##varname + 1); \ - modified_##varname[0] = '0' + (fd)->unit; \ - modified_##varname[1] = ':'; \ - modified_##varname[2] = '/'; \ - modified_##varname[3 + strlen_##varname] = '\x00'; + { \ + { \ + int strlen_##varname; \ + char *modified_scope_##varname; \ + \ + strlen_##varname = strlen(varname); \ + modified_scope_##varname = __builtin_alloca(3 + strlen_##varname + 1); \ + modified_scope_##varname[0] = '0' + (fd)->unit; \ + modified_scope_##varname[1] = ':'; \ + modified_scope_##varname[2] = '/'; \ + memcpy((modified_scope_##varname) + 3, varname, strlen_##varname); \ + modified_scope_##varname[3 + strlen_##varname] = '\x00'; \ + modified_##varname = modified_scope_##varname; \ + } \ + } + + //--------------------------------------------------------------------------- static int _fs_lock_sema_id = -1; From ec76e667bc341d5fcc491d5217af39cc1b2ce0ad Mon Sep 17 00:00:00 2001 From: uyjulian Date: Fri, 19 Aug 2022 23:15:23 -0500 Subject: [PATCH 2/2] bdmfs_fatfs: Avoid unnecesary allocation on device 0 --- iop/fs/bdmfs_fatfs/src/fs_driver.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/iop/fs/bdmfs_fatfs/src/fs_driver.c b/iop/fs/bdmfs_fatfs/src/fs_driver.c index 025472a8fc1..a3b6e8ee519 100644 --- a/iop/fs/bdmfs_fatfs/src/fs_driver.c +++ b/iop/fs/bdmfs_fatfs/src/fs_driver.c @@ -38,6 +38,7 @@ fatfs_fs_driver_mount_info fs_driver_mount_info[FF_VOLUMES]; #define FATFS_FS_DRIVER_NAME_ALLOC_ON_STACK_IMPLEMENTATION(varname, fd) \ { \ + if ((fd)->unit != 0) \ { \ int strlen_##varname; \ char *modified_scope_##varname; \ @@ -51,6 +52,10 @@ fatfs_fs_driver_mount_info fs_driver_mount_info[FF_VOLUMES]; modified_scope_##varname[3 + strlen_##varname] = '\x00'; \ modified_##varname = modified_scope_##varname; \ } \ + else \ + { \ + modified_##varname = varname; \ + } \ }