Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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