rafalh / rust-fatfs

A FAT filesystem library implemented in Rust.
MIT License
291 stars 53 forks source link

Multi-thread safety about disk #91

Open coolyjg opened 5 months ago

coolyjg commented 5 months ago

It seems that this implementation do not guarantee multi-thread safety? Since in struct FileSystem, the disk field is wrapped by RefCell which would panic if two thread call borrow_mut() (considering multi-core scenario). By the way, if fatfs do not guarantee multi-thread safety, I think it at least should not panic, but keep related data dirty.

rafalh commented 5 months ago

AFAIK FileSystem is not Send so you can't share it between threads . To use it in a multi-threaded application you have to wrap it in a Mutex. Therefore there is no risk of borrow_mut panicking. If I'm wrong please provide an example where it could panic.

coolyjg commented 5 months ago

We tried to use rust-fatfs for our own operating system in non-std scenario. A mutex for the whole file system could work, but every fs operation is serialized.