Norimasa Okamoto / F12RFileSystem

Fork of FATFileSystem by mbed official

Committer:
va009039
Date:
Wed Nov 11 19:47:04 2015 +0900
Revision:
7:f9f52d9c0c57
Parent:
6:3c5b3606e019
Child:
8:6c6acf81ff08
first commit F12RFileSystem

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:46ce1e16c870 1 /* mbed Microcontroller Library
va009039 7:f9f52d9c0c57 2 * Copyright (c) 2006-2016 ARM Limited
emilmont 1:46ce1e16c870 3 *
emilmont 1:46ce1e16c870 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
emilmont 1:46ce1e16c870 5 * of this software and associated documentation files (the "Software"), to deal
emilmont 1:46ce1e16c870 6 * in the Software without restriction, including without limitation the rights
emilmont 1:46ce1e16c870 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
emilmont 1:46ce1e16c870 8 * copies of the Software, and to permit persons to whom the Software is
emilmont 1:46ce1e16c870 9 * furnished to do so, subject to the following conditions:
emilmont 1:46ce1e16c870 10 *
emilmont 1:46ce1e16c870 11 * The above copyright notice and this permission notice shall be included in
emilmont 1:46ce1e16c870 12 * all copies or substantial portions of the Software.
emilmont 1:46ce1e16c870 13 *
emilmont 1:46ce1e16c870 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
emilmont 1:46ce1e16c870 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
emilmont 1:46ce1e16c870 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
emilmont 1:46ce1e16c870 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
emilmont 1:46ce1e16c870 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
emilmont 1:46ce1e16c870 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
emilmont 1:46ce1e16c870 20 * SOFTWARE.
emilmont 1:46ce1e16c870 21 */
va009039 7:f9f52d9c0c57 22 #ifndef MBED_F12R_FILESYSTEM_H
va009039 7:f9f52d9c0c57 23 #define MBED_F12R_FILESYSTEM_H
emilmont 1:46ce1e16c870 24
emilmont 1:46ce1e16c870 25 #include "FileSystemLike.h"
emilmont 1:46ce1e16c870 26 #include "FileHandle.h"
emilmont 1:46ce1e16c870 27 #include <stdint.h>
va009039 7:f9f52d9c0c57 28 #include "StorageInterface.h"
va009039 7:f9f52d9c0c57 29
va009039 7:f9f52d9c0c57 30 typedef uint32_t sector_t;
va009039 7:f9f52d9c0c57 31 typedef uint32_t cluster_t;
va009039 7:f9f52d9c0c57 32 typedef uint32_t filesize_t;
emilmont 1:46ce1e16c870 33
emilmont 1:46ce1e16c870 34 using namespace mbed;
emilmont 1:46ce1e16c870 35
screamer 3:e960e2b81a3c 36 /**
va009039 7:f9f52d9c0c57 37 * F12RFileSystem
mbed_official 4:3ff2606d5713 38 */
va009039 6:3c5b3606e019 39 class F12RFileSystem : public FileSystemLike {
emilmont 1:46ce1e16c870 40 public:
va009039 7:f9f52d9c0c57 41 F12RFileSystem(StorageInterface* storage_, const char* n);
va009039 6:3c5b3606e019 42 virtual ~F12RFileSystem();
emilmont 1:46ce1e16c870 43
screamer 3:e960e2b81a3c 44 /**
mbed_official 4:3ff2606d5713 45 * Opens a file on the filesystem
mbed_official 4:3ff2606d5713 46 */
emilmont 1:46ce1e16c870 47 virtual FileHandle *open(const char* name, int flags);
screamer 3:e960e2b81a3c 48
screamer 3:e960e2b81a3c 49 /**
screamer 3:e960e2b81a3c 50 * Removes a file path
screamer 3:e960e2b81a3c 51 */
emilmont 1:46ce1e16c870 52 virtual int remove(const char *filename);
mbed_official 4:3ff2606d5713 53
mbed_official 4:3ff2606d5713 54 /**
mbed_official 4:3ff2606d5713 55 * Renames a file
mbed_official 4:3ff2606d5713 56 */
mbed_official 4:3ff2606d5713 57 virtual int rename(const char *oldname, const char *newname);
mbed_official 4:3ff2606d5713 58
screamer 3:e960e2b81a3c 59 /**
screamer 3:e960e2b81a3c 60 * Formats a logical drive, FDISK artitioning rule, 512 bytes per cluster
screamer 3:e960e2b81a3c 61 */
emilmont 1:46ce1e16c870 62 virtual int format();
mbed_official 4:3ff2606d5713 63
screamer 3:e960e2b81a3c 64 /**
mbed_official 4:3ff2606d5713 65 * Opens a directory on the filesystem
mbed_official 4:3ff2606d5713 66 */
emilmont 1:46ce1e16c870 67 virtual DirHandle *opendir(const char *name);
screamer 3:e960e2b81a3c 68
screamer 3:e960e2b81a3c 69 /**
screamer 3:e960e2b81a3c 70 * Creates a directory path
screamer 3:e960e2b81a3c 71 */
emilmont 1:46ce1e16c870 72 virtual int mkdir(const char *name, mode_t mode);
mbed_official 4:3ff2606d5713 73
mbed_official 4:3ff2606d5713 74 /**
mbed_official 4:3ff2606d5713 75 * Mounts the filesystem
mbed_official 4:3ff2606d5713 76 */
mbed_official 4:3ff2606d5713 77 virtual int mount();
mbed_official 4:3ff2606d5713 78
mbed_official 4:3ff2606d5713 79 /**
mbed_official 4:3ff2606d5713 80 * Unmounts the filesystem
mbed_official 4:3ff2606d5713 81 */
mbed_official 4:3ff2606d5713 82 virtual int unmount();
emilmont 1:46ce1e16c870 83
emilmont 1:46ce1e16c870 84 virtual int disk_initialize() { return 0; }
emilmont 1:46ce1e16c870 85 virtual int disk_status() { return 0; }
va009039 7:f9f52d9c0c57 86 int disk_read(uint8_t * buffer, uint64_t sector, uint8_t count) {
va009039 7:f9f52d9c0c57 87 return storage->storage_read(sector * 512, buffer, 512);
va009039 7:f9f52d9c0c57 88 }
va009039 7:f9f52d9c0c57 89 int disk_write(const uint8_t * buffer, uint64_t sector, uint8_t count) {
va009039 7:f9f52d9c0c57 90 return storage->storage_write(sector * 512, buffer, 512);
va009039 7:f9f52d9c0c57 91 }
emilmont 1:46ce1e16c870 92 virtual int disk_sync() { return 0; }
va009039 7:f9f52d9c0c57 93 uint64_t disk_sectors() { return storage->storage_size() / 512; }
emilmont 1:46ce1e16c870 94
va009039 7:f9f52d9c0c57 95 private:
va009039 7:f9f52d9c0c57 96 friend class F12RFileHandle;
va009039 7:f9f52d9c0c57 97 friend class F12RDirHandle;
va009039 7:f9f52d9c0c57 98 uint32_t storage_peek(uint32_t offset, int n);
va009039 7:f9f52d9c0c57 99 cluster_t fat_read(cluster_t index);
va009039 7:f9f52d9c0c57 100 StorageInterface* storage;
va009039 7:f9f52d9c0c57 101 sector_t base_fat;
va009039 7:f9f52d9c0c57 102 sector_t base_dir;
va009039 7:f9f52d9c0c57 103 sector_t base_data;
va009039 7:f9f52d9c0c57 104 uint32_t cluster_size;
va009039 7:f9f52d9c0c57 105 uint32_t cluster_head(uint32_t pos) const { return pos % cluster_size; }
va009039 7:f9f52d9c0c57 106 uint32_t cluster_tail(uint32_t pos) const { return cluster_size - cluster_head(pos); }
va009039 7:f9f52d9c0c57 107 int max_root_dir_entries;
va009039 7:f9f52d9c0c57 108 bool mounted;
emilmont 1:46ce1e16c870 109 };
emilmont 1:46ce1e16c870 110
emilmont 1:46ce1e16c870 111 #endif