From 7560abbfbdf187bbb91fc292bb5b6e62bd22be36 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Wed, 9 May 2018 11:36:49 +0200 Subject: [PATCH] Fix FindDevice and RemoveDevice calls in fs_dev.c --- fusee/fusee-secondary/src/fs_dev.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/fusee/fusee-secondary/src/fs_dev.c b/fusee/fusee-secondary/src/fs_dev.c index 071a35d95..239fb5638 100644 --- a/fusee/fusee-secondary/src/fs_dev.c +++ b/fusee/fusee-secondary/src/fs_dev.c @@ -82,6 +82,8 @@ int fsdev_mount_device(const char *name, unsigned int id) { fsdev_fsdevice_t *device = &g_devices[id]; FRESULT rc; char drname[40]; + strcpy(drname, name); + strcat(drname, ":"); if (id >= FF_VOLUMES) { errno = EINVAL; @@ -91,7 +93,7 @@ int fsdev_mount_device(const char *name, unsigned int id) { errno = ENAMETOOLONG; return -1; } - if (FindDevice(name) != -1 || g_devices[id].setup) { + if (FindDevice(drname) != -1 || g_devices[id].setup) { errno = EEXIST; /* Device already exists */ return -1; } @@ -103,9 +105,6 @@ int fsdev_mount_device(const char *name, unsigned int id) { device->devoptab.deviceData = device; VolumeStr[id] = device->name; - strcpy(drname, name); - strcat(drname, ":"); - rc = f_mount(&device->fatfs, drname, 1); if (rc != FR_OK) { @@ -125,7 +124,12 @@ int fsdev_mount_device(const char *name, unsigned int id) { int fsdev_set_default_device(const char *name) { int ret = 0; - int devid = FindDevice(name); + int devid; + char drname[40]; + + strcpy(drname, name); + strcat(drname, ":"); + devid = FindDevice(drname); if (devid == -1) { errno = ENOENT; @@ -133,11 +137,6 @@ int fsdev_set_default_device(const char *name) { } #if FF_VOLUMES >= 2 - char drname[40]; - - strcpy(drname, name); - strcat(drname, ":"); - ret = fsdev_convert_rc(NULL, f_chdrive(drname)); #endif if (ret == 0) { @@ -150,20 +149,23 @@ int fsdev_set_default_device(const char *name) { int fsdev_unmount_device(const char *name) { int ret; char drname[40]; - int devid = FindDevice(name); + int devid; + + strcpy(drname, name); + strcat(drname, ":"); + + devid = FindDevice(drname); if (devid == -1) { errno = ENOENT; return -1; } - strcpy(drname, name); - strcat(drname, ":"); ret = fsdev_convert_rc(NULL, f_unmount(drname)); if (ret == 0) { fsdev_fsdevice_t *device = (fsdev_fsdevice_t *)(GetDeviceOpTab(name)->deviceData); - RemoveDevice(name); + RemoveDevice(drname); memset(device, 0, sizeof(fsdev_fsdevice_t)); }