From b78d5b42414518dd85b2ebf2f15ba8a742ead399 Mon Sep 17 00:00:00 2001 From: Brooks Davis Date: Thu, 12 Jan 2023 18:18:45 +0000 Subject: [PATCH] makefs: handle mtree link= for ZFS When a link target is specified use it rather than attempting to read a potentially non-existant file. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D38028 --- usr.sbin/makefs/zfs/fs.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/usr.sbin/makefs/zfs/fs.c b/usr.sbin/makefs/zfs/fs.c index b9cc860c2e29..3cf328122df8 100644 --- a/usr.sbin/makefs/zfs/fs.c +++ b/usr.sbin/makefs/zfs/fs.c @@ -297,15 +297,23 @@ fs_readlink(const fsnode *cur, struct fs_populate_arg *arg, char *buf, size_t bufsz) { char path[PATH_MAX]; - ssize_t n; int fd; - fs_populate_path(cur, arg, path, sizeof(path), &fd); + if (cur->symlink != NULL) { + size_t n; - n = readlinkat(fd, path, buf, bufsz - 1); - if (n == -1) - err(1, "readlinkat(%s)", cur->name); - buf[n] = '\0'; + n = strlcpy(buf, cur->symlink, bufsz); + assert(n < bufsz); + } else { + ssize_t n; + + fs_populate_path(cur, arg, path, sizeof(path), &fd); + + n = readlinkat(fd, path, buf, bufsz - 1); + if (n == -1) + err(1, "readlinkat(%s)", cur->name); + buf[n] = '\0'; + } } static void