Merge tag 'pull-request-2022-09-28' of https://gitlab.com/thuth/qemu into staging
[qemu.git] / hw / 9pfs / 9p-util.c
1 /*
2 * 9p utilities
3 *
4 * Copyright IBM, Corp. 2017
5 *
6 * Authors:
7 * Greg Kurz <groug@kaod.org>
8 *
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.
11 */
12
13 /*
14 * Not so fast! You might want to read the 9p developer docs first:
15 * https://wiki.qemu.org/Documentation/9p
16 */
17
18 #include "qemu/osdep.h"
19 #include "qemu/xattr.h"
20 #include "9p-util.h"
21
22 ssize_t fgetxattrat_nofollow(int dirfd, const char *filename, const char *name,
23 void *value, size_t size)
24 {
25 char *proc_path = g_strdup_printf("/proc/self/fd/%d/%s", dirfd, filename);
26 int ret;
27
28 ret = lgetxattr(proc_path, name, value, size);
29 g_free(proc_path);
30 return ret;
31 }
32
33 ssize_t flistxattrat_nofollow(int dirfd, const char *filename,
34 char *list, size_t size)
35 {
36 char *proc_path = g_strdup_printf("/proc/self/fd/%d/%s", dirfd, filename);
37 int ret;
38
39 ret = llistxattr(proc_path, list, size);
40 g_free(proc_path);
41 return ret;
42 }
43
44 ssize_t fremovexattrat_nofollow(int dirfd, const char *filename,
45 const char *name)
46 {
47 char *proc_path = g_strdup_printf("/proc/self/fd/%d/%s", dirfd, filename);
48 int ret;
49
50 ret = lremovexattr(proc_path, name);
51 g_free(proc_path);
52 return ret;
53 }
54
55 int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name,
56 void *value, size_t size, int flags)
57 {
58 char *proc_path = g_strdup_printf("/proc/self/fd/%d/%s", dirfd, filename);
59 int ret;
60
61 ret = lsetxattr(proc_path, name, value, size, flags);
62 g_free(proc_path);
63 return ret;
64 }