1 year, 6 months ago.

filesystem.mount() error codes ?

Hi there. So I have this code on a FRDM-K66F:

SDBlockDevice sd( PTE3, PTE1, PTE2, PTE4 );
MBRBlockDevice part1( &sd, 3 );
FATFileSystem fs( "fs", &part1 );
...
int main() {

    int errCode = NOERR;

    int err = fs.mount( &sd );
    if ( err != 0 ) {
        pc.printf( "fs.mount failed: err = %d.\n\r", err );
        // other stuff as needed
    }
...

In my diagnostic output, I see that it's returning an error code of "-5." Where do I find out what this return values means? It would go far toward figuring out why the mount isn't working.

Edited for code formatting.

Comment on this question

1 Answer

1 year, 6 months ago.

Hi Aaron,

The filesystem uses POSIX error codes. You can find the full list of error codes here:
https://github.com/ARMmbed/mbed-os/blob/8b6a7aacc5d2b90ba40d89c8eeb680ebee81ea18/platform/mbed_retarget.h#L132-L393

You can also use the strerror function to get a human readable string describing the error. However, this comes with a code size cost, so you should remove it if you are tight on space.

5 is EIO, which indicates an IO error. Most likely something is going wrong with the block device. If you call sd.init() before the mount, it should return a more descriptive error.

Also, are you meaning to pass "sd" to the filesystem and not the "part1"? Are you using partitions?

Ah, thank you kindly. I'm using a 32G microSD card - it was handy; nothing more - that has been formatted for FAT - yes, using partitions - and it's recognized on Mac and Linux, but seems to be problematic for the K66. I'm trying to avoid having to initialize it under mbed so I can bring in existing files for a particular application. I want the files to be used on both a Mac and the mbed app I'm developing. Maybe due to the SD size, requiring the extended partitions, that might be the problem. I'll see if I can find a 2G SD card that just uses the 4 primary partitions.

posted by Aaron Minner 28 Feb 2018

And there we go. I found a 2G card and the software now works as expected. Thanks so much.

posted by Aaron Minner 28 Feb 2018

Ah! That's good news.

Although that's a bit odd, a primary MBR partition should be able to support up to 2TiB. Maybe it was partitioned for an OS at some point that needed many partitions?

You may be able to get the 32GiB card working if you repartition the MBR.

posted by Christopher Haster 01 Mar 2018