Daniel Vizcaya
/
04_RTOS_Embebidos
Entrega 3er corte - sistemas embebidos
mbed-os/features/filesystem/File.h@0:6ad07c9019fd, 2018-05-30 (annotated)
- Committer:
- Bethory
- Date:
- Wed May 30 00:01:50 2018 +0000
- Revision:
- 0:6ad07c9019fd
Codigo de tales para todos los pasculaes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bethory | 0:6ad07c9019fd | 1 | /* mbed Microcontroller Library |
Bethory | 0:6ad07c9019fd | 2 | * Copyright (c) 2015 ARM Limited |
Bethory | 0:6ad07c9019fd | 3 | * |
Bethory | 0:6ad07c9019fd | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Bethory | 0:6ad07c9019fd | 5 | * you may not use this file except in compliance with the License. |
Bethory | 0:6ad07c9019fd | 6 | * You may obtain a copy of the License at |
Bethory | 0:6ad07c9019fd | 7 | * |
Bethory | 0:6ad07c9019fd | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Bethory | 0:6ad07c9019fd | 9 | * |
Bethory | 0:6ad07c9019fd | 10 | * Unless required by applicable law or agreed to in writing, software |
Bethory | 0:6ad07c9019fd | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Bethory | 0:6ad07c9019fd | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Bethory | 0:6ad07c9019fd | 13 | * See the License for the specific language governing permissions and |
Bethory | 0:6ad07c9019fd | 14 | * limitations under the License. |
Bethory | 0:6ad07c9019fd | 15 | */ |
Bethory | 0:6ad07c9019fd | 16 | |
Bethory | 0:6ad07c9019fd | 17 | #ifndef FILE_H |
Bethory | 0:6ad07c9019fd | 18 | #define FILE_H |
Bethory | 0:6ad07c9019fd | 19 | |
Bethory | 0:6ad07c9019fd | 20 | #include "filesystem/FileSystem.h" |
Bethory | 0:6ad07c9019fd | 21 | #include "platform/FileHandle.h" |
Bethory | 0:6ad07c9019fd | 22 | |
Bethory | 0:6ad07c9019fd | 23 | namespace mbed { |
Bethory | 0:6ad07c9019fd | 24 | /** \addtogroup filesystem */ |
Bethory | 0:6ad07c9019fd | 25 | /** @{*/ |
Bethory | 0:6ad07c9019fd | 26 | |
Bethory | 0:6ad07c9019fd | 27 | |
Bethory | 0:6ad07c9019fd | 28 | /** File class |
Bethory | 0:6ad07c9019fd | 29 | */ |
Bethory | 0:6ad07c9019fd | 30 | class File : public FileHandle { |
Bethory | 0:6ad07c9019fd | 31 | public: |
Bethory | 0:6ad07c9019fd | 32 | /** Create an uninitialized file |
Bethory | 0:6ad07c9019fd | 33 | * |
Bethory | 0:6ad07c9019fd | 34 | * Must call open to initialize the file on a file system |
Bethory | 0:6ad07c9019fd | 35 | */ |
Bethory | 0:6ad07c9019fd | 36 | File(); |
Bethory | 0:6ad07c9019fd | 37 | |
Bethory | 0:6ad07c9019fd | 38 | /** Create a file on a filesystem |
Bethory | 0:6ad07c9019fd | 39 | * |
Bethory | 0:6ad07c9019fd | 40 | * Creates and opens a file on a filesystem |
Bethory | 0:6ad07c9019fd | 41 | * |
Bethory | 0:6ad07c9019fd | 42 | * @param fs Filesystem as target for the file |
Bethory | 0:6ad07c9019fd | 43 | * @param path The name of the file to open |
Bethory | 0:6ad07c9019fd | 44 | * @param flags The flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR, |
Bethory | 0:6ad07c9019fd | 45 | * bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND |
Bethory | 0:6ad07c9019fd | 46 | */ |
Bethory | 0:6ad07c9019fd | 47 | File(FileSystem *fs, const char *path, int flags = O_RDONLY); |
Bethory | 0:6ad07c9019fd | 48 | |
Bethory | 0:6ad07c9019fd | 49 | /** Destroy a file |
Bethory | 0:6ad07c9019fd | 50 | * |
Bethory | 0:6ad07c9019fd | 51 | * Closes file if the file is still open |
Bethory | 0:6ad07c9019fd | 52 | */ |
Bethory | 0:6ad07c9019fd | 53 | virtual ~File(); |
Bethory | 0:6ad07c9019fd | 54 | |
Bethory | 0:6ad07c9019fd | 55 | /** Open a file on the filesystem |
Bethory | 0:6ad07c9019fd | 56 | * |
Bethory | 0:6ad07c9019fd | 57 | * @param fs Filesystem as target for the file |
Bethory | 0:6ad07c9019fd | 58 | * @param path The name of the file to open |
Bethory | 0:6ad07c9019fd | 59 | * @param flags The flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR, |
Bethory | 0:6ad07c9019fd | 60 | * bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND |
Bethory | 0:6ad07c9019fd | 61 | * @return 0 on success, negative error code on failure |
Bethory | 0:6ad07c9019fd | 62 | */ |
Bethory | 0:6ad07c9019fd | 63 | virtual int open(FileSystem *fs, const char *path, int flags=O_RDONLY); |
Bethory | 0:6ad07c9019fd | 64 | |
Bethory | 0:6ad07c9019fd | 65 | /** Close a file |
Bethory | 0:6ad07c9019fd | 66 | * |
Bethory | 0:6ad07c9019fd | 67 | * @return 0 on success, negative error code on failure |
Bethory | 0:6ad07c9019fd | 68 | */ |
Bethory | 0:6ad07c9019fd | 69 | virtual int close(); |
Bethory | 0:6ad07c9019fd | 70 | |
Bethory | 0:6ad07c9019fd | 71 | /** Read the contents of a file into a buffer |
Bethory | 0:6ad07c9019fd | 72 | * |
Bethory | 0:6ad07c9019fd | 73 | * @param buffer The buffer to read in to |
Bethory | 0:6ad07c9019fd | 74 | * @param size The number of bytes to read |
Bethory | 0:6ad07c9019fd | 75 | * @return The number of bytes read, 0 at end of file, negative error on failure |
Bethory | 0:6ad07c9019fd | 76 | */ |
Bethory | 0:6ad07c9019fd | 77 | |
Bethory | 0:6ad07c9019fd | 78 | virtual ssize_t read(void *buffer, size_t size); |
Bethory | 0:6ad07c9019fd | 79 | |
Bethory | 0:6ad07c9019fd | 80 | /** Write the contents of a buffer to a file |
Bethory | 0:6ad07c9019fd | 81 | * |
Bethory | 0:6ad07c9019fd | 82 | * @param buffer The buffer to write from |
Bethory | 0:6ad07c9019fd | 83 | * @param size The number of bytes to write |
Bethory | 0:6ad07c9019fd | 84 | * @return The number of bytes written, negative error on failure |
Bethory | 0:6ad07c9019fd | 85 | */ |
Bethory | 0:6ad07c9019fd | 86 | virtual ssize_t write(const void *buffer, size_t size); |
Bethory | 0:6ad07c9019fd | 87 | |
Bethory | 0:6ad07c9019fd | 88 | /** Flush any buffers associated with the file |
Bethory | 0:6ad07c9019fd | 89 | * |
Bethory | 0:6ad07c9019fd | 90 | * @return 0 on success, negative error code on failure |
Bethory | 0:6ad07c9019fd | 91 | */ |
Bethory | 0:6ad07c9019fd | 92 | virtual int sync(); |
Bethory | 0:6ad07c9019fd | 93 | |
Bethory | 0:6ad07c9019fd | 94 | /** Check if the file in an interactive terminal device |
Bethory | 0:6ad07c9019fd | 95 | * |
Bethory | 0:6ad07c9019fd | 96 | * @return True if the file is a terminal |
Bethory | 0:6ad07c9019fd | 97 | */ |
Bethory | 0:6ad07c9019fd | 98 | virtual int isatty(); |
Bethory | 0:6ad07c9019fd | 99 | |
Bethory | 0:6ad07c9019fd | 100 | /** Move the file position to a given offset from from a given location |
Bethory | 0:6ad07c9019fd | 101 | * |
Bethory | 0:6ad07c9019fd | 102 | * @param offset The offset from whence to move to |
Bethory | 0:6ad07c9019fd | 103 | * @param whence The start of where to seek |
Bethory | 0:6ad07c9019fd | 104 | * SEEK_SET to start from beginning of file, |
Bethory | 0:6ad07c9019fd | 105 | * SEEK_CUR to start from current position in file, |
Bethory | 0:6ad07c9019fd | 106 | * SEEK_END to start from end of file |
Bethory | 0:6ad07c9019fd | 107 | * @return The new offset of the file |
Bethory | 0:6ad07c9019fd | 108 | */ |
Bethory | 0:6ad07c9019fd | 109 | virtual off_t seek(off_t offset, int whence = SEEK_SET); |
Bethory | 0:6ad07c9019fd | 110 | |
Bethory | 0:6ad07c9019fd | 111 | /** Get the file position of the file |
Bethory | 0:6ad07c9019fd | 112 | * |
Bethory | 0:6ad07c9019fd | 113 | * @return The current offset in the file |
Bethory | 0:6ad07c9019fd | 114 | */ |
Bethory | 0:6ad07c9019fd | 115 | virtual off_t tell(); |
Bethory | 0:6ad07c9019fd | 116 | |
Bethory | 0:6ad07c9019fd | 117 | /** Rewind the file position to the beginning of the file |
Bethory | 0:6ad07c9019fd | 118 | * |
Bethory | 0:6ad07c9019fd | 119 | * @note This is equivalent to file_seek(file, 0, FS_SEEK_SET) |
Bethory | 0:6ad07c9019fd | 120 | */ |
Bethory | 0:6ad07c9019fd | 121 | virtual void rewind(); |
Bethory | 0:6ad07c9019fd | 122 | |
Bethory | 0:6ad07c9019fd | 123 | /** Get the size of the file |
Bethory | 0:6ad07c9019fd | 124 | * |
Bethory | 0:6ad07c9019fd | 125 | * @return Size of the file in bytes |
Bethory | 0:6ad07c9019fd | 126 | */ |
Bethory | 0:6ad07c9019fd | 127 | virtual off_t size(); |
Bethory | 0:6ad07c9019fd | 128 | |
Bethory | 0:6ad07c9019fd | 129 | private: |
Bethory | 0:6ad07c9019fd | 130 | FileSystem *_fs; |
Bethory | 0:6ad07c9019fd | 131 | fs_file_t _file; |
Bethory | 0:6ad07c9019fd | 132 | }; |
Bethory | 0:6ad07c9019fd | 133 | |
Bethory | 0:6ad07c9019fd | 134 | |
Bethory | 0:6ad07c9019fd | 135 | /** @}*/ |
Bethory | 0:6ad07c9019fd | 136 | } // namespace mbed |
Bethory | 0:6ad07c9019fd | 137 | |
Bethory | 0:6ad07c9019fd | 138 | #endif |