Norimasa Okamoto / F12RFileSystem

Fork of FATFileSystem by mbed official

Revision:
7:f9f52d9c0c57
Parent:
6:3c5b3606e019
Child:
8:6c6acf81ff08
diff -r 3c5b3606e019 -r f9f52d9c0c57 F12RFileSystem.h
--- a/F12RFileSystem.h	Sat Oct 31 00:30:21 2015 +0000
+++ b/F12RFileSystem.h	Wed Nov 11 19:47:04 2015 +0900
@@ -1,5 +1,5 @@
 /* mbed Microcontroller Library
- * Copyright (c) 2006-2015 ARM Limited
+ * Copyright (c) 2006-2016 ARM Limited
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -19,29 +19,28 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
-#ifndef MBED_FATFILESYSTEM_H
-#define MBED_FATFILESYSTEM_H
+#ifndef MBED_F12R_FILESYSTEM_H
+#define MBED_F12R_FILESYSTEM_H
 
 #include "FileSystemLike.h"
 #include "FileHandle.h"
-#include "ff.h"
 #include <stdint.h>
+#include "StorageInterface.h"
+
+typedef uint32_t sector_t;
+typedef uint32_t cluster_t;
+typedef uint32_t filesize_t;
 
 using namespace mbed;
 
 /**
- * F12RFileSystem based on ChaN's Fat Filesystem library v0.8 
+ * F12RFileSystem
  */
 class F12RFileSystem : public FileSystemLike {
 public:
-
-    F12RFileSystem(const char* n);
+    F12RFileSystem(StorageInterface* storage_, const char* n);
     virtual ~F12RFileSystem();
 
-    static F12RFileSystem * _ffs[_VOLUMES];   // F12RFileSystem objects, as parallel to FatFs drives array
-    FATFS _fs;                               // Work area (file system object) for logical drive
-    char _fsid[2];
-
     /**
      * Opens a file on the filesystem
      */
@@ -84,11 +83,29 @@
 
     virtual int disk_initialize() { return 0; }
     virtual int disk_status() { return 0; }
-    virtual int disk_read(uint8_t * buffer, uint64_t sector, uint8_t count) = 0;
-    virtual int disk_write(const uint8_t * buffer, uint64_t sector, uint8_t count) = 0;
+    int disk_read(uint8_t * buffer, uint64_t sector, uint8_t count) {
+        return storage->storage_read(sector * 512, buffer, 512);
+    }
+    int disk_write(const uint8_t * buffer, uint64_t sector, uint8_t count) {
+        return storage->storage_write(sector * 512, buffer, 512);
+    }
     virtual int disk_sync() { return 0; }
-    virtual uint64_t disk_sectors() = 0;
+    uint64_t disk_sectors() { return storage->storage_size() / 512; }
 
+private:
+    friend class F12RFileHandle;
+    friend class F12RDirHandle;
+    uint32_t storage_peek(uint32_t offset, int n);
+    cluster_t fat_read(cluster_t index);
+    StorageInterface* storage;
+    sector_t base_fat;
+    sector_t base_dir;
+    sector_t base_data;
+    uint32_t cluster_size;
+    uint32_t cluster_head(uint32_t pos) const { return pos % cluster_size; }
+    uint32_t cluster_tail(uint32_t pos) const { return cluster_size - cluster_head(pos); }
+    int max_root_dir_entries;
+    bool mounted;
 };
 
 #endif