cloudabi_file.c revision 285596
1285307Sed/*-
2285307Sed * Copyright (c) 2015 Nuxi, https://nuxi.nl/
3285307Sed *
4285307Sed * Redistribution and use in source and binary forms, with or without
5285307Sed * modification, are permitted provided that the following conditions
6285307Sed * are met:
7285307Sed * 1. Redistributions of source code must retain the above copyright
8285307Sed *    notice, this list of conditions and the following disclaimer.
9285307Sed * 2. Redistributions in binary form must reproduce the above copyright
10285307Sed *    notice, this list of conditions and the following disclaimer in the
11285307Sed *    documentation and/or other materials provided with the distribution.
12285307Sed *
13285307Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14285307Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15285307Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16285307Sed * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17285307Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18285307Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19285307Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20285307Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21285307Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22285307Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23285307Sed * SUCH DAMAGE.
24285307Sed */
25285307Sed
26285307Sed#include <sys/cdefs.h>
27285307Sed__FBSDID("$FreeBSD: head/sys/compat/cloudabi/cloudabi_file.c 285596 2015-07-15 09:14:06Z ed $");
28285307Sed
29285596Sed#include <sys/param.h>
30285596Sed#include <sys/fcntl.h>
31285596Sed#include <sys/syscallsubr.h>
32285596Sed
33285307Sed#include <compat/cloudabi/cloudabi_proto.h>
34285596Sed#include <compat/cloudabi/cloudabi_syscalldefs.h>
35285307Sed
36285307Sedint
37285307Sedcloudabi_sys_file_advise(struct thread *td,
38285307Sed    struct cloudabi_sys_file_advise_args *uap)
39285307Sed{
40285596Sed	int advice;
41285307Sed
42285596Sed	switch (uap->advice) {
43285596Sed	case CLOUDABI_ADVICE_DONTNEED:
44285596Sed		advice = POSIX_FADV_DONTNEED;
45285596Sed		break;
46285596Sed	case CLOUDABI_ADVICE_NOREUSE:
47285596Sed		advice = POSIX_FADV_NOREUSE;
48285596Sed		break;
49285596Sed	case CLOUDABI_ADVICE_NORMAL:
50285596Sed		advice = POSIX_FADV_NORMAL;
51285596Sed		break;
52285596Sed	case CLOUDABI_ADVICE_RANDOM:
53285596Sed		advice = POSIX_FADV_RANDOM;
54285596Sed		break;
55285596Sed	case CLOUDABI_ADVICE_SEQUENTIAL:
56285596Sed		advice = POSIX_FADV_SEQUENTIAL;
57285596Sed		break;
58285596Sed	case CLOUDABI_ADVICE_WILLNEED:
59285596Sed		advice = POSIX_FADV_WILLNEED;
60285596Sed		break;
61285596Sed	default:
62285596Sed		return (EINVAL);
63285596Sed	}
64285596Sed
65285596Sed	return (kern_posix_fadvise(td, uap->fd, uap->offset, uap->len, advice));
66285307Sed}
67285307Sed
68285307Sedint
69285307Sedcloudabi_sys_file_allocate(struct thread *td,
70285307Sed    struct cloudabi_sys_file_allocate_args *uap)
71285307Sed{
72285307Sed
73285596Sed	return (kern_posix_fallocate(td, uap->fd, uap->offset, uap->len));
74285307Sed}
75285307Sed
76285307Sedint
77285307Sedcloudabi_sys_file_create(struct thread *td,
78285307Sed    struct cloudabi_sys_file_create_args *uap)
79285307Sed{
80285307Sed
81285307Sed	/* Not implemented. */
82285307Sed	return (ENOSYS);
83285307Sed}
84285307Sed
85285307Sedint
86285307Sedcloudabi_sys_file_link(struct thread *td,
87285307Sed    struct cloudabi_sys_file_link_args *uap)
88285307Sed{
89285307Sed
90285307Sed	/* Not implemented. */
91285307Sed	return (ENOSYS);
92285307Sed}
93285307Sed
94285307Sedint
95285307Sedcloudabi_sys_file_open(struct thread *td,
96285307Sed    struct cloudabi_sys_file_open_args *uap)
97285307Sed{
98285307Sed
99285307Sed	/* Not implemented. */
100285307Sed	return (ENOSYS);
101285307Sed}
102285307Sed
103285307Sedint
104285307Sedcloudabi_sys_file_readdir(struct thread *td,
105285307Sed    struct cloudabi_sys_file_readdir_args *uap)
106285307Sed{
107285307Sed
108285307Sed	/* Not implemented. */
109285307Sed	return (ENOSYS);
110285307Sed}
111285307Sed
112285307Sedint
113285307Sedcloudabi_sys_file_readlink(struct thread *td,
114285307Sed    struct cloudabi_sys_file_readlink_args *uap)
115285307Sed{
116285307Sed
117285307Sed	/* Not implemented. */
118285307Sed	return (ENOSYS);
119285307Sed}
120285307Sed
121285307Sedint
122285307Sedcloudabi_sys_file_rename(struct thread *td,
123285307Sed    struct cloudabi_sys_file_rename_args *uap)
124285307Sed{
125285307Sed
126285307Sed	/* Not implemented. */
127285307Sed	return (ENOSYS);
128285307Sed}
129285307Sed
130285307Sedint
131285307Sedcloudabi_sys_file_stat_fget(struct thread *td,
132285307Sed    struct cloudabi_sys_file_stat_fget_args *uap)
133285307Sed{
134285307Sed
135285307Sed	/* Not implemented. */
136285307Sed	return (ENOSYS);
137285307Sed}
138285307Sed
139285307Sedint
140285307Sedcloudabi_sys_file_stat_fput(struct thread *td,
141285307Sed    struct cloudabi_sys_file_stat_fput_args *uap)
142285307Sed{
143285307Sed
144285307Sed	/* Not implemented. */
145285307Sed	return (ENOSYS);
146285307Sed}
147285307Sed
148285307Sedint
149285307Sedcloudabi_sys_file_stat_get(struct thread *td,
150285307Sed    struct cloudabi_sys_file_stat_get_args *uap)
151285307Sed{
152285307Sed
153285307Sed	/* Not implemented. */
154285307Sed	return (ENOSYS);
155285307Sed}
156285307Sed
157285307Sedint
158285307Sedcloudabi_sys_file_stat_put(struct thread *td,
159285307Sed    struct cloudabi_sys_file_stat_put_args *uap)
160285307Sed{
161285307Sed
162285307Sed	/* Not implemented. */
163285307Sed	return (ENOSYS);
164285307Sed}
165285307Sed
166285307Sedint
167285307Sedcloudabi_sys_file_symlink(struct thread *td,
168285307Sed    struct cloudabi_sys_file_symlink_args *uap)
169285307Sed{
170285307Sed
171285307Sed	/* Not implemented. */
172285307Sed	return (ENOSYS);
173285307Sed}
174285307Sed
175285307Sedint
176285307Sedcloudabi_sys_file_unlink(struct thread *td,
177285307Sed    struct cloudabi_sys_file_unlink_args *uap)
178285307Sed{
179285307Sed
180285307Sed	/* Not implemented. */
181285307Sed	return (ENOSYS);
182285307Sed}
183