[Concept,05/33] ext4l: Move struct inode and time accessors to linux/fs.h

Message ID 20260121220857.2137568-6-sjg@u-boot.org
State New
Headers
Series Reorganise ext4l compatibility stubs |

Commit Message

Simon Glass Jan. 21, 2026, 10:08 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Move the inode structure definition and its time accessor functions
from ext4_uboot.h to include/linux/fs.h where they belong according
to Linux kernel conventions.

This includes:
- struct inode definition
- inode_get_atime(), inode_get_mtime(), inode_get_ctime()
- inode_get_atime_sec(), inode_get_mtime_sec(), inode_get_ctime_sec()
- inode_set_atime(), inode_set_mtime(), inode_set_ctime()
- inode_set_atime_to_ts(), inode_set_ctime_to_ts()
- simple_inode_init_ts()
- i_uid_read(), i_gid_read()

Add necessary includes to linux/fs.h for inode dependencies (cred.h,
rwsem.h, time.h, atomic.h).

Co-developed-by: Claude (Anthropic)
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 fs/ext4l/ext4_uboot.h | 126 -----------------------------------------
 include/linux/fs.h    | 129 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 128 insertions(+), 127 deletions(-)
  

Patch

diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h
index fb5c7cc8872..6f4ebd7e68b 100644
--- a/fs/ext4l/ext4_uboot.h
+++ b/fs/ext4l/ext4_uboot.h
@@ -181,105 +181,9 @@  static inline int bdev_read_only(struct block_device *bdev)
 	return bdev ? bdev->read_only : 0;
 }
 
-#include <linux/cred.h>
-
 #define WHITEOUT_DEV	0
 #define WHITEOUT_MODE	0
 
-struct swap_info_struct;
-struct inode_operations;
-struct file_operations;
-
-struct inode {
-	struct super_block *i_sb;
-	unsigned long i_ino;
-	umode_t i_mode;
-	unsigned int i_nlink;
-	loff_t i_size;
-	struct address_space *i_mapping;
-	struct address_space i_data;
-	kuid_t i_uid;
-	kgid_t i_gid;
-	unsigned long i_blocks;
-	unsigned int i_generation;
-	unsigned int i_flags;
-	unsigned int i_blkbits;
-	unsigned long i_state;
-	struct timespec64 i_atime;
-	struct timespec64 i_mtime;
-	struct timespec64 i_ctime;
-	struct list_head i_io_list;
-	dev_t i_rdev;
-	const struct inode_operations *i_op;
-	const struct file_operations *i_fop;
-	atomic_t i_writecount;		/* Count of writers */
-	atomic_t i_count;		/* Reference count */
-	struct rw_semaphore i_rwsem;	/* inode lock */
-	const char *i_link;		/* Symlink target for fast symlinks */
-	unsigned short i_write_hint;	/* Write life time hint */
-
-	/* U-Boot: linkage into super_block s_inodes list */
-	struct list_head i_sb_list;
-};
-
-/* Inode time accessors */
-static inline struct timespec64 inode_get_atime(const struct inode *inode)
-{
-	return inode->i_atime;
-}
-
-static inline struct timespec64 inode_get_mtime(const struct inode *inode)
-{
-	return inode->i_mtime;
-}
-
-static inline struct timespec64 inode_get_ctime(const struct inode *inode)
-{
-	return inode->i_ctime;
-}
-
-static inline time_t inode_get_atime_sec(const struct inode *inode)
-{
-	return inode->i_atime.tv_sec;
-}
-
-static inline time_t inode_get_ctime_sec(const struct inode *inode)
-{
-	return inode->i_ctime.tv_sec;
-}
-
-static inline time_t inode_get_mtime_sec(const struct inode *inode)
-{
-	return inode->i_mtime.tv_sec;
-}
-
-static inline void inode_set_ctime(struct inode *inode, time_t sec, long nsec)
-{
-	inode->i_ctime.tv_sec = sec;
-	inode->i_ctime.tv_nsec = nsec;
-}
-
-static inline void inode_set_atime(struct inode *inode, time_t sec, long nsec)
-{
-	inode->i_atime.tv_sec = sec;
-	inode->i_atime.tv_nsec = nsec;
-}
-
-static inline void inode_set_mtime(struct inode *inode, time_t sec, long nsec)
-{
-	inode->i_mtime.tv_sec = sec;
-	inode->i_mtime.tv_nsec = nsec;
-}
-
-static inline void simple_inode_init_ts(struct inode *inode)
-{
-	struct timespec64 ts = { .tv_sec = 0, .tv_nsec = 0 };
-
-	inode->i_atime = ts;
-	inode->i_mtime = ts;
-	inode->i_ctime = ts;
-}
-
 /*
  * Inode state accessors - simplified for single-threaded U-Boot.
  * Linux uses READ_ONCE/WRITE_ONCE and lockdep assertions; we use direct access.
@@ -450,37 +354,7 @@  struct dx_hash_info {
 #include <linux/path.h>
 
 #include <linux/fsverity.h>
-
-/* Inode time setters - needed for ext4.h */
-static inline struct timespec64 inode_set_atime_to_ts(struct inode *inode,
-						      struct timespec64 ts)
-{
-	inode->i_atime = ts;
-	return ts;
-}
-
-static inline struct timespec64 inode_set_ctime_to_ts(struct inode *inode,
-						      struct timespec64 ts)
-{
-	inode->i_ctime = ts;
-	return ts;
-}
-
-/* Inode version operations - use linux/iversion.h */
 #include <linux/iversion.h>
-
-/* Inode credential helpers - i_uid_read, i_gid_read need struct inode */
-static inline unsigned int i_uid_read(const struct inode *inode)
-{
-	return inode->i_uid.val;
-}
-
-static inline unsigned int i_gid_read(const struct inode *inode)
-{
-	return inode->i_gid.val;
-}
-
-/* Device encoding helpers are now in linux/kdev_t.h */
 #include <linux/kdev_t.h>
 
 /* UID/GID bit helpers - use linux/highuid.h */
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 3f82a027931..e78ac5f7284 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -11,9 +11,12 @@ 
 #include <linux/list.h>
 #include <linux/mutex.h>
 #include <linux/fs/super_types.h>
+#include <linux/cred.h>
+#include <linux/rwsem.h>
+#include <linux/time.h>
+#include <asm-generic/atomic.h>
 
 /* Forward declarations */
-struct inode;
 struct buffer_head;
 struct file;
 struct folio;
@@ -100,6 +103,130 @@  struct address_space_operations {
 			     sector_t *);
 };
 
+/* Forward declarations for inode */
+struct inode_operations;
+struct file_operations;
+
+/**
+ * struct inode - filesystem inode
+ *
+ * Core filesystem object representing a file, directory, or other entity.
+ */
+struct inode {
+	struct super_block *i_sb;
+	unsigned long i_ino;
+	umode_t i_mode;
+	unsigned int i_nlink;
+	loff_t i_size;
+	struct address_space *i_mapping;
+	struct address_space i_data;
+	kuid_t i_uid;
+	kgid_t i_gid;
+	unsigned long i_blocks;
+	unsigned int i_generation;
+	unsigned int i_flags;
+	unsigned int i_blkbits;
+	unsigned long i_state;
+	struct timespec64 i_atime;
+	struct timespec64 i_mtime;
+	struct timespec64 i_ctime;
+	struct list_head i_io_list;
+	dev_t i_rdev;
+	const struct inode_operations *i_op;
+	const struct file_operations *i_fop;
+	atomic_t i_writecount;		/* Count of writers */
+	atomic_t i_count;		/* Reference count */
+	struct rw_semaphore i_rwsem;	/* inode lock */
+	const char *i_link;		/* Symlink target for fast symlinks */
+	unsigned short i_write_hint;	/* Write life time hint */
+#ifdef __UBOOT__
+	struct list_head i_sb_list;	/* Linkage into super_block s_inodes */
+#endif
+};
+
+/* Inode time accessors */
+static inline struct timespec64 inode_get_atime(const struct inode *inode)
+{
+	return inode->i_atime;
+}
+
+static inline struct timespec64 inode_get_mtime(const struct inode *inode)
+{
+	return inode->i_mtime;
+}
+
+static inline struct timespec64 inode_get_ctime(const struct inode *inode)
+{
+	return inode->i_ctime;
+}
+
+static inline time_t inode_get_atime_sec(const struct inode *inode)
+{
+	return inode->i_atime.tv_sec;
+}
+
+static inline time_t inode_get_ctime_sec(const struct inode *inode)
+{
+	return inode->i_ctime.tv_sec;
+}
+
+static inline time_t inode_get_mtime_sec(const struct inode *inode)
+{
+	return inode->i_mtime.tv_sec;
+}
+
+static inline void inode_set_ctime(struct inode *inode, time_t sec, long nsec)
+{
+	inode->i_ctime.tv_sec = sec;
+	inode->i_ctime.tv_nsec = nsec;
+}
+
+static inline void inode_set_atime(struct inode *inode, time_t sec, long nsec)
+{
+	inode->i_atime.tv_sec = sec;
+	inode->i_atime.tv_nsec = nsec;
+}
+
+static inline void inode_set_mtime(struct inode *inode, time_t sec, long nsec)
+{
+	inode->i_mtime.tv_sec = sec;
+	inode->i_mtime.tv_nsec = nsec;
+}
+
+static inline void simple_inode_init_ts(struct inode *inode)
+{
+	struct timespec64 ts = { .tv_sec = 0, .tv_nsec = 0 };
+
+	inode->i_atime = ts;
+	inode->i_mtime = ts;
+	inode->i_ctime = ts;
+}
+
+static inline struct timespec64 inode_set_atime_to_ts(struct inode *inode,
+						      struct timespec64 ts)
+{
+	inode->i_atime = ts;
+	return ts;
+}
+
+static inline struct timespec64 inode_set_ctime_to_ts(struct inode *inode,
+						      struct timespec64 ts)
+{
+	inode->i_ctime = ts;
+	return ts;
+}
+
+/* Inode credential helpers */
+static inline unsigned int i_uid_read(const struct inode *inode)
+{
+	return inode->i_uid.val;
+}
+
+static inline unsigned int i_gid_read(const struct inode *inode)
+{
+	return inode->i_gid.val;
+}
+
 /* block_device - minimal stub */
 struct block_device {
 	struct address_space *bd_mapping;