Skip to content

Commit

Permalink
lklfuse: map more open flags
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ddiss committed Jun 27, 2024
1 parent 72b7ed2 commit b42cf5f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tools/lkl/lklfuse.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only
#define _GNU_SOURCE
#include <fcntl.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b42cf5f

Please sign in to comment.