Remove FAT dependency on MMC

Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/59cdc465
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/59cdc465
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/59cdc465

Branch: refs/heads/develop
Commit: 59cdc465195bb9422c3b3f5d93091c5aa97a7ed3
Parents: 06b5f0a
Author: Fabio Utzig <[email protected]>
Authored: Thu Jan 12 12:20:17 2017 -0200
Committer: Fabio Utzig <[email protected]>
Committed: Thu Jan 12 12:20:17 2017 -0200

----------------------------------------------------------------------
 fs/disk/src/disk.c         | 12 ++++--------
 fs/fatfs/src/mynewt_glue.c | 21 +++++++++++++++------
 2 files changed, 19 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/59cdc465/fs/disk/src/disk.c
----------------------------------------------------------------------
diff --git a/fs/disk/src/disk.c b/fs/disk/src/disk.c
index 550dade..4c915d4 100644
--- a/fs/disk/src/disk.c
+++ b/fs/disk/src/disk.c
@@ -64,37 +64,33 @@ int disk_register(const char *disk_name, const char 
*fs_name, struct disk_ops *d
 struct disk_ops *
 disk_ops_for(const char *disk_name)
 {
-    struct disk_ops *dops = NULL;
     struct disk_info *sc;
 
     if (disk_name) {
         SLIST_FOREACH(sc, &disks, sc_next) {
             if (strcmp(sc->disk_name, disk_name) == 0) {
-                dops = sc->dops;
-                break;
+                return sc->dops;
             }
         }
     }
 
-    return dops;
+    return NULL;
 }
 
 char *
 disk_fs_for(const char *disk_name)
 {
-    char *fs_name = NULL;
     struct disk_info *sc;
 
     if (disk_name) {
         SLIST_FOREACH(sc, &disks, sc_next) {
             if (strcmp(sc->disk_name, disk_name) == 0) {
-                fs_name = (char *) sc->fs_name;
-                break;
+                return ((char *) sc->fs_name);
             }
         }
     }
 
-    return fs_name;
+    return NULL;
 }
 
 char *

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/59cdc465/fs/fatfs/src/mynewt_glue.c
----------------------------------------------------------------------
diff --git a/fs/fatfs/src/mynewt_glue.c b/fs/fatfs/src/mynewt_glue.c
index 189ca8a..c840185 100644
--- a/fs/fatfs/src/mynewt_glue.c
+++ b/fs/fatfs/src/mynewt_glue.c
@@ -1,7 +1,7 @@
 #include <assert.h>
 #include <sysinit/sysinit.h>
 #include <hal/hal_flash.h>
-#include <mmc/mmc.h>
+#include <disk/disk.h>
 #include <flash_map/flash_map.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -151,6 +151,7 @@ int fatfs_to_vfs_error(FRESULT res)
 struct mounted_disk {
     char *disk_name;
     int disk_number;
+    struct disk_ops *dops;
 
     SLIST_ENTRY(mounted_disk) sc_next;
 };
@@ -185,6 +186,7 @@ drivenumber_from_disk(char *disk_name)
     new_disk = malloc(sizeof(struct mounted_disk));
     new_disk->disk_name = strdup(disk_name);
     new_disk->disk_number = disk_number;
+    new_disk->dops = disk_ops_for(disk_name);
     SLIST_INSERT_HEAD(&mounted_disks, new_disk, sc_next);
 
     return disk_number;
@@ -472,10 +474,17 @@ disk_status(BYTE pdrv)
     return RES_OK;
 }
 
-/* FIXME */
-static struct disk_ops *disk_ops_from_handle(BYTE pdrv)
+static struct disk_ops *dops_from_handle(BYTE pdrv)
 {
-    return &mmc_ops;
+    struct mounted_disk *sc;
+
+    SLIST_FOREACH(sc, &mounted_disks, sc_next) {
+        if (sc->disk_number == pdrv) {
+            return sc->dops;
+        }
+    }
+
+    return NULL;
 }
 
 DRESULT
@@ -490,7 +499,7 @@ disk_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count)
     address = (uint32_t) sector * 512;
     num_bytes = (uint32_t) count * 512;
 
-    dops = disk_ops_from_handle(pdrv);
+    dops = dops_from_handle(pdrv);
     if (dops == NULL) {
         return STA_NOINIT;
     }
@@ -515,7 +524,7 @@ disk_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT 
count)
     address = (uint32_t) sector * 512;
     num_bytes = (uint32_t) count * 512;
 
-    dops = disk_ops_from_handle(pdrv);
+    dops = dops_from_handle(pdrv);
     if (dops == NULL) {
         return STA_NOINIT;
     }

Reply via email to