mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
AP_Filesystem: add support for blocking filesystem access
This commit is contained in:
parent
6d6c791fdf
commit
414606ba31
@ -306,6 +306,24 @@ AP_Filesystem_Backend::FormatStatus AP_Filesystem::get_format_status(void) const
|
|||||||
#endif
|
#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
|
namespace AP
|
||||||
{
|
{
|
||||||
AP_Filesystem &FS()
|
AP_Filesystem &FS()
|
||||||
|
@ -128,6 +128,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
FileData *load_file(const char *filename);
|
FileData *load_file(const char *filename);
|
||||||
|
|
||||||
|
|
||||||
|
// block filesystem access
|
||||||
|
void block_access(void);
|
||||||
|
|
||||||
|
// free filesystem access
|
||||||
|
void free_access(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Backend {
|
struct Backend {
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
|
@ -36,7 +36,7 @@ static bool remount_needed;
|
|||||||
// use a semaphore to ensure that only one filesystem operation is
|
// use a semaphore to ensure that only one filesystem operation is
|
||||||
// happening at a time. A recursive semaphore is used to cope with the
|
// happening at a time. A recursive semaphore is used to cope with the
|
||||||
// mkdir() inside sdcard_retry()
|
// mkdir() inside sdcard_retry()
|
||||||
static HAL_Semaphore sem;
|
HAL_Semaphore AP_Filesystem_FATFS::sem;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
FIL *fh;
|
FIL *fh;
|
||||||
|
@ -55,9 +55,16 @@ public:
|
|||||||
bool format(void) override;
|
bool format(void) override;
|
||||||
AP_Filesystem_Backend::FormatStatus get_format_status() const 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:
|
private:
|
||||||
void format_handler(void);
|
void format_handler(void);
|
||||||
FormatStatus format_status;
|
FormatStatus format_status;
|
||||||
|
static HAL_Semaphore sem;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // #if AP_FILESYSTEM_FATFS_ENABLED
|
#endif // #if AP_FILESYSTEM_FATFS_ENABLED
|
||||||
|
@ -94,6 +94,13 @@ public:
|
|||||||
// unload data from load_file()
|
// unload data from load_file()
|
||||||
virtual void unload_file(FileData *fd);
|
virtual void unload_file(FileData *fd);
|
||||||
|
|
||||||
|
|
||||||
|
// block filesystem access
|
||||||
|
virtual void block_access(void) {}
|
||||||
|
|
||||||
|
// free filesystem access
|
||||||
|
virtual void free_access(void) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// return true if file operations are allowed
|
// return true if file operations are allowed
|
||||||
bool file_op_allowed(void) const;
|
bool file_op_allowed(void) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user