From af94077a7ab7108e4431a360364f5bec4e94b8f5 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Sat, 30 May 2009 15:54:52 +0000 Subject: [PATCH] move device startup to fatMount shut device down in fatUnmount --- source/libfat.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/source/libfat.c b/source/libfat.c index 8bdc895..cb71414 100644 --- a/source/libfat.c +++ b/source/libfat.c @@ -69,8 +69,17 @@ bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSec devoptab_t* devops; char* nameCopy; + if(!interface->startup()) + return false; + + if(!interface->isInserted()) { + interface->shutdown(); + return false; + } + devops = _FAT_mem_allocate (sizeof(devoptab_t) + strlen(name) + 1); if (!devops) { + interface->shutdown(); return false; } // Use the space allocated at the end of the devoptab struct for storing the name @@ -80,6 +89,7 @@ bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSec partition = _FAT_partition_constructor (interface, cacheSize, SectorsPerPage, startSector); if (!partition) { _FAT_mem_free (devops); + interface->shutdown(); return false; } @@ -101,6 +111,7 @@ bool fatMountSimple (const char* name, const DISC_INTERFACE* interface) { void fatUnmount (const char* name) { devoptab_t *devops; PARTITION* partition; + const DISC_INTERFACE *disc; devops = (devoptab_t*)GetDeviceOpTab (name); if (!devops) { @@ -112,13 +123,15 @@ void fatUnmount (const char* name) { return; } - if (!RemoveDevice (name)) { + if (RemoveDevice (name) == -1) { return; } partition = (PARTITION*)devops->deviceData; + disc = partition->disc; _FAT_partition_destructor (partition); _FAT_mem_free (devops); + disc->shutdown(); } bool fatInit (uint32_t cacheSize, bool setAsDefaultDevice) { @@ -131,7 +144,7 @@ bool fatInit (uint32_t cacheSize, bool setAsDefaultDevice) { i++) { disc = _FAT_disc_interfaces[i].getInterface(); - if (disc->startup() && fatMount (_FAT_disc_interfaces[i].name, disc, 0, cacheSize, DEFAULT_SECTORS_PAGE)) { + if (fatMount (_FAT_disc_interfaces[i].name, disc, 0, cacheSize, DEFAULT_SECTORS_PAGE)) { // The first device to successfully mount is set as the default if (defaultDevice < 0) { defaultDevice = i;