mbed-os for GR-LYCHEE
Dependents: mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more
features/filesystem/Dir.cpp@0:f782d9c66c49, 2018-02-02 (annotated)
- Committer:
- dkato
- Date:
- Fri Feb 02 05:42:23 2018 +0000
- Revision:
- 0:f782d9c66c49
mbed-os for GR-LYCHEE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dkato | 0:f782d9c66c49 | 1 | /* mbed Microcontroller Library |
dkato | 0:f782d9c66c49 | 2 | * Copyright (c) 2015 ARM Limited |
dkato | 0:f782d9c66c49 | 3 | * |
dkato | 0:f782d9c66c49 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
dkato | 0:f782d9c66c49 | 5 | * you may not use this file except in compliance with the License. |
dkato | 0:f782d9c66c49 | 6 | * You may obtain a copy of the License at |
dkato | 0:f782d9c66c49 | 7 | * |
dkato | 0:f782d9c66c49 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
dkato | 0:f782d9c66c49 | 9 | * |
dkato | 0:f782d9c66c49 | 10 | * Unless required by applicable law or agreed to in writing, software |
dkato | 0:f782d9c66c49 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
dkato | 0:f782d9c66c49 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
dkato | 0:f782d9c66c49 | 13 | * See the License for the specific language governing permissions and |
dkato | 0:f782d9c66c49 | 14 | * limitations under the License. |
dkato | 0:f782d9c66c49 | 15 | */ |
dkato | 0:f782d9c66c49 | 16 | |
dkato | 0:f782d9c66c49 | 17 | #include "Dir.h" |
dkato | 0:f782d9c66c49 | 18 | #include "mbed.h" |
dkato | 0:f782d9c66c49 | 19 | #include <errno.h> |
dkato | 0:f782d9c66c49 | 20 | |
dkato | 0:f782d9c66c49 | 21 | |
dkato | 0:f782d9c66c49 | 22 | Dir::Dir() |
dkato | 0:f782d9c66c49 | 23 | : _fs(0), _dir(0) |
dkato | 0:f782d9c66c49 | 24 | { |
dkato | 0:f782d9c66c49 | 25 | } |
dkato | 0:f782d9c66c49 | 26 | |
dkato | 0:f782d9c66c49 | 27 | Dir::Dir(FileSystem *fs, const char *path) |
dkato | 0:f782d9c66c49 | 28 | : _fs(0), _dir(0) |
dkato | 0:f782d9c66c49 | 29 | { |
dkato | 0:f782d9c66c49 | 30 | open(fs, path); |
dkato | 0:f782d9c66c49 | 31 | } |
dkato | 0:f782d9c66c49 | 32 | |
dkato | 0:f782d9c66c49 | 33 | Dir::~Dir() |
dkato | 0:f782d9c66c49 | 34 | { |
dkato | 0:f782d9c66c49 | 35 | if (_fs) { |
dkato | 0:f782d9c66c49 | 36 | close(); |
dkato | 0:f782d9c66c49 | 37 | } |
dkato | 0:f782d9c66c49 | 38 | } |
dkato | 0:f782d9c66c49 | 39 | |
dkato | 0:f782d9c66c49 | 40 | int Dir::open(FileSystem *fs, const char *path) |
dkato | 0:f782d9c66c49 | 41 | { |
dkato | 0:f782d9c66c49 | 42 | if (_fs) { |
dkato | 0:f782d9c66c49 | 43 | return -EINVAL; |
dkato | 0:f782d9c66c49 | 44 | } |
dkato | 0:f782d9c66c49 | 45 | |
dkato | 0:f782d9c66c49 | 46 | _fs = fs; |
dkato | 0:f782d9c66c49 | 47 | return _fs->dir_open(&_dir, path); |
dkato | 0:f782d9c66c49 | 48 | } |
dkato | 0:f782d9c66c49 | 49 | |
dkato | 0:f782d9c66c49 | 50 | int Dir::close() |
dkato | 0:f782d9c66c49 | 51 | { |
dkato | 0:f782d9c66c49 | 52 | if (!_fs) { |
dkato | 0:f782d9c66c49 | 53 | return -EINVAL; |
dkato | 0:f782d9c66c49 | 54 | } |
dkato | 0:f782d9c66c49 | 55 | |
dkato | 0:f782d9c66c49 | 56 | int err = _fs->dir_close(_dir); |
dkato | 0:f782d9c66c49 | 57 | _fs = 0; |
dkato | 0:f782d9c66c49 | 58 | return err; |
dkato | 0:f782d9c66c49 | 59 | } |
dkato | 0:f782d9c66c49 | 60 | |
dkato | 0:f782d9c66c49 | 61 | ssize_t Dir::read(struct dirent *ent) |
dkato | 0:f782d9c66c49 | 62 | { |
dkato | 0:f782d9c66c49 | 63 | MBED_ASSERT(_fs); |
dkato | 0:f782d9c66c49 | 64 | memset(ent, 0, sizeof(struct dirent)); |
dkato | 0:f782d9c66c49 | 65 | return _fs->dir_read(_dir, ent); |
dkato | 0:f782d9c66c49 | 66 | } |
dkato | 0:f782d9c66c49 | 67 | |
dkato | 0:f782d9c66c49 | 68 | void Dir::seek(off_t offset) |
dkato | 0:f782d9c66c49 | 69 | { |
dkato | 0:f782d9c66c49 | 70 | MBED_ASSERT(_fs); |
dkato | 0:f782d9c66c49 | 71 | return _fs->dir_seek(_dir, offset); |
dkato | 0:f782d9c66c49 | 72 | } |
dkato | 0:f782d9c66c49 | 73 | |
dkato | 0:f782d9c66c49 | 74 | off_t Dir::tell() |
dkato | 0:f782d9c66c49 | 75 | { |
dkato | 0:f782d9c66c49 | 76 | MBED_ASSERT(_fs); |
dkato | 0:f782d9c66c49 | 77 | return _fs->dir_tell(_dir); |
dkato | 0:f782d9c66c49 | 78 | } |
dkato | 0:f782d9c66c49 | 79 | |
dkato | 0:f782d9c66c49 | 80 | void Dir::rewind() |
dkato | 0:f782d9c66c49 | 81 | { |
dkato | 0:f782d9c66c49 | 82 | MBED_ASSERT(_fs); |
dkato | 0:f782d9c66c49 | 83 | return _fs->dir_rewind(_dir); |
dkato | 0:f782d9c66c49 | 84 | } |
dkato | 0:f782d9c66c49 | 85 | |
dkato | 0:f782d9c66c49 | 86 | size_t Dir::size() |
dkato | 0:f782d9c66c49 | 87 | { |
dkato | 0:f782d9c66c49 | 88 | MBED_ASSERT(_fs); |
dkato | 0:f782d9c66c49 | 89 | return _fs->dir_size(_dir); |
dkato | 0:f782d9c66c49 | 90 | } |