Mbed-os: FATFileSystem.cpp int FATFileSystem::format have bug

Created on 12 Jun 2017  路  7Comments  路  Source: ARMmbed/mbed-os

int FATFileSystem::format(BlockDevice *bd, int allocation_unit) {
    FATFileSystem fs;   //this is a not init variable
    int err = fs.mount(bd, false);
    if (err) {
        return err;
    }

FATFileSystem fs; before use Variables are not initialized

storage

All 7 comments

cc @geky

In C++, declaring a variable calls its constructor. The FATFileSystem constructor is here:
https://github.com/ARMmbed/mbed-os/blob/master/features/filesystem/fat/FATFileSystem.cpp#L235-L240

The fs.mount function sets up the FATFileSystem to use the BlockDevice in the f_mkfs function.

@wjffsx have you had any problems with the function ? any runtime error/compile warning or?

complie is ok ; in runtime ;i can not format SD card

Ah ok, then a few questions:

  1. Do any asserts fail? (an error would be printed in debug mode)
  2. What is the return value of the format function? It should return an error code.
  3. Do you have a code snippet we could use to reproduce the failure?

have found reason, code is ok;
before format() ; should call unmount();

Use the following order:
unmount();
format();
mount();

Ah thats good to know. Glad you found a fix.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  4Comments

MarceloSalazar picture MarceloSalazar  路  3Comments

toyowata picture toyowata  路  4Comments

sarahmarshy picture sarahmarshy  路  4Comments

neilt6 picture neilt6  路  4Comments