FatFS - Mount same SD card twice

Discussions about all user software around SAM Series.

Moderator: nferre

M14
Posts: 20
Joined: Thu Mar 27, 2014 10:51 am

FatFS - Mount same SD card twice

Thu Aug 07, 2014 5:27 pm

A while ago I implemented the FatFS library and everything seems to be working fine. Now I want to open different files in different source files. 1 file is used as read only, the other file is mainly used for writing. Since the sourcefiles work independent, they don't know of each other if the FatFS module is mounted.

There is some strange behavior when I mount the module twice (in each sourcefile where it is used). The power of the SD card is disabled and SPI read/write locks up. I can't tell in which order this happens. It seems to work (sometimes) when I step thru in the debugger.

Should it be possible to mount the same module twice from different source files, like this? :

Code: Select all

// srcfile_1
static FATFS FatFs;

void init_function_source1(void) {
fr = f_mount(&FatFs, "", 0);
}


// srcfile_2
static FATFS FatFs;

void init_function_source2(void) {
fr = f_mount(&FatFs, "", 0);
}
Or should I add a kind of manager so the FatFS module is only mounted when it was not before? Other possible solutions are welcome to :).
blue_z
Location: USA
Posts: 1560
Joined: Thu Apr 19, 2007 10:15 pm

Re: FatFS - Mount same SD card twice

Fri Aug 08, 2014 1:22 am

M14 wrote:A while ago I implemented the FatFS library
What's your definition of "implemented"?
Did you actually write this library, or merely install it?
M14 wrote:Since the sourcefiles work independent, they don't know of each other if the FatFS module is mounted.
What OS (or kernel) is this for?
Normally there is no specified correlation between routines in source files and their runtime properties.
Routines in several "source files" could all be executed as part on just one process or thread.
You have not concisely described if these mount requests are in competing processes/tasks/threads or are cooperating.
M14 wrote:There is some strange behavior when I mount the module twice (in each sourcefile where it is used).
Actually the mount is performed on a filesystem, not a device. If there's no filesystem, you cannot mount a device or partition.
The "strange behavior" indicates a flawed implementation of mounting a filesystem.
M14 wrote:Should it be possible to mount the same module twice from different source files, like this? :
Attempting to mount a filesystem that is already mounted should always be rejected as an error.
Otherwise you risk corrupting any open files and pending I/O for that filesystem.
Again "source file " is not a proper unit of execution and probably not salient to the problem.
M14 wrote:Or should I add a kind of manager so the FatFS module is only mounted when it was not before?
You haven't provided enough requirements.
How often is this SD card likely to be inserted and removed?
Do you want/need a hotplug daemon/monitor?
How are you going to handle error conditions such as mount failures and file open/writes when the card is removed?

Regards
M14
Posts: 20
Joined: Thu Mar 27, 2014 10:51 am

Re: FatFS - Mount same SD card twice

Fri Aug 08, 2014 11:12 am

There is no OS or kernel running on the uC (ATSAMD20J18). Just plain code. Since FatFS is an existing library, 'implementing' in this case is writing the interface with the hardware.

The 'mount' is nothing more than store a pointer to an FatFS variable. f_mount does not return an error when mounted again.

I agree the SD card should be mounted only once, I guess I have to make a kind of manager for it in order to track the status of it.

Return to “Software”

Who is online

Users browsing this forum: No registered users and 1 guest