extmod: Remove MICROPY_FSUSERMOUNT and related files.

Replaced by MICROPY_VFS and the VFS sub-system.
This commit is contained in:
Damien George 2017-01-29 15:21:46 +11:00
parent 3d6f957208
commit 1808b2e8d5
11 changed files with 5 additions and 394 deletions

View File

@ -1,244 +0,0 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2014 Damien P. George
*
* 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 "py/mpconfig.h"
#if MICROPY_FSUSERMOUNT
#include <string.h>
#include <errno.h>
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/mperrno.h"
#if MICROPY_FATFS_OO
#include "lib/oofatfs/ff.h"
#else
#include "lib/fatfs/ff.h"
#endif
#include "extmod/fsusermount.h"
fs_user_mount_t *fatfs_mount_mkfs(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, bool mkfs) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_readonly, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
{ MP_QSTR_mkfs, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
};
// parse args
mp_obj_t device = pos_args[0];
mp_obj_t mount_point = pos_args[1];
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 2, pos_args + 2, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
// get the mount point
mp_uint_t mnt_len;
const char *mnt_str = mp_obj_str_get_data(mount_point, &mnt_len);
if (device == mp_const_none) {
// umount
FRESULT res = FR_NO_FILESYSTEM;
for (size_t i = 0; i < MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount)); ++i) {
fs_user_mount_t *vfs = MP_STATE_PORT(fs_user_mount)[i];
if (vfs != NULL && !memcmp(mnt_str, vfs->str, mnt_len + 1)) {
#if MICROPY_FATFS_OO
res = f_umount(&vfs->fatfs);
#else
res = f_mount(NULL, vfs->str, 0);
#endif
if (vfs->flags & FSUSER_FREE_OBJ) {
m_del_obj(fs_user_mount_t, vfs);
}
MP_STATE_PORT(fs_user_mount)[i] = NULL;
break;
}
}
if (res != FR_OK) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't umount"));
}
return NULL;
} else {
// mount
size_t i = 0;
for (; i < MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount)); ++i) {
if (MP_STATE_PORT(fs_user_mount)[i] == NULL) {
break;
}
}
if (i == MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount))) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "too many devices mounted"));
}
// create new object
fs_user_mount_t *vfs = m_new_obj(fs_user_mount_t);
vfs->str = mnt_str;
vfs->len = mnt_len;
vfs->flags = FSUSER_FREE_OBJ;
#if MICROPY_FATFS_OO
vfs->fatfs.drv = vfs;
#endif
// load block protocol methods
mp_load_method(device, MP_QSTR_readblocks, vfs->readblocks);
mp_load_method_maybe(device, MP_QSTR_writeblocks, vfs->writeblocks);
mp_load_method_maybe(device, MP_QSTR_ioctl, vfs->u.ioctl);
if (vfs->u.ioctl[0] != MP_OBJ_NULL) {
// device supports new block protocol, so indicate it
vfs->flags |= FSUSER_HAVE_IOCTL;
} else {
// no ioctl method, so assume the device uses the old block protocol
mp_load_method_maybe(device, MP_QSTR_sync, vfs->u.old.sync);
mp_load_method(device, MP_QSTR_count, vfs->u.old.count);
}
// Read-only device indicated by writeblocks[0] == MP_OBJ_NULL.
// User can specify read-only device by:
// 1. readonly=True keyword argument
// 2. nonexistent writeblocks method (then writeblocks[0] == MP_OBJ_NULL already)
if (args[0].u_bool) {
vfs->writeblocks[0] = MP_OBJ_NULL;
}
// Register the vfs object so that it can be found by the FatFS driver using
// ff_get_ldnumber. We don't register it any earlier than this point in case there
// is an exception, in which case there would remain a partially mounted device.
MP_STATE_PORT(fs_user_mount)[i] = vfs;
// mount the block device (if mkfs, only pre-mount)
FRESULT res;
#if MICROPY_FATFS_OO
if (mkfs) {
res = FR_OK;
} else {
res = f_mount(&vfs->fatfs);
}
#else
res = f_mount(&vfs->fatfs, vfs->str, !mkfs);
#endif
// check the result
if (res == FR_OK) {
if (mkfs) {
goto mkfs;
}
} else if (res == FR_NO_FILESYSTEM && args[1].u_bool) {
mkfs:;
#if MICROPY_FATFS_OO
uint8_t working_buf[_MAX_SS];
res = f_mkfs(&vfs->fatfs, FM_FAT | FM_SFD, 0, working_buf, sizeof(working_buf));
#else
res = f_mkfs(vfs->str, 1, 0);
#endif
if (res != FR_OK) {
mkfs_error:
MP_STATE_PORT(fs_user_mount)[i] = NULL;
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't mkfs"));
}
if (mkfs) {
// If requested to only mkfs, unmount pre-mounted device
#if MICROPY_FATFS_OO
res = FR_OK;
#else
res = f_mount(NULL, vfs->str, 0);
#endif
if (res != FR_OK) {
goto mkfs_error;
}
MP_STATE_PORT(fs_user_mount)[i] = NULL;
return NULL;
}
} else {
MP_STATE_PORT(fs_user_mount)[i] = NULL;
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't mount"));
}
/*
if (vfs->writeblocks[0] == MP_OBJ_NULL) {
printf("mounted read-only");
} else {
printf("mounted read-write");
}
DWORD nclst;
FATFS *fatfs;
f_getfree(vfs->str, &nclst, &fatfs);
printf(" on %s with %u bytes free\n", vfs->str, (uint)(nclst * fatfs->csize * 512));
*/
return vfs;
}
}
STATIC mp_obj_t fatfs_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
fatfs_mount_mkfs(n_args, pos_args, kw_args, false);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(fsuser_mount_obj, 2, fatfs_mount);
mp_obj_t fatfs_umount(mp_obj_t bdev_or_path_in) {
size_t i = 0;
if (MP_OBJ_IS_STR(bdev_or_path_in)) {
mp_uint_t mnt_len;
const char *mnt_str = mp_obj_str_get_data(bdev_or_path_in, &mnt_len);
for (; i < MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount)); ++i) {
fs_user_mount_t *vfs = MP_STATE_PORT(fs_user_mount)[i];
if (vfs != NULL && !memcmp(mnt_str, vfs->str, mnt_len + 1)) {
break;
}
}
} else {
for (; i < MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount)); ++i) {
fs_user_mount_t *vfs = MP_STATE_PORT(fs_user_mount)[i];
if (vfs != NULL && bdev_or_path_in == vfs->readblocks[1]) {
break;
}
}
}
if (i == MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount))) {
mp_raise_OSError(MP_EINVAL);
}
fs_user_mount_t *vfs = MP_STATE_PORT(fs_user_mount)[i];
FRESULT res;
#if MICROPY_FATFS_OO
res = f_umount(&vfs->fatfs);
#else
res = f_mount(NULL, vfs->str, 0);
#endif
if (vfs->flags & FSUSER_FREE_OBJ) {
m_del_obj(fs_user_mount_t, vfs);
}
MP_STATE_PORT(fs_user_mount)[i] = NULL;
if (res != FR_OK) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't umount"));
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(fsuser_umount_obj, fatfs_umount);
STATIC mp_obj_t fatfs_mkfs(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
fatfs_mount_mkfs(n_args, pos_args, kw_args, true);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(fsuser_mkfs_obj, 2, fatfs_mkfs);
#endif // MICROPY_FSUSERMOUNT

View File

@ -31,8 +31,6 @@ struct _fs_user_mount_t;
extern const byte fresult_to_errno_table[20];
extern const mp_obj_type_t mp_fat_vfs_type;
struct _fs_user_mount_t *ff_get_vfs(const char **path);
mp_import_stat_t fat_vfs_import_stat(struct _fs_user_mount_t *vfs, const char *path);
mp_obj_t fatfs_builtin_open(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwargs);
mp_obj_t fatfs_builtin_open_self(mp_obj_t self_in, mp_obj_t path, mp_obj_t mode);

View File

@ -28,7 +28,7 @@
*/
#include "py/mpconfig.h"
#if MICROPY_VFS || MICROPY_FSUSERMOUNT
#if MICROPY_VFS
#include <stdint.h>
#include <stdio.h>
@ -305,4 +305,4 @@ DRESULT disk_ioctl (
}
#endif
#endif // MICROPY_VFS || MICROPY_FSUSERMOUNT
#endif // MICROPY_VFS

View File

@ -1,118 +0,0 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
*
* 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 "py/mpconfig.h"
#if MICROPY_FSUSERMOUNT
#include <string.h>
#include "py/mpstate.h"
#if MICROPY_FATFS_OO
#include "lib/oofatfs/ff.h"
#else
#include "lib/fatfs/ff.h"
#endif
#include "extmod/fsusermount.h"
#include "extmod/vfs_fat.h"
STATIC bool check_path(const TCHAR **path, const char *mount_point_str, mp_uint_t mount_point_len) {
if (strncmp(*path, mount_point_str, mount_point_len) == 0) {
if ((*path)[mount_point_len] == '/') {
*path += mount_point_len;
return true;
} else if ((*path)[mount_point_len] == '\0') {
*path = "/";
return true;
}
}
return false;
}
#if MICROPY_FATFS_OO
STATIC fs_user_mount_t *vfs_cur_obj = NULL;
// "path" is the path to lookup; will advance this pointer beyond the volume name.
// Returns a pointer to the VFS object, NULL means path not found.
fs_user_mount_t *ff_get_vfs(const char **path) {
if (!(*path)) {
return NULL;
}
if (**path != '/') {
#if _FS_RPATH
return vfs_cur_obj;
#else
return NULL;
#endif
}
for (size_t i = 0; i < MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount)); ++i) {
fs_user_mount_t *vfs = MP_STATE_PORT(fs_user_mount)[i];
if (vfs != NULL && check_path(path, vfs->str, vfs->len)) {
return vfs;
}
}
return NULL;
}
#else
// "path" is the path to lookup; will advance this pointer beyond the volume name.
// Returns logical drive number (-1 means invalid path).
int ff_get_ldnumber (const TCHAR **path) {
if (!(*path)) {
return -1;
}
if (**path != '/') {
#if _FS_RPATH
return ff_CurrVol;
#else
return -1;
#endif
}
for (size_t i = 0; i < MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount)); ++i) {
fs_user_mount_t *vfs = MP_STATE_PORT(fs_user_mount)[i];
if (vfs != NULL && check_path(path, vfs->str, vfs->len)) {
return i;
}
}
return -1;
}
void ff_get_volname(BYTE vol, TCHAR **dest) {
fs_user_mount_t *vfs = MP_STATE_PORT(fs_user_mount)[vol];
memcpy(*dest, vfs->str, vfs->len);
*dest += vfs->len;
}
#endif
#endif // MICROPY_FSUSERMOUNT

View File

@ -25,7 +25,7 @@
*/
#include "py/mpconfig.h"
#if MICROPY_VFS || MICROPY_FSUSERMOUNT
#if MICROPY_VFS
#include <stdio.h>
#include <errno.h>
@ -322,4 +322,4 @@ mp_obj_t fatfs_builtin_open_self(mp_obj_t self_in, mp_obj_t path, mp_obj_t mode)
return file_open(self, &mp_type_textio, arg_vals);
}
#endif // MICROPY_VFS || MICROPY_FSUSERMOUNT
#endif // MICROPY_VFS

View File

@ -25,7 +25,7 @@
*/
#include "py/mpconfig.h"
#if MICROPY_VFS_FAT || MICROPY_FSUSERMOUNT
#if MICROPY_VFS_FAT
#include <string.h>
#include "py/nlr.h"

View File

@ -616,11 +616,6 @@ typedef double mp_float_t;
#define MICROPY_USE_INTERNAL_PRINTF (1)
#endif
// Support for user-space VFS mount (selected ports)
#ifndef MICROPY_FSUSERMOUNT
#define MICROPY_FSUSERMOUNT (0)
#endif
// Support for generic VFS sub-system
#ifndef MICROPY_VFS
#define MICROPY_VFS (0)

View File

@ -160,11 +160,6 @@ typedef struct _mp_state_vm_t {
mp_obj_t lwip_slip_stream;
#endif
#if MICROPY_FSUSERMOUNT
// for user-mountable block device (max fixed at compile time)
struct _fs_user_mount_t *fs_user_mount[MICROPY_FATFS_VOLUMES];
#endif
#if MICROPY_VFS
struct _mp_vfs_mount_t *vfs_cur;
struct _mp_vfs_mount_t *vfs_mount_table;

View File

@ -233,11 +233,9 @@ PY_O_BASENAME = \
../extmod/modwebsocket.o \
../extmod/modwebrepl.o \
../extmod/modframebuf.o \
../extmod/fsusermount.o \
../extmod/vfs.o \
../extmod/vfs_reader.o \
../extmod/vfs_fat.o \
../extmod/vfs_fat_ffconf.o \
../extmod/vfs_fat_diskio.o \
../extmod/vfs_fat_file.o \
../extmod/vfs_fat_misc.o \

View File

@ -41,13 +41,6 @@
#include "extmod/misc.h"
#include "extmod/vfs_fat.h"
// Can't include this, as FATFS structure definition is required,
// and FatFs header defining it conflicts with POSIX.
//#include "extmod/fsusermount.h"
MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mount_obj);
MP_DECLARE_CONST_FUN_OBJ_1(fsuser_umount_obj);
MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mkfs_obj);
#ifdef __ANDROID__
#define USE_STATFS 1
#endif
@ -233,11 +226,6 @@ STATIC const mp_rom_map_elem_t mp_module_os_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_getenv), MP_ROM_PTR(&mod_os_getenv_obj) },
{ MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&mod_os_mkdir_obj) },
{ MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&mod_os_ilistdir_obj) },
#if MICROPY_FSUSERMOUNT
{ MP_ROM_QSTR(MP_QSTR_vfs_mount), MP_ROM_PTR(&fsuser_mount_obj) },
{ MP_ROM_QSTR(MP_QSTR_vfs_umount), MP_ROM_PTR(&fsuser_umount_obj) },
{ MP_ROM_QSTR(MP_QSTR_vfs_mkfs), MP_ROM_PTR(&fsuser_mkfs_obj) },
#endif
#if MICROPY_VFS_FAT
{ MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) },
#endif

View File

@ -139,7 +139,6 @@
#define MICROPY_FATFS_VOLUMES (3)
#define MICROPY_FATFS_MAX_SS (4096)
#define MICROPY_FATFS_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
#define MICROPY_FSUSERMOUNT (0)
#define MICROPY_VFS_FAT (0)
// Define to MICROPY_ERROR_REPORTING_DETAILED to get function, etc.