Skip to content

Commit

Permalink
windows: Switch to VFS subsystem and use VfsPosix.
Browse files Browse the repository at this point in the history
Following the unix port.

Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Mar 9, 2022
1 parent 2b409ef commit 0149cd6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
13 changes: 13 additions & 0 deletions extmod/vfs_posix.c
Expand Up @@ -37,6 +37,9 @@
#include <string.h>
#include <sys/stat.h>
#include <dirent.h>
#ifdef _MSC_VER
#include <direct.h> // For mkdir etc.
#endif

typedef struct _mp_obj_vfs_posix_t {
mp_obj_base_t base;
Expand Down Expand Up @@ -254,7 +257,11 @@ STATIC mp_obj_t vfs_posix_mkdir(mp_obj_t self_in, mp_obj_t path_in) {
mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in);
const char *path = vfs_posix_get_path_str(self, path_in);
MP_THREAD_GIL_EXIT();
#ifdef _WIN32
int ret = mkdir(path);
#else
int ret = mkdir(path, 0777);
#endif
MP_THREAD_GIL_ENTER();
if (ret != 0) {
mp_raise_OSError(errno);
Expand Down Expand Up @@ -308,6 +315,8 @@ STATIC mp_obj_t vfs_posix_stat(mp_obj_t self_in, mp_obj_t path_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_stat_obj, vfs_posix_stat);

#if MICROPY_PY_UOS_STATVFS

#ifdef __ANDROID__
#define USE_STATFS 1
#endif
Expand Down Expand Up @@ -349,6 +358,8 @@ STATIC mp_obj_t vfs_posix_statvfs(mp_obj_t self_in, mp_obj_t path_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_statvfs_obj, vfs_posix_statvfs);

#endif

STATIC const mp_rom_map_elem_t vfs_posix_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&vfs_posix_mount_obj) },
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&vfs_posix_umount_obj) },
Expand All @@ -362,7 +373,9 @@ STATIC const mp_rom_map_elem_t vfs_posix_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&vfs_posix_rename_obj) },
{ MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&vfs_posix_rmdir_obj) },
{ MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&vfs_posix_stat_obj) },
#if MICROPY_PY_UOS_STATVFS
{ MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&vfs_posix_statvfs_obj) },
#endif
};
STATIC MP_DEFINE_CONST_DICT(vfs_posix_locals_dict, vfs_posix_locals_dict_table);

Expand Down
1 change: 0 additions & 1 deletion ports/windows/Makefile
Expand Up @@ -49,7 +49,6 @@ SRC_C = \
shared/runtime/gchelper_generic.c \
ports/unix/main.c \
ports/unix/input.c \
ports/unix/modos.c \
ports/unix/modmachine.c \
ports/unix/modtime.c \
ports/unix/gccollect.c \
Expand Down
1 change: 0 additions & 1 deletion ports/windows/micropython.vcxproj
Expand Up @@ -93,7 +93,6 @@
<ClCompile Include="$(PyBaseDir)ports\unix\gccollect.c"/>
<ClCompile Include="$(PyBaseDir)ports\unix\input.c"/>
<ClCompile Include="$(PyBaseDir)ports\unix\main.c"/>
<ClCompile Include="$(PyBaseDir)ports\unix\modos.c"/>
<ClCompile Include="$(PyBaseDir)ports\unix\modtime.c"/>
<ClCompile Include="$(PyBaseDir)ports\unix\modmachine.c" />
<ClCompile Include="$(PyVariantDir)*.c" />
Expand Down
16 changes: 13 additions & 3 deletions ports/windows/mpconfigport.h
Expand Up @@ -51,6 +51,7 @@
#define MICROPY_DEBUG_PRINTER (&mp_stderr_print)
#define MICROPY_DEBUG_PRINTERS (1)
#define MICROPY_READER_POSIX (1)
#define MICROPY_READER_VFS (1)
#define MICROPY_USE_READLINE_HISTORY (1)
#define MICROPY_HELPER_REPL (1)
#define MICROPY_REPL_EMACS_KEYS (1)
Expand All @@ -72,7 +73,8 @@
#ifndef MICROPY_ENABLE_SCHEDULER
#define MICROPY_ENABLE_SCHEDULER (1)
#endif
#define MICROPY_VFS_POSIX_FILE (1)
#define MICROPY_VFS (1)
#define MICROPY_VFS_POSIX (1)
#define MICROPY_PY_FUNCTION_ATTRS (1)
#define MICROPY_PY_DESCRIPTORS (1)
#define MICROPY_PY_DELATTR_SETATTR (1)
Expand Down Expand Up @@ -124,6 +126,14 @@
#define MICROPY_STACKLESS_STRICT (0)
#endif

#define MICROPY_PY_UOS (1)
#define MICROPY_PY_UOS_INCLUDEFILE "ports/unix/moduos.c"
#define MICROPY_PY_UOS_ERRNO (1)
#define MICROPY_PY_UOS_GETENV_PUTENV_UNSETENV (1)
#define MICROPY_PY_UOS_SEP (1)
#define MICROPY_PY_UOS_STATVFS (0)
#define MICROPY_PY_UOS_SYSTEM (1)
#define MICROPY_PY_UOS_URANDOM (1)
#define MICROPY_PY_UTIME (1)
#define MICROPY_PY_UTIME_MP_HAL (1)
#define MICROPY_PY_UERRNO (1)
Expand Down Expand Up @@ -161,6 +171,8 @@ extern const struct _mp_print_t mp_stderr_print;
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (256)
#define MICROPY_KBD_EXCEPTION (1)

#define mp_import_stat mp_vfs_import_stat
#define mp_builtin_open_obj mp_vfs_open_obj
#define mp_type_fileio mp_type_vfs_posix_fileio
#define mp_type_textio mp_type_vfs_posix_textio

Expand Down Expand Up @@ -203,11 +215,9 @@ typedef long mp_off_t;
#define MICROPY_PORT_BUILTINS \
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },

extern const struct _mp_obj_module_t mp_module_os;
extern const struct _mp_obj_module_t mp_module_time;
#define MICROPY_PORT_BUILTIN_MODULES \
{ MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_time) }, \
{ MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_os) }, \

#if MICROPY_USE_READLINE == 1
#define MICROPY_PORT_ROOT_POINTERS \
Expand Down
4 changes: 4 additions & 0 deletions ports/windows/msvc/sources.props
Expand Up @@ -13,14 +13,18 @@
<PyExtModSource Include="$(PyBaseDir)extmod\moduhashlib.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\moduheapq.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\modujson.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\moduos.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\modurandom.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\modure.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\moduselect.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\modutimeq.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\moduzlib.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\utime_mphal.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\virtpin.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\vfs.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\vfs_posix.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\vfs_posix_file.c" />
<PyExtModSource Include="$(PyBaseDir)extmod\vfs_reader.c" />
</ItemGroup>
<ItemGroup>
<PyCoreInclude Include="$(PyBaseDir)py\*.h" />
Expand Down
4 changes: 4 additions & 0 deletions py/mpconfig.h
Expand Up @@ -1459,6 +1459,10 @@ typedef double mp_float_t;
#define MICROPY_PY_UOS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
#endif

#ifndef MICROPY_PY_UOS_STATVFS
#define MICROPY_PY_UOS_STATVFS (MICROPY_PY_UOS)
#endif

#ifndef MICROPY_PY_URE
#define MICROPY_PY_URE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
#endif
Expand Down

0 comments on commit 0149cd6

Please sign in to comment.