Rahul Dahiya / Mbed OS STM32F7 Ethernet
Committer:
rahul_dahiya
Date:
Wed Jan 15 15:57:15 2020 +0530
Revision:
0:fb8047b156bb
STM32F7 LWIP

Who changed what in which revision?

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