2 * 9p utilities (Darwin Implementation)
4 * This work is licensed under the terms of the GNU GPL, version 2 or later.
5 * See the COPYING file in the top-level directory.
8 #include "qemu/osdep.h"
9 #include "qemu/xattr.h"
10 #include "qapi/error.h"
11 #include "qemu/error-report.h"
14 ssize_t
fgetxattrat_nofollow(int dirfd
, const char *filename
, const char *name
,
15 void *value
, size_t size
)
18 int fd
= openat_file(dirfd
, filename
,
19 O_RDONLY
| O_PATH_9P_UTIL
| O_NOFOLLOW
, 0);
23 ret
= fgetxattr(fd
, name
, value
, size
, 0, 0);
24 close_preserve_errno(fd
);
28 ssize_t
flistxattrat_nofollow(int dirfd
, const char *filename
,
29 char *list
, size_t size
)
32 int fd
= openat_file(dirfd
, filename
,
33 O_RDONLY
| O_PATH_9P_UTIL
| O_NOFOLLOW
, 0);
37 ret
= flistxattr(fd
, list
, size
, 0);
38 close_preserve_errno(fd
);
42 ssize_t
fremovexattrat_nofollow(int dirfd
, const char *filename
,
46 int fd
= openat_file(dirfd
, filename
, O_PATH_9P_UTIL
| O_NOFOLLOW
, 0);
50 ret
= fremovexattr(fd
, name
, 0);
51 close_preserve_errno(fd
);
55 int fsetxattrat_nofollow(int dirfd
, const char *filename
, const char *name
,
56 void *value
, size_t size
, int flags
)
59 int fd
= openat_file(dirfd
, filename
, O_PATH_9P_UTIL
| O_NOFOLLOW
, 0);
63 ret
= fsetxattr(fd
, name
, value
, size
, 0, flags
);
64 close_preserve_errno(fd
);
69 * As long as mknodat is not available on macOS, this workaround
70 * using pthread_fchdir_np is needed.
72 * Radar filed with Apple for implementing mknodat:
73 * rdar://FB9862426 (https://openradar.appspot.com/FB9862426)
75 #if defined CONFIG_PTHREAD_FCHDIR_NP
77 int qemu_mknodat(int dirfd
, const char *filename
, mode_t mode
, dev_t dev
)
79 int preserved_errno
, err
;
80 if (!pthread_fchdir_np
) {
81 error_report_once("pthread_fchdir_np() not available on this version of macOS");
84 if (pthread_fchdir_np(dirfd
) < 0) {
87 err
= mknod(filename
, mode
, dev
);
88 preserved_errno
= errno
;
89 /* Stop using the thread-local cwd */
90 pthread_fchdir_np(-1);
92 errno
= preserved_errno
;