diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index ee1169b8c3193..6f3582f550660 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -39,6 +39,7 @@ #include #include "py/runtime.h" #include "py/mperrno.h" +#include "py/objstr.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs_fat.h" #include "shared/timeutils/timeutils.h" @@ -378,6 +379,22 @@ static mp_obj_t fat_vfs_statvfs(mp_obj_t vfs_in, mp_obj_t path_in) { } static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_statvfs_obj, fat_vfs_statvfs); +static mp_obj_t fat_vfs_label(mp_obj_t vfs_in, mp_obj_t label_in) { + #ifdef MICROPY_FATFS_USE_LABEL + mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); + const char *label = mp_obj_str_get_str(label_in); + + FRESULT res = f_setlabel(&self->fatfs, label); + + if (FR_OK != res) { + mp_raise_OSError(fresult_to_errno_table[res]); + } + + #endif + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_label_obj, fat_vfs_label); + static mp_obj_t vfs_fat_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs) { fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in); @@ -426,6 +443,7 @@ static const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&fat_vfs_rename_obj) }, { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&fat_vfs_stat_obj) }, { MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&fat_vfs_statvfs_obj) }, + { MP_ROM_QSTR(MP_QSTR_label), MP_ROM_PTR(&fat_vfs_label_obj) }, { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&vfs_fat_mount_obj) }, { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&fat_vfs_umount_obj) }, }; diff --git a/ports/rp2/modules/_boot_fat.py b/ports/rp2/modules/_boot_fat.py index 02d1f99f0daf3..e086a5d9bf31a 100644 --- a/ports/rp2/modules/_boot_fat.py +++ b/ports/rp2/modules/_boot_fat.py @@ -5,9 +5,12 @@ # Try to mount the filesystem, and format the flash if it doesn't exist. bdev = rp2.Flash() try: - vfs.mount(vfs.VfsFat(bdev), "/") + fat = vfs.VfsFat(bdev) + vfs.mount(fat, "/") except: vfs.VfsFat.mkfs(bdev) - vfs.mount(vfs.VfsFat(bdev), "/") + fat = vfs.VfsFat(bdev) + fat.label("RP2_MSC") + vfs.mount(fat, "/") -del vfs, bdev +del vfs, bdev, fat 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