Preliminary main mbed library for nexpaq development
libraries/fs/fat/FATFileSystem.h@1:d96dbedaebdb, 2016-11-04 (annotated)
- Committer:
- nexpaq
- Date:
- Fri Nov 04 20:54:50 2016 +0000
- Revision:
- 1:d96dbedaebdb
- Parent:
- 0:6c56fb4bc5f0
Removed extra directories for other platforms
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 0:6c56fb4bc5f0 | 1 | /* mbed Microcontroller Library |
nexpaq | 0:6c56fb4bc5f0 | 2 | * Copyright (c) 2006-2012 ARM Limited |
nexpaq | 0:6c56fb4bc5f0 | 3 | * |
nexpaq | 0:6c56fb4bc5f0 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
nexpaq | 0:6c56fb4bc5f0 | 5 | * of this software and associated documentation files (the "Software"), to deal |
nexpaq | 0:6c56fb4bc5f0 | 6 | * in the Software without restriction, including without limitation the rights |
nexpaq | 0:6c56fb4bc5f0 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
nexpaq | 0:6c56fb4bc5f0 | 8 | * copies of the Software, and to permit persons to whom the Software is |
nexpaq | 0:6c56fb4bc5f0 | 9 | * furnished to do so, subject to the following conditions: |
nexpaq | 0:6c56fb4bc5f0 | 10 | * |
nexpaq | 0:6c56fb4bc5f0 | 11 | * The above copyright notice and this permission notice shall be included in |
nexpaq | 0:6c56fb4bc5f0 | 12 | * all copies or substantial portions of the Software. |
nexpaq | 0:6c56fb4bc5f0 | 13 | * |
nexpaq | 0:6c56fb4bc5f0 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
nexpaq | 0:6c56fb4bc5f0 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
nexpaq | 0:6c56fb4bc5f0 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
nexpaq | 0:6c56fb4bc5f0 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
nexpaq | 0:6c56fb4bc5f0 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
nexpaq | 0:6c56fb4bc5f0 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
nexpaq | 0:6c56fb4bc5f0 | 20 | * SOFTWARE. |
nexpaq | 0:6c56fb4bc5f0 | 21 | */ |
nexpaq | 0:6c56fb4bc5f0 | 22 | #ifndef MBED_FATFILESYSTEM_H |
nexpaq | 0:6c56fb4bc5f0 | 23 | #define MBED_FATFILESYSTEM_H |
nexpaq | 0:6c56fb4bc5f0 | 24 | |
nexpaq | 0:6c56fb4bc5f0 | 25 | #include "FileSystemLike.h" |
nexpaq | 0:6c56fb4bc5f0 | 26 | #include "FileHandle.h" |
nexpaq | 0:6c56fb4bc5f0 | 27 | #include "ff.h" |
nexpaq | 0:6c56fb4bc5f0 | 28 | #include <stdint.h> |
nexpaq | 0:6c56fb4bc5f0 | 29 | #include "PlatformMutex.h" |
nexpaq | 0:6c56fb4bc5f0 | 30 | |
nexpaq | 0:6c56fb4bc5f0 | 31 | using namespace mbed; |
nexpaq | 0:6c56fb4bc5f0 | 32 | |
nexpaq | 0:6c56fb4bc5f0 | 33 | /** |
nexpaq | 0:6c56fb4bc5f0 | 34 | * FATFileSystem based on ChaN's Fat Filesystem library v0.8 |
nexpaq | 0:6c56fb4bc5f0 | 35 | */ |
nexpaq | 0:6c56fb4bc5f0 | 36 | class FATFileSystem : public FileSystemLike { |
nexpaq | 0:6c56fb4bc5f0 | 37 | public: |
nexpaq | 0:6c56fb4bc5f0 | 38 | |
nexpaq | 0:6c56fb4bc5f0 | 39 | FATFileSystem(const char* n); |
nexpaq | 0:6c56fb4bc5f0 | 40 | virtual ~FATFileSystem(); |
nexpaq | 0:6c56fb4bc5f0 | 41 | |
nexpaq | 0:6c56fb4bc5f0 | 42 | static FATFileSystem * _ffs[_VOLUMES]; // FATFileSystem objects, as parallel to FatFs drives array |
nexpaq | 0:6c56fb4bc5f0 | 43 | FATFS _fs; // Work area (file system object) for logical drive |
nexpaq | 0:6c56fb4bc5f0 | 44 | char _fsid[2]; |
nexpaq | 0:6c56fb4bc5f0 | 45 | |
nexpaq | 0:6c56fb4bc5f0 | 46 | /** |
nexpaq | 0:6c56fb4bc5f0 | 47 | * Opens a file on the filesystem |
nexpaq | 0:6c56fb4bc5f0 | 48 | */ |
nexpaq | 0:6c56fb4bc5f0 | 49 | virtual FileHandle *open(const char* name, int flags); |
nexpaq | 0:6c56fb4bc5f0 | 50 | |
nexpaq | 0:6c56fb4bc5f0 | 51 | /** |
nexpaq | 0:6c56fb4bc5f0 | 52 | * Removes a file path |
nexpaq | 0:6c56fb4bc5f0 | 53 | */ |
nexpaq | 0:6c56fb4bc5f0 | 54 | virtual int remove(const char *filename); |
nexpaq | 0:6c56fb4bc5f0 | 55 | |
nexpaq | 0:6c56fb4bc5f0 | 56 | /** |
nexpaq | 0:6c56fb4bc5f0 | 57 | * Renames a file |
nexpaq | 0:6c56fb4bc5f0 | 58 | */ |
nexpaq | 0:6c56fb4bc5f0 | 59 | virtual int rename(const char *oldname, const char *newname); |
nexpaq | 0:6c56fb4bc5f0 | 60 | |
nexpaq | 0:6c56fb4bc5f0 | 61 | /** |
nexpaq | 0:6c56fb4bc5f0 | 62 | * Formats a logical drive, FDISK artitioning rule, 512 bytes per cluster |
nexpaq | 0:6c56fb4bc5f0 | 63 | */ |
nexpaq | 0:6c56fb4bc5f0 | 64 | virtual int format(); |
nexpaq | 0:6c56fb4bc5f0 | 65 | |
nexpaq | 0:6c56fb4bc5f0 | 66 | /** |
nexpaq | 0:6c56fb4bc5f0 | 67 | * Opens a directory on the filesystem |
nexpaq | 0:6c56fb4bc5f0 | 68 | */ |
nexpaq | 0:6c56fb4bc5f0 | 69 | virtual DirHandle *opendir(const char *name); |
nexpaq | 0:6c56fb4bc5f0 | 70 | |
nexpaq | 0:6c56fb4bc5f0 | 71 | /** |
nexpaq | 0:6c56fb4bc5f0 | 72 | * Creates a directory path |
nexpaq | 0:6c56fb4bc5f0 | 73 | */ |
nexpaq | 0:6c56fb4bc5f0 | 74 | virtual int mkdir(const char *name, mode_t mode); |
nexpaq | 0:6c56fb4bc5f0 | 75 | |
nexpaq | 0:6c56fb4bc5f0 | 76 | /** |
nexpaq | 0:6c56fb4bc5f0 | 77 | * Mounts the filesystem |
nexpaq | 0:6c56fb4bc5f0 | 78 | */ |
nexpaq | 0:6c56fb4bc5f0 | 79 | virtual int mount(); |
nexpaq | 0:6c56fb4bc5f0 | 80 | |
nexpaq | 0:6c56fb4bc5f0 | 81 | /** |
nexpaq | 0:6c56fb4bc5f0 | 82 | * Unmounts the filesystem |
nexpaq | 0:6c56fb4bc5f0 | 83 | */ |
nexpaq | 0:6c56fb4bc5f0 | 84 | virtual int unmount(); |
nexpaq | 0:6c56fb4bc5f0 | 85 | |
nexpaq | 0:6c56fb4bc5f0 | 86 | virtual int disk_initialize() { return 0; } |
nexpaq | 0:6c56fb4bc5f0 | 87 | virtual int disk_status() { return 0; } |
nexpaq | 0:6c56fb4bc5f0 | 88 | virtual int disk_read(uint8_t *buffer, uint32_t sector, uint32_t count) = 0; |
nexpaq | 0:6c56fb4bc5f0 | 89 | virtual int disk_write(const uint8_t *buffer, uint32_t sector, uint32_t count) = 0; |
nexpaq | 0:6c56fb4bc5f0 | 90 | virtual int disk_sync() { return 0; } |
nexpaq | 0:6c56fb4bc5f0 | 91 | virtual uint32_t disk_sectors() = 0; |
nexpaq | 0:6c56fb4bc5f0 | 92 | |
nexpaq | 0:6c56fb4bc5f0 | 93 | protected: |
nexpaq | 0:6c56fb4bc5f0 | 94 | |
nexpaq | 0:6c56fb4bc5f0 | 95 | virtual void lock(); |
nexpaq | 0:6c56fb4bc5f0 | 96 | virtual void unlock(); |
nexpaq | 0:6c56fb4bc5f0 | 97 | |
nexpaq | 0:6c56fb4bc5f0 | 98 | private: |
nexpaq | 0:6c56fb4bc5f0 | 99 | |
nexpaq | 0:6c56fb4bc5f0 | 100 | PlatformMutex *_mutex; |
nexpaq | 0:6c56fb4bc5f0 | 101 | |
nexpaq | 0:6c56fb4bc5f0 | 102 | }; |
nexpaq | 0:6c56fb4bc5f0 | 103 | |
nexpaq | 0:6c56fb4bc5f0 | 104 | #endif |