029ed1bd9d
Darwin does not support mknodat. However, to avoid race conditions with later setting the permissions, we must avoid using mknod on the full path instead. We could try to fchdir, but that would cause problems if multiple threads try to call mknodat at the same time. However, luckily there is a solution: Darwin includes a function that sets the cwd for the current thread only. This should suffice to use mknod safely. This function (pthread_fchdir_np) is protected by a check in meson in a patch later in this series. Signed-off-by: Keno Fischer <keno@juliacomputing.com> Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com> [Will Cohen: - Adjust coding style - Replace clang references with gcc - Note radar filed with Apple for missing syscall - Replace direct syscall with pthread_fchdir_np and adjust patch notes accordingly - Declare pthread_fchdir_np with - __attribute__((weak_import)) to allow checking for its presence before usage - Move declarations above cplusplus guard - Add CONFIG_PTHREAD_FCHDIR_NP to meson and check for presence in 9p-util - Rebase to apply cleanly on top of the 2022-02-10 changes to 9pfs - Fix line over 90 characters formatting error] Signed-off-by: Will Cohen <wwcohen@gmail.com> Message-Id: <20220227223522.91937-10-wwcohen@gmail.com> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com> Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
71 lines
1.8 KiB
C
71 lines
1.8 KiB
C
/*
|
|
* 9p utilities (Linux Implementation)
|
|
*
|
|
* Copyright IBM, Corp. 2017
|
|
*
|
|
* Authors:
|
|
* Greg Kurz <groug@kaod.org>
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*/
|
|
|
|
/*
|
|
* Not so fast! You might want to read the 9p developer docs first:
|
|
* https://wiki.qemu.org/Documentation/9p
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qemu/xattr.h"
|
|
#include "9p-util.h"
|
|
|
|
ssize_t fgetxattrat_nofollow(int dirfd, const char *filename, const char *name,
|
|
void *value, size_t size)
|
|
{
|
|
char *proc_path = g_strdup_printf("/proc/self/fd/%d/%s", dirfd, filename);
|
|
int ret;
|
|
|
|
ret = lgetxattr(proc_path, name, value, size);
|
|
g_free(proc_path);
|
|
return ret;
|
|
}
|
|
|
|
ssize_t flistxattrat_nofollow(int dirfd, const char *filename,
|
|
char *list, size_t size)
|
|
{
|
|
char *proc_path = g_strdup_printf("/proc/self/fd/%d/%s", dirfd, filename);
|
|
int ret;
|
|
|
|
ret = llistxattr(proc_path, list, size);
|
|
g_free(proc_path);
|
|
return ret;
|
|
}
|
|
|
|
ssize_t fremovexattrat_nofollow(int dirfd, const char *filename,
|
|
const char *name)
|
|
{
|
|
char *proc_path = g_strdup_printf("/proc/self/fd/%d/%s", dirfd, filename);
|
|
int ret;
|
|
|
|
ret = lremovexattr(proc_path, name);
|
|
g_free(proc_path);
|
|
return ret;
|
|
}
|
|
|
|
int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name,
|
|
void *value, size_t size, int flags)
|
|
{
|
|
char *proc_path = g_strdup_printf("/proc/self/fd/%d/%s", dirfd, filename);
|
|
int ret;
|
|
|
|
ret = lsetxattr(proc_path, name, value, size, flags);
|
|
g_free(proc_path);
|
|
return ret;
|
|
|
|
}
|
|
|
|
int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
|
|
{
|
|
return mknodat(dirfd, filename, mode, dev);
|
|
}
|