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