summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--cc3200/mods/moduos.c60
-rw-r--r--cc3200/mods/moduos.h1
-rw-r--r--cc3200/mptask.c3
-rw-r--r--tests/wipy/os.py10
-rw-r--r--tests/wipy/os.py.exp2
5 files changed, 51 insertions, 25 deletions
diff --git a/cc3200/mods/moduos.c b/cc3200/mods/moduos.c
index b058436b56..1601ee5b03 100644
--- a/cc3200/mods/moduos.c
+++ b/cc3200/mods/moduos.c
@@ -63,6 +63,14 @@ STATIC uint32_t os_num_mounted_devices;
STATIC os_term_dup_obj_t os_term_dup_obj;
/******************************************************************************
+ DECLARE PRIVATE FUNCTIONS
+ ******************************************************************************/
+STATIC void unmount (os_fs_mount_t *mount_obj);
+STATIC bool path_equal(const char *path, const char *path_canonical);
+STATIC void append_dir_item (mp_obj_t dirlist, const char *item, bool string);
+STATIC void mount (mp_obj_t device, const char *path, uint pathlen, bool readonly);
+
+/******************************************************************************
DEFINE PUBLIC FUNCTIONS
******************************************************************************/
@@ -102,6 +110,13 @@ os_fs_mount_t *osmount_find_by_device (mp_obj_t device) {
return NULL;
}
+void osmount_unmount_all (void) {
+ for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) {
+ os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i]));
+ unmount(mount_obj);
+ }
+}
+
/******************************************************************************
DEFINE PRIVATE FUNCTIONS
******************************************************************************/
@@ -188,19 +203,11 @@ STATIC void mount (mp_obj_t device, const char *path, uint pathlen, bool readonl
os_num_mounted_devices++;
}
-STATIC void unmount (const char *path) {
- if (FR_OK != f_mount (NULL, path, 1)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_operation_failed));
- }
-
- // remove from the list after the actual unmount
- os_fs_mount_t *mount_obj;
- if ((mount_obj = osmount_find_by_path(path))) {
- mp_obj_list_remove(&MP_STATE_PORT(mount_obj_list), mount_obj);
- os_num_mounted_devices--;
- } else {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
- }
+STATIC void unmount (os_fs_mount_t *mount_obj) {
+ // remove it from the list and then call FatFs
+ f_mount (NULL, mount_obj->path, 1);
+ mp_obj_list_remove(&MP_STATE_PORT(mount_obj_list), mount_obj);
+ os_num_mounted_devices--;
}
/******************************************************************************/
@@ -487,7 +494,12 @@ STATIC mp_obj_t os_unmount(mp_obj_t path_o) {
}
// now unmount it
- unmount (path);
+ os_fs_mount_t *mount_obj;
+ if ((mount_obj = osmount_find_by_path(path))) {
+ unmount (mount_obj);
+ } else {
+ nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
+ }
return mp_const_none;
}
@@ -495,6 +507,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_unmount_obj, os_unmount);
STATIC mp_obj_t os_mkfs(mp_obj_t device) {
const char *path = "/__mkfs__mnt__";
+ os_fs_mount_t *mount_obj = NULL;
bool unmt = false;
FRESULT res;
@@ -505,29 +518,26 @@ STATIC mp_obj_t os_mkfs(mp_obj_t device) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_value_invalid_arguments));
}
} else {
- // mount it and unmount it briefly
- unmt = true;
+ // mount it briefly
mount(device, path, strlen(path), false);
+ unmt = true;
}
byte sfd = 0;
if (!memcmp(path, "/flash", strlen("/flash"))) {
sfd = 1;
- } else {
- os_fs_mount_t *mount_obj;
- if ((mount_obj = osmount_find_by_path(path))) {
- if (mount_obj->device != (mp_obj_t)&pybsd_obj &&
- mp_obj_get_int(mp_call_method_n_kw(0, 0, mount_obj->count)) < 2048) {
- sfd = 1;
- }
+ } else if ((mount_obj = osmount_find_by_path(path))) {
+ if (mount_obj->device != (mp_obj_t)&pybsd_obj &&
+ mp_obj_get_int(mp_call_method_n_kw(0, 0, mount_obj->count)) < 2048) {
+ sfd = 1;
}
}
// now format the device
res = f_mkfs(path, sfd, 0);
- if (unmt) {
- unmount (path);
+ if (unmt && mount_obj) {
+ unmount (mount_obj);
}
if (res != FR_OK) {
diff --git a/cc3200/mods/moduos.h b/cc3200/mods/moduos.h
index fa59071257..1ebf16cdfa 100644
--- a/cc3200/mods/moduos.h
+++ b/cc3200/mods/moduos.h
@@ -57,5 +57,6 @@ typedef struct _os_term_dup_obj_t {
void moduos_init0 (void);
os_fs_mount_t *osmount_find_by_path (const char *path);
os_fs_mount_t *osmount_find_by_volume (uint8_t vol);
+void osmount_unmount_all (void);
#endif // MODUOS_H_
diff --git a/cc3200/mptask.c b/cc3200/mptask.c
index 96a4001ad0..f8f33c2959 100644
--- a/cc3200/mptask.c
+++ b/cc3200/mptask.c
@@ -235,6 +235,9 @@ soft_reset_exit:
// clean-up the user socket space
modusocket_close_all_user_sockets();
+ // unmount all user file systems
+ osmount_unmount_all();
+
// wait for pending transactions to complete
mp_hal_delay_ms(20);
diff --git a/tests/wipy/os.py b/tests/wipy/os.py
index cacd10958a..f81d1cee8a 100644
--- a/tests/wipy/os.py
+++ b/tests/wipy/os.py
@@ -125,6 +125,16 @@ except:
print('Exception')
try:
+ os.unmount('/something')
+except:
+ print('Exception')
+
+try:
+ os.unmount('something')
+except:
+ print('Exception')
+
+try:
os.mkfs('flash') # incorrect path format
except:
print('Exception')
diff --git a/tests/wipy/os.py.exp b/tests/wipy/os.py.exp
index 55a0879aad..a0f01e35e1 100644
--- a/tests/wipy/os.py.exp
+++ b/tests/wipy/os.py.exp
@@ -27,4 +27,6 @@ Exception
Exception
Exception
Exception
+Exception
+Exception
['flash', 'sd']