linux32_stat.c revision 1.1.10.2 1 /* $NetBSD: linux32_stat.c,v 1.1.10.2 2006/04/22 11:38:14 simonb Exp $ */
2
3 /*-
4 * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Emmanuel Dreyfus
17 * 4. The name of the author may not be used to endorse or promote
18 * products derived from this software without specific prior written
19 * permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE THE AUTHOR AND CONTRIBUTORS ``AS IS''
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/cdefs.h>
35
36 __KERNEL_RCSID(0, "$NetBSD: linux32_stat.c,v 1.1.10.2 2006/04/22 11:38:14 simonb Exp $");
37
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/fstypes.h>
41 #include <sys/signal.h>
42 #include <sys/dirent.h>
43 #include <sys/kernel.h>
44 #include <sys/fcntl.h>
45 #include <sys/select.h>
46 #include <sys/sa.h>
47 #include <sys/proc.h>
48 #include <sys/ucred.h>
49 #include <sys/swap.h>
50
51 #include <machine/types.h>
52
53 #include <sys/syscallargs.h>
54
55 #include <compat/netbsd32/netbsd32.h>
56 #include <compat/netbsd32/netbsd32_conv.h>
57 #include <compat/netbsd32/netbsd32_syscallargs.h>
58
59 #include <compat/linux/common/linux_types.h>
60 #include <compat/linux/common/linux_signal.h>
61 #include <compat/linux/common/linux_machdep.h>
62 #include <compat/linux/common/linux_misc.h>
63 #include <compat/linux/common/linux_oldolduname.h>
64 #include <compat/linux/linux_syscallargs.h>
65
66 #include <compat/linux32/common/linux32_types.h>
67 #include <compat/linux32/common/linux32_signal.h>
68 #include <compat/linux32/common/linux32_machdep.h>
69 #include <compat/linux32/common/linux32_sysctl.h>
70 #include <compat/linux32/common/linux32_socketcall.h>
71 #include <compat/linux32/linux32_syscallargs.h>
72
73 static inline void linux32_from_stat(struct stat *, struct linux32_stat64 *);
74
75 #define linux_fakedev(x,y) (x)
76 static inline void
77 linux32_from_stat(st, st32)
78 struct stat *st;
79 struct linux32_stat64 *st32;
80 {
81 bzero(st32, sizeof(*st32));
82 st32->lst_dev = linux_fakedev(st->st_dev, 0);
83 st32->__lst_ino = st->st_ino;
84 st32->lst_mode = st->st_mode;
85 if (st->st_nlink >= (1 << 15))
86 st32->lst_nlink = (1 << 15) - 1;
87 else
88 st32->lst_nlink = st->st_nlink;
89 st32->lst_uid = st->st_uid;
90 st32->lst_gid = st->st_gid;
91 st32->lst_rdev = linux_fakedev(st->st_rdev, 0);
92 st32->lst_size = st->st_size;
93 st32->lst_blksize = st->st_blksize;
94 st32->lst_blocks = st->st_blocks;
95 st32->lst_atime = st->st_atime;
96 st32->lst_mtime = st->st_mtime;
97 st32->lst_ctime = st->st_ctime;
98 #ifdef LINUX32_STAT64_HAS_NSEC
99 st32->lst_atime_nsec = st->st_atimensec;
100 st32->lst_mtime_nsec = st->st_mtimensec;
101 st32->lst_ctime_nsec = st->st_ctimensec;
102 #endif
103 #ifdef LINUX32_STAT64_HAS_BROKEN_ST_INO
104 st32->lst_ino = st->st_ino;
105 #endif
106
107 return;
108 }
109
110 int
111 linux32_sys_stat64(l, v, retval)
112 struct lwp *l;
113 void *v;
114 register_t *retval;
115 {
116 struct linux32_sys_stat64_args /* {
117 syscallarg(netbsd32_charp) path;
118 syscallarg(linux32_statp) sp;
119 } */ *uap = v;
120 struct sys___stat30_args ua;
121 caddr_t sg = stackgap_init(l->l_proc, 0);
122 int error;
123 struct stat st;
124 struct linux32_stat64 st32;
125 struct stat *stp;
126 struct linux32_stat64 *st32p;
127
128 NETBSD32TOP_UAP(path, const char);
129
130 CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));
131
132 stp = stackgap_alloc(l->l_proc, &sg, sizeof(*stp));
133 SCARG(&ua, ub) = stp;
134
135 if ((error = sys___stat30(l, &ua, retval)) != 0)
136 return error;
137
138 if ((error = copyin(stp, &st, sizeof(st))) != 0)
139 return error;
140
141 linux32_from_stat(&st, &st32);
142
143 st32p = (struct linux32_stat64 *)(long)SCARG(uap, sp);
144
145 if ((error = copyout(&st32, st32p, sizeof(*st32p))) != 0)
146 return error;
147
148 return 0;
149 }
150
151 int
152 linux32_sys_lstat64(l, v, retval)
153 struct lwp *l;
154 void *v;
155 register_t *retval;
156 {
157 struct linux32_sys_lstat64_args /* {
158 syscallarg(netbsd32_charp) path;
159 syscallarg(linux32_stat64p) sp;
160 } */ *uap = v;
161 struct sys___lstat30_args ua;
162 caddr_t sg = stackgap_init(l->l_proc, 0);
163 int error;
164 struct stat st;
165 struct linux32_stat64 st32;
166 struct stat *stp;
167 struct linux32_stat64 *st32p;
168
169 NETBSD32TOP_UAP(path, const char);
170
171 CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));
172
173 stp = stackgap_alloc(l->l_proc, &sg, sizeof(*stp));
174 SCARG(&ua, ub) = stp;
175
176 if ((error = sys___lstat30(l, &ua, retval)) != 0)
177 return error;
178
179 if ((error = copyin(stp, &st, sizeof(st))) != 0)
180 return error;
181
182 linux32_from_stat(&st, &st32);
183
184 st32p = (struct linux32_stat64 *)(long)SCARG(uap, sp);
185
186 if ((error = copyout(&st32, st32p, sizeof(*st32p))) != 0)
187 return error;
188
189 return 0;
190 }
191
192 int
193 linux32_sys_fstat64(l, v, retval)
194 struct lwp *l;
195 void *v;
196 register_t *retval;
197 {
198 struct linux32_sys_fstat64_args /* {
199 syscallarg(int) fd;
200 syscallarg(linux32_stat64p) sp;
201 } */ *uap = v;
202 struct sys___fstat30_args ua;
203 caddr_t sg = stackgap_init(l->l_proc, 0);
204 int error;
205 struct stat st;
206 struct linux32_stat64 st32;
207 struct stat *stp;
208 struct linux32_stat64 *st32p;
209
210 NETBSD32TO64_UAP(fd);
211
212 stp = stackgap_alloc(l->l_proc, &sg, sizeof(*stp));
213 SCARG(&ua, sb) = stp;
214
215 if ((error = sys___fstat30(l, &ua, retval)) != 0)
216 return error;
217
218 if ((error = copyin(stp, &st, sizeof(st))) != 0)
219 return error;
220
221 linux32_from_stat(&st, &st32);
222
223 st32p = (struct linux32_stat64 *)(long)SCARG(uap, sp);
224
225 if ((error = copyout(&st32, st32p, sizeof(*st32p))) != 0)
226 return error;
227
228 return 0;
229 }
230