4 * Copyright IBM, Corp. 2017
7 * Greg Kurz <groug@kaod.org>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 #ifndef QEMU_9P_UTIL_H
14 #define QEMU_9P_UTIL_H
17 #define O_PATH_9P_UTIL O_PATH
19 #define O_PATH_9P_UTIL 0
22 static inline void close_preserve_errno(int fd
)
29 static inline int openat_dir(int dirfd
, const char *name
)
31 return openat(dirfd
, name
,
32 O_DIRECTORY
| O_RDONLY
| O_NOFOLLOW
| O_PATH_9P_UTIL
);
35 static inline int openat_file(int dirfd
, const char *name
, int flags
,
40 fd
= openat(dirfd
, name
, flags
| O_NOFOLLOW
| O_NOCTTY
| O_NONBLOCK
,
47 /* O_NONBLOCK was only needed to open the file. Let's drop it. We don't
48 * do that with O_PATH since fcntl(F_SETFL) isn't supported, and openat()
51 if (!(flags
& O_PATH_9P_UTIL
)) {
52 ret
= fcntl(fd
, F_SETFL
, flags
);
59 ssize_t
fgetxattrat_nofollow(int dirfd
, const char *path
, const char *name
,
60 void *value
, size_t size
);
61 int fsetxattrat_nofollow(int dirfd
, const char *path
, const char *name
,
62 void *value
, size_t size
, int flags
);