From 2c07b5a2fb42a73c9e1b688018bb420aeda4b3e1 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Sun, 6 May 2018 18:39:46 +0200 Subject: [PATCH] Rework fs_dev mount code --- fusee/fusee-secondary/src/fs_dev.c | 76 ++++++++++---------- fusee/fusee-secondary/src/fs_dev.h | 2 +- fusee/fusee-secondary/src/lib/fatfs/ffconf.h | 2 +- fusee/fusee-secondary/src/main.c | 3 - 4 files changed, 39 insertions(+), 44 deletions(-) diff --git a/fusee/fusee-secondary/src/fs_dev.c b/fusee/fusee-secondary/src/fs_dev.c index aaf16d6ea..6141c07d3 100644 --- a/fusee/fusee-secondary/src/fs_dev.c +++ b/fusee/fusee-secondary/src/fs_dev.c @@ -75,53 +75,52 @@ typedef struct fsdev_fsdevice_t { FATFS fatfs; } fsdev_fsdevice_t; -static fsdev_fsdevice_t g_devices[10] = { 0 }; +static fsdev_fsdevice_t g_devices[FF_VOLUMES] = { 0 }; +const char *VolumeStr[FF_VOLUMES] = { 0 }; -/* Restrictions: 10 drives max, and **update FF_VOLUME_STRS accordingly** */ -int fsdev_mount_device(const char *name) { +int fsdev_mount_device(const char *name, unsigned int id) { + fsdev_fsdevice_t *device = &g_devices[id]; + FRESULT rc; + char drname[40]; + + if (id >= FF_VOLUMES) { + errno = EINVAL; + return -1; + } if (name[0] == '\0' || strlen(name) > 32) { errno = ENAMETOOLONG; return -1; } - - if (FindDevice(name) != -1) { + if (FindDevice(name) != -1 || g_devices[id].setup) { errno = EEXIST; /* Device already exists */ return -1; } - /* Find a free slot and use it */ - for (size_t i = 0; i < 10; i++) { - if (!g_devices[i].setup) { - fsdev_fsdevice_t *device = &g_devices[i]; - FRESULT rc; - char drname[40]; - strcpy(drname, name); - strcat(drname, ":"); + strcpy(device->name, name); - rc = f_mount(&device->fatfs, drname, 1); + memcpy(&device->devoptab, &g_fsdev_devoptab, sizeof(devoptab_t)); + device->devoptab.name = device->name; + device->devoptab.deviceData = device; + VolumeStr[id] = device->name; - if (rc != FR_OK) { - return fsdev_convert_rc(NULL, rc); - } + strcpy(drname, name); + strcat(drname, ":"); - strcpy(device->name, name); + rc = f_mount(&device->fatfs, drname, 1); - memcpy(&device->devoptab, &g_fsdev_devoptab, sizeof(devoptab_t)); - device->devoptab.name = device->name; - device->devoptab.deviceData = device; - - if (AddDevice(&device->devoptab) == -1) { - errno = ENOMEM; - return -1; - } else { - device->setup = true; - return 0; - } - } + if (rc != FR_OK) { + return fsdev_convert_rc(NULL, rc); } - errno = ENOMEM; - return -1; + if (AddDevice(&device->devoptab) == -1) { + f_unmount(drname); + VolumeStr[id] = NULL; + errno = ENOMEM; + return -1; + } else { + device->setup = true; + return 0; + } } int fsdev_set_default_device(const char *name) { @@ -175,10 +174,11 @@ int fsdev_unmount_device(const char *name) { } int fsdev_mount_all(void) { - static const char* const volid[] = { FF_VOLUME_STRS }; + /* Change this accordingly: */ + static const char* const volumes[] = { "sdmc" }; - for (size_t i = 0; i < sizeof(volid)/sizeof(volid[0]); i++) { - int ret = fsdev_mount_device(volid[i]); + for (size_t i = 0; i < FF_VOLUMES; i++) { + int ret = fsdev_mount_device(volumes[i], i); if (ret != 0) { return ret; } @@ -188,10 +188,8 @@ int fsdev_mount_all(void) { } int fsdev_unmount_all(void) { - static const char* const volid[] = { FF_VOLUME_STRS }; - - for (size_t i = 0; i < sizeof(volid)/sizeof(volid[0]); i++) { - int ret = fsdev_unmount_device(volid[i]); + for (size_t i = 0; i < FF_VOLUMES; i++) { + int ret = fsdev_unmount_device(VolumeStr[i]); if (ret != 0) { return ret; } diff --git a/fusee/fusee-secondary/src/fs_dev.h b/fusee/fusee-secondary/src/fs_dev.h index 817c28a3f..415c1d611 100644 --- a/fusee/fusee-secondary/src/fs_dev.h +++ b/fusee/fusee-secondary/src/fs_dev.h @@ -5,7 +5,7 @@ #include #include -int fsdev_mount_device(const char *name); +int fsdev_mount_device(const char *name, unsigned int id); int fsdev_set_default_device(const char *name); int fsdev_unmount_device(const char *name); diff --git a/fusee/fusee-secondary/src/lib/fatfs/ffconf.h b/fusee/fusee-secondary/src/lib/fatfs/ffconf.h index c9cad1335..5a38ae01d 100644 --- a/fusee/fusee-secondary/src/lib/fatfs/ffconf.h +++ b/fusee/fusee-secondary/src/lib/fatfs/ffconf.h @@ -168,7 +168,7 @@ #define FF_STR_VOLUME_ID 1 -#define FF_VOLUME_STRS "sdmc" +//#define FF_VOLUME_STRS "sdmc" /* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings. / When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive / number in the path name. FF_VOLUME_STRS defines the volume ID strings for each diff --git a/fusee/fusee-secondary/src/main.c b/fusee/fusee-secondary/src/main.c index 041823abf..bdb3ce174 100644 --- a/fusee/fusee-secondary/src/main.c +++ b/fusee/fusee-secondary/src/main.c @@ -47,9 +47,6 @@ int main(int argc, void **argv) { /* TODO: What other hardware init should we do here? */ - /* Setup console/stdout. */ - console_resume(args.lfb, args.console_row, args.console_col); - printf(u8"Welcome to Atmosphère Fusée Stage 2!\n"); printf("Stage 2 executing from: %s\n", (const char *)argv[STAGE2_ARGV_PROGRAM_PATH]);