[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240514131711.379322-15-wedsonaf@gmail.com>
Date: Tue, 14 May 2024 10:16:55 -0300
From: Wedson Almeida Filho <wedsonaf@...il.com>
To: Alexander Viro <viro@...iv.linux.org.uk>,
Christian Brauner <brauner@...nel.org>,
Matthew Wilcox <willy@...radead.org>,
Dave Chinner <david@...morbit.com>
Cc: Kent Overstreet <kent.overstreet@...il.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-fsdevel@...r.kernel.org,
rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org,
Wedson Almeida Filho <walmeida@...rosoft.com>
Subject: [RFC PATCH v2 14/30] rust: fs: add empty inode operations
From: Wedson Almeida Filho <walmeida@...rosoft.com>
This is in preparation for allowing modules to implement different inode
callbacks, which will be introduced in subsequent patches.
Signed-off-by: Wedson Almeida Filho <walmeida@...rosoft.com>
---
rust/kernel/fs/inode.rs | 48 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/rust/kernel/fs/inode.rs b/rust/kernel/fs/inode.rs
index d84d8d2f7076..3d65b917af0e 100644
--- a/rust/kernel/fs/inode.rs
+++ b/rust/kernel/fs/inode.rs
@@ -12,10 +12,18 @@
use crate::{bindings, block, time::Timespec};
use core::mem::ManuallyDrop;
use core::{marker::PhantomData, ptr};
+use macros::vtable;
/// The number of an inode.
pub type Ino = u64;
+/// Operations implemented by inodes.
+#[vtable]
+pub trait Operations {
+ /// File system that these operations are compatible with.
+ type FileSystem: FileSystem + ?Sized;
+}
+
/// A node (inode) in the file index.
///
/// Wraps the kernel's `struct inode`.
@@ -203,3 +211,43 @@ pub struct Params {
/// Last access time.
pub atime: Timespec,
}
+
+/// Represents inode operations.
+pub struct Ops<T: FileSystem + ?Sized>(*const bindings::inode_operations, PhantomData<T>);
+
+impl<T: FileSystem + ?Sized> Ops<T> {
+ /// Creates the inode operations from a type that implements the [`Operations`] trait.
+ pub const fn new<U: Operations<FileSystem = T> + ?Sized>() -> Self {
+ struct Table<T: Operations + ?Sized>(PhantomData<T>);
+ impl<T: Operations + ?Sized> Table<T> {
+ const TABLE: bindings::inode_operations = bindings::inode_operations {
+ lookup: None,
+ get_link: None,
+ permission: None,
+ get_inode_acl: None,
+ readlink: None,
+ create: None,
+ link: None,
+ unlink: None,
+ symlink: None,
+ mkdir: None,
+ rmdir: None,
+ mknod: None,
+ rename: None,
+ setattr: None,
+ getattr: None,
+ listxattr: None,
+ fiemap: None,
+ update_time: None,
+ atomic_open: None,
+ tmpfile: None,
+ get_acl: None,
+ set_acl: None,
+ fileattr_set: None,
+ fileattr_get: None,
+ get_offset_ctx: None,
+ };
+ }
+ Self(&Table::<U>::TABLE, PhantomData)
+ }
+}
--
2.34.1
Powered by blists - more mailing lists