|
| 1 | +/* |
| 2 | + * This file is part of the Micro Python project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | + * of this software and associated documentation files (the "Software"), to deal |
| 10 | + * in the Software without restriction, including without limitation the rights |
| 11 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | + * copies of the Software, and to permit persons to whom the Software is |
| 13 | + * furnished to do so, subject to the following conditions: |
| 14 | + * |
| 15 | + * The above copyright notice and this permission notice shall be included in |
| 16 | + * all copies or substantial portions of the Software. |
| 17 | + * |
| 18 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | + * THE SOFTWARE. |
| 25 | + */ |
| 26 | + |
| 27 | +#include <string.h> |
| 28 | + |
| 29 | +#include "py/obj.h" |
| 30 | +#include "py/objnamedtuple.h" |
| 31 | +#include "shared-bindings/time/__init__.h" |
| 32 | + |
| 33 | +//| :mod:`filesystem` --- filesystem related functions |
| 34 | +//| ======================================================== |
| 35 | +//| |
| 36 | +//| .. module:: filesystem |
| 37 | +//| :synopsis: filesystem |
| 38 | +//| :platform: SAMD21, ESP8266 |
| 39 | +//| |
| 40 | +//| Normally filesystems are managed by an operating system. However, |
| 41 | +//| CircuitPython runs at a very low level and must manage the filesystems |
| 42 | +//| itself. This module allows you to do that. |
| 43 | +//| |
| 44 | +//| .. method:: mount(block_device, mount_point) |
| 45 | +//| |
| 46 | +//| Mounts the FATFS on the given block device at the given mount point. |
| 47 | +//| |
| 48 | +//| :param object block_device: Any class that implements `readblocks`, `writeblocks` and `count` |
| 49 | +//| :param str mount_point: Path where to mount the device. |
| 50 | +//| |
| 51 | +STATIC mp_obj_t filesystem_mount(void) { |
| 52 | + return mp_obj_new_float(common_hal_time_monotonic() / 1000.0); |
| 53 | +} |
| 54 | +MP_DEFINE_CONST_FUN_OBJ_0(filesystem_mount_obj, filesystem_mount); |
| 55 | + |
| 56 | +//| .. method:: unmount(mount_point) |
| 57 | +//| |
| 58 | +//| Unmounts the filesystem mounted at mount_point. |
| 59 | +//| |
| 60 | +//| :param str mount_point: the path of the filesystem to unmount |
| 61 | +//| |
| 62 | +STATIC mp_obj_t filesystem_unmount(mp_obj_t mount_point) { |
| 63 | + shared_module_filesystem_unmount(); |
| 64 | + return mp_const_none; |
| 65 | +} |
| 66 | +MP_DEFINE_CONST_FUN_OBJ_1(filesystem_unmount_obj, filesystem_unmount); |
| 67 | + |
| 68 | +STATIC const mp_map_elem_t filesystem_module_globals_table[] = { |
| 69 | + { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_filesystem) }, |
| 70 | + |
| 71 | + { MP_OBJ_NEW_QSTR(MP_QSTR_mount), (mp_obj_t)&filesystem_mount_obj }, |
| 72 | + { MP_OBJ_NEW_QSTR(MP_QSTR_unmount), (mp_obj_t)&filesystem_unmount_obj }, |
| 73 | +}; |
| 74 | + |
| 75 | +STATIC MP_DEFINE_CONST_DICT(filesystem_module_globals, filesystem_module_globals_table); |
| 76 | + |
| 77 | +const mp_obj_module_t filesystem_module = { |
| 78 | + .base = { &mp_filesystem_module }, |
| 79 | + .globals = (mp_obj_dict_t*)&filesystem_module_globals, |
| 80 | +}; |
0 commit comments