From ae2e101c03ae6dc66cf908cb0c84fab002d0e1e3 Mon Sep 17 00:00:00 2001 From: Terence Stenvold Date: Fri, 19 Jul 2024 12:38:44 +0200 Subject: [PATCH 1/4] extmod/vfs_fat: Allow setting label of partition when creating FAT fs --- extmod/vfs_fat.c | 17 +++++++++++++++-- extmod/vfs_fat.h | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 4f01432f54968..373de75d0145e 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -100,7 +100,9 @@ static mp_obj_t fat_vfs_del(mp_obj_t self_in) { static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_del_obj, fat_vfs_del); #endif -static mp_obj_t fat_vfs_mkfs(mp_obj_t bdev_in) { +static mp_obj_t fat_vfs_mkfs(size_t n_args, const mp_obj_t *args) { + mp_obj_t bdev_in = args[0]; + // create new object fs_user_mount_t *vfs = MP_OBJ_TO_PTR(fat_vfs_make_new(&mp_fat_vfs_type, 1, 0, &bdev_in)); @@ -114,9 +116,20 @@ static mp_obj_t fat_vfs_mkfs(mp_obj_t bdev_in) { mp_raise_OSError(fresult_to_errno_table[res]); } + // Set the volume label if provided + if (n_args > 1 && mp_obj_is_str(args[1])) { + const char *label = mp_obj_str_get_str(args[1]); + if (strlen(label) <= MICROPY_VFS_FAT_MAX_LABEL_LENGTH) { + f_setlabel(&vfs->fatfs, label); + } else { + mp_raise_OSError(fresult_to_errno_table[FR_INVALID_PARAMETER]); + } + } + return mp_const_none; } -static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_mkfs_fun_obj, fat_vfs_mkfs); + +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fat_vfs_mkfs_fun_obj, 1, 2, fat_vfs_mkfs); static MP_DEFINE_CONST_STATICMETHOD_OBJ(fat_vfs_mkfs_obj, MP_ROM_PTR(&fat_vfs_mkfs_fun_obj)); typedef struct _mp_vfs_fat_ilistdir_it_t { diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h index 83685b5027b32..017ac5d6bf23e 100644 --- a/extmod/vfs_fat.h +++ b/extmod/vfs_fat.h @@ -30,6 +30,10 @@ #include "lib/oofatfs/ff.h" #include "extmod/vfs.h" +#ifndef MICROPY_VFS_FAT_MAX_LABEL_LENGTH +#define MICROPY_VFS_FAT_MAX_LABEL_LENGTH (8) +#endif + typedef struct _fs_user_mount_t { mp_obj_base_t base; mp_vfs_blockdev_t blockdev; From be81322be159f6bffa60a2096212f64ac5b187dc Mon Sep 17 00:00:00 2001 From: Terence Stenvold Date: Mon, 22 Jul 2024 11:09:53 +0200 Subject: [PATCH 2/4] Revert added define --- extmod/vfs_fat.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h index 017ac5d6bf23e..83685b5027b32 100644 --- a/extmod/vfs_fat.h +++ b/extmod/vfs_fat.h @@ -30,10 +30,6 @@ #include "lib/oofatfs/ff.h" #include "extmod/vfs.h" -#ifndef MICROPY_VFS_FAT_MAX_LABEL_LENGTH -#define MICROPY_VFS_FAT_MAX_LABEL_LENGTH (8) -#endif - typedef struct _fs_user_mount_t { mp_obj_base_t base; mp_vfs_blockdev_t blockdev; From da1ab4baee19d0c3b6779f14eb599c25164b81c3 Mon Sep 17 00:00:00 2001 From: Terence Stenvold Date: Mon, 22 Jul 2024 11:11:41 +0200 Subject: [PATCH 3/4] extmod/vfs_fat: set default label on mkfs for fat --- extmod/vfs_fat.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 373de75d0145e..92d5dbafb96c3 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -100,7 +100,7 @@ static mp_obj_t fat_vfs_del(mp_obj_t self_in) { static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_del_obj, fat_vfs_del); #endif -static mp_obj_t fat_vfs_mkfs(size_t n_args, const mp_obj_t *args) { +static mp_obj_t fat_vfs_mkfs(mp_obj_t bdev_in) { mp_obj_t bdev_in = args[0]; // create new object @@ -116,20 +116,13 @@ static mp_obj_t fat_vfs_mkfs(size_t n_args, const mp_obj_t *args) { mp_raise_OSError(fresult_to_errno_table[res]); } - // Set the volume label if provided - if (n_args > 1 && mp_obj_is_str(args[1])) { - const char *label = mp_obj_str_get_str(args[1]); - if (strlen(label) <= MICROPY_VFS_FAT_MAX_LABEL_LENGTH) { - f_setlabel(&vfs->fatfs, label); - } else { - mp_raise_OSError(fresult_to_errno_table[FR_INVALID_PARAMETER]); - } - } + // Set the volume + f_setlabel(&vfs->fatfs, MICROPY_VFS_FAT_MAX_LABEL_LENGTH); return mp_const_none; } -static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fat_vfs_mkfs_fun_obj, 1, 2, fat_vfs_mkfs); +static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_mkfs_fun_obj, fat_vfs_mkfs); static MP_DEFINE_CONST_STATICMETHOD_OBJ(fat_vfs_mkfs_obj, MP_ROM_PTR(&fat_vfs_mkfs_fun_obj)); typedef struct _mp_vfs_fat_ilistdir_it_t { From 8c52f66b626675c130fdc8e2e613026a50a70da5 Mon Sep 17 00:00:00 2001 From: Terence Stenvold Date: Mon, 22 Jul 2024 11:14:38 +0200 Subject: [PATCH 4/4] extmod/vfs_fat: Use FS label in mkfs Correcting using the wrong def --- extmod/vfs_fat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 92d5dbafb96c3..e7b44656e7f5e 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -117,7 +117,7 @@ static mp_obj_t fat_vfs_mkfs(mp_obj_t bdev_in) { } // Set the volume - f_setlabel(&vfs->fatfs, MICROPY_VFS_FAT_MAX_LABEL_LENGTH); + f_setlabel(&vfs->fatfs, MICROPY_HW_FLASH_FS_LABEL); return mp_const_none; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy