[Concept,08/19] linux: Add dcache.h header with dentry stubs

Message ID 20260117011448.3007171-9-sjg@u-boot.org
State New
Headers
Series ext4l: Reduce ext4_uboot.h size by moving code to include/linux |

Commit Message

Simon Glass Jan. 17, 2026, 1:14 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Move dentry and directory cache stubs to a dedicated header file
that mirrors the Linux kernel organisation.

dcache.h provides:
- struct qstr and QSTR_INIT() for quick strings
- dotdot_name constant for ".." lookups
- struct dentry with minimal fields for ext4l
- struct name_snapshot for dentry name snapshots
- d_inode() accessor
- Dentry operation stubs: d_find_any_alias(), dget_parent(), dput(),
  d_splice_alias(), d_obtain_alias(), d_instantiate_new(),
  d_instantiate(), d_tmpfile(), d_invalidate(), d_alloc(), d_drop()
- Name snapshot operations: take_dentry_name_snapshot(),
  release_dentry_name_snapshot()
- Declarations for generic_set_sb_d_ops() and d_make_root()

Also update ext4_fscrypt.h to include dcache.h instead of defining
its own struct qstr, avoiding duplication.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 fs/ext4l/ext4_fscrypt.h |  9 +---
 fs/ext4l/ext4_uboot.h   | 47 ++++-----------------
 include/linux/dcache.h  | 94 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 103 insertions(+), 47 deletions(-)
 create mode 100644 include/linux/dcache.h
  

Patch

diff --git a/fs/ext4l/ext4_fscrypt.h b/fs/ext4l/ext4_fscrypt.h
index da91af74343..91f08229e32 100644
--- a/fs/ext4l/ext4_fscrypt.h
+++ b/fs/ext4l/ext4_fscrypt.h
@@ -13,6 +13,7 @@ 
 #include <linux/errno.h>
 #include <linux/err.h>
 #include <linux/string.h>
+#include <linux/dcache.h>
 
 /* Forward declarations */
 struct inode;
@@ -21,16 +22,8 @@  struct page;
 struct folio;
 struct bio;
 struct buffer_head;
-struct dentry;
 struct super_block;
 
-/* qstr - quick string for filenames (needed by fscrypt_name) */
-struct qstr {
-	u32 hash;
-	u32 len;
-	const unsigned char *name;
-};
-
 /* fscrypt_str - encrypted filename string */
 struct fscrypt_str {
 	unsigned char *name;
diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h
index a1047607e79..9423c92169e 100644
--- a/fs/ext4l/ext4_uboot.h
+++ b/fs/ext4l/ext4_uboot.h
@@ -86,6 +86,7 @@ 
 #include <linux/blk_types.h>
 #include <linux/fs_context.h>
 #include <linux/fs_parser.h>
+#include <linux/dcache.h>
 
 /* atomic_dec_if_positive, atomic_add_unless, etc. are now in asm-generic/atomic.h */
 
@@ -300,8 +301,7 @@  struct buffer_head *sb_getblk(struct super_block *sb, sector_t block);
 /* icount - inode reference count */
 #define icount_read(inode)			(1)
 
-/* d_inode - get inode from dentry */
-#define d_inode(dentry)				((dentry) ? (dentry)->d_inode : NULL)
+/* d_inode is now in linux/dcache.h */
 
 /* Random number functions */
 #define get_random_u32_below(max)		(0)
@@ -444,18 +444,7 @@  struct ratelimit_state {
 /* IS_NOQUOTA - stub */
 #define IS_NOQUOTA(inode)	(0)
 
-/* dentry - stub */
-struct dentry {
-	struct qstr d_name;
-	struct inode *d_inode;
-	struct super_block *d_sb;
-	struct dentry *d_parent;
-};
-
-/* name_snapshot - for dentry name snapshots */
-struct name_snapshot {
-	struct qstr name;
-};
+/* dentry, name_snapshot are now in linux/dcache.h */
 
 /* VM types - use linux/mm_types.h */
 #include <linux/mm_types.h>
@@ -758,10 +747,7 @@  static inline void inode_state_assign(struct inode *inode, unsigned long flags)
 	inode->i_state = flags;
 }
 
-#define QSTR_INIT(n, l) { .name = (const unsigned char *)(n), .len = (l) }
-
-/* dotdot_name for ".." lookups */
-static const struct qstr dotdot_name = QSTR_INIT("..", 2);
+/* QSTR_INIT and dotdot_name are now in linux/dcache.h */
 
 /*
  * Hash info structure - defined in ext4.h.
@@ -999,16 +985,7 @@  typedef unsigned int projid_t;
 /* hash_64 - simple 64-bit hash */
 #define hash_64(val, bits)	((unsigned long)((val) >> (64 - (bits))))
 
-/* Dentry operations - stubs */
-#define d_find_any_alias(i)			({ (void)(i); (struct dentry *)NULL; })
-#define dget_parent(d)				({ (void)(d); (struct dentry *)NULL; })
-#define dput(d)					do { (void)(d); } while (0)
-#define d_splice_alias(i, d)			({ (d)->d_inode = (i); (d); })
-#define d_obtain_alias(i)			({ (void)(i); (struct dentry *)NULL; })
-#define d_instantiate_new(d, i)			((void)((d)->d_inode = (i)))
-#define d_instantiate(d, i)			((void)((d)->d_inode = (i)))
-#define d_tmpfile(f, i)				do { (void)(f); (void)(i); } while (0)
-#define d_invalidate(d)				do { (void)(d); } while (0)
+/* Dentry operations are now in linux/dcache.h */
 #define finish_open_simple(f, e)		(e)
 #define ihold(i)				do { (void)(i); } while (0)
 
@@ -1678,9 +1655,7 @@  struct mb_cache_entry {
 #define PF_MEMALLOC_NOFS	0x00040000
 #endif
 
-/* Dentry operations - declarations for stub.c */
-void generic_set_sb_d_ops(struct super_block *sb);
-struct dentry *d_make_root(struct inode *inode);
+/* generic_set_sb_d_ops, d_make_root are now in linux/dcache.h */
 
 /* strreplace is in linux/string.h */
 
@@ -1909,11 +1884,7 @@  struct wait_bit_entry {
 #define finish_wait(wq, wait) \
 	do { (void)(wq); (void)(wait); } while (0)
 
-/* Dentry name snapshot operations */
-#define take_dentry_name_snapshot(snap, dentry) \
-	do { (snap)->name = (dentry)->d_name; } while (0)
-#define release_dentry_name_snapshot(snap) \
-	do { (void)(snap); } while (0)
+/* Dentry name snapshot operations are now in linux/dcache.h */
 
 /* lockdep_assert_not_held is in linux/lockdep.h */
 
@@ -1924,9 +1895,7 @@  struct wait_bit_entry {
 /* wake_up_bit - wake up threads waiting on a bit */
 #define wake_up_bit(word, bit)		do { (void)(word); (void)(bit); } while (0)
 
-/* Dentry allocation stubs */
-#define d_alloc(parent, name)		({ (void)(parent); (void)(name); (struct dentry *)NULL; })
-#define d_drop(dentry)			do { (void)(dentry); } while (0)
+/* d_alloc, d_drop are now in linux/dcache.h */
 
 /* get_current_ioprio - I/O priority (not used in U-Boot) */
 #define get_current_ioprio()		(0)
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
new file mode 100644
index 00000000000..bf8d1e4755e
--- /dev/null
+++ b/include/linux/dcache.h
@@ -0,0 +1,94 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Dentry cache stubs for U-Boot
+ *
+ * Based on Linux dcache.h - U-Boot doesn't have a real dentry cache,
+ * so these are stubs for compilation.
+ */
+#ifndef _LINUX_DCACHE_H
+#define _LINUX_DCACHE_H
+
+#include <linux/types.h>
+#include <linux/list.h>
+
+/* Forward declarations */
+struct inode;
+struct super_block;
+
+/**
+ * struct qstr - quick string for filenames
+ * @hash: filename hash
+ * @len: filename length
+ * @name: filename
+ *
+ * Note: Also defined in ext4_fscrypt.h for fscrypt support.
+ */
+struct qstr {
+	u32 hash;
+	u32 len;
+	const unsigned char *name;
+};
+
+/**
+ * QSTR_INIT - initialise a qstr
+ * @n: name string
+ * @l: length
+ */
+#define QSTR_INIT(n, l) { .name = (const unsigned char *)(n), .len = (l) }
+
+/* dotdot_name for ".." lookups */
+static const struct qstr dotdot_name = QSTR_INIT("..", 2);
+
+/**
+ * struct dentry - directory entry
+ * @d_name: filename
+ * @d_inode: associated inode
+ * @d_sb: superblock
+ * @d_parent: parent directory
+ *
+ * U-Boot stub - minimal fields for ext4l.
+ */
+struct dentry {
+	struct qstr d_name;
+	struct inode *d_inode;
+	struct super_block *d_sb;
+	struct dentry *d_parent;
+};
+
+/**
+ * struct name_snapshot - dentry name snapshot
+ * @name: snapshot of the name
+ *
+ * Used for safe name access during operations.
+ */
+struct name_snapshot {
+	struct qstr name;
+};
+
+/* d_inode - get inode from dentry */
+#define d_inode(dentry)		((dentry) ? (dentry)->d_inode : NULL)
+
+/* Dentry operations - stubs */
+#define d_find_any_alias(i)	({ (void)(i); (struct dentry *)NULL; })
+#define dget_parent(d)		({ (void)(d); (struct dentry *)NULL; })
+#define dput(d)			do { (void)(d); } while (0)
+#define d_splice_alias(i, d)	({ (d)->d_inode = (i); (d); })
+#define d_obtain_alias(i)	({ (void)(i); (struct dentry *)NULL; })
+#define d_instantiate_new(d, i)	((void)((d)->d_inode = (i)))
+#define d_instantiate(d, i)	((void)((d)->d_inode = (i)))
+#define d_tmpfile(f, i)		do { (void)(f); (void)(i); } while (0)
+#define d_invalidate(d)		do { (void)(d); } while (0)
+#define d_alloc(parent, name)	({ (void)(parent); (void)(name); (struct dentry *)NULL; })
+#define d_drop(dentry)		do { (void)(dentry); } while (0)
+
+/* Name snapshot operations */
+#define take_dentry_name_snapshot(sn, d) \
+	do { (sn)->name = (d)->d_name; } while (0)
+#define release_dentry_name_snapshot(sn) \
+	do { (void)(sn); } while (0)
+
+/* Dentry operations - declarations for stub.c */
+void generic_set_sb_d_ops(struct super_block *sb);
+struct dentry *d_make_root(struct inode *inode);
+
+#endif /* _LINUX_DCACHE_H */