Merge "virtio-9p: enable the virtfs on Windows." into tizen
[sdk/emulator/qemu.git] / hw / 9pfs / virtio-9p-xattr.h
1 /*
2  * Virtio 9p
3  *
4  * Copyright IBM, Corp. 2010
5  *
6  * Authors:
7  *  Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  *
12  */
13 #ifndef _QEMU_VIRTIO_9P_XATTR_H
14 #define _QEMU_VIRTIO_9P_XATTR_H
15
16 #include "qemu/xattr.h"
17
18 typedef struct xattr_operations
19 {
20     const char *name;
21     ssize_t (*getxattr)(FsContext *ctx, const char *path,
22                         const char *name, void *value, size_t size);
23     ssize_t (*listxattr)(FsContext *ctx, const char *path,
24                          char *name, void *value, size_t size);
25     int (*setxattr)(FsContext *ctx, const char *path, const char *name,
26                     void *value, size_t size, int flags);
27     int (*removexattr)(FsContext *ctx,
28                        const char *path, const char *name);
29 } XattrOperations;
30
31
32 extern XattrOperations mapped_user_xattr;
33 extern XattrOperations passthrough_user_xattr;
34
35 extern XattrOperations mapped_pacl_xattr;
36 extern XattrOperations mapped_dacl_xattr;
37 extern XattrOperations passthrough_acl_xattr;
38 extern XattrOperations none_acl_xattr;
39
40 extern XattrOperations *mapped_xattr_ops[];
41 extern XattrOperations *passthrough_xattr_ops[];
42 extern XattrOperations *none_xattr_ops[];
43
44 ssize_t v9fs_get_xattr(FsContext *ctx, const char *path, const char *name,
45                        void *value, size_t size);
46 ssize_t v9fs_list_xattr(FsContext *ctx, const char *path, void *value,
47                         size_t vsize);
48 int v9fs_set_xattr(FsContext *ctx, const char *path, const char *name,
49                           void *value, size_t size, int flags);
50 int v9fs_remove_xattr(FsContext *ctx, const char *path, const char *name);
51 ssize_t pt_listxattr(FsContext *ctx, const char *path, char *name, void *value,
52                      size_t size);
53
54 static inline ssize_t pt_getxattr(FsContext *ctx, const char *path,
55                                   const char *name, void *value, size_t size)
56 {
57 #ifdef CONFIG_MARU
58 #ifndef CONFIG_WIN32
59     char buffer[PATH_MAX];
60 #ifdef CONFIG_LINUX
61     return lgetxattr(rpath(ctx, path, buffer), name, value, size);
62 #else
63     return getxattr(rpath(ctx, path, buffer), name, value, size, 0, XATTR_NOFOLLOW);
64 #endif
65 #else
66     return 0;
67 #endif
68 #else
69     char buffer[PATH_MAX];
70     return lgetxattr(rpath(ctx, path, buffer), name, value, size);
71 #endif
72 }
73
74 static inline int pt_setxattr(FsContext *ctx, const char *path,
75                               const char *name, void *value,
76                               size_t size, int flags)
77 {
78 #ifdef CONFIG_MARU
79 #ifndef CONFIG_WIN32
80     char buffer[PATH_MAX];
81 #ifdef CONFIG_LINUX
82     return lsetxattr(rpath(ctx, path, buffer), name, value, size, flags);
83 #else
84     return setxattr(rpath(ctx, path, buffer), name, value, size, 0, flags | XATTR_NOFOLLOW);
85 #endif
86 #else
87     return 0;
88 #endif
89 #else
90     char buffer[PATH_MAX];
91     return lsetxattr(rpath(ctx, path, buffer), name, value, size, flags);
92 #endif
93 }
94
95 static inline int pt_removexattr(FsContext *ctx,
96                                  const char *path, const char *name)
97 {
98 #ifdef CONFIG_MARU
99 #ifndef CONFIG_WIN32
100     char buffer[PATH_MAX];
101 #ifdef CONFIG_LINUX
102     return lremovexattr(rpath(ctx, path, buffer), name);
103 #else
104     return removexattr(rpath(ctx, path, buffer), name, XATTR_NOFOLLOW);
105 #endif
106 #else
107     return 0;
108 #endif
109 #else
110     char buffer[PATH_MAX];
111     return lremovexattr(rpath(ctx, path, buffer), name);
112 #endif
113 }
114
115 static inline ssize_t notsup_getxattr(FsContext *ctx, const char *path,
116                                       const char *name, void *value,
117                                       size_t size)
118 {
119     errno = ENOTSUP;
120     return -1;
121 }
122
123 static inline int notsup_setxattr(FsContext *ctx, const char *path,
124                                   const char *name, void *value,
125                                   size_t size, int flags)
126 {
127     errno = ENOTSUP;
128     return -1;
129 }
130
131 static inline ssize_t notsup_listxattr(FsContext *ctx, const char *path,
132                                        char *name, void *value, size_t size)
133 {
134     return 0;
135 }
136
137 static inline int notsup_removexattr(FsContext *ctx,
138                                      const char *path, const char *name)
139 {
140     errno = ENOTSUP;
141     return -1;
142 }
143
144 #endif