Skip to content

ports/rp2: Add a means to set mass-storage filesystem label #13470

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions extmod/vfs_fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <string.h>
#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"
Expand Down Expand Up @@ -378,6 +379,22 @@
}
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;

Check warning on line 394 in extmod/vfs_fat.c

View check run for this annotation

Codecov / codecov/patch

extmod/vfs_fat.c#L394

Added line #L394 was not covered by tests
}
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);

Expand Down Expand Up @@ -426,6 +443,7 @@
{ 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) },
};
Expand Down
9 changes: 6 additions & 3 deletions ports/rp2/modules/_boot_fat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading
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