8000 windows: Switch to VFS subsystem and use VfsPosix. · micropython/micropython@313c575 · GitHub
[go: up one dir, main page]

Skip to content

Commit 313c575

Browse files
committed
windows: Switch to VFS subsystem and use VfsPosix.
Following the unix port. Signed-off-by: Damien George <damien@micropython.org>
1 parent 2b409ef commit 313c575

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

extmod/vfs_posix.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
#include <string.h>
3838
#include <sys/stat.h>
3939
#include <dirent.h>
40+
#ifdef _MSC_VER
41+
#include <direct.h> // For mkdir etc.
42+
#endif
4043

4144
typedef struct _mp_obj_vfs_posix_t {
4245
mp_obj_base_t base;
@@ -254,7 +257,11 @@ STATIC mp_obj_t vfs_posix_mkdir(mp_obj_t self_in, mp_obj_t path_in) {
254257
mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in);
255258
const char *path = vfs_posix_get_path_str(self, path_in);
256259
MP_THREAD_GIL_EXIT();
260+
#ifdef _MSC_VER
261+
int ret = mkdir(path);
262+
#else
257263
int ret = mkdir(path, 0777);
264+
#endif
258265
MP_THREAD_GIL_ENTER();
259266
if (ret != 0) {
260267
mp_raise_OSError(errno);
@@ -308,6 +315,8 @@ STATIC mp_obj_t vfs_posix_stat(mp_obj_t self_in, mp_obj_t path_in) {
308315
}
309316
STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_stat_obj, vfs_posix_stat);
310317

318+
#if MICROPY_PY_UOS_STATVFS
319+
311320
#ifdef __ANDROID__
312321
#define USE_STATFS 1
313322
#endif
@@ -349,6 +358,8 @@ STATIC mp_obj_t vfs_posix_statvfs(mp_obj_t self_in, mp_obj_t path_in) {
349358
}
350359
STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_statvfs_obj, vfs_posix_statvfs);
351360

361+
#endif
362+
352363
STATIC const mp_rom_map_elem_t vfs_posix_locals_dict_table[] = {
353364
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&vfs_posix_mount_obj) },
354365
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&vfs_posix_umount_obj) },
@@ -362,7 +373,9 @@ STATIC const mp_rom_map_elem_t vfs_posix_locals_dict_table[] = {
362373
{ MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&vfs_posix_rename_obj) },
363374
{ MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&vfs_posix_rmdir_obj) },
364375
{ MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&vfs_posix_stat_obj) },
376+
#if MICROPY_PY_UOS_STATVFS
365377
{ MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&vfs_posix_statvfs_obj) },
378+
#endif
366379
};
367380
STATIC MP_DEFINE_CONST_DICT(vfs_posix_locals_dict, vfs_posix_locals_dict_table);
368381

ports/windows/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ SRC_C = \
4949
shared/runtime/gchelper_generic.c \
5050
ports/unix/main.c \
5151
ports/unix/input.c \
52-
ports/unix/modos.c \
5352
ports/unix/modmachine.c \
5453
ports/unix/modtime.c \
5554
ports/unix/gccollect.c \

ports/windows/micropython.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
<ClCompile Include="$(PyBaseDir)ports\unix\gccollect.c"/>
9494
<ClCompile Include="$(PyBaseDir)ports\unix\input.c"/>
9595
<ClCompile Include="$(PyBaseDir)ports\unix\main.c"/>
96-
<ClCompile Include="$(PyBaseDir)ports\unix\modos.c"/>
9796
<ClCompile Include="$(PyBaseDir)ports\unix\modtime.c"/>
9897
<ClCompile Include="$(PyBaseDir)ports\unix\modmachine.c" />
9998
<ClCompile Include="$(PyVariantDir)*.c" />

ports/windows/mpconfigport.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#define MICROPY_DEBUG_PRINTER (&mp_stderr_print)
5252
#define MICROPY_DEBUG_PRINTERS (1)
5353
#define MICROPY_READER_POSIX (1)
54+
#define MICROPY_READER_VFS (1)
5455
#define MICROPY_USE_READLINE_HISTORY (1)
5556
#define MICROPY_HELPER_REPL (1)
5657
#define MICROPY_REPL_EMACS_KEYS (1)
@@ -72,7 +73,8 @@
7273
#ifndef MICROPY_ENABLE_SCHEDULER
7374
#define MICROPY_ENABLE_SCHEDULER (1)
7475
#endif
75-
#define MICROPY_VFS_POSIX_FILE (1)
76+
#define MICROPY_VFS (1)
77+
#define MICROPY_VFS_POSIX (1)
7678
#define MICROPY_PY_FUNCTION_ATTRS (1)
7779
#define MICROPY_PY_DESCRIPTORS (1)
7880
#define MICROPY_PY_DELATTR_SETATTR (1)
@@ -124,6 +126,14 @@
124126
#define MICROPY_STACKLESS_STRICT (0)
125127
#endif
126128

129+
#define MICROPY_PY_UOS (1)
130+
#define MICROPY_PY_UOS_INCLUDEFILE "ports/unix/moduos.c"
131+
#define MICROPY_PY_UOS_ERRNO (1)
132+
#define MICROPY_PY_UOS_GETENV_PUTENV_UNSETENV (1)
133+
#define MICROPY_PY_UOS_SEP (1)
134+
#define MICROPY_PY_UOS_STATVFS (0)
135+
#define MICROPY_PY_UOS_SYSTEM (1)
136+
#define MICROPY_PY_UOS_URANDOM (1)
127137
#define MICROPY_PY_UTIME (1)
128138
#define MICROPY_PY_UTIME_MP_HAL (1)
129139
#define MICROPY_PY_UERRNO (1)
@@ -161,6 +171,8 @@ extern const struct _mp_print_t mp_stderr_print;
161171
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (256)
162172
#define MICROPY_KBD_EXCEPTION (1)
163173

174+
#define mp_import_stat mp_vfs_import_stat
175+
#define mp_builtin_open_obj mp_vfs_open_obj
164176
#define mp_type_fileio mp_type_vfs_posix_fileio
165177
#define mp_type_textio mp_type_vfs_posix_textio
166178

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

206-
extern const struct _mp_obj_module_t mp_module_os;
207218
extern const struct _mp_obj_module_t mp_module_time;
208219
#define MICROPY_PORT_BUILTIN_MODULES \
209220
{ MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_time) }, \
210-
{ MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_os) }, \
211221

212222
#if MICROPY_USE_READLINE == 1
213223
#define MICROPY_PORT_ROOT_POINTERS \

ports/windows/msvc/sources.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@
1313
<PyExtModSource Include="$(PyBaseDir)extmod\moduhashlib.c" />
1414
<PyExtModSource Include="$(PyBaseDir)extmod\moduheapq.c" />
1515
<PyExtModSource Include="$(PyBaseDir)extmod\modujson.c" />
16+
<PyExtModSource Include="$(PyBaseDir)extmod\moduos.c" />
1617
<PyExtModSource Include="$(PyBaseDir)extmod\modurandom.c" />
1718
<PyExtModSource Include="$(PyBaseDir)extmod\modure.c" />
1819
<PyExtModSource Include="$(PyBaseDir)extmod\moduselect.c" />
1920
<PyExtModSource Include="$(PyBaseDir)extmod\modutimeq.c" />
2021
<PyExtModSource Include="$(PyBaseDir)extmod\moduzlib.c" />
2122
<PyExtModSource Include="$(PyBaseDir)extmod\utime_mphal.c" />
2223
<PyExtModSource Include="$(PyBaseDir)extmod\virtpin.c" />
24+
<PyExtModSource Include="$(PyBaseDir)extmod\vfs.c" />
25+
<PyExtModSource Include="$(PyBaseDir)extmod\vfs_posix.c" />
2326
<PyExtModSource Include="$(PyBaseDir)extmod\vfs_posix_file.c" />
27+
<PyExtModSource Include="$(PyBaseDir)extmod\vfs_reader.c" />
2428
</ItemGroup>
2529
<ItemGroup>
2630
<PyCoreInclude Include="$(PyBaseDir)py\*.h" />

py/mpconfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,10 @@ typedef double mp_float_t;
14591459
#define MICROPY_PY_UOS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
14601460
#endif
14611461

1462+
#ifndef MICROPY_PY_UOS_STATVFS
1463+
#define MICROPY_PY_UOS_STATVFS (MICROPY_PY_UOS)
1464+
#endif
1465+
14621466
#ifndef MICROPY_PY_URE
14631467
#define MICROPY_PY_URE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
14641468
#endif

0 commit comments

Comments
 (0)
0