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