Start on vfs_mac

This commit is contained in:
Jeff Epler 2025-06-28 14:29:21 +02:00
parent 8293b7a9eb
commit dabaf8451f
8 changed files with 95 additions and 41 deletions

View file

@ -214,6 +214,9 @@ static const mp_rom_map_elem_t os_module_globals_table[] = {
#if MICROPY_VFS_POSIX
{ MP_ROM_QSTR(MP_QSTR_VfsPosix), MP_ROM_PTR(&mp_type_vfs_posix) },
#endif
#if defined(MICROPY_VFS_PORT)
MICROPY_VFS_PORT,
#endif
#endif
#if MICROPY_MBFS

View file

@ -42,9 +42,7 @@
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#if MICROPY_VFS_POSIX_DIRENT
#include <dirent.h>
#endif
#ifdef _MSC_VER
#include <direct.h> // For mkdir etc.
#endif
@ -200,7 +198,6 @@ static mp_obj_t vfs_posix_getcwd(mp_obj_t self_in) {
}
static MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_getcwd_obj, vfs_posix_getcwd);
#if MICROPY_VFS_POSIX_DIRENT
typedef struct _vfs_posix_ilistdir_it_t {
mp_obj_base_t base;
mp_fun_1_t iternext;
@ -278,10 +275,8 @@ static mp_obj_t vfs_posix_ilistdir_it_del(mp_obj_t self_in) {
}
return mp_const_none;
}
#endif
static mp_obj_t vfs_posix_ilistdir(mp_obj_t self_in, mp_obj_t path_in) {
#if MICROPY_VFS_POSIX_DIRENT
mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in);
vfs_posix_ilistdir_it_t *iter = mp_obj_malloc_with_finaliser(vfs_posix_ilistdir_it_t, &mp_type_polymorph_iter_with_finaliser);
iter->iternext = vfs_posix_ilistdir_it_iternext;
@ -298,18 +293,13 @@ static mp_obj_t vfs_posix_ilistdir(mp_obj_t self_in, mp_obj_t path_in) {
mp_raise_OSError(errno);
}
return MP_OBJ_FROM_PTR(iter);
#else
mp_raise_OSError(EINVAL);
#endif
}
static MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_ilistdir_obj, vfs_posix_ilistdir);
typedef struct _mp_obj_listdir_t {
mp_obj_base_t base;
mp_fun_1_t iternext;
#if MICROPY_VFS_POSIX_DIRENT
DIR *dir;
#endif
} mp_obj_listdir_t;
static mp_obj_t vfs_posix_mkdir(mp_obj_t self_in, mp_obj_t path_in) {

View file

@ -38,6 +38,8 @@ LIBS =
SRC_C = \
main.c \
vfs_mac.c \
macutil.c \
SRC_C += \
$(BUILD)/_frozen_mpy.c \
@ -56,6 +58,7 @@ SRC_S += \
shared/runtime/gchelper_m68k.S \
SRC_QSTR += \
vfs_mac.c \
shared/readline/readline.c \
shared/runtime/pyexec.c \

6
ports/m68kmac/macutil.c Normal file
View file

@ -0,0 +1,6 @@
#include <py/runtime.h>
#include "macutil.h"
mp_obj_t new_str_from_pstr(Byte *pStr) {
return mp_obj_new_str((const char *)pStr + 1, *pStr);
}

4
ports/m68kmac/macutil.h Normal file
View file

@ -0,0 +1,4 @@
#include <py/obj.h>
#include "Multiverse.h"
extern mp_obj_t new_str_from_pstr(Byte *pStr);

View file

@ -118,33 +118,6 @@ void MP_NORETURN __fatal_error(const char *msg) {
}
}
char *getcwd(char buf[], size_t size) {
snprintf(buf, size, "/");
return buf;
}
int mkdir(const char *pathname) {
errno = -EINVAL;
return -1;
}
int rmdir(const char *pathname) {
errno = -EINVAL;
return -1;
}
int chdir(const char *pathname) {
if (strcmp(pathname, "/") == 0 || strcmp(pathname, ".") == 0 || strcmp(pathname, "") == 0) {
return 0;
}
errno = -ENOENT;
return -1;
}
int fsync(int fd) {
return 0;
}
#ifndef NDEBUG
void MP_WEAK __assert_func(const char *file, int line, const char *func, const char *expr) {
printf("Assertion '%s' failed, at file %s:%d\n", expr, file, line);

View file

@ -23,12 +23,10 @@
#define MICROPY_STACK_CHECK (0)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
#define MICROPY_READER_POSIX (1)
#define MICROPY_READER_POSIX (0)
#define MICROPY_READER_VFS (1)
#define MICROPY_VFS (1)
#define MICROPY_VFS_POSIX (1)
#define MICROPY_PY_OS_STATVFS (0)
#define MICROPY_VFS_POSIX_DIRENT (0)
#define MP_SSIZE_MAX LONG_MAX
@ -46,10 +44,14 @@ typedef long mp_off_t;
// We need to provide a declaration/definition of alloca()
#include <alloca.h>
#define MICROPY_HW_BOARD_NAME "minimal"
#define MICROPY_HW_BOARD_NAME "macplus"
#define MICROPY_HW_MCU_NAME "m68000"
#define MICROPY_MIN_USE_STDOUT (0)
#define MICROPY_HEAP_SIZE (100 * 1024)
#define MP_STATE_PORT MP_STATE_VM
typedef struct _mp_obj_type_t mp_obj_type_t;
extern const mp_obj_type_t mp_type_vfs_mac;
#define MICROPY_VFS_PORT { MP_ROM_QSTR(MP_QSTR_VfsMac), MP_ROM_PTR(&mp_type_vfs_mac) }

73
ports/m68kmac/vfs_mac.c Normal file
View file

@ -0,0 +1,73 @@
#include "py/mpconfig.h"
#include "py/obj.h"
#include "py/runtime.h"
#include "extmod/vfs.h"
#include "macutil.h"
typedef struct _mp_obj_vfs_mac_t {
mp_obj_base_t base;
vstr_t root;
size_t root_len;
bool readonly;
} mp_obj_vfs_mac_t;
static mp_obj_t vfs_mac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 1, 1, false);
// create new object
mp_obj_vfs_mac_t *vfs = mp_obj_malloc(mp_obj_vfs_mac_t, type);
return MP_OBJ_FROM_PTR(vfs);
}
static mp_obj_t volumes(mp_obj_t self_in) {
mp_obj_t result = mp_obj_list_make_new(&mp_type_list, 0, 0, NULL);
VCB *vol = (VCB *)LMGetVCBQHdr().qHead;
mp_obj_t args[3];
mp_load_method(result, MP_QSTR_append, args);
while (vol) {
args[2] = new_str_from_pstr(vol->vcbVN + 1);
mp_call_method_n_kw(1, 0, args);
vol = (VCB *)vol->qLink;
}
return result;
}
MP_DEFINE_CONST_FUN_OBJ_1(volumes_obj, volumes);
static const mp_rom_map_elem_t vfs_mac_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_volumes), MP_ROM_PTR(&volumes_obj) },
#if 0
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&vfs_mac_mount_obj) },
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&vfs_mac_umount_obj) },
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&vfs_mac_open_obj) },
{ MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&vfs_mac_chdir_obj) },
{ MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&vfs_mac_getcwd_obj) },
{ MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&vfs_mac_ilistdir_obj) },
{ MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&vfs_mac_mkdir_obj) },
{ MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&vfs_mac_remove_obj) },
{ MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&vfs_mac_rename_obj) },
{ MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&vfs_mac_rmdir_obj) },
{ MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&vfs_mac_stat_obj) },
#if MICROPY_PY_OS_STATVFS
{ MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&vfs_mac_statvfs_obj) },
#endif
#endif
};
static MP_DEFINE_CONST_DICT(vfs_mac_locals_dict, vfs_mac_locals_dict_table);
static const mp_vfs_proto_t vfs_mac_proto = {
#if 0
.import_stat = mp_vfs_mac_import_stat,
#endif
};
MP_DEFINE_CONST_OBJ_TYPE(
mp_type_vfs_mac,
MP_QSTR_VfsMac,
MP_TYPE_FLAG_NONE,
make_new, vfs_mac_make_new,
protocol, &vfs_mac_proto,
locals_dict, &vfs_mac_locals_dict
);