Skip to content

Commit e4404fb

Browse files
author
danicampora
committed
cc3200: Unmount all user file systems after a soft reset.
1 parent 65971f5 commit e4404fb

File tree

5 files changed

+51
-25
lines changed

5 files changed

+51
-25
lines changed

cc3200/mods/moduos.c

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@
6262
STATIC uint32_t os_num_mounted_devices;
6363
STATIC os_term_dup_obj_t os_term_dup_obj;
6464

65+
/******************************************************************************
66+
DECLARE PRIVATE FUNCTIONS
67+
******************************************************************************/
68+
STATIC void unmount (os_fs_mount_t *mount_obj);
69+
STATIC bool path_equal(const char *path, const char *path_canonical);
70+
STATIC void append_dir_item (mp_obj_t dirlist, const char *item, bool string);
71+
STATIC void mount (mp_obj_t device, const char *path, uint pathlen, bool readonly);
72+
6573
/******************************************************************************
6674
DEFINE PUBLIC FUNCTIONS
6775
******************************************************************************/
@@ -102,6 +110,13 @@ os_fs_mount_t *osmount_find_by_device (mp_obj_t device) {
102110
return NULL;
103111
}
104112

113+
void osmount_unmount_all (void) {
114+
for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) {
115+
os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i]));
116+
unmount(mount_obj);
117+
}
118+
}
119+
105120
/******************************************************************************
106121
DEFINE PRIVATE FUNCTIONS
107122
******************************************************************************/
@@ -188,19 +203,11 @@ STATIC void mount (mp_obj_t device, const char *path, uint pathlen, bool readonl
188203
os_num_mounted_devices++;
189204
}
190205

191-
STATIC void unmount (const char *path) {
192-
if (FR_OK != f_mount (NULL, path, 1)) {
193-
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_operation_failed));
194-
}
195-
196-
// remove from the list after the actual unmount
197-
os_fs_mount_t *mount_obj;
198-
if ((mount_obj = osmount_find_by_path(path))) {
199-
mp_obj_list_remove(&MP_STATE_PORT(mount_obj_list), mount_obj);
200-
os_num_mounted_devices--;
201-
} else {
202-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
203-
}
206+
STATIC void unmount (os_fs_mount_t *mount_obj) {
207+
// remove it from the list and then call FatFs
208+
f_mount (NULL, mount_obj->path, 1);
209+
mp_obj_list_remove(&MP_STATE_PORT(mount_obj_list), mount_obj);
210+
os_num_mounted_devices--;
204211
}
205212

206213
/******************************************************************************/
@@ -487,14 +494,20 @@ STATIC mp_obj_t os_unmount(mp_obj_t path_o) {
487494
}
488495

489496
// now unmount it
490-
unmount (path);
497+
os_fs_mount_t *mount_obj;
498+
if ((mount_obj = osmount_find_by_path(path))) {
499+
unmount (mount_obj);
500+
} else {
501+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
502+
}
491503

492504
return mp_const_none;
493505
}
494506
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_unmount_obj, os_unmount);
495507

496508
STATIC mp_obj_t os_mkfs(mp_obj_t device) {
497509
const char *path = "/__mkfs__mnt__";
510+
os_fs_mount_t *mount_obj = NULL;
498511
bool unmt = false;
499512
FRESULT res;
500513

@@ -505,29 +518,26 @@ STATIC mp_obj_t os_mkfs(mp_obj_t device) {
505518
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_value_invalid_arguments));
506519
}
507520
} else {
508-
// mount it and unmount it briefly
509-
unmt = true;
521+
// mount it briefly
510522
mount(device, path, strlen(path), false);
523+
unmt = true;
511524
}
512525

513526
byte sfd = 0;
514527
if (!memcmp(path, "/flash", strlen("/flash"))) {
515528
sfd = 1;
516-
} else {
517-
os_fs_mount_t *mount_obj;
518-
if ((mount_obj = osmount_find_by_path(path))) {
519-
if (mount_obj->device != (mp_obj_t)&pybsd_obj &&
520-
mp_obj_get_int(mp_call_method_n_kw(0, 0, mount_obj->count)) < 2048) {
521-
sfd = 1;
522-
}
529+
} else if ((mount_obj = osmount_find_by_path(path))) {
530+
if (mount_obj->device != (mp_obj_t)&pybsd_obj &&
531+
mp_obj_get_int(mp_call_method_n_kw(0, 0, mount_obj->count)) < 2048) {
532+
sfd = 1;
523533
}
524534
}
525535

526536
// now format the device
527537
res = f_mkfs(path, sfd, 0);
528538

529-
if (unmt) {
530-
unmount (path);
539+
if (unmt && mount_obj) {
540+
unmount (mount_obj);
531541
}
532542

533543
if (res != FR_OK) {

cc3200/mods/moduos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ typedef struct _os_term_dup_obj_t {
5757
void moduos_init0 (void);
5858
os_fs_mount_t *osmount_find_by_path (const char *path);
5959
os_fs_mount_t *osmount_find_by_volume (uint8_t vol);
60+
void osmount_unmount_all (void);
6061

6162
#endif // MODUOS_H_

cc3200/mptask.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ void TASK_Micropython (void *pvParameters) {
235235
// clean-up the user socket space
236236
modusocket_close_all_user_sockets();
237237

238+
// unmount all user file systems
239+
osmount_unmount_all();
240+
238241
// wait for pending transactions to complete
239242
mp_hal_delay_ms(20);
240243

tests/wipy/os.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@
124124
except:
125125
print('Exception')
126126

127+
try:
128+
os.unmount('/something')
129+
except:
130+
print('Exception')
131+
132+
try:
133+
os.unmount('something')
134+
except:
135+
print('Exception')
136+
127137
try:
128138
os.mkfs('flash') # incorrect path format
129139
except:

tests/wipy/os.py.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ Exception
2727
Exception
2828
Exception
2929
Exception
30+
Exception
31+
Exception
3032
['flash', 'sd']

0 commit comments

Comments
 (0)