mbed-os5 only for TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Committer:
kenjiArai
Date:
Tue Dec 31 06:02:27 2019 +0000
Revision:
1:9db0e321a9f4
Parent:
0:5b88d5760320
updated based on mbed-os5.15.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 0:5b88d5760320 1 /* mbed Microcontroller Library
kenjiArai 0:5b88d5760320 2 * Copyright (c) 2015 ARM Limited
kenjiArai 0:5b88d5760320 3 *
kenjiArai 0:5b88d5760320 4 * Licensed under the Apache License, Version 2.0 (the "License");
kenjiArai 0:5b88d5760320 5 * you may not use this file except in compliance with the License.
kenjiArai 0:5b88d5760320 6 * You may obtain a copy of the License at
kenjiArai 0:5b88d5760320 7 *
kenjiArai 0:5b88d5760320 8 * http://www.apache.org/licenses/LICENSE-2.0
kenjiArai 0:5b88d5760320 9 *
kenjiArai 0:5b88d5760320 10 * Unless required by applicable law or agreed to in writing, software
kenjiArai 0:5b88d5760320 11 * distributed under the License is distributed on an "AS IS" BASIS,
kenjiArai 0:5b88d5760320 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kenjiArai 0:5b88d5760320 13 * See the License for the specific language governing permissions and
kenjiArai 0:5b88d5760320 14 * limitations under the License.
kenjiArai 0:5b88d5760320 15 */
kenjiArai 0:5b88d5760320 16
kenjiArai 0:5b88d5760320 17 #ifndef DIR_H
kenjiArai 0:5b88d5760320 18 #define DIR_H
kenjiArai 0:5b88d5760320 19
kenjiArai 1:9db0e321a9f4 20 #include "features/storage/filesystem/FileSystem.h"
kenjiArai 0:5b88d5760320 21 #include "platform/DirHandle.h"
kenjiArai 0:5b88d5760320 22
kenjiArai 0:5b88d5760320 23 namespace mbed {
kenjiArai 0:5b88d5760320 24 /** \addtogroup filesystem */
kenjiArai 0:5b88d5760320 25 /** @{*/
kenjiArai 0:5b88d5760320 26
kenjiArai 0:5b88d5760320 27
kenjiArai 0:5b88d5760320 28 /** Dir class
kenjiArai 0:5b88d5760320 29 */
kenjiArai 0:5b88d5760320 30 class Dir : public DirHandle {
kenjiArai 0:5b88d5760320 31 public:
kenjiArai 0:5b88d5760320 32 /** Create an uninitialized directory
kenjiArai 0:5b88d5760320 33 *
kenjiArai 0:5b88d5760320 34 * Must call open to initialize the directory on a file system
kenjiArai 0:5b88d5760320 35 */
kenjiArai 0:5b88d5760320 36 Dir();
kenjiArai 0:5b88d5760320 37
kenjiArai 0:5b88d5760320 38 /** Open a directory on a filesystem
kenjiArai 0:5b88d5760320 39 *
kenjiArai 0:5b88d5760320 40 * @param fs Filesystem as target for a directory
kenjiArai 0:5b88d5760320 41 * @param path Name of the directory to open
kenjiArai 0:5b88d5760320 42 */
kenjiArai 0:5b88d5760320 43 Dir(FileSystem *fs, const char *path);
kenjiArai 0:5b88d5760320 44
kenjiArai 0:5b88d5760320 45 /** Destroy a file
kenjiArai 0:5b88d5760320 46 *
kenjiArai 0:5b88d5760320 47 * Closes file if the file is still open
kenjiArai 0:5b88d5760320 48 */
kenjiArai 0:5b88d5760320 49 virtual ~Dir();
kenjiArai 0:5b88d5760320 50
kenjiArai 0:5b88d5760320 51 /** Open a directory on the filesystem
kenjiArai 0:5b88d5760320 52 *
kenjiArai 0:5b88d5760320 53 * @param fs Filesystem as target for a directory
kenjiArai 0:5b88d5760320 54 * @param path Name of the directory to open
kenjiArai 0:5b88d5760320 55 * @return 0 on success, negative error code on failure
kenjiArai 0:5b88d5760320 56 */
kenjiArai 0:5b88d5760320 57 virtual int open(FileSystem *fs, const char *path);
kenjiArai 0:5b88d5760320 58
kenjiArai 0:5b88d5760320 59 /** Close a directory
kenjiArai 0:5b88d5760320 60 *
kenjiArai 0:5b88d5760320 61 * @return 0 on success, negative error code on failure
kenjiArai 0:5b88d5760320 62 */
kenjiArai 0:5b88d5760320 63 virtual int close();
kenjiArai 0:5b88d5760320 64
kenjiArai 0:5b88d5760320 65 /** Read the next directory entry
kenjiArai 0:5b88d5760320 66 *
kenjiArai 0:5b88d5760320 67 * @param ent The directory entry to fill out
kenjiArai 0:5b88d5760320 68 * @return 1 on reading a filename, 0 at end of directory, negative error on failure
kenjiArai 0:5b88d5760320 69 */
kenjiArai 0:5b88d5760320 70 virtual ssize_t read(struct dirent *ent);
kenjiArai 0:5b88d5760320 71
kenjiArai 0:5b88d5760320 72 /** Set the current position of the directory
kenjiArai 0:5b88d5760320 73 *
kenjiArai 0:5b88d5760320 74 * @param offset Offset of the location to seek to,
kenjiArai 0:5b88d5760320 75 * must be a value returned from tell
kenjiArai 0:5b88d5760320 76 */
kenjiArai 0:5b88d5760320 77 virtual void seek(off_t offset);
kenjiArai 0:5b88d5760320 78
kenjiArai 0:5b88d5760320 79 /** Get the current position of the directory
kenjiArai 0:5b88d5760320 80 *
kenjiArai 0:5b88d5760320 81 * @return Position of the directory that can be passed to rewind
kenjiArai 0:5b88d5760320 82 */
kenjiArai 0:5b88d5760320 83 virtual off_t tell();
kenjiArai 0:5b88d5760320 84
kenjiArai 0:5b88d5760320 85 /** Rewind the current position to the beginning of the directory
kenjiArai 0:5b88d5760320 86 */
kenjiArai 0:5b88d5760320 87 virtual void rewind();
kenjiArai 0:5b88d5760320 88
kenjiArai 0:5b88d5760320 89 /** Get the sizeof the directory
kenjiArai 0:5b88d5760320 90 *
kenjiArai 0:5b88d5760320 91 * @return Number of files in the directory
kenjiArai 0:5b88d5760320 92 */
kenjiArai 0:5b88d5760320 93 virtual size_t size();
kenjiArai 0:5b88d5760320 94
kenjiArai 0:5b88d5760320 95 private:
kenjiArai 0:5b88d5760320 96 FileSystem *_fs;
kenjiArai 0:5b88d5760320 97 fs_dir_t _dir;
kenjiArai 0:5b88d5760320 98 };
kenjiArai 0:5b88d5760320 99
kenjiArai 0:5b88d5760320 100
kenjiArai 0:5b88d5760320 101 /** @}*/
kenjiArai 0:5b88d5760320 102 } // namespace mbed
kenjiArai 0:5b88d5760320 103
kenjiArai 0:5b88d5760320 104 #endif