AP_Filesystem: add support for blocking filesystem access

This commit is contained in:
bugobliterator 2022-07-22 05:16:56 +05:30 committed by Andrew Tridgell
parent 6d6c791fdf
commit 414606ba31
5 changed files with 41 additions and 2 deletions

View File

@ -306,6 +306,24 @@ AP_Filesystem_Backend::FormatStatus AP_Filesystem::get_format_status(void) const
#endif
}
// block filesystem access
void AP_Filesystem::block_access(void)
{
for (uint8_t i=0; i<ARRAY_SIZE(backends); i++) {
backends[i].fs.block_access();
}
}
// free filesystem access
void AP_Filesystem::free_access(void)
{
for (uint8_t i=0; i<ARRAY_SIZE(backends); i++) {
backends[i].fs.free_access();
}
}
namespace AP
{
AP_Filesystem &FS()

View File

@ -127,7 +127,14 @@ public:
load a full file. Use delete to free the data
*/
FileData *load_file(const char *filename);
// block filesystem access
void block_access(void);
// free filesystem access
void free_access(void);
private:
struct Backend {
const char *prefix;

View File

@ -36,7 +36,7 @@ static bool remount_needed;
// use a semaphore to ensure that only one filesystem operation is
// happening at a time. A recursive semaphore is used to cope with the
// mkdir() inside sdcard_retry()
static HAL_Semaphore sem;
HAL_Semaphore AP_Filesystem_FATFS::sem;
typedef struct {
FIL *fh;

View File

@ -55,9 +55,16 @@ public:
bool format(void) override;
AP_Filesystem_Backend::FormatStatus get_format_status() const override;
// block filesystem access
void block_access(void) override { sem.take_blocking(); }
// free filesystem access
void free_access(void) override { sem.give(); }
private:
void format_handler(void);
FormatStatus format_status;
static HAL_Semaphore sem;
};
#endif // #if AP_FILESYSTEM_FATFS_ENABLED

View File

@ -94,6 +94,13 @@ public:
// unload data from load_file()
virtual void unload_file(FileData *fd);
// block filesystem access
virtual void block_access(void) {}
// free filesystem access
virtual void free_access(void) {}
protected:
// return true if file operations are allowed
bool file_op_allowed(void) const;