Hi,
Re: MDK-ARM CM3 Middleware FileSystem. FAT Drive on a NAND Flash ("N0:").
I'm looking for a method to check, wether a FAT drive is initialized or not! I must check, wether finit() had already been called or not.
I could not find a sufficient "high"-level Utility Routine. Thus I considered about using IO Control Interface Routines. Therfore I first had to get an id: fs_ioc_get_id("N0:") returns drv_id = 1 on an uninitialized(!) drive which causes further fs_ioc-functions to crash.
Do anyone have an idea, how to check wether a (nonremovable NAND Flash) FAT drive is initialized or not?
Best regards Matz
At a very basic level you could walk the MBR and BPB sectors, checking the 0xAA/0x55 patterns at the end, and the structures.
Sorry, I wasn't precise enough in my question: I only want to check wether finit() has already been called. Thus to ensure that the file system and the driver are initialized for the drive.
There is no need for me to check wether the drive is formatted or something else.
The background: I basicly want to call fs_ioc_get_id() to get a drv_id. But I must be sure that drv_id is valid. One way in general to ensure that is to call finit previously. But in my app I should not call finit if it has been already called before, because a second finit will unmount the drive. This will interfere with other stuff accessing the mounted drive.
Maybe I'm thinking too complicately. But I dont find a way to check wether the drv_id from fs_ioc_get_id is valid.
Would the following be sufficient?
uint32_t Drive_N_Initialized; //global scope void Drive_N_Init(void) { fsStatus stat; stat = finit("N0:"); if (stat == fsOK) { Drive_N_Initialized = 1; } else { Drive_N_Initialized = 0; } }
Hi Vladimir,
thanks, this will work of corse. But in my case finit is done by another (third party) modul not providing a separat status variable. I do not believe that it should be impossible to query the state (is finit?) directly from the file system middleware itself. Unfortunately it seems to be so. Or does someone else have a solution?
Best regards. Matz
I guess there is no easy way, but linker can help us a bit: www.keil.com/.../armclang_link_pge1362065967698.htm
uint32_t Drive_N_Initialized; //global scope extern fsStatus $Sub$$finit (const char *drive); extern fsStatus $Super$$finit (const char *drive); fsStatus $Sub$$finit (const char *drive) { fsStatus stat; stat = $Super$$finit(drive); if ((drive[0] == 'N') && (drive[1] == '0')) { if (stat == fsOK) { Drive_N_Initialized = 1; } else { Drive_N_Initialized = 0; } } return (stat); }
Great. I never get in touch with $Super$$ and $Sub$$ before. I admit that I did not learn the manual completely by heart... I'm happy that there is this forum. Thanks for now.
Matz.