From b42cf5fbc661185a6c27bb9a7c5f09b6ccfce48f Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Fri, 21 Jun 2024 15:58:19 +0200 Subject: [PATCH] lklfuse: map more open flags Proper open flag semantics are important for some applications and tests such as xfstests generic/130 (for O_TRUNCATE). Pass all open flags from fuse through to the corresponding LKL open syscall, with the exception of O_CREAT, O_EXCL and O_NOCTTY, which fuse handles internally. Other flags may also be filtered out by fuse. Signed-off-by: David Disseldorp --- tools/lkl/lklfuse.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tools/lkl/lklfuse.c b/tools/lkl/lklfuse.c index a6e46787b1dc4c..d71b4b0df6efba 100644 --- a/tools/lkl/lklfuse.c +++ b/tools/lkl/lklfuse.c @@ -1,3 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-only +#define _GNU_SOURCE +#include #include #include #include @@ -257,8 +260,39 @@ static int lklfuse_open3(const char *path, bool create, mode_t mode, else return -EINVAL; + /* + * XXX see rules in fuse3/fuse.h: + * Creation (O_CREAT, O_EXCL, O_NOCTTY) flags will be filtered out / + * handled by FUSE kernel... + */ if (create) flags |= LKL_O_CREAT; + if (fi->flags & O_TRUNC) + flags |= LKL_O_TRUNC; + if (fi->flags & O_APPEND) + flags |= LKL_O_APPEND; + if (fi->flags & O_NONBLOCK) + flags |= LKL_O_NONBLOCK; + if (fi->flags & O_DSYNC) + flags |= LKL_O_DSYNC; + if (fi->flags & O_DIRECT) + flags |= LKL_O_DIRECT; + if (fi->flags & O_LARGEFILE) + flags |= LKL_O_LARGEFILE; + if (fi->flags & O_DIRECTORY) + flags |= LKL_O_DIRECTORY; + if (fi->flags & O_NOFOLLOW) + flags |= LKL_O_NOFOLLOW; + if (fi->flags & O_NOATIME) + flags |= LKL_O_NOATIME; + if (fi->flags & O_CLOEXEC) + flags |= LKL_O_CLOEXEC; + if (fi->flags & O_SYNC) + flags |= LKL_O_SYNC; + if (fi->flags & O_PATH) + flags |= LKL_O_PATH; + if (fi->flags & O_TMPFILE) + flags |= LKL_O_TMPFILE; ret = lkl_sys_open(path, flags, mode); if (ret < 0)