[Concept,05/16] ext4l: Fix path lookup by implementing dentry operations

Message ID 20251227204318.886983-6-sjg@u-boot.org
State New
Headers
Series fs: ext4l: Complete read-only filesystem support (Part I) |

Commit Message

Simon Glass Dec. 27, 2025, 8:43 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

The fscrypt_match_name stub macro always returns 1, causing every
directory entry to match regardless of name. Also d_splice_alias is
a no-op that returns NULL, so the inode found by ext4_lookup is
never associated with the dentry.

Fix fscrypt_match_name to properly compare name lengths and contents.
Fix d_splice_alias, d_instantiate and d_instantiate_new to set
d->d_inode.

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

 fs/ext4l/ext4_uboot.h | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
  

Patch

diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h
index 52f479e9673..a90289c8fa5 100644
--- a/fs/ext4l/ext4_uboot.h
+++ b/fs/ext4l/ext4_uboot.h
@@ -1426,10 +1426,10 @@  typedef unsigned int projid_t;
 #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)			({ (void)(i); (void)(d); (struct dentry *)NULL; })
+#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)			do { (void)(d); (void)(i); } while (0)
-#define d_instantiate(d, i)			do { (void)(d); (void)(i); } while (0)
+#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 finish_open_simple(f, e)		(e)
@@ -1555,7 +1555,6 @@  static inline char *d_path(const struct path *path, char *buf, int buflen)
 #define fscrypt_limit_io_blocks(i, lb, l)	(l)
 #define fscrypt_prepare_setattr(d, a)		({ (void)(d); (void)(a); 0; })
 #define fscrypt_dio_supported(i)		(1)
-#define fscrypt_match_name(f, n, l)		({ (void)(f); (void)(n); (void)(l); 1; })
 #define fscrypt_has_permitted_context(p, c)	({ (void)(p); (void)(c); 1; })
 #define fscrypt_is_nokey_name(d)		({ (void)(d); 0; })
 #define fscrypt_prepare_symlink(d, s, l, m, dl)	({ (void)(d); (void)(s); (void)(l); (void)(m); (void)(dl); 0; })
@@ -1572,6 +1571,15 @@  struct fscrypt_name {
 	bool is_nokey_name;
 };
 
+static inline int fscrypt_match_name(const struct fscrypt_name *fname,
+				     const u8 *de_name, u32 de_name_len)
+{
+	if (fname->usr_fname->len != de_name_len)
+		return 0;
+
+	return !memcmp(fname->usr_fname->name, de_name, de_name_len);
+}
+
 /* fsverity stubs */
 #define fsverity_prepare_setattr(d, a)		({ (void)(d); (void)(a); 0; })
 #define fsverity_active(i)			(0)