Skip to content

Commit 89e6c58

Browse files
committed
extmod/modvfs: Add vfs.rom_ioctl function and its ioctl constants.
This is a generic interface to allow querying and modifying the read-only memory area of a device, if it has such an area. Signed-off-by: Damien George <damien@micropython.org>
1 parent 9dd4cef commit 89e6c58

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

extmod/modvfs.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,18 @@
3838
#error "MICROPY_PY_VFS requires MICROPY_VFS"
3939
#endif
4040

41+
#if MICROPY_VFS_ROM_IOCTL
42+
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_vfs_rom_ioctl_obj, 1, 4, mp_vfs_rom_ioctl);
43+
#endif
44+
4145
static const mp_rom_map_elem_t vfs_module_globals_table[] = {
4246
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_vfs) },
4347

4448
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) },
4549
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) },
50+
#if MICROPY_VFS_ROM_IOCTL
51+
{ MP_ROM_QSTR(MP_QSTR_rom_ioctl), MP_ROM_PTR(&mp_vfs_rom_ioctl_obj) },
52+
#endif
4653
#if MICROPY_VFS_FAT
4754
{ MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) },
4855
#endif

extmod/vfs.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@
5252
#define MP_BLOCKDEV_IOCTL_BLOCK_SIZE (5)
5353
#define MP_BLOCKDEV_IOCTL_BLOCK_ERASE (6)
5454

55+
// Constants for vfs.rom_ioctl() function.
56+
#define MP_VFS_ROM_IOCTL_GET_NUMBER_OF_SEGMENTS (1) // rom_ioctl(1)
57+
#define MP_VFS_ROM_IOCTL_GET_SEGMENT (2) // rom_ioctl(2, <id>)
58+
#define MP_VFS_ROM_IOCTL_WRITE_PREPARE (3) // rom_ioctl(3, <id>, <len>)
59+
#define MP_VFS_ROM_IOCTL_WRITE (4) // rom_ioctl(4, <id>, <offset>, <buf>)
60+
#define MP_VFS_ROM_IOCTL_WRITE_COMPLETE (5) // rom_ioctl(5, <id>)
61+
5562
// At the moment the VFS protocol just has import_stat, but could be extended to other methods
5663
typedef struct _mp_vfs_proto_t {
5764
mp_import_stat_t (*import_stat)(void *self, const char *path);
@@ -122,4 +129,12 @@ MP_DECLARE_CONST_FUN_OBJ_1(mp_vfs_rmdir_obj);
122129
MP_DECLARE_CONST_FUN_OBJ_1(mp_vfs_stat_obj);
123130
MP_DECLARE_CONST_FUN_OBJ_1(mp_vfs_statvfs_obj);
124131

132+
#if MICROPY_VFS_ROM_IOCTL
133+
// When MICROPY_VFS_ROM_IOCTL is enabled a port must define the following function.
134+
// This is a generic interface to allow querying and modifying the user-accessible,
135+
// read-only memory area of a device, if it is configured with such an area.
136+
// Supported ioctl commands are given by MP_VFS_ROM_IOCTL_xxx.
137+
mp_obj_t mp_vfs_rom_ioctl(size_t n_args, const mp_obj_t *args);
138+
#endif
139+
125140
#endif // MICROPY_INCLUDED_EXTMOD_VFS_H

ports/qemu/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#define MICROPY_PY_MACHINE_PIN_BASE (1)
6565
#define MICROPY_VFS (1)
6666
#define MICROPY_VFS_ROM (1)
67+
#define MICROPY_VFS_ROM_IOCTL (0)
6768

6869
// type definitions for the specific machine
6970

ports/unix/variants/mpconfigvariant_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,4 @@
123123
#define MICROPY_PY_MACHINE_PIN_BASE (1)
124124

125125
#define MICROPY_VFS_ROM (1)
126+
#define MICROPY_VFS_ROM_IOCTL (0)

py/mpconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,11 @@ typedef double mp_float_t;
10061006
#define MICROPY_VFS_WRITABLE (1)
10071007
#endif
10081008

1009+
// Whether to enable the mp_vfs_rom_ioctl C function, and vfs.rom_ioctl Python function
1010+
#ifndef MICROPY_VFS_ROM_IOCTL
1011+
#define MICROPY_VFS_ROM_IOCTL (MICROPY_VFS_ROM)
1012+
#endif
1013+
10091014
// Support for VFS POSIX component, to mount a POSIX filesystem within VFS
10101015
#ifndef MICROPY_VFS_POSIX
10111016
#define MICROPY_VFS_POSIX (0)

0 commit comments

Comments
 (0)
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