From 4f2ba9fbdcbafd7ae09199186320f4173bcc8c31 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 10 May 2016 23:25:39 +0100 Subject: esp8266: Convert to use new MP_Exxx errno symbols. These symbols are still defined in terms of the system Exxx symbols, and can be switched to internal numeric definitions at a later stage. Note that extmod/modlwip still uses many system Exxx symbols. --- esp8266/moduos.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'esp8266/moduos.c') diff --git a/esp8266/moduos.c b/esp8266/moduos.c index d75062eaf7..bc2838d2d4 100644 --- a/esp8266/moduos.c +++ b/esp8266/moduos.c @@ -25,7 +25,6 @@ */ #include -#include #include "py/mpconfig.h" #include "py/nlr.h" @@ -33,6 +32,7 @@ #include "py/objtuple.h" #include "py/objstr.h" #include "py/runtime.h" +#include "py/mperrno.h" #include "extmod/misc.h" #include "genhdr/mpversion.h" #include "esp_mphal.h" @@ -74,7 +74,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname); #if MICROPY_VFS_FAT mp_obj_t vfs_proxy_call(qstr method_name, mp_uint_t n_args, const mp_obj_t *args) { if (MP_STATE_PORT(fs_user_mount)[0] == NULL) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENODEV))); + nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_ENODEV))); } mp_obj_t meth[n_args + 2]; -- cgit v1.2.3 From a676a41cb7f50d0aab4230be19e9b2bb508f754e Mon Sep 17 00:00:00 2001 From: Robert HH Date: Mon, 16 May 2016 10:17:11 +0200 Subject: esp8266/moduos.c: Addition of the rename method to module uos. That one was missing in the module, even if it was available in the vfs object. The change consist of adding the name and preparing the call to the underlying vfs module, similar to what was already implemented e.g. for remove. Rename is useful by itself, or for instance for a safe file replace, consisting of the sequence: write to a temp file delete the original file rename the temp file to the original file's name --- esp8266/moduos.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'esp8266/moduos.c') diff --git a/esp8266/moduos.c b/esp8266/moduos.c index bc2838d2d4..deac0c960b 100644 --- a/esp8266/moduos.c +++ b/esp8266/moduos.c @@ -97,6 +97,15 @@ STATIC mp_obj_t os_remove(mp_obj_t path_in) { return vfs_proxy_call(MP_QSTR_remove, 1, &path_in); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_remove_obj, os_remove); + +STATIC mp_obj_t os_rename(mp_obj_t path_old, mp_obj_t path_new) { + mp_obj_t args[2]; + args[0] = path_old; + args[1] = path_new; + return vfs_proxy_call(MP_QSTR_rename, 2, args); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(os_rename_obj, os_rename); + #endif STATIC mp_obj_t os_urandom(mp_obj_t num) { @@ -130,6 +139,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&os_listdir_obj) }, { MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&os_mkdir_obj) }, { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&os_remove_obj) }, + { MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&os_rename_obj) }, #endif }; -- cgit v1.2.3 From 12401f337e9accbf69836f39e536ec33c3e4fa4b Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 29 May 2016 19:28:21 +0300 Subject: esp8266/moduos: Add chdir() and getcwd() functions. --- esp8266/moduos.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'esp8266/moduos.c') diff --git a/esp8266/moduos.c b/esp8266/moduos.c index deac0c960b..44821d3ce9 100644 --- a/esp8266/moduos.c +++ b/esp8266/moduos.c @@ -79,7 +79,9 @@ mp_obj_t vfs_proxy_call(qstr method_name, mp_uint_t n_args, const mp_obj_t *args mp_obj_t meth[n_args + 2]; mp_load_method(MP_STATE_PORT(fs_user_mount)[0], method_name, meth); - memcpy(meth + 2, args, n_args * sizeof(*args)); + if (args != NULL) { + memcpy(meth + 2, args, n_args * sizeof(*args)); + } return mp_call_method_n_kw(n_args, 0, meth); } @@ -93,6 +95,16 @@ STATIC mp_obj_t os_mkdir(mp_obj_t path_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mkdir_obj, os_mkdir); +STATIC mp_obj_t os_chdir(mp_obj_t path_in) { + return vfs_proxy_call(MP_QSTR_chdir, 1, &path_in); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_chdir_obj, os_chdir); + +STATIC mp_obj_t os_getcwd(void) { + return vfs_proxy_call(MP_QSTR_getcwd, 0, NULL); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_getcwd_obj, os_getcwd); + STATIC mp_obj_t os_remove(mp_obj_t path_in) { return vfs_proxy_call(MP_QSTR_remove, 1, &path_in); } @@ -138,6 +150,8 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) }, { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&os_listdir_obj) }, { MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&os_mkdir_obj) }, + { MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&os_chdir_obj) }, + { MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&os_getcwd_obj) }, { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&os_remove_obj) }, { MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&os_rename_obj) }, #endif -- cgit v1.2.3 From 4f3fbf09cc5f9e135a47744ccc89c72918a97812 Mon Sep 17 00:00:00 2001 From: Robert HH Date: Tue, 31 May 2016 18:22:35 +0200 Subject: esp8266/moduos.c: Add stat() to the module uos of esp8266. This implementation makes use of vfs.stat() and therefore has the same properties. Known issues for all ports: uos.stat(".") on the top level returns the error code 22, EINVAL. The same happens with uos.stat("dirname/") where dirname IS the name of a directory. --- esp8266/moduos.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'esp8266/moduos.c') diff --git a/esp8266/moduos.c b/esp8266/moduos.c index 44821d3ce9..74262d86b1 100644 --- a/esp8266/moduos.c +++ b/esp8266/moduos.c @@ -138,6 +138,11 @@ STATIC mp_obj_t os_dupterm_notify(mp_obj_t obj_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_dupterm_notify_obj, os_dupterm_notify); +STATIC mp_obj_t os_stat(mp_obj_t path_in) { + return vfs_proxy_call(MP_QSTR_stat, 1, &path_in); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_stat_obj, os_stat); + 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) }, @@ -154,6 +159,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&os_getcwd_obj) }, { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&os_remove_obj) }, { MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&os_rename_obj) }, + { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&os_stat_obj) }, #endif }; -- cgit v1.2.3