Mark Schwarzer / SDFileSystem

Dependents:   Schwarzer_A7_1

Committer:
markschwarzer
Date:
Mon Nov 09 14:25:13 2020 +0000
Revision:
0:964d386ab059
logged data in SD card

Who changed what in which revision?

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