Madeline Kistler / SDFileSystem2
Committer:
mkistler
Date:
Tue Nov 17 20:30:08 2020 +0000
Revision:
0:812e8b0b2832
Final draft.

Who changed what in which revision?

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