Deleted Added
full compact
cloudabi_file.c (285596) cloudabi_file.c (285834)
1/*-
2 * Copyright (c) 2015 Nuxi, https://nuxi.nl/
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 10 unchanged lines hidden (view full) ---

19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2015 Nuxi, https://nuxi.nl/
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 10 unchanged lines hidden (view full) ---

19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26#include <sys/cdefs.h>
27__FBSDID("$FreeBSD: head/sys/compat/cloudabi/cloudabi_file.c 285596 2015-07-15 09:14:06Z ed $");
27__FBSDID("$FreeBSD: head/sys/compat/cloudabi/cloudabi_file.c 285834 2015-07-24 07:46:02Z ed $");
28
29#include <sys/param.h>
30#include <sys/fcntl.h>
28
29#include <sys/param.h>
30#include <sys/fcntl.h>
31#include <sys/kernel.h>
32#include <sys/malloc.h>
33#include <sys/namei.h>
31#include <sys/syscallsubr.h>
32
33#include <compat/cloudabi/cloudabi_proto.h>
34#include <compat/cloudabi/cloudabi_syscalldefs.h>
35
34#include <sys/syscallsubr.h>
35
36#include <compat/cloudabi/cloudabi_proto.h>
37#include <compat/cloudabi/cloudabi_syscalldefs.h>
38
39static MALLOC_DEFINE(M_CLOUDABI_PATH, "cloudabipath", "CloudABI pathnames");
40
41/*
42 * Copying pathnames from userspace to kernelspace.
43 *
44 * Unlike most operating systems, CloudABI doesn't use null-terminated
45 * pathname strings. Processes always pass pathnames to the kernel by
46 * providing a base pointer and a length. This has a couple of reasons:
47 *
48 * - It makes it easier to use CloudABI in combination with programming
49 * languages other than C, that may use non-null terminated strings.
50 * - It allows for calling system calls on individual components of the
51 * pathname without modifying the input string.
52 *
53 * The function below copies in pathname strings and null-terminates it.
54 * It also ensure that the string itself does not contain any null
55 * bytes.
56 *
57 * TODO(ed): Add an abstraction to vfs_lookup.c that allows us to pass
58 * in unterminated pathname strings, so we can do away with
59 * the copying.
60 */
61
62static int
63copyin_path(const char *uaddr, size_t len, char **result)
64{
65 char *buf;
66 int error;
67
68 if (len >= PATH_MAX)
69 return (ENAMETOOLONG);
70 buf = malloc(len + 1, M_CLOUDABI_PATH, M_WAITOK);
71 error = copyin(uaddr, buf, len);
72 if (error != 0) {
73 free(buf, M_CLOUDABI_PATH);
74 return (error);
75 }
76 if (memchr(buf, '\0', len) != NULL) {
77 free(buf, M_CLOUDABI_PATH);
78 return (EINVAL);
79 }
80 buf[len] = '\0';
81 *result = buf;
82 return (0);
83}
84
85static void
86cloudabi_freestr(char *buf)
87{
88
89 free(buf, M_CLOUDABI_PATH);
90}
91
36int
37cloudabi_sys_file_advise(struct thread *td,
38 struct cloudabi_sys_file_advise_args *uap)
39{
40 int advice;
41
42 switch (uap->advice) {
43 case CLOUDABI_ADVICE_DONTNEED:

--- 37 unchanged lines hidden (view full) ---

81 /* Not implemented. */
82 return (ENOSYS);
83}
84
85int
86cloudabi_sys_file_link(struct thread *td,
87 struct cloudabi_sys_file_link_args *uap)
88{
92int
93cloudabi_sys_file_advise(struct thread *td,
94 struct cloudabi_sys_file_advise_args *uap)
95{
96 int advice;
97
98 switch (uap->advice) {
99 case CLOUDABI_ADVICE_DONTNEED:

--- 37 unchanged lines hidden (view full) ---

137 /* Not implemented. */
138 return (ENOSYS);
139}
140
141int
142cloudabi_sys_file_link(struct thread *td,
143 struct cloudabi_sys_file_link_args *uap)
144{
145 char *path1, *path2;
146 int error;
89
147
90 /* Not implemented. */
91 return (ENOSYS);
148 error = copyin_path(uap->path1, uap->path1len, &path1);
149 if (error != 0)
150 return (error);
151 error = copyin_path(uap->path2, uap->path2len, &path2);
152 if (error != 0) {
153 cloudabi_freestr(path1);
154 return (error);
155 }
156
157 error = kern_linkat(td, uap->fd1, uap->fd2, path1, path2,
158 UIO_SYSSPACE, (uap->fd1 & CLOUDABI_LOOKUP_SYMLINK_FOLLOW) != 0 ?
159 FOLLOW : NOFOLLOW);
160 cloudabi_freestr(path1);
161 cloudabi_freestr(path2);
162 return (error);
92}
93
94int
95cloudabi_sys_file_open(struct thread *td,
96 struct cloudabi_sys_file_open_args *uap)
97{
98
99 /* Not implemented. */

--- 8 unchanged lines hidden (view full) ---

108 /* Not implemented. */
109 return (ENOSYS);
110}
111
112int
113cloudabi_sys_file_readlink(struct thread *td,
114 struct cloudabi_sys_file_readlink_args *uap)
115{
163}
164
165int
166cloudabi_sys_file_open(struct thread *td,
167 struct cloudabi_sys_file_open_args *uap)
168{
169
170 /* Not implemented. */

--- 8 unchanged lines hidden (view full) ---

179 /* Not implemented. */
180 return (ENOSYS);
181}
182
183int
184cloudabi_sys_file_readlink(struct thread *td,
185 struct cloudabi_sys_file_readlink_args *uap)
186{
187 char *path;
188 int error;
116
189
117 /* Not implemented. */
118 return (ENOSYS);
190 error = copyin_path(uap->path, uap->pathlen, &path);
191 if (error != 0)
192 return (error);
193
194 error = kern_readlinkat(td, uap->fd, path, UIO_SYSSPACE,
195 uap->buf, UIO_USERSPACE, uap->bufsize);
196 cloudabi_freestr(path);
197 return (error);
119}
120
121int
122cloudabi_sys_file_rename(struct thread *td,
123 struct cloudabi_sys_file_rename_args *uap)
124{
198}
199
200int
201cloudabi_sys_file_rename(struct thread *td,
202 struct cloudabi_sys_file_rename_args *uap)
203{
204 char *old, *new;
205 int error;
125
206
126 /* Not implemented. */
127 return (ENOSYS);
207 error = copyin_path(uap->old, uap->oldlen, &old);
208 if (error != 0)
209 return (error);
210 error = copyin_path(uap->new, uap->newlen, &new);
211 if (error != 0) {
212 cloudabi_freestr(old);
213 return (error);
214 }
215
216 error = kern_renameat(td, uap->oldfd, old, uap->newfd, new,
217 UIO_SYSSPACE);
218 cloudabi_freestr(old);
219 cloudabi_freestr(new);
220 return (error);
128}
129
130int
131cloudabi_sys_file_stat_fget(struct thread *td,
132 struct cloudabi_sys_file_stat_fget_args *uap)
133{
134
135 /* Not implemented. */

--- 26 unchanged lines hidden (view full) ---

162 /* Not implemented. */
163 return (ENOSYS);
164}
165
166int
167cloudabi_sys_file_symlink(struct thread *td,
168 struct cloudabi_sys_file_symlink_args *uap)
169{
221}
222
223int
224cloudabi_sys_file_stat_fget(struct thread *td,
225 struct cloudabi_sys_file_stat_fget_args *uap)
226{
227
228 /* Not implemented. */

--- 26 unchanged lines hidden (view full) ---

255 /* Not implemented. */
256 return (ENOSYS);
257}
258
259int
260cloudabi_sys_file_symlink(struct thread *td,
261 struct cloudabi_sys_file_symlink_args *uap)
262{
263 char *path1, *path2;
264 int error;
170
265
171 /* Not implemented. */
172 return (ENOSYS);
266 error = copyin_path(uap->path1, uap->path1len, &path1);
267 if (error != 0)
268 return (error);
269 error = copyin_path(uap->path2, uap->path2len, &path2);
270 if (error != 0) {
271 cloudabi_freestr(path1);
272 return (error);
273 }
274
275 error = kern_symlinkat(td, path1, uap->fd, path2, UIO_SYSSPACE);
276 cloudabi_freestr(path1);
277 cloudabi_freestr(path2);
278 return (error);
173}
174
175int
176cloudabi_sys_file_unlink(struct thread *td,
177 struct cloudabi_sys_file_unlink_args *uap)
178{
279}
280
281int
282cloudabi_sys_file_unlink(struct thread *td,
283 struct cloudabi_sys_file_unlink_args *uap)
284{
285 char *path;
286 int error;
179
287
180 /* Not implemented. */
181 return (ENOSYS);
288 error = copyin_path(uap->path, uap->pathlen, &path);
289 if (error != 0)
290 return (error);
291
292 if (uap->flag & CLOUDABI_UNLINK_REMOVEDIR)
293 error = kern_rmdirat(td, uap->fd, path, UIO_SYSSPACE);
294 else
295 error = kern_unlinkat(td, uap->fd, path, UIO_SYSSPACE, 0);
296 cloudabi_freestr(path);
297 return (error);
182}
298}