[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 0/1] Rewrite /hurd/symlink on top of trivfs
From: |
Sergey Bugaev |
Subject: |
[PATCH 0/1] Rewrite /hurd/symlink on top of trivfs |
Date: |
Mon, 21 Jun 2021 16:20:23 +0300 |
Hello,
I came by this issue [0], which basically states that /hurd/symlink was
behaving in a weird way. Namely, when opened with O_NOLINK, it would
appear to be an empty file, not a symlink. The report talks about broken
symlinks, but the issue is more fundamental:
$ settrans -ac /tmp/demo /hurd/symlink /etc/hostname
$ cat /tmp/demo
sergey-hurd-box
$ file /tmp/demo
/tmp/demo: empty
$ ls -l /tmp/demo
-rw-r--r-- 1 sergey sergey 0 Jun 21 15:52 /tmp/demo
$ fsysopts /tmp/demo
ext2fs --writable --relatime --no-inherit-dir-group --store-type=typed
device:hd0s1
[0]: https://www.gnu.org/software/hurd/open_issues/symlink_translator.html
I took a look at trans/symlink.c, and found out that:
* It was not using libtrivs, as I would expect it to.
* It was treating O_NOLINK like O_NOTRANS; namely by returning the underlying
node. This is the cause of the issue: O_NOLINK has very different semantics.
It should open the link itself, and then suppport io_stat () and io_read ()
on it, returning S_IFLNK | 0777 for the mode, and the link target as
contents.
* It was leaking ports (should deallocate dotdot when not MOVE_SEND'ing it),
and skipping some error checks.
So I thought I'd try rewriting /hurd/symlink to use trivfs. This is possible
because trivfs has this convenient trivfs_getroot_hook mechanism, which lets me
either handle fsys_getroot () any way I want to, or continue with the default
implementation found in trivfs (for O_NOLINK).
End result: it seems to work great. Absolute, relative; file, ls, ls -l, stat,
readlink, cat; everything just does what I'd expect it to. Even fsysopts now
shows the invocation properly. Some demos:
$ settrans -ac /tmp/demo trans/symlink /etc/hostname
$ cat /etc/hostname
sergey-hurd-box
$ cat /tmp/demo
sergey-hurd-box
$ file /tmp/demo
/tmp/demo: symbolic link to /etc/hostname
$ ls -l /tmp/demo
lrwxrwxrwx 1 sergey sergey 13 Jun 21 16:11 /tmp/demo -> /etc/hostname
$ fsysopts /tmp/demo
trans/symlink /etc/hostname
$ settrans -ac /tmp/demo trans/symlink no-such-file
$ cat /tmp/demo
cat: /tmp/demo: No such file or directory
$ file /tmp/demo
/tmp/demo: broken symbolic link to no-such-file
$ ls -l /tmp/demo
lrwxrwxrwx 1 sergey sergey 12 Jun 21 16:11 /tmp/demo -> no-such-file
Sergey Bugaev (1):
trans/symlink.c: Rewrite on top of trivfs
trans/Makefile | 10 +-
trans/symlink.c | 243 +++++++++++++++++++++++++++---------------------
2 files changed, 137 insertions(+), 116 deletions(-)
--
2.31.1
- [PATCH 0/1] Rewrite /hurd/symlink on top of trivfs,
Sergey Bugaev <=