mbed-os

Fork of mbed-os by erkin yucel

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

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