Просмотр исходного кода

Merge pull request #9 from SummerGGift/2018_1_17

update uos functiion
朱天龙 (Armink) 8 лет назад
Родитель
Сommit
d5cad4e0f2
6 измененных файлов с 342 добавлено и 47 удалено
  1. 7 7
      port/genhdr/qstrdefs.generated.h
  2. 25 38
      port/moduos.c
  3. 226 0
      port/moduos_file.c
  4. 69 0
      port/moduos_file.h
  5. 8 2
      port/mpconfigport.h
  6. 7 0
      py/mpstate.h

+ 7 - 7
port/genhdr/qstrdefs.generated.h

@@ -497,6 +497,13 @@ QDEF(MP_QSTR_uselect, (const byte*)"\x58\x07" "uselect")
 QDEF(MP_QSTR_writeblocks, (const byte*)"\x02\x0b" "writeblocks")
 QDEF(MP_QSTR_writebyte, (const byte*)"\xd2\x09" "writebyte")
 QDEF(MP_QSTR_tell, (const byte*)"\x14\x04" "tell")
+QDEF(MP_QSTR_listdir, (const byte*)"\x98\x07" "listdir")
+QDEF(MP_QSTR_ilistdir, (const byte*)"\x71\x08" "ilistdir")
+QDEF(MP_QSTR_mkdir, (const byte*)"\x9c\x05" "mkdir")
+QDEF(MP_QSTR_VfsFat, (const byte*)"\x15\x06" "VfsFat")
+QDEF(MP_QSTR_rename, (const byte*)"\x35\x06" "rename")
+QDEF(MP_QSTR_rmdir, (const byte*)"\x45\x05" "rmdir")
+QDEF(MP_QSTR_mkfs, (const byte*)"\x76\x04" "mkfs")
 
 // This file was automatically generated by makeqstrdata.py
 
@@ -1381,7 +1388,6 @@ QDEF(MP_QSTR_UP, (const byte*)"\xa0\x73\x02" "UP")
 QDEF(MP_QSTR_USB_HID, (const byte*)"\x5b\xb6\x07" "USB_HID")
 QDEF(MP_QSTR_USB_VCP, (const byte*)"\x1b\x8a\x07" "USB_VCP")
 QDEF(MP_QSTR_VCP, (const byte*)"\x40\xf6\x03" "VCP")
-QDEF(MP_QSTR_VfsFat, (const byte*)"\x15\x9b\x06" "VfsFat")
 QDEF(MP_QSTR_ViperTypeError, (const byte*)"\xdd\x05\x0e" "ViperTypeError")
 QDEF(MP_QSTR_WDT, (const byte*)"\x62\x03\x03" "WDT")
 QDEF(MP_QSTR___aenter__, (const byte*)"\x4c\x84\x0a" "__aenter__")
@@ -1437,7 +1443,6 @@ QDEF(MP_QSTR_heapq, (const byte*)"\x68\x1d\x05" "heapq")
 QDEF(MP_QSTR_hid, (const byte*)"\xe0\x4f\x03" "hid")
 QDEF(MP_QSTR_hid_keyboard, (const byte*)"\x92\xb1\x0c" "hid_keyboard")
 QDEF(MP_QSTR_hid_mouse, (const byte*)"\x3e\x1e\x09" "hid_mouse")
-QDEF(MP_QSTR_ilistdir, (const byte*)"\x71\x6a\x08" "ilistdir")
 QDEF(MP_QSTR_implementation, (const byte*)"\x17\x2d\x0e" "implementation")
 QDEF(MP_QSTR_initfilterbanks, (const byte*)"\x2a\x2b\x0f" "initfilterbanks")
 QDEF(MP_QSTR_intensity, (const byte*)"\xca\x3d\x09" "intensity")
@@ -1452,7 +1457,6 @@ QDEF(MP_QSTR_label, (const byte*)"\x43\xe7\x05" "label")
 QDEF(MP_QSTR_ldr, (const byte*)"\x5f\x40\x03" "ldr")
 QDEF(MP_QSTR_ldrb, (const byte*)"\x5d\x4c\x04" "ldrb")
 QDEF(MP_QSTR_ldrex, (const byte*)"\xe2\xd7\x05" "ldrex")
-QDEF(MP_QSTR_listdir, (const byte*)"\x98\xe3\x07" "listdir")
 QDEF(MP_QSTR_localtime, (const byte*)"\x7d\x46\x09" "localtime")
 QDEF(MP_QSTR_lsl, (const byte*)"\xb6\x41\x03" "lsl")
 QDEF(MP_QSTR_lsr, (const byte*)"\xa8\x41\x03" "lsr")
@@ -1465,8 +1469,6 @@ QDEF(MP_QSTR_mem_read, (const byte*)"\x8d\xeb\x08" "mem_read")
 QDEF(MP_QSTR_mem_write, (const byte*)"\x62\x8c\x09" "mem_write")
 QDEF(MP_QSTR_memaddr, (const byte*)"\x93\xe8\x07" "memaddr")
 QDEF(MP_QSTR_miso, (const byte*)"\x9d\x98\x04" "miso")
-QDEF(MP_QSTR_mkdir, (const byte*)"\x9c\xb5\x05" "mkdir")
-QDEF(MP_QSTR_mkfs, (const byte*)"\x76\xb0\x04" "mkfs")
 QDEF(MP_QSTR_mktime, (const byte*)"\x96\x2b\x06" "mktime")
 QDEF(MP_QSTR_modify, (const byte*)"\xf5\x66\x06" "modify")
 QDEF(MP_QSTR_mosi, (const byte*)"\x1d\xc2\x04" "mosi")
@@ -1530,9 +1532,7 @@ QDEF(MP_QSTR_reg, (const byte*)"\x75\x8b\x03" "reg")
 QDEF(MP_QSTR_register, (const byte*)"\xac\xa1\x08" "register")
 QDEF(MP_QSTR_regs, (const byte*)"\x66\xfa\x04" "regs")
 QDEF(MP_QSTR_release, (const byte*)"\xec\x8f\x07" "release")
-QDEF(MP_QSTR_rename, (const byte*)"\x35\x18\x06" "rename")
 QDEF(MP_QSTR_repl_uart, (const byte*)"\x23\x58\x09" "repl_uart")
-QDEF(MP_QSTR_rmdir, (const byte*)"\x45\xa7\x05" "rmdir")
 QDEF(MP_QSTR_rng, (const byte*)"\x9e\x8b\x03" "rng")
 QDEF(MP_QSTR_route, (const byte*)"\x3c\x28\x05" "route")
 QDEF(MP_QSTR_rtr, (const byte*)"\x51\x89\x03" "rtr")

+ 25 - 38
port/moduos.c

@@ -3,7 +3,7 @@
  *
  * The MIT License (MIT)
  *
- * Copyright (c) 2013, 2014 Damien P. George
+ * Copyright (c) 2017 SummerGift <zhangyuan@rt-thread.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -30,27 +30,24 @@
 #include "py/runtime.h"
 #include "py/objtuple.h"
 #include "py/objstr.h"
+#include "py/mperrno.h"
 #include "lib/timeutils/timeutils.h"
 #include "lib/oofatfs/ff.h"
 #include "lib/oofatfs/diskio.h"
 #include "extmod/misc.h"
-#include "extmod/vfs.h"
-#include "extmod/vfs_fat.h"
 #include "genhdr/mpversion.h"
 #include "portmodules.h"
 
-/// \module os - basic "operating system" services
-///
-/// The `os` module contains functions for filesystem access and `urandom`.
-///
-/// The filesystem has `/` as the root directory, and the available physical
-/// drives are accessible from here.  They are currently:
-///
-///     /flash      -- the internal flash filesystem
-///     /sd         -- the SD card (if it exists)
-///
-/// On boot up, the current directory is `/flash` if no SD card is inserted,
-/// otherwise it is `/sd`.
+#if !MICROPY_VFS
+#if MICROPY_PY_MODUOS_FILE
+#include "moduos_file.h"
+#endif
+#else
+#include "extmod/vfs.h"
+#if MICROPY_VFS_FAT
+#include "extmod/vfs_fat.h"
+#endif
+#endif
 
 STATIC const qstr os_uname_info_fields[] = {
     MP_QSTR_sysname, MP_QSTR_nodename,
@@ -77,13 +74,7 @@ STATIC mp_obj_t os_uname(void) {
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname);
 
-/// \function sync()
-/// Sync all filesystems.
 STATIC mp_obj_t os_sync(void) {
-    for (mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table); vfs != NULL; vfs = vfs->next) {
-        // this assumes that vfs->obj is fs_user_mount_t with block device functions
-        disk_ioctl(MP_OBJ_TO_PTR(vfs->obj), CTRL_SYNC, NULL);
-    }
     return mp_const_none;
 }
 MP_DEFINE_CONST_FUN_OBJ_0(mod_os_sync_obj, os_sync);
@@ -106,25 +97,20 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom);
 
 STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
     { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uos) },
-
     { MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&os_uname_obj) },
-
-    { MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&mp_vfs_chdir_obj) },
-    { MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&mp_vfs_getcwd_obj) },
-    { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&mp_vfs_ilistdir_obj) },
-    { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&mp_vfs_listdir_obj) },
-    { MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&mp_vfs_mkdir_obj) },
-    { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&mp_vfs_remove_obj) },
-    { MP_ROM_QSTR(MP_QSTR_rename),MP_ROM_PTR(&mp_vfs_rename_obj)},
-    { MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&mp_vfs_rmdir_obj) },
-    { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&mp_vfs_stat_obj) },
-    { MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&mp_vfs_statvfs_obj) },
-    { MP_ROM_QSTR(MP_QSTR_unlink), MP_ROM_PTR(&mp_vfs_remove_obj) }, // unlink aliases to remove
-
+    { MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&mp_posix_chdir_obj) },
+    { MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&mp_posix_getcwd_obj) },
+    { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&mp_posix_listdir_obj) },
+    { MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&mp_posix_mkdir_obj) },
+    { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&mp_posix_remove_obj) },
+    { MP_ROM_QSTR(MP_QSTR_rename),MP_ROM_PTR(&mp_posix_rename_obj)},
+    { MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&mp_posix_rmdir_obj) },
+    { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&mp_posix_stat_obj) },
+    { MP_ROM_QSTR(MP_QSTR_unlink), MP_ROM_PTR(&mp_posix_remove_obj) },     // unlink aliases to remove
     { MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&mod_os_sync_obj) },
 
     /// \constant sep - separation character used in paths
-    { MP_ROM_QSTR(MP_QSTR_sep), MP_ROM_QSTR(MP_QSTR__slash_) },
+    //{ MP_ROM_QSTR(MP_QSTR_sep), MP_ROM_QSTR(MP_QSTR__slash_) },
 
 #if MICROPY_HW_ENABLE_RNG
     { MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&os_urandom_obj) },
@@ -132,8 +118,8 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
 
     // these are MicroPython extensions
     //{ MP_ROM_QSTR(MP_QSTR_dupterm), MP_ROM_PTR(&mp_uos_dupterm_obj) },
-    //{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) },
-    //{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) },
+    { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_posix_mount_obj) },
+    { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_posix_umount_obj) },
     //{ MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) },
 };
 
@@ -143,3 +129,4 @@ const mp_obj_module_t mp_module_uos = {
     .base = { &mp_type_module },
     .globals = (mp_obj_dict_t*)&os_module_globals,
 };
+

+ 226 - 0
port/moduos_file.c

@@ -0,0 +1,226 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 SummerGift <zhangyuan@rt-thread.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdint.h>
+#include <string.h>
+
+#include "py/runtime.h"
+#include "py/objstr.h"
+#include "py/mperrno.h"
+#include "moduos_file.h"
+
+#if MICROPY_PY_MODUOS_FILE
+
+mp_obj_t mp_posix_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+
+    return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_KW(mp_posix_mount_obj, 2, mp_posix_mount);
+
+mp_obj_t mp_posix_umount(mp_obj_t mnt_in) {
+
+    return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_1(mp_posix_umount_obj, mp_posix_umount);
+
+mp_obj_t mp_posix_chdir(mp_obj_t path_in) {
+    char *changepath = mp_obj_str_get_str(path_in);
+    if (chdir(changepath) != 0) {
+        rt_kprintf("No such directory: %s\n", changepath);
+    }
+    return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_1(mp_posix_chdir_obj, mp_posix_chdir);
+
+mp_obj_t mp_posix_getcwd(void) {
+    char buf[MICROPY_ALLOC_PATH_MAX + 1];
+    getcwd(buf, sizeof(buf));
+    return mp_obj_new_str(buf, strlen(buf), false);
+}
+MP_DEFINE_CONST_FUN_OBJ_0(mp_posix_getcwd_obj, mp_posix_getcwd);
+
+#include <dfs_file.h>
+static struct dfs_fd fd;
+static struct dirent dirent;
+mp_obj_t mp_posix_listdir(size_t n_args, const mp_obj_t *args) {
+
+    mp_obj_t dir_list = mp_obj_new_list(0, NULL);
+
+    struct stat stat;
+    int length;
+    char *fullpath, *path;
+    char *pathname;
+
+    if (n_args == 0) {
+#ifdef DFS_USING_WORKDIR
+        extern char working_directory[];
+        pathname = working_directory;
+#else
+        pathname = "/";
+#endif
+    }else{
+
+       pathname = mp_obj_str_get_str(args[0]);
+    }
+
+    fullpath = NULL;
+    if (pathname == NULL)
+    {
+#ifdef DFS_USING_WORKDIR
+        extern char working_directory[];
+        /* open current working directory */
+        path = rt_strdup(working_directory);
+#else
+        path = rt_strdup("/");
+#endif
+        if (path == NULL)
+            return ; /* out of memory */
+    }
+    else
+    {
+        path = (char *)pathname;
+    }
+
+    /* list directory */
+    if (dfs_file_open(&fd, path, O_DIRECTORY) == 0)
+    {
+        do {
+            memset(&dirent, 0, sizeof(struct dirent));
+            length = dfs_file_getdents(&fd, &dirent, sizeof(struct dirent));
+            if (length > 0) {
+                memset(&stat, 0, sizeof(struct stat));
+
+                /* build full path for each file */
+                fullpath = dfs_normalize_path(path, dirent.d_name);
+                if (fullpath == NULL)
+                    break;
+
+                if (dfs_file_stat(fullpath, &stat) == 0) {
+                    mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
+                    t->items[0] = mp_obj_new_str(dirent.d_name, strlen(dirent.d_name), false);
+                    t->items[1] = MP_OBJ_NEW_SMALL_INT(MP_S_IFDIR);
+                    t->items[2] = MP_OBJ_NEW_SMALL_INT(0); // no inode number
+                    mp_obj_t next = MP_OBJ_FROM_PTR(t);
+                    mp_obj_t *items;
+                    mp_obj_get_array_fixed_n(next, 3, &items);
+                    mp_obj_list_append(dir_list, items[0]);
+                } else {
+                    rt_kprintf("BAD file: %s\n", dirent.d_name);
+                }
+                rt_free(fullpath);
+            }
+        } while (length > 0);
+
+        dfs_file_close(&fd);
+    }
+    else
+    {
+        rt_kprintf("No such directory\n");
+    }
+    if (pathname == NULL)
+        rt_free(path);
+
+    return dir_list;
+}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_posix_listdir_obj, 0, 1, mp_posix_listdir);
+
+mp_obj_t mp_posix_mkdir(mp_obj_t path_in) {
+    char *createpath = mp_obj_str_get_str(path_in);
+    int res = mkdir(createpath, 0);
+    if (res != 0) {
+        mp_raise_OSError(MP_EEXIST);
+    }
+    return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_1(mp_posix_mkdir_obj, mp_posix_mkdir);
+
+mp_obj_t mp_posix_remove(uint n_args, const mp_obj_t *arg) {
+    int index;
+    if (n_args == 0) {
+        rt_kprintf("Usage: rm FILE...\n");
+        rt_kprintf("Remove (unlink) the FILE(s).\n");
+        return mp_const_none;
+    }
+    for (index = 0; index < n_args; index++) {
+        //rt_kprintf("Remove %s.\n", mp_obj_str_get_str(arg[index]));
+        rm(mp_obj_str_get_str(arg[index]));
+    }
+    // TODO  recursive deletion
+    return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_VAR(mp_posix_remove_obj, 0, mp_posix_remove);
+
+mp_obj_t mp_posix_rename(mp_obj_t old_path_in, mp_obj_t new_path_in) {
+    char *old_path = mp_obj_str_get_str(old_path_in);
+    char *new_path = mp_obj_str_get_str(new_path_in);
+    int res = rename(old_path, new_path);
+    if (res != 0) {
+        mp_raise_OSError(MP_EPERM);
+    }
+    return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_2(mp_posix_rename_obj, mp_posix_rename);
+
+mp_obj_t mp_posix_rmdir(uint n_args, const mp_obj_t *arg) {
+    int index;
+    if (n_args == 0) {
+        rt_kprintf("Usage: rm FILE...\n");
+        rt_kprintf("Remove (unlink) the FILE(s).\n");
+        return mp_const_none;
+    }
+    for (index = 0; index < n_args; index++) {
+        //rt_kprintf("Remove %s.\n", mp_obj_str_get_str(arg[index]));
+        rmdir(mp_obj_str_get_str(arg[index]));
+    }
+    // TODO  recursive deletion
+    return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_VAR(mp_posix_rmdir_obj, 0, mp_posix_rmdir);
+
+mp_obj_t mp_posix_stat(mp_obj_t path_in) {
+    struct stat buf;
+    char *createpath = mp_obj_str_get_str(path_in);
+    int res = stat(createpath, &buf);
+    if (res != 0) {
+        mp_raise_OSError(MP_EPERM);
+    }
+    mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL));
+    t->items[0] = MP_OBJ_NEW_SMALL_INT(buf.st_mode); // st_mode
+    t->items[1] = MP_OBJ_NEW_SMALL_INT(buf.st_ino); // st_ino
+    t->items[2] = MP_OBJ_NEW_SMALL_INT(buf.st_dev); // st_dev
+    t->items[3] = MP_OBJ_NEW_SMALL_INT(buf.st_nlink); // st_nlink
+    t->items[4] = MP_OBJ_NEW_SMALL_INT(buf.st_uid); // st_uid
+    t->items[5] = MP_OBJ_NEW_SMALL_INT(buf.st_gid); // st_gid
+    t->items[6] = mp_obj_new_int_from_uint(buf.st_size); // st_size
+    t->items[7] = MP_OBJ_NEW_SMALL_INT(buf.st_atime); // st_atime
+    t->items[8] = MP_OBJ_NEW_SMALL_INT(buf.st_mtime); // st_mtime
+    t->items[9] = MP_OBJ_NEW_SMALL_INT(buf.st_ctime); // st_ctime
+    return MP_OBJ_FROM_PTR(t);
+}
+MP_DEFINE_CONST_FUN_OBJ_1(mp_posix_stat_obj, mp_posix_stat);
+
+
+#endif //MICROPY_MODUOS_FILE

+ 69 - 0
port/moduos_file.h

@@ -0,0 +1,69 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 SummerGift <zhangyuan@rt-thread.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef MICROPY_INCLUDED_PY_MODUOS_FILE_H
+#define MICROPY_INCLUDED_PY_MODUOS_FILE_H
+
+#include "py/lexer.h"
+#include "py/obj.h"
+
+// MicroPython's port-standardized versions of stat constants
+#define MP_S_IFDIR (0x4000)
+#define MP_S_IFREG (0x8000)
+
+// constants for block protocol ioctl
+#define BP_IOCTL_INIT           (1)
+#define BP_IOCTL_DEINIT         (2)
+#define BP_IOCTL_SYNC           (3)
+#define BP_IOCTL_SEC_COUNT      (4)
+#define BP_IOCTL_SEC_SIZE       (5)
+
+mp_obj_t mp_posix_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
+mp_obj_t mp_posix_umount(mp_obj_t mnt_in);
+mp_obj_t mp_posix_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
+mp_obj_t mp_posix_chdir(mp_obj_t path_in);
+mp_obj_t mp_posix_getcwd(void);
+mp_obj_t mp_posix_listdir(size_t n_args, const mp_obj_t *args);
+mp_obj_t mp_posix_mkdir(mp_obj_t path_in);
+mp_obj_t mp_posix_remove(uint n_args, const mp_obj_t *arg);
+mp_obj_t mp_posix_rename(mp_obj_t old_path_in, mp_obj_t new_path_in);
+mp_obj_t mp_posix_rmdir(uint n_args, const mp_obj_t *arg);
+mp_obj_t mp_posix_stat(mp_obj_t path_in);
+mp_obj_t mp_posix_statvfs(mp_obj_t path_in);
+
+MP_DECLARE_CONST_FUN_OBJ_KW(mp_posix_mount_obj);
+MP_DECLARE_CONST_FUN_OBJ_1(mp_posix_umount_obj);
+MP_DECLARE_CONST_FUN_OBJ_KW(mp_posix_open_obj);
+MP_DECLARE_CONST_FUN_OBJ_1(mp_posix_chdir_obj);
+MP_DECLARE_CONST_FUN_OBJ_0(mp_posix_getcwd_obj);
+MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_posix_listdir_obj);
+MP_DECLARE_CONST_FUN_OBJ_1(mp_posix_mkdir_obj);
+MP_DECLARE_CONST_FUN_OBJ_VAR(mp_posix_remove_obj);
+MP_DECLARE_CONST_FUN_OBJ_2(mp_posix_rename_obj);
+MP_DECLARE_CONST_FUN_OBJ_VAR(mp_posix_rmdir_obj);
+MP_DECLARE_CONST_FUN_OBJ_1(mp_posix_stat_obj);
+MP_DECLARE_CONST_FUN_OBJ_1(mp_posix_statvfs_obj);
+
+#endif // MICROPY_INCLUDED_PY_MODUOS_FILE_H

+ 8 - 2
port/mpconfigport.h

@@ -120,9 +120,10 @@
 #define MICROPY_READER_POSIX        (1)
 #define MICROPY_READER_VFS          (0)
 #define MICROPY_PY_PIN              (0)
-#define MICROPY_PY_OS_DUPTERM       (0)
-#define MICROPY_VFS                 (1)
+#define MICROPY_PY_OS_DUPTERM       (1)
+#define MICROPY_VFS                 (0)
 #define MICROPY_VFS_FAT             (0)
+#define MICROPY_PY_MODUOS_FILE      (1)
 
 
 // extended modules
@@ -228,6 +229,9 @@ extern const struct _mp_obj_module_t pyb_module;
 extern const struct _mp_obj_module_t mp_module_rtthread;
 extern const struct _mp_obj_module_t mp_module_time;
 extern const struct _mp_obj_module_t mp_module_machine;
+extern const struct _mp_obj_module_t mp_module_uos;
+extern const struct _mp_obj_module_t mp_module_uselect;
+extern const struct _mp_obj_module_t mp_module_usocket;
 
 #if MICROPY_PY_RTTHREAD
 #define MICROPY_PY_RTTHREAD_DEF { MP_ROM_QSTR(MP_QSTR_rtthread), MP_ROM_PTR(&mp_module_rtthread) },
@@ -239,9 +243,11 @@ extern const struct _mp_obj_module_t mp_module_machine;
     { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&mp_module_machine) }, \
     { MP_ROM_QSTR(MP_QSTR_pyb), MP_ROM_PTR(&pyb_module) }, \
     MICROPY_PY_RTTHREAD_DEF \
+    { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_uos) }, \
 
 #define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
     { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_module_time) }, \
+    { MP_ROM_QSTR(MP_QSTR_os), MP_ROM_PTR(&mp_module_uos) }, \
 
 
 #define MP_RTT_NOT_IMPL_PRINT rt_kprintf("Not implement on %s:%ld, Please add for your board!\n", __FILE__, __FUNCTION__)

+ 7 - 0
py/mpstate.h

@@ -176,6 +176,13 @@ typedef struct _mp_state_vm_t {
     mp_obj_t lwip_slip_stream;
     #endif
 
+    #if !MICROPY_VFS  //If not difined MICROPY_VFS,only define MICROPY_MODUOS_FILE
+    #if MICROPY_MODUOS_FILE
+    struct _mp_vfs_mount_t *vfs_cur;
+    struct _mp_vfs_mount_t *vfs_mount_table;
+    #endif
+    #endif
+
     #if MICROPY_VFS
     struct _mp_vfs_mount_t *vfs_cur;
     struct _mp_vfs_mount_t *vfs_mount_table;