Sync usage with man page.
[netbsd-mini2440.git] / sys / rump / librump / rumpvfs / compat.c
blobf181d593508e9c94f699d42624b9e2d8c74556e8
1 /* $NetBSD: compat.c,v 1.4 2009/10/14 17:29:20 pooka Exp $ */
3 /*
4 * Copyright (c) 2009 Antti Kantee. All Rights Reserved.
6 * Development of this software was supported by the Nokia Foundation
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: compat.c,v 1.4 2009/10/14 17:29:20 pooka Exp $");
33 #include <sys/param.h>
34 #include <sys/kmem.h>
35 #include <sys/sched.h>
36 #include <sys/syscallargs.h>
37 #include <sys/vnode.h>
39 #include <compat/sys/time.h>
41 #include <rump/rump.h>
42 #include <rump/rumpuser.h>
44 #include "rump_vfs_private.h"
47 * XXX: these are handwritten for now. They provide compat for
48 * calling post-time_t file systems from a pre-time_t userland.
49 * (mknod is missing. I don't care very much)
51 * Doing remote system calls with these does not (obviously) work.
53 #if BYTE_ORDER == BIG_ENDIAN
54 #define SPARG(p,k) ((p)->k.be.datum)
55 #else /* LITTLE_ENDIAN, I hope dearly */
56 #define SPARG(p,k) ((p)->k.le.datum)
57 #endif
59 struct vattr50 {
60 enum vtype va_type; /* vnode type (for create) */
61 mode_t va_mode; /* files access mode and type */
62 nlink_t va_nlink; /* number of references to file */
63 uid_t va_uid; /* owner user id */
64 gid_t va_gid; /* owner group id */
65 u_long va_fsid; /* file system id (dev for now) */
66 ino_t va_fileid; /* file id */
67 u_quad_t va_size; /* file size in bytes */
68 long va_blocksize; /* blocksize preferred for i/o */
69 struct timespec50 va_atime; /* time of last access */
70 struct timespec50 va_mtime; /* time of last modification */
71 struct timespec50 va_ctime; /* time file changed */
72 struct timespec50 va_birthtime; /* time file created */
73 u_long va_gen; /* generation number of file */
74 u_long va_flags; /* flags defined for file */
75 uint32_t va_rdev; /* device the special file represents */
76 u_quad_t va_bytes; /* bytes of disk space held by file */
77 u_quad_t va_filerev; /* file modification number */
78 u_int va_vaflags; /* operations flags, see below */
79 long va_spare; /* remain quad aligned */
82 int
83 rump_sys___stat30(const char *path, struct stat *sb)
85 struct compat_50_sys___stat30_args args;
86 register_t retval = 0;
87 int error = 0;
89 SPARG(&args, path) = path;
90 SPARG(&args, ub) = (struct stat30 *)sb;
92 error = compat_50_sys___stat30(curlwp, &args, &retval);
93 if (error) {
94 retval = -1;
95 rumpuser_seterrno(error);
97 return retval;
101 rump_sys___lstat30(const char *path, struct stat *sb)
103 struct compat_50_sys___lstat30_args args;
104 register_t retval = 0;
105 int error = 0;
107 SPARG(&args, path) = path;
108 SPARG(&args, ub) = (struct stat30 *)sb;
110 error = compat_50_sys___lstat30(curlwp, &args, &retval);
111 if (error) {
112 retval = -1;
113 rumpuser_seterrno(error);
115 return retval;
119 * XXX: types. But I don't want to start playing compat games in
120 * the userspace namespace too
122 void
123 rump_vattr50_to_vattr(const struct vattr *_va50, struct vattr *va)
125 const struct vattr50 *va50 = (const struct vattr50 *)_va50;
127 va->va_type = va50->va_type;
128 va->va_mode = va50->va_mode;
129 va->va_nlink = va50->va_nlink;
130 va->va_uid = va50->va_uid;
131 va->va_gid = va50->va_gid;
132 va->va_fsid = (long)va50->va_fsid;
133 va->va_fileid = va50->va_fileid;
134 va->va_size = va50->va_size;
135 va->va_blocksize = va50->va_blocksize;
136 timespec50_to_timespec(&va50->va_atime, &va->va_atime);
137 timespec50_to_timespec(&va50->va_ctime, &va->va_ctime);
138 timespec50_to_timespec(&va50->va_mtime, &va->va_mtime);
139 timespec50_to_timespec(&va50->va_birthtime, &va->va_birthtime);
140 va->va_gen = va50->va_gen;
141 va->va_flags = va50->va_flags;
142 va->va_rdev = (int32_t)va50->va_rdev;
143 va->va_bytes = va50->va_bytes;
144 va->va_filerev = va50->va_filerev;
145 va->va_vaflags = va50->va_flags;
148 void
149 rump_vattr_to_vattr50(const struct vattr *va, struct vattr *_va50)
151 struct vattr50 *va50 = (struct vattr50 *)_va50;
153 va50->va_type = va->va_type;
154 va50->va_mode = va->va_mode;
155 va50->va_nlink = va->va_nlink;
156 va50->va_uid = va->va_uid;
157 va50->va_gid = va->va_gid;
158 va50->va_fsid = (u_long)va->va_fsid;
159 va50->va_fileid = va->va_fileid;
160 va50->va_size = va->va_size;
161 va50->va_blocksize = va->va_blocksize;
162 timespec_to_timespec50(&va->va_atime, &va50->va_atime);
163 timespec_to_timespec50(&va->va_ctime, &va50->va_ctime);
164 timespec_to_timespec50(&va->va_mtime, &va50->va_mtime);
165 timespec_to_timespec50(&va->va_birthtime, &va50->va_birthtime);
166 va50->va_gen = va->va_gen;
167 va50->va_flags = va->va_flags;
168 va50->va_rdev = (uint32_t)va->va_rdev;
169 va50->va_bytes = va->va_bytes;
170 va50->va_filerev = va->va_filerev;
171 va50->va_vaflags = va->va_flags;