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