kernel/fs/vfs_v2/
cache.rs

1//! VFS v2 Page Cache integration helpers
2//!
3//! Defines the `CacheId` newtype and the `PageCacheCapable` trait that
4//! provides a common interface for FileObjects supporting the global page cache.
5
6use core::hash::Hash;
7
8/// Opaque identifier for a cacheable file object
9/// Drivers are responsible for returning a stable, globally unique id
10/// for the lifetime of the filesystem instance.
11#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
12pub struct CacheId(pub u64);
13
14impl CacheId {
15    #[inline]
16    pub const fn new(v: u64) -> Self {
17        Self(v)
18    }
19    #[inline]
20    pub const fn get(self) -> u64 {
21        self.0
22    }
23}
24
25/// FileObjects that support the global page cache must implement this trait.
26///
27/// Implementors should compose the id from (filesystem identity, file identity).
28/// The concrete composition is left to the filesystem driver for now.
29pub trait PageCacheCapable {
30    /// Returns a stable `CacheId` for this file for the lifetime of the
31    /// underlying filesystem instance.
32    fn cache_id(&self) -> CacheId;
33}