2 * Copyright (c) 2015 Nuxi, https://nuxi.nl/
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
29 #include <sys/param.h>
30 #include <sys/filedesc.h>
32 #include <sys/syscallsubr.h>
33 #include <sys/sysproto.h>
34 #include <sys/unistd.h>
36 #include <compat/cloudabi/cloudabi_proto.h>
39 cloudabi_sys_fd_close(struct thread *td, struct cloudabi_sys_fd_close_args *uap)
42 return (kern_close(td, uap->fd));
46 cloudabi_sys_fd_create1(struct thread *td,
47 struct cloudabi_sys_fd_create1_args *uap)
50 /* Not implemented. */
55 cloudabi_sys_fd_create2(struct thread *td,
56 struct cloudabi_sys_fd_create2_args *uap)
59 /* Not implemented. */
64 cloudabi_sys_fd_datasync(struct thread *td,
65 struct cloudabi_sys_fd_datasync_args *uap)
67 struct fsync_args fsync_args = {
71 /* Call into fsync(), as FreeBSD lacks fdatasync(). */
72 return (sys_fsync(td, &fsync_args));
76 cloudabi_sys_fd_dup(struct thread *td, struct cloudabi_sys_fd_dup_args *uap)
79 return (kern_dup(td, FDDUP_NORMAL, 0, uap->from, 0));
83 cloudabi_sys_fd_replace(struct thread *td,
84 struct cloudabi_sys_fd_replace_args *uap)
89 * CloudABI's equivalent to dup2(). CloudABI processes should
90 * not depend on hardcoded file descriptor layouts, but simply
91 * use the file descriptor numbers that are allocated by the
92 * kernel. Duplicating file descriptors to arbitrary numbers
95 * Invoke kern_dup() with FDDUP_MUSTREPLACE, so that we return
96 * EBADF when duplicating to a nonexistent file descriptor. Also
97 * clear the return value, as this system call yields no return
100 error = kern_dup(td, FDDUP_MUSTREPLACE, 0, uap->from, uap->to);
101 td->td_retval[0] = 0;
106 cloudabi_sys_fd_seek(struct thread *td, struct cloudabi_sys_fd_seek_args *uap)
108 struct lseek_args lseek_args = {
110 .offset = uap->offset
113 switch (uap->whence) {
114 case CLOUDABI_WHENCE_CUR:
115 lseek_args.whence = SEEK_CUR;
117 case CLOUDABI_WHENCE_END:
118 lseek_args.whence = SEEK_END;
120 case CLOUDABI_WHENCE_SET:
121 lseek_args.whence = SEEK_SET;
127 return (sys_lseek(td, &lseek_args));
131 cloudabi_sys_fd_stat_get(struct thread *td,
132 struct cloudabi_sys_fd_stat_get_args *uap)
135 /* Not implemented. */
140 cloudabi_sys_fd_stat_put(struct thread *td,
141 struct cloudabi_sys_fd_stat_put_args *uap)
144 /* Not implemented. */
149 cloudabi_sys_fd_sync(struct thread *td, struct cloudabi_sys_fd_sync_args *uap)
151 struct fsync_args fsync_args = {
155 return (sys_fsync(td, &fsync_args));