2013-02-18 15:32:11 +00:00
|
|
|
/* mbed Microcontroller Library
|
|
|
|
* Copyright (c) 2006-2013 ARM Limited
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
#ifndef MBED_FILESYSTEMLIKE_H
|
|
|
|
#define MBED_FILESYSTEMLIKE_H
|
|
|
|
|
2016-10-01 07:11:36 +00:00
|
|
|
#include "platform/platform.h"
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2017-03-30 19:36:21 +00:00
|
|
|
#include "platform/FileSystemHandle.h"
|
2017-03-07 16:40:37 +00:00
|
|
|
#include "platform/FileHandle.h"
|
|
|
|
#include "platform/DirHandle.h"
|
2017-03-30 19:36:21 +00:00
|
|
|
#include <errno.h>
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
namespace mbed {
|
2017-04-04 19:21:53 +00:00
|
|
|
/** \addtogroup platform */
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2017-03-30 19:36:21 +00:00
|
|
|
|
|
|
|
/** A filesystem-like object is one that can be used to open file-like
|
|
|
|
* objects though it by fopen("/name/filename", mode)
|
2013-02-18 15:32:11 +00:00
|
|
|
*
|
|
|
|
* Implementations must define at least open (the default definitions
|
|
|
|
* of the rest of the functions just return error values).
|
2016-06-08 12:52:14 +00:00
|
|
|
*
|
2017-04-25 19:37:08 +00:00
|
|
|
* @note Synchronization level: Set by subclass
|
2017-04-04 19:21:53 +00:00
|
|
|
* @ingroup platform
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
2017-03-30 19:36:21 +00:00
|
|
|
class FileSystemLike : public FileSystemHandle, public FileBase {
|
2013-02-18 15:32:11 +00:00
|
|
|
public:
|
2017-03-30 19:36:21 +00:00
|
|
|
/** FileSystemLike lifetime
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
2017-03-30 19:36:21 +00:00
|
|
|
FileSystemLike(const char *name = NULL) : FileBase(name, FileSystemPathType) {}
|
|
|
|
virtual ~FileSystemLike() {}
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2017-03-30 19:36:21 +00:00
|
|
|
/** Open a file on the filesystem
|
2013-02-18 15:32:11 +00:00
|
|
|
*
|
2017-03-30 19:36:21 +00:00
|
|
|
* @param file Destination for the handle to a newly created file
|
|
|
|
* @param path The name of the file to open
|
|
|
|
* @param flags The flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR,
|
|
|
|
* bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
|
|
|
|
* @return 0 on success, negative error code on failure
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
2017-03-30 19:36:21 +00:00
|
|
|
virtual int open(FileHandle **file, const char *filename, int flags) = 0;
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2017-03-30 19:36:21 +00:00
|
|
|
/** Open a directory on the filesystem
|
2013-02-18 15:32:11 +00:00
|
|
|
*
|
2017-03-30 19:36:21 +00:00
|
|
|
* @param dir Destination for the handle to the directory
|
|
|
|
* @param path Name of the directory to open
|
|
|
|
* @return 0 on success, negative error code on failure
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
2017-03-30 19:36:21 +00:00
|
|
|
virtual int open(DirHandle **dir, const char *path)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2017-03-30 19:36:21 +00:00
|
|
|
/** Open a file on the filesystem
|
2013-02-18 15:32:11 +00:00
|
|
|
*
|
2017-03-30 19:36:21 +00:00
|
|
|
* @param path The name of the file to open
|
|
|
|
* @param flags The flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR,
|
|
|
|
* bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
|
|
|
|
* @return A file handle on success, NULL on failure
|
|
|
|
* @deprecated Replaced by `int open(FileHandle **, ...)` for propagating error codes
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
2017-03-30 19:36:21 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.5",
|
|
|
|
"Replaced by `int open(FileHandle **, ...)` for propagating error codes")
|
|
|
|
virtual FileHandle *open(const char *path, int flags)
|
|
|
|
{
|
|
|
|
FileHandle *file;
|
|
|
|
int err = open(&file, path, flags);
|
|
|
|
return err ? NULL : file;
|
|
|
|
}
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2017-03-30 19:36:21 +00:00
|
|
|
/** Open a directory on the filesystem
|
2017-01-19 15:30:06 +00:00
|
|
|
*
|
2017-03-30 19:36:21 +00:00
|
|
|
* @param path Name of the directory to open
|
|
|
|
* @return A directory handle on success, NULL on failure
|
|
|
|
* @deprecated Replaced by `int open(DirHandle **, ...)` for propagating error codes
|
2017-01-19 15:30:06 +00:00
|
|
|
*/
|
2017-03-30 19:36:21 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.5",
|
|
|
|
"Replaced by `int open(DirHandle **, ...)` for propagating error codes")
|
|
|
|
virtual DirHandle *opendir(const char *path)
|
|
|
|
{
|
|
|
|
DirHandle *dir;
|
|
|
|
int err = open(&dir, path);
|
|
|
|
return err ? NULL : dir;
|
|
|
|
}
|
2013-02-18 15:32:11 +00:00
|
|
|
};
|
|
|
|
|
2017-03-30 19:36:21 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
} // namespace mbed
|
|
|
|
|
|
|
|
#endif
|