I have an application where I'm writing data on the removable media (SD card/ pendrive). Now, I want to add a functionality where I can format the SD card in case it's not mounted properly or got corrupted for any reason.
I know I can use system() method to call an underlying utility like mkfs.ext4 for formatting the removable partition as we do via terminal, or a bash script which will unmount, format and remount the removable media. But I would like to avoid system() call because:
It spawns a new shell over which I will have no control. In this particular case, I cannot check the status of unmounting/ formatting/ remounting, which prevents me from proper error handling in the application. Is there a system library I can use to do the same task in C++ way (using APIs/ method calls) rather than having to call system() and then a bash script within.
Please correct if I misunderstood something.
Please suggest.
Thanks