]>
Commit | Line | Data |
---|---|---|
86e42d74 VJ |
1 | |
2 | /* | |
3 | * Virtio 9p backend | |
4 | * | |
5 | * Copyright IBM, Corp. 2011 | |
6 | * | |
7 | * Authors: | |
8 | * Aneesh Kumar K.V <[email protected]> | |
9 | * | |
10 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
11 | * the COPYING file in the top-level directory. | |
12 | * | |
13 | */ | |
14 | ||
15 | #include "fsdev/qemu-fsdev.h" | |
16 | #include "qemu-thread.h" | |
17 | #include "qemu-coroutine.h" | |
18 | #include "virtio-9p-coth.h" | |
19 | ||
20 | int v9fs_co_readlink(V9fsState *s, V9fsString *path, V9fsString *buf) | |
21 | { | |
22 | int err; | |
23 | ssize_t len; | |
24 | ||
7267c094 | 25 | buf->data = g_malloc(PATH_MAX); |
86e42d74 VJ |
26 | v9fs_co_run_in_worker( |
27 | { | |
28 | len = s->ops->readlink(&s->ctx, path->data, | |
29 | buf->data, PATH_MAX - 1); | |
30 | if (len > -1) { | |
31 | buf->size = len; | |
32 | buf->data[len] = 0; | |
33 | err = 0; | |
34 | } else { | |
35 | err = -errno; | |
36 | } | |
37 | }); | |
38 | if (err) { | |
7267c094 | 39 | g_free(buf->data); |
86e42d74 VJ |
40 | buf->data = NULL; |
41 | buf->size = 0; | |
42 | } | |
43 | return err; | |
44 | } | |
94840ff9 AK |
45 | |
46 | int v9fs_co_statfs(V9fsState *s, V9fsString *path, struct statfs *stbuf) | |
47 | { | |
48 | int err; | |
49 | ||
50 | v9fs_co_run_in_worker( | |
51 | { | |
52 | err = s->ops->statfs(&s->ctx, path->data, stbuf); | |
53 | if (err < 0) { | |
54 | err = -errno; | |
55 | } | |
56 | }); | |
57 | return err; | |
58 | } | |
4011ead2 AK |
59 | |
60 | int v9fs_co_chmod(V9fsState *s, V9fsString *path, mode_t mode) | |
61 | { | |
62 | int err; | |
63 | FsCred cred; | |
64 | ||
65 | cred_init(&cred); | |
66 | cred.fc_mode = mode; | |
67 | v9fs_co_run_in_worker( | |
68 | { | |
69 | err = s->ops->chmod(&s->ctx, path->data, &cred); | |
70 | if (err < 0) { | |
71 | err = -errno; | |
72 | } | |
73 | }); | |
74 | return err; | |
75 | } | |
76 | ||
77 | int v9fs_co_utimensat(V9fsState *s, V9fsString *path, | |
78 | struct timespec times[2]) | |
79 | { | |
80 | int err; | |
81 | ||
82 | v9fs_co_run_in_worker( | |
83 | { | |
84 | err = s->ops->utimensat(&s->ctx, path->data, times); | |
85 | if (err < 0) { | |
86 | err = -errno; | |
87 | } | |
88 | }); | |
89 | return err; | |
90 | } | |
91 | ||
92 | int v9fs_co_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t gid) | |
93 | { | |
94 | int err; | |
95 | FsCred cred; | |
96 | ||
97 | cred_init(&cred); | |
98 | cred.fc_uid = uid; | |
99 | cred.fc_gid = gid; | |
100 | v9fs_co_run_in_worker( | |
101 | { | |
102 | err = s->ops->chown(&s->ctx, path->data, &cred); | |
103 | if (err < 0) { | |
104 | err = -errno; | |
105 | } | |
106 | }); | |
107 | return err; | |
108 | } | |
109 | ||
110 | int v9fs_co_truncate(V9fsState *s, V9fsString *path, off_t size) | |
111 | { | |
112 | int err; | |
113 | ||
114 | v9fs_co_run_in_worker( | |
115 | { | |
116 | err = s->ops->truncate(&s->ctx, path->data, size); | |
117 | if (err < 0) { | |
118 | err = -errno; | |
119 | } | |
120 | }); | |
121 | return err; | |
122 | } | |
00ace8c5 AK |
123 | |
124 | int v9fs_co_mknod(V9fsState *s, V9fsString *path, uid_t uid, | |
125 | gid_t gid, dev_t dev, mode_t mode) | |
126 | { | |
127 | int err; | |
128 | FsCred cred; | |
129 | ||
130 | cred_init(&cred); | |
131 | cred.fc_uid = uid; | |
132 | cred.fc_gid = gid; | |
133 | cred.fc_mode = mode; | |
134 | cred.fc_rdev = dev; | |
135 | v9fs_co_run_in_worker( | |
136 | { | |
137 | err = s->ops->mknod(&s->ctx, path->data, &cred); | |
138 | if (err < 0) { | |
139 | err = -errno; | |
140 | } | |
141 | }); | |
142 | return err; | |
143 | } | |
b4b1537b VJ |
144 | |
145 | int v9fs_co_remove(V9fsState *s, V9fsString *path) | |
146 | { | |
147 | int err; | |
148 | ||
149 | v9fs_co_run_in_worker( | |
150 | { | |
151 | err = s->ops->remove(&s->ctx, path->data); | |
152 | if (err < 0) { | |
153 | err = -errno; | |
154 | } | |
155 | }); | |
156 | return err; | |
157 | } | |
2a487e05 AK |
158 | |
159 | int v9fs_co_rename(V9fsState *s, V9fsString *oldpath, V9fsString *newpath) | |
160 | { | |
161 | int err; | |
162 | ||
163 | v9fs_co_run_in_worker( | |
164 | { | |
165 | err = s->ops->rename(&s->ctx, oldpath->data, newpath->data); | |
166 | if (err < 0) { | |
167 | err = -errno; | |
168 | } | |
169 | }); | |
170 | return err; | |
171 | } | |
02ac7a34 VJ |
172 | |
173 | int v9fs_co_symlink(V9fsState *s, V9fsFidState *fidp, | |
174 | const char *oldpath, const char *newpath, gid_t gid) | |
175 | { | |
176 | int err; | |
177 | FsCred cred; | |
178 | ||
179 | cred_init(&cred); | |
180 | cred.fc_uid = fidp->uid; | |
181 | cred.fc_gid = gid; | |
182 | cred.fc_mode = 0777; | |
183 | v9fs_co_run_in_worker( | |
184 | { | |
185 | err = s->ops->symlink(&s->ctx, oldpath, newpath, &cred); | |
186 | if (err < 0) { | |
187 | err = -errno; | |
188 | } | |
189 | }); | |
190 | return err; | |
191 | } |