Skip to main content

starnix_core/vfs/
file_system.rs

1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use crate::security;
6use crate::task::{CurrentTask, Kernel};
7use crate::vfs::fs_args::MountParams;
8use crate::vfs::fs_node_cache::FsNodeCache;
9use crate::vfs::{
10    DirEntry, DirEntryHandle, FsNode, FsNodeFlags, FsNodeHandle, FsNodeInfo, FsNodeOps, FsStr,
11    FsString, RenameContext,
12};
13use flyweights::FlyByteStr;
14use linked_hash_map::LinkedHashMap;
15use ref_cast::RefCast;
16use smallvec::SmallVec;
17use starnix_crypt::CryptService;
18use starnix_logging::log_warn;
19use starnix_sync::{
20    DynamicLockDepMutex, FileSystemEntriesLock, FileSystemPermanentLock, FsRename,
21    FsRenameRecursive, FuseFsRenameLevel, LockDepMutex,
22};
23use starnix_uapi::arc_key::ArcKey;
24use starnix_uapi::as_any::AsAny;
25use starnix_uapi::auth::FsCred;
26use starnix_uapi::device_id::DeviceId;
27use starnix_uapi::errors::Errno;
28use starnix_uapi::file_mode::mode;
29use starnix_uapi::mount_flags::{AtomicFileSystemFlags, FileSystemFlags};
30use starnix_uapi::{error, ino_t, statfs};
31use std::collections::HashSet;
32use std::ops::Range;
33use std::sync::atomic::Ordering;
34use std::sync::{Arc, OnceLock, Weak};
35
36#[derive(Debug, Default)]
37pub struct FileSystemRenameToken {}
38
39/// The type of the filesystem for LockDep purposes.
40///
41/// `Normal` filesystems use standard lock levels.
42/// `Recursive` filesystems (like OverlayFS) use lock levels that precede normal ones,
43/// allowing them to lock the underlying filesystem without violating the hierarchy.
44/// `Fuse` filesystems do blocking calls while holding locks and require specific lock
45/// ordering because of this.
46#[derive(Debug, Clone, Copy, PartialEq, Eq)]
47pub enum FsLockDepType {
48    Normal,
49    Recursive,
50    Fuse,
51}
52
53/// A file system that can be mounted in a namespace.
54pub struct FileSystem {
55    pub kernel: Weak<Kernel>,
56    root: OnceLock<DirEntryHandle>,
57    ops: Box<dyn FileSystemOps>,
58
59    /// The options specified when mounting the filesystem. Saved here for display in
60    /// /proc/[pid]/mountinfo.
61    pub options: FileSystemOptions,
62
63    /// The device ID of this filesystem. Returned in the st_dev field when stating an inode in
64    /// this filesystem.
65    pub dev_id: DeviceId,
66
67    /// A file-system global mutex to serialize rename operations.
68    ///
69    /// This mutex is useful because the invariants enforced during a rename
70    /// operation involve many DirEntry objects. In the future, we might be
71    /// able to remove this mutex, but we will need to think carefully about
72    /// how rename operations can interleave.
73    ///
74    /// See DirEntry::rename.
75    pub rename_mutex: DynamicLockDepMutex<FileSystemRenameToken>,
76
77    /// The FsNode cache for this file system.
78    ///
79    /// When two directory entries are hard links to the same underlying inode,
80    /// this cache lets us re-use the same FsNode object for both directory
81    /// entries.
82    ///
83    /// Rather than calling FsNode::new directly, file systems should call
84    /// FileSystem::get_or_create_node to see if the FsNode already exists in
85    /// the cache.
86    node_cache: Arc<FsNodeCache>,
87
88    /// DirEntryHandle cache for the filesystem. Holds strong references to DirEntry objects. For
89    /// filesystems with permanent entries, this will hold a strong reference to every node to make
90    /// sure it doesn't get freed without being explicitly unlinked. Otherwise, entries are
91    /// maintained in an LRU cache.
92    dcache: DirEntryCache,
93
94    /// Holds security state for this file system, which is created and used by the Linux Security
95    /// Modules subsystem hooks.
96    pub security_state: security::FileSystemState,
97}
98
99impl std::fmt::Debug for FileSystem {
100    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
101        write!(f, "FileSystem")
102    }
103}
104
105#[derive(Debug, Default)]
106pub struct FileSystemOptions {
107    /// The source string passed as the first argument to mount(), e.g. a block device.
108    pub source: FlyByteStr,
109    /// Flags kept per-superblock.
110    pub flags: AtomicFileSystemFlags,
111    /// Filesystem options passed as the last argument to mount().
112    pub params: MountParams,
113}
114
115impl Clone for FileSystemOptions {
116    fn clone(&self) -> Self {
117        Self {
118            source: self.source.clone(),
119            flags: self.flags.load(Ordering::Relaxed).into(),
120            params: self.params.clone(),
121        }
122    }
123}
124
125impl FileSystemOptions {
126    pub fn source_for_display(&self) -> &FsStr {
127        if self.source.is_empty() {
128            return "none".into();
129        }
130        self.source.as_ref()
131    }
132}
133
134struct LruCache {
135    capacity: usize,
136    entries: LockDepMutex<LinkedHashMap<ArcKey<DirEntry>, ()>, FileSystemEntriesLock>,
137}
138
139enum DirEntryCache {
140    Permanent(LockDepMutex<HashSet<ArcKey<DirEntry>>, FileSystemPermanentLock>),
141    Lru(LruCache),
142    Uncached,
143}
144
145/// Configuration for CacheMode::Cached.
146pub struct CacheConfig {
147    pub capacity: usize,
148}
149
150pub enum CacheMode {
151    /// Entries are pemanent, instead of a cache of the backing storage. An example is tmpfs: the
152    /// DirEntry tree *is* the backing storage, as opposed to ext4, which uses the DirEntry tree as
153    /// a cache and removes unused nodes from it.
154    Permanent,
155    /// Entries are cached.
156    Cached(CacheConfig),
157    /// Entries are uncached. This can be appropriate in cases where it is difficult for the
158    /// filesystem to keep the cache coherent: e.g. the /proc/<pid>/task directory.
159    Uncached,
160}
161
162impl FileSystem {
163    /// Create a new filesystem.
164    pub fn new(
165        kernel: &Kernel,
166        cache_mode: CacheMode,
167        ops: impl FileSystemOps,
168        mut options: FileSystemOptions,
169    ) -> Result<FileSystemHandle, Errno> {
170        let uses_external_node_ids = ops.uses_external_node_ids();
171        let node_cache = Arc::new(FsNodeCache::new(uses_external_node_ids));
172        assert_eq!(ops.uses_external_node_ids(), node_cache.uses_external_node_ids());
173
174        let mount_options = security::sb_eat_lsm_opts(&kernel, &mut options.params)?;
175        let security_state = security::file_system_init_security(&mount_options, &ops)?;
176
177        let fs_lockdep_type = ops.fs_lockdep_type();
178
179        let file_system = Arc::new(FileSystem {
180            kernel: kernel.weak_self.clone(),
181            root: OnceLock::new(),
182            ops: Box::new(ops),
183            options,
184            dev_id: kernel.device_registry.next_anonymous_dev_id(),
185            rename_mutex: match fs_lockdep_type {
186                FsLockDepType::Normal => {
187                    DynamicLockDepMutex::new::<FsRename>(FileSystemRenameToken::default())
188                }
189                FsLockDepType::Recursive => {
190                    DynamicLockDepMutex::new::<FsRenameRecursive>(FileSystemRenameToken::default())
191                }
192                FsLockDepType::Fuse => {
193                    DynamicLockDepMutex::new::<FuseFsRenameLevel>(FileSystemRenameToken::default())
194                }
195            },
196            node_cache,
197            dcache: match cache_mode {
198                CacheMode::Permanent => DirEntryCache::Permanent(Default::default()),
199                CacheMode::Cached(CacheConfig { capacity }) => {
200                    DirEntryCache::Lru(LruCache { capacity, entries: Default::default() })
201                }
202                CacheMode::Uncached => DirEntryCache::Uncached,
203            },
204            security_state,
205        });
206
207        // TODO: https://fxbug.dev/366405587 - Workaround to allow SELinux to note that this
208        // `FileSystem` needs labeling, once a policy has been loaded.
209        security::file_system_post_init_security(kernel, &file_system);
210
211        Ok(file_system)
212    }
213
214    fn set_root(self: &FileSystemHandle, root: FsNodeHandle) {
215        // No need to cache the root directory, it is owned by the filesystem.
216        let root_dir = DirEntry::new_uncached(root, None, FsString::default());
217        assert!(
218            self.root.set(root_dir).is_ok(),
219            "FileSystem::set_root can't be called more than once"
220        );
221    }
222
223    pub fn has_permanent_entries(&self) -> bool {
224        matches!(self.dcache, DirEntryCache::Permanent(_))
225    }
226
227    /// Returns whether this filesystem supports casefolded directory lookups.
228    pub fn has_casefold_support(&self) -> bool {
229        self.ops.has_casefold_support()
230    }
231
232    /// Returns the `FsLockDepType` of this filesystem, delegated from `FileSystemOps`.
233    pub fn fs_lockdep_type(&self) -> FsLockDepType {
234        self.ops.fs_lockdep_type()
235    }
236
237    /// The root directory entry of this file system.
238    ///
239    /// Panics if this file system does not have a root directory.
240    pub fn root(&self) -> &DirEntryHandle {
241        self.root.get().unwrap_or_else(|| panic!("FileSystem {} has no root", self.name()))
242    }
243
244    /// The root directory entry of this `FileSystem`, if it has one.
245    pub fn maybe_root(&self) -> Option<&DirEntryHandle> {
246        self.root.get()
247    }
248
249    pub fn get_or_create_node<F>(
250        &self,
251        node_key: ino_t,
252        create_fn: F,
253    ) -> Result<FsNodeHandle, Errno>
254    where
255        F: FnOnce() -> Result<FsNodeHandle, Errno>,
256    {
257        self.get_and_validate_or_create_node(node_key, |_| true, create_fn)
258    }
259
260    /// Get a node that is validated with the callback, or create an FsNode for
261    /// this file system.
262    ///
263    /// If node_id is Some, then this function checks the node cache to
264    /// determine whether this node is already open. If so, the function
265    /// returns the existing FsNode if it passes the validation check. If no
266    /// node exists, or a node does but fails the validation check, the function
267    /// calls the given create_fn function to create the FsNode.
268    ///
269    /// If node_id is None, then this function assigns a new identifier number
270    /// and calls the given create_fn function to create the FsNode with the
271    /// assigned number.
272    ///
273    /// Returns Err only if create_fn returns Err.
274    pub fn get_and_validate_or_create_node<V, C>(
275        &self,
276        node_key: ino_t,
277        validate_fn: V,
278        create_fn: C,
279    ) -> Result<FsNodeHandle, Errno>
280    where
281        V: Fn(&FsNodeHandle) -> bool,
282        C: FnOnce() -> Result<FsNodeHandle, Errno>,
283    {
284        self.node_cache.get_and_validate_or_create_node(node_key, validate_fn, create_fn)
285    }
286
287    /// File systems that produce their own IDs for nodes should invoke this
288    /// function. The ones who leave to this object to assign the IDs should
289    /// call |create_node_and_allocate_node_id|.
290    pub fn create_node_with_flags(
291        self: &Arc<Self>,
292        ino: Option<ino_t>,
293        ops: impl Into<Box<dyn FsNodeOps>>,
294        info: FsNodeInfo,
295        flags: FsNodeFlags,
296    ) -> FsNodeHandle {
297        let ino = ino.unwrap_or_else(|| self.allocate_ino());
298        let node = FsNode::new_uncached(ino, ops, self, info, flags);
299        self.node_cache.insert_node(&node);
300        node
301    }
302
303    pub fn create_node(
304        self: &Arc<Self>,
305        ino: ino_t,
306        ops: impl Into<Box<dyn FsNodeOps>>,
307        info: FsNodeInfo,
308    ) -> FsNodeHandle {
309        self.create_node_with_flags(Some(ino), ops, info, FsNodeFlags::empty())
310    }
311
312    pub fn create_node_and_allocate_node_id(
313        self: &Arc<Self>,
314        ops: impl Into<Box<dyn FsNodeOps>>,
315        info: FsNodeInfo,
316    ) -> FsNodeHandle {
317        self.create_node_with_flags(None, ops, info, FsNodeFlags::empty())
318    }
319
320    /// Create a node for a directory that has no parent.
321    pub fn create_detached_node(
322        self: &Arc<Self>,
323        ino: ino_t,
324        ops: impl Into<Box<dyn FsNodeOps>>,
325        info: FsNodeInfo,
326    ) -> FsNodeHandle {
327        assert!(info.mode.is_dir());
328        let node = FsNode::new_uncached(ino, ops, self, info, FsNodeFlags::empty());
329        self.node_cache.insert_node(&node);
330        node
331    }
332
333    /// Create a root node for the filesystem.
334    ///
335    /// This is a convenience function that creates a root node with the default
336    /// directory mode and root credentials.
337    pub fn create_root(self: &Arc<Self>, ino: ino_t, ops: impl Into<Box<dyn FsNodeOps>>) {
338        let info = FsNodeInfo::new(mode!(IFDIR, 0o777), FsCred::root());
339        self.create_root_with_info(ino, ops, info);
340    }
341
342    pub fn create_root_with_info(
343        self: &Arc<Self>,
344        ino: ino_t,
345        ops: impl Into<Box<dyn FsNodeOps>>,
346        info: FsNodeInfo,
347    ) {
348        let node = self.create_detached_node(ino, ops, info);
349        self.set_root(node);
350    }
351
352    /// Remove the given FsNode from the node cache.
353    ///
354    /// Called from the Release trait of FsNode.
355    pub fn remove_node(&self, node: &FsNode) {
356        self.node_cache.remove_node(node);
357    }
358
359    pub fn allocate_ino(&self) -> ino_t {
360        self.node_cache
361            .allocate_ino()
362            .expect("allocate_ino called on a filesystem that uses external node IDs")
363    }
364
365    /// Allocate a contiguous block of node ids.
366    pub fn allocate_ino_range(&self, size: usize) -> Range<ino_t> {
367        self.node_cache
368            .allocate_ino_range(size)
369            .expect("allocate_ino_range called on a filesystem that uses external node IDs")
370    }
371
372    /// Move |renamed| that is at |old_name| in |old_parent| to |new_name| in |new_parent|
373    /// replacing |replaced|.
374    /// If |replaced| exists and is a directory, this function must check that |renamed| is n
375    /// directory and that |replaced| is empty.
376    pub fn rename(
377        &self,
378        current_task: &CurrentTask,
379        context: &mut RenameContext<'_>,
380        old_name: &FsStr,
381        new_name: &FsStr,
382    ) -> Result<(), Errno> {
383        self.ops.rename(self, current_task, context, old_name, new_name)
384    }
385
386    /// Exchanges the two nodes identified by `name1` and `name2` in the context.
387    /// The parent directories and other metadata are contained within the `context`.
388    pub fn exchange(
389        &self,
390        current_task: &CurrentTask,
391        context: &mut RenameContext<'_>,
392        name1: &FsStr,
393        name2: &FsStr,
394    ) -> Result<(), Errno> {
395        self.ops.exchange(self, current_task, context, name1, name2)
396    }
397
398    /// Forces a FileSystem unmount.
399    // TODO(https://fxbug.dev/394694891): kernel shutdown should ideally unmount FileSystems via
400    // their drop impl, which should be triggered by Mount.unmount().
401    pub fn force_unmount_ops(&self) {
402        self.ops.unmount();
403    }
404
405    /// Returns the `statfs` for this filesystem.
406    ///
407    /// Each `FileSystemOps` impl is expected to override this to return the specific statfs for
408    /// the filesystem.
409    ///
410    /// Returns `ENOSYS` if the `FileSystemOps` don't implement `stat`.
411    pub fn statfs(&self, current_task: &CurrentTask) -> Result<statfs, Errno> {
412        security::sb_statfs(current_task, &self)?;
413        let mut stat = self.ops.statfs(self, current_task)?;
414        if stat.f_frsize == 0 {
415            stat.f_frsize = stat.f_bsize as i64;
416        }
417        Ok(stat)
418    }
419
420    pub fn sync(&self, current_task: &CurrentTask) -> Result<(), Errno> {
421        self.ops.sync(self, current_task)
422    }
423
424    pub fn did_create_dir_entry(&self, entry: &DirEntryHandle) {
425        match &self.dcache {
426            DirEntryCache::Permanent(p) => {
427                p.lock().insert(ArcKey(entry.clone()));
428            }
429            DirEntryCache::Lru(LruCache { entries, .. }) => {
430                entries.lock().insert(ArcKey(entry.clone()), ());
431            }
432            DirEntryCache::Uncached => {}
433        }
434    }
435
436    pub fn will_destroy_dir_entry(&self, entry: &DirEntryHandle) {
437        match &self.dcache {
438            DirEntryCache::Permanent(p) => {
439                p.lock().remove(ArcKey::ref_cast(entry));
440            }
441            DirEntryCache::Lru(LruCache { entries, .. }) => {
442                entries.lock().remove(ArcKey::ref_cast(entry));
443            }
444            DirEntryCache::Uncached => {}
445        };
446    }
447
448    /// Informs the cache that the entry was used.
449    pub fn did_access_dir_entry(&self, entry: &DirEntryHandle) {
450        if let DirEntryCache::Lru(LruCache { entries, .. }) = &self.dcache {
451            entries.lock().get_refresh(ArcKey::ref_cast(entry));
452        }
453    }
454
455    /// Purges old entries from the cache. This is done as a separate step to avoid potential
456    /// deadlocks that could occur if done at admission time (where locks might be held that are
457    /// required when dropping old entries). This should be called after any new entries are
458    /// admitted with no locks held that might be required for dropping entries.
459    pub fn purge_old_entries(&self) {
460        if let DirEntryCache::Lru(l) = &self.dcache {
461            let mut purged = SmallVec::<[DirEntryHandle; 4]>::new();
462            {
463                let mut entries = l.entries.lock();
464                while entries.len() > l.capacity {
465                    purged.push(entries.pop_front().unwrap().0.0);
466                }
467            }
468            // Entries will get dropped here whilst we're not holding a lock.
469            std::mem::drop(purged);
470        }
471    }
472
473    /// Returns the `FileSystem`'s `FileSystemOps` as a `&T`, or `None` if the downcast fails.
474    pub fn downcast_ops<T: 'static>(&self) -> Option<&T> {
475        self.ops.as_ref().as_any().downcast_ref()
476    }
477
478    pub fn name(&self) -> &'static FsStr {
479        self.ops.name()
480    }
481
482    pub fn manages_timestamps(&self) -> bool {
483        self.ops.manages_timestamps()
484    }
485
486    /// Returns the crypt service associated with this filesystem, if any. The crypt service
487    /// implements the fuchsia.fxfs.Crypt protocol and maintains an internal structure that maps
488    /// each encryption key id to the actual key.
489    pub fn crypt_service(&self) -> Option<Arc<CryptService>> {
490        self.ops.crypt_service()
491    }
492
493    /// Reconfigures the MountFlags associated with the filesystem with the specified `flags`.
494    /// Filesystems may customize `FsNodeOps::update_flags()` to take action (e.g. flushing dirty
495    /// files when transitioning from read-write to read-only), or to reject reconfiguration.
496    pub fn update_flags(
497        &self,
498        current_task: &CurrentTask,
499        flags: FileSystemFlags,
500    ) -> Result<(), Errno> {
501        self.ops.update_flags(self, current_task, flags)
502    }
503
504    pub fn sub_filesystems(&self) -> Vec<Arc<FileSystem>> {
505        self.ops.sub_filesystems()
506    }
507
508    pub fn purge_dcache(&self) {
509        if let DirEntryCache::Lru(l) = &self.dcache {
510            let entries = std::mem::take(&mut *l.entries.lock());
511            // Entries will get dropped here outside of the lock.
512            std::mem::drop(entries);
513        }
514    }
515
516    pub fn drop_backend_caches(&self) {
517        if let Err(e) = self.ops.drop_caches(self) {
518            log_warn!("drop_caches failed for filesystem {:?}: {:?}", self.name(), e);
519        }
520    }
521
522    pub fn purge_all_entries(&self) {
523        self.purge_dcache();
524        self.drop_backend_caches();
525    }
526}
527
528/// The filesystem-implementation-specific data for FileSystem.
529pub trait FileSystemOps: AsAny + Send + Sync + 'static {
530    /// Returns the `FsLockDepType` of this filesystem.
531    ///
532    /// Defaults to `FsLockDepType::Normal`. Filesystems that can be stacked (like OverlayFS)
533    /// should override this to return `FsLockDepType::Recursive`.
534    fn fs_lockdep_type(&self) -> FsLockDepType {
535        FsLockDepType::Normal
536    }
537
538    /// Return information about this filesystem.
539    ///
540    /// A typical implementation looks like this:
541    /// ```
542    /// Ok(statfs::default(FILE_SYSTEM_MAGIC))
543    /// ```
544    /// or, if the filesystem wants to customize fields:
545    /// ```
546    /// Ok(statfs {
547    ///     f_blocks: self.blocks,
548    ///     ..statfs::default(FILE_SYSTEM_MAGIC)
549    /// })
550    /// ```
551    fn statfs(&self, _fs: &FileSystem, _current_task: &CurrentTask) -> Result<statfs, Errno>;
552
553    /// Reconfigure the filesystem with the given flags.
554    ///
555    /// This is called during a remount operation (MS_REMOUNT), to allow the filesystem to update
556    /// internal resources as necessary to support the new flags.
557    fn update_flags(
558        &self,
559        fs: &FileSystem,
560        _current_task: &CurrentTask,
561        new_flags: FileSystemFlags,
562    ) -> Result<(), Errno> {
563        fs.options.flags.store(new_flags, Ordering::Relaxed);
564        Ok(())
565    }
566
567    fn name(&self) -> &'static FsStr;
568
569    /// Whether this file system uses external node IDs.
570    ///
571    /// If this is true, then the file system is responsible for assigning node IDs to its nodes.
572    /// Otherwise, the VFS will assign node IDs to the nodes.
573    fn uses_external_node_ids(&self) -> bool {
574        false
575    }
576
577    /// Returns whether this filesystem supports casefolded directory lookups.
578    fn has_casefold_support(&self) -> bool {
579        false
580    }
581
582    /// Rename the given node.
583    ///
584    /// The node to be renamed is passed as "renamed". It currently has
585    /// old_name in old_parent. After the rename operation, it should have
586    /// new_name in new_parent.
587    ///
588    /// If new_parent already has a child named new_name, that node is passed as
589    /// "replaced". In that case, both "renamed" and "replaced" will be
590    /// directories and the rename operation should succeed only if "replaced"
591    /// is empty. The VFS will check that there are no children of "replaced" in
592    /// the DirEntry cache, but the implementation of this function is
593    /// responsible for checking that there are no children of replaced that are
594    /// known only to the file system implementation (e.g., present on-disk but
595    /// not in the DirEntry cache).
596    fn rename(
597        &self,
598        _fs: &FileSystem,
599        _current_task: &CurrentTask,
600        _context: &mut RenameContext<'_>,
601        _old_name: &FsStr,
602        _new_name: &FsStr,
603    ) -> Result<(), Errno> {
604        error!(EROFS)
605    }
606
607    /// Exchanges the two nodes identified by `name1` and `name2` in the context.
608    ///
609    /// Semantically, this is an atomic exchange of two paths (similar to two
610    /// renames, one in each direction). It uses `RenameContext` because the
611    /// locking requirements and metadata needed (parent directories, node info)
612    /// are identical to a rename operation involving two paths.
613    fn exchange(
614        &self,
615        _fs: &FileSystem,
616        _current_task: &CurrentTask,
617        _context: &mut RenameContext<'_>,
618        _name1: &FsStr,
619        _name2: &FsStr,
620    ) -> Result<(), Errno> {
621        error!(EINVAL)
622    }
623
624    /// Called when the filesystem is unmounted.
625    fn unmount(&self) {}
626
627    /// Indicates if the filesystem can manage the timestamps (i.e. ctime and mtime).
628    ///
629    /// Starnix updates the timestamps in FsNode's `info` directly. However, if the filesystem can
630    /// manage the timestamps, then Starnix does not need to do so. `info` will be refreshed with
631    /// the timestamps from the filesystem by calling `fetch_and_refresh_info(..)` on the FsNode.
632    fn manages_timestamps(&self) -> bool {
633        false
634    }
635
636    /// Returns the crypt service associated with this filesystem, if any.
637    fn crypt_service(&self) -> Option<Arc<CryptService>> {
638        None
639    }
640
641    fn sync(&self, _fs: &FileSystem, _current_task: &CurrentTask) -> Result<(), Errno> {
642        Ok(())
643    }
644
645    fn drop_caches(&self, _fs: &FileSystem) -> Result<(), Errno> {
646        Ok(())
647    }
648
649    /// Returns any underlying filesystems wrapped by this filesystem (e.g. OverlayFs lower/upper).
650    fn sub_filesystems(&self) -> Vec<Arc<FileSystem>> {
651        Vec::new()
652    }
653}
654
655impl Drop for FileSystem {
656    fn drop(&mut self) {
657        self.ops.unmount();
658    }
659}
660
661pub type FileSystemHandle = Arc<FileSystem>;