Dependents:   microSD_Card

Committer:
adrevong
Date:
Tue Jan 28 11:11:57 2020 +0000
Revision:
0:c9f6f3f0cd78

        

Who changed what in which revision?

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