mbed-dev-f303

Committer:
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4
Date:
Tue Jun 14 09:21:18 2022 +0000
Revision:
0:bdf663c61a82
lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 1 /* mbed Microcontroller Library
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 2 * Copyright (c) 2006-2013 ARM Limited
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 3 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 4 * Licensed under the Apache License, Version 2.0 (the "License");
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 5 * you may not use this file except in compliance with the License.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 6 * You may obtain a copy of the License at
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 7 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 8 * http://www.apache.org/licenses/LICENSE-2.0
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 9 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 10 * Unless required by applicable law or agreed to in writing, software
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 11 * distributed under the License is distributed on an "AS IS" BASIS,
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 13 * See the License for the specific language governing permissions and
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 14 * limitations under the License.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 15 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 16 #ifndef MBED_FILESYSTEMHANDLE_H
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 17 #define MBED_FILESYSTEMHANDLE_H
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 18
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 19 #include "platform/platform.h"
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 20
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 21 #include "platform/FileBase.h"
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 22 #include "platform/FileHandle.h"
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 23 #include "platform/DirHandle.h"
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 24 #include "platform/NonCopyable.h"
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 25
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 26 namespace mbed {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 27 /** \addtogroup drivers */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 28 /** @{*/
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 29
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 30
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 31 /** A filesystem-like object is one that can be used to open file-like
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 32 * objects though it by fopen("/name/filename", mode)
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 33 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 34 * Implementations must define at least open (the default definitions
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 35 * of the rest of the functions just return error values).
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 36 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 37 * @note Synchronization level: Set by subclass
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 38 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 39 class FileSystemHandle : private NonCopyable<FileSystemHandle> {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 40 public:
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 41 /** FileSystemHandle lifetime
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 42 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 43 virtual ~FileSystemHandle() {}
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 44
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 45 /** Open a file on the filesystem
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 46 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 47 * @param file Destination for the handle to a newly created file
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 48 * @param filename The name of the file to open
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 49 * @param flags The flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR,
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 50 * bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 51 * @return 0 on success, negative error code on failure
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 52 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 53 virtual int open(FileHandle **file, const char *filename, int flags) = 0;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 54
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 55 /** Open a directory on the filesystem
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 56 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 57 * @param dir Destination for the handle to the directory
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 58 * @param path Name of the directory to open
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 59 * @return 0 on success, negative error code on failure
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 60 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 61 virtual int open(DirHandle **dir, const char *path);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 62
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 63 /** Remove a file from the filesystem.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 64 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 65 * @param path The name of the file to remove.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 66 * @return 0 on success, negative error code on failure
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 67 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 68 virtual int remove(const char *path);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 69
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 70 /** Rename a file in the filesystem.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 71 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 72 * @param path The name of the file to rename.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 73 * @param newpath The name to rename it to
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 74 * @return 0 on success, negative error code on failure
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 75 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 76 virtual int rename(const char *path, const char *newpath);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 77
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 78 /** Store information about the file in a stat structure
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 79 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 80 * @param path The name of the file to find information about
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 81 * @param st The stat buffer to write to
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 82 * @return 0 on success, negative error code on failure
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 83 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 84 virtual int stat(const char *path, struct stat *st);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 85
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 86 /** Create a directory in the filesystem.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 87 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 88 * @param path The name of the directory to create.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 89 * @param mode The permissions with which to create the directory
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 90 * @return 0 on success, negative error code on failure
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 91 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 92 virtual int mkdir(const char *path, mode_t mode);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 93 };
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 94
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 95
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 96 } // namespace mbed
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 97
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 98 #endif
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 99
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 100 /** @}*/
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 101