[PATCH 1/9] fs: ramfs: report symlink target length as st_size

Sascha Hauer s.hauer at pengutronix.de
Tue Oct 20 00:09:26 PDT 2026


Since the switch to the dentry cache, ramfs symlinks report a size of 0.
Before that, st_size was the length of the link target, as on Linux and
as all other barebox filesystems that support symlinks still do.

Besides the cosmetic issue in 'ls -l', this breaks saveenv: file_action()
allocates the readlink buffer based on st_size, so every symlink in /env
is stored in the environment truncated to its first character:

  ln env/init/automount /tmp/e/foo
  saveenv /tmp/e.img /tmp/e
  loadenv /tmp/e.img /tmp/l
  ls -l /tmp/l
  l---rwx---                    0 foo -> e

Set i_size to the length of the link target again.

Fixes: b283b72639 ("fs: ramfs: Switch to dentry cache implementation")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 fs/ramfs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/ramfs.c b/fs/ramfs.c
index d86bf6144e..c843df6c5c 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -176,6 +176,7 @@ static int ramfs_symlink(struct inode *dir, struct dentry *dentry,
 		return -ENOSPC;
 
 	inode->i_link = xstrdup(symname);
+	inode->i_size = strlen(symname);
 	d_instantiate(dentry, inode);
 
 	return 0;

-- 
2.47.3




More information about the barebox mailing list