File: | modules/linux/../../compat/linux/linux_stats.c |
Warning: | line 519, column 10 Copies out a struct with untouched element(s): f_spare |
1 | /*- | |||
2 | * Copyright (c) 1994-1995 Søren Schmidt | |||
3 | * All rights reserved. | |||
4 | * | |||
5 | * Redistribution and use in source and binary forms, with or without | |||
6 | * modification, are permitted provided that the following conditions | |||
7 | * are met: | |||
8 | * 1. Redistributions of source code must retain the above copyright | |||
9 | * notice, this list of conditions and the following disclaimer | |||
10 | * in this position and unchanged. | |||
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. The name of the author may not be used to endorse or promote products | |||
15 | * derived from this software without specific prior written permission | |||
16 | * | |||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |||
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
27 | */ | |||
28 | ||||
29 | #include <sys/cdefs.h> | |||
30 | __FBSDID("$FreeBSD: releng/11.0/sys/compat/linux/linux_stats.c 297072 2016-03-20 19:06:21Z dchagin $")__asm__(".ident\t\"" "$FreeBSD: releng/11.0/sys/compat/linux/linux_stats.c 297072 2016-03-20 19:06:21Z dchagin $" "\""); | |||
31 | ||||
32 | #include "opt_compat.h" | |||
33 | ||||
34 | #include <sys/param.h> | |||
35 | #include <sys/capsicum.h> | |||
36 | #include <sys/dirent.h> | |||
37 | #include <sys/file.h> | |||
38 | #include <sys/filedesc.h> | |||
39 | #include <sys/proc.h> | |||
40 | #include <sys/malloc.h> | |||
41 | #include <sys/mount.h> | |||
42 | #include <sys/namei.h> | |||
43 | #include <sys/stat.h> | |||
44 | #include <sys/syscallsubr.h> | |||
45 | #include <sys/systm.h> | |||
46 | #include <sys/tty.h> | |||
47 | #include <sys/vnode.h> | |||
48 | #include <sys/conf.h> | |||
49 | #include <sys/fcntl.h> | |||
50 | ||||
51 | #ifdef COMPAT_LINUX321 | |||
52 | #include <machine/../linux32/linux.h> | |||
53 | #include <machine/../linux32/linux32_proto.h> | |||
54 | #else | |||
55 | #include <machine/../linux/linux.h> | |||
56 | #include <machine/../linux/linux_proto.h> | |||
57 | #endif | |||
58 | ||||
59 | #include <compat/linux/linux_util.h> | |||
60 | #include <compat/linux/linux_file.h> | |||
61 | ||||
62 | ||||
63 | static void | |||
64 | translate_vnhook_major_minor(struct vnode *vp, struct stat *sb) | |||
65 | { | |||
66 | int major, minor; | |||
67 | ||||
68 | if (vp->v_type == VCHR && vp->v_rdevv_un.vu_cdev != NULL((void *)0) && | |||
69 | linux_driver_get_major_minor(devtoname(vp->v_rdevv_un.vu_cdev), | |||
70 | &major, &minor) == 0) { | |||
71 | sb->st_rdev = (major << 8 | minor); | |||
72 | } | |||
73 | } | |||
74 | ||||
75 | static int | |||
76 | linux_kern_statat(struct thread *td, int flag, int fd, char *path, | |||
77 | enum uio_seg pathseg, struct stat *sbp) | |||
78 | { | |||
79 | ||||
80 | return (kern_statat(td, flag, fd, path, pathseg, sbp, | |||
81 | translate_vnhook_major_minor)); | |||
82 | } | |||
83 | ||||
84 | static int | |||
85 | linux_kern_stat(struct thread *td, char *path, enum uio_seg pathseg, | |||
86 | struct stat *sbp) | |||
87 | { | |||
88 | ||||
89 | return (linux_kern_statat(td, 0, AT_FDCWD-100, path, pathseg, sbp)); | |||
90 | } | |||
91 | ||||
92 | static int | |||
93 | linux_kern_lstat(struct thread *td, char *path, enum uio_seg pathseg, | |||
94 | struct stat *sbp) | |||
95 | { | |||
96 | ||||
97 | return (linux_kern_statat(td, AT_SYMLINK_NOFOLLOW0x200, AT_FDCWD-100, path, | |||
98 | pathseg, sbp)); | |||
99 | } | |||
100 | ||||
101 | /* | |||
102 | * XXX: This was removed from newstat_copyout(), and almost identical | |||
103 | * XXX: code was in stat64_copyout(). findcdev() needs to be replaced | |||
104 | * XXX: with something that does lookup and locking properly. | |||
105 | * XXX: When somebody fixes this: please try to avoid duplicating it. | |||
106 | */ | |||
107 | #if 0 | |||
108 | static void | |||
109 | disk_foo(struct somestat *tbuf) | |||
110 | { | |||
111 | struct cdevsw *cdevsw; | |||
112 | struct cdev *dev; | |||
113 | ||||
114 | /* Lie about disk drives which are character devices | |||
115 | * in FreeBSD but block devices under Linux. | |||
116 | */ | |||
117 | if (S_ISCHR(tbuf.st_mode)(((tbuf.st_mode) & 0170000) == 0020000) && | |||
118 | (dev = findcdev(buf->st_rdev)) != NULL((void *)0)) { | |||
119 | cdevsw = dev_refthread(dev); | |||
120 | if (cdevsw != NULL((void *)0)) { | |||
121 | if (cdevsw->d_flags & D_DISK0x0002) { | |||
122 | tbuf.st_mode &= ~S_IFMT0170000; | |||
123 | tbuf.st_mode |= S_IFBLK0060000; | |||
124 | ||||
125 | /* XXX this may not be quite right */ | |||
126 | /* Map major number to 0 */ | |||
127 | tbuf.st_dev = minor(buf->st_dev)((int)((buf->st_dev)&0xffff00ff)) & 0xf; | |||
128 | tbuf.st_rdev = buf->st_rdev & 0xff; | |||
129 | } | |||
130 | dev_relthread(dev); | |||
131 | } | |||
132 | } | |||
133 | ||||
134 | } | |||
135 | #endif | |||
136 | ||||
137 | static void | |||
138 | translate_fd_major_minor(struct thread *td, int fd, struct stat *buf) | |||
139 | { | |||
140 | struct file *fp; | |||
141 | struct vnode *vp; | |||
142 | cap_rights_t rights; | |||
143 | int major, minor; | |||
144 | ||||
145 | /* | |||
146 | * No capability rights required here. | |||
147 | */ | |||
148 | if ((!S_ISCHR(buf->st_mode)(((buf->st_mode) & 0170000) == 0020000) && !S_ISBLK(buf->st_mode)(((buf->st_mode) & 0170000) == 0060000)) || | |||
149 | fget(td, fd, cap_rights_init(&rights)__cap_rights_init(0, &rights, 0ULL), &fp) != 0) | |||
150 | return; | |||
151 | vp = fp->f_vnode; | |||
152 | if (vp != NULL((void *)0) && vp->v_rdevv_un.vu_cdev != NULL((void *)0) && | |||
153 | linux_driver_get_major_minor(devtoname(vp->v_rdevv_un.vu_cdev), | |||
154 | &major, &minor) == 0) { | |||
155 | buf->st_rdev = (major << 8 | minor); | |||
156 | } else if (fp->f_type == DTYPE_PTS10) { | |||
157 | struct tty *tp = fp->f_data; | |||
158 | ||||
159 | /* Convert the numbers for the slave device. */ | |||
160 | if (linux_driver_get_major_minor(devtoname(tp->t_dev), | |||
161 | &major, &minor) == 0) { | |||
162 | buf->st_rdev = (major << 8 | minor); | |||
163 | } | |||
164 | } | |||
165 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
166 | } | |||
167 | ||||
168 | static int | |||
169 | newstat_copyout(struct stat *buf, void *ubuf) | |||
170 | { | |||
171 | struct l_newstat tbuf; | |||
172 | ||||
173 | bzero(&tbuf, sizeof(tbuf)); | |||
174 | tbuf.st_dev = minor(buf->st_dev)((int)((buf->st_dev)&0xffff00ff)) | (major(buf->st_dev)((int)(((u_int)(buf->st_dev) >> 8)&0xff)) << 8); | |||
175 | tbuf.st_ino = buf->st_ino; | |||
176 | tbuf.st_mode = buf->st_mode; | |||
177 | tbuf.st_nlink = buf->st_nlink; | |||
178 | tbuf.st_uid = buf->st_uid; | |||
179 | tbuf.st_gid = buf->st_gid; | |||
180 | tbuf.st_rdev = buf->st_rdev; | |||
181 | tbuf.st_size = buf->st_size; | |||
182 | tbuf.st_atim.tv_sec = buf->st_atim.tv_sec; | |||
183 | tbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec; | |||
184 | tbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec; | |||
185 | tbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec; | |||
186 | tbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec; | |||
187 | tbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec; | |||
188 | tbuf.st_blksize = buf->st_blksize; | |||
189 | tbuf.st_blocks = buf->st_blocks; | |||
190 | ||||
191 | return (copyout(&tbuf, ubuf, sizeof(tbuf))); | |||
192 | } | |||
193 | ||||
194 | int | |||
195 | linux_newstat(struct thread *td, struct linux_newstat_args *args) | |||
196 | { | |||
197 | struct stat buf; | |||
198 | char *path; | |||
199 | int error; | |||
200 | ||||
201 | LCONVPATHEXIST(td, args->path, &path)do { int _error; _error = linux_emul_convpath(td, args->path , UIO_USERSPACE, &path, 0, -100); if (*(&path) == ((void *)0)) return (_error); } while (0); | |||
202 | ||||
203 | #ifdef DEBUG | |||
204 | if (ldebug(newstat)((((const unsigned char *)(linux_debug_map))[(106)/8] & ( 1<<((106)%8))) == 0)) | |||
205 | printf(ARGS(newstat, "%s, *")"linux(%ld/%ld): ""newstat""(""%s, *"")\n", (long)td->td_proc ->p_pid, (long)td->td_tid, path); | |||
206 | #endif | |||
207 | ||||
208 | error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf); | |||
209 | LFREEPATH(path)free(path, M_TEMP); | |||
210 | if (error) | |||
211 | return (error); | |||
212 | return (newstat_copyout(&buf, args->buf)); | |||
213 | } | |||
214 | ||||
215 | int | |||
216 | linux_newlstat(struct thread *td, struct linux_newlstat_args *args) | |||
217 | { | |||
218 | struct stat sb; | |||
219 | char *path; | |||
220 | int error; | |||
221 | ||||
222 | LCONVPATHEXIST(td, args->path, &path)do { int _error; _error = linux_emul_convpath(td, args->path , UIO_USERSPACE, &path, 0, -100); if (*(&path) == ((void *)0)) return (_error); } while (0); | |||
223 | ||||
224 | #ifdef DEBUG | |||
225 | if (ldebug(newlstat)((((const unsigned char *)(linux_debug_map))[(107)/8] & ( 1<<((107)%8))) == 0)) | |||
226 | printf(ARGS(newlstat, "%s, *")"linux(%ld/%ld): ""newlstat""(""%s, *"")\n", (long)td->td_proc ->p_pid, (long)td->td_tid, path); | |||
227 | #endif | |||
228 | ||||
229 | error = linux_kern_lstat(td, path, UIO_SYSSPACE, &sb); | |||
230 | LFREEPATH(path)free(path, M_TEMP); | |||
231 | if (error) | |||
232 | return (error); | |||
233 | return (newstat_copyout(&sb, args->buf)); | |||
234 | } | |||
235 | ||||
236 | int | |||
237 | linux_newfstat(struct thread *td, struct linux_newfstat_args *args) | |||
238 | { | |||
239 | struct stat buf; | |||
240 | int error; | |||
241 | ||||
242 | #ifdef DEBUG | |||
243 | if (ldebug(newfstat)((((const unsigned char *)(linux_debug_map))[(108)/8] & ( 1<<((108)%8))) == 0)) | |||
244 | printf(ARGS(newfstat, "%d, *")"linux(%ld/%ld): ""newfstat""(""%d, *"")\n", (long)td->td_proc ->p_pid, (long)td->td_tid, args->fd); | |||
245 | #endif | |||
246 | ||||
247 | error = kern_fstat(td, args->fd, &buf); | |||
248 | translate_fd_major_minor(td, args->fd, &buf); | |||
249 | if (!error) | |||
250 | error = newstat_copyout(&buf, args->buf); | |||
251 | ||||
252 | return (error); | |||
253 | } | |||
254 | ||||
255 | #if defined(__i386__) || (defined(__amd64__1) && defined(COMPAT_LINUX321)) | |||
256 | static int | |||
257 | stat_copyout(struct stat *buf, void *ubuf) | |||
258 | { | |||
259 | struct l_stat lbuf; | |||
260 | ||||
261 | bzero(&lbuf, sizeof(lbuf)); | |||
262 | lbuf.st_dev = buf->st_dev; | |||
263 | lbuf.st_ino = buf->st_ino; | |||
264 | lbuf.st_mode = buf->st_mode; | |||
265 | lbuf.st_nlink = buf->st_nlink; | |||
266 | lbuf.st_uid = buf->st_uid; | |||
267 | lbuf.st_gid = buf->st_gid; | |||
268 | lbuf.st_rdev = buf->st_rdev; | |||
269 | if (buf->st_size < (quad_t)1 << 32) | |||
270 | lbuf.st_size = buf->st_size; | |||
271 | else | |||
272 | lbuf.st_size = -2; | |||
273 | lbuf.st_atim.tv_sec = buf->st_atim.tv_sec; | |||
274 | lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec; | |||
275 | lbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec; | |||
276 | lbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec; | |||
277 | lbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec; | |||
278 | lbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec; | |||
279 | lbuf.st_blksize = buf->st_blksize; | |||
280 | lbuf.st_blocks = buf->st_blocks; | |||
281 | lbuf.st_flags = buf->st_flags; | |||
282 | lbuf.st_gen = buf->st_gen; | |||
283 | ||||
284 | return (copyout(&lbuf, ubuf, sizeof(lbuf))); | |||
285 | } | |||
286 | ||||
287 | int | |||
288 | linux_stat(struct thread *td, struct linux_stat_args *args) | |||
289 | { | |||
290 | struct stat buf; | |||
291 | char *path; | |||
292 | int error; | |||
293 | ||||
294 | LCONVPATHEXIST(td, args->path, &path)do { int _error; _error = linux_emul_convpath(td, args->path , UIO_USERSPACE, &path, 0, -100); if (*(&path) == ((void *)0)) return (_error); } while (0); | |||
295 | ||||
296 | #ifdef DEBUG | |||
297 | if (ldebug(stat)((((const unsigned char *)(linux_debug_map))[(18)/8] & (1 <<((18)%8))) == 0)) | |||
298 | printf(ARGS(stat, "%s, *")"linux(%ld/%ld): ""stat""(""%s, *"")\n", (long)td->td_proc ->p_pid, (long)td->td_tid, path); | |||
299 | #endif | |||
300 | error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf); | |||
301 | if (error) { | |||
302 | LFREEPATH(path)free(path, M_TEMP); | |||
303 | return (error); | |||
304 | } | |||
305 | LFREEPATH(path)free(path, M_TEMP); | |||
306 | return (stat_copyout(&buf, args->up)); | |||
307 | } | |||
308 | ||||
309 | int | |||
310 | linux_lstat(struct thread *td, struct linux_lstat_args *args) | |||
311 | { | |||
312 | struct stat buf; | |||
313 | char *path; | |||
314 | int error; | |||
315 | ||||
316 | LCONVPATHEXIST(td, args->path, &path)do { int _error; _error = linux_emul_convpath(td, args->path , UIO_USERSPACE, &path, 0, -100); if (*(&path) == ((void *)0)) return (_error); } while (0); | |||
317 | ||||
318 | #ifdef DEBUG | |||
319 | if (ldebug(lstat)((((const unsigned char *)(linux_debug_map))[(84)/8] & (1 <<((84)%8))) == 0)) | |||
320 | printf(ARGS(lstat, "%s, *")"linux(%ld/%ld): ""lstat""(""%s, *"")\n", (long)td->td_proc ->p_pid, (long)td->td_tid, path); | |||
321 | #endif | |||
322 | error = linux_kern_lstat(td, path, UIO_SYSSPACE, &buf); | |||
323 | if (error) { | |||
324 | LFREEPATH(path)free(path, M_TEMP); | |||
325 | return (error); | |||
326 | } | |||
327 | LFREEPATH(path)free(path, M_TEMP); | |||
328 | return (stat_copyout(&buf, args->up)); | |||
329 | } | |||
330 | #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ | |||
331 | ||||
332 | struct l_statfs { | |||
333 | l_long f_type; | |||
334 | l_long f_bsize; | |||
335 | l_long f_blocks; | |||
336 | l_long f_bfree; | |||
337 | l_long f_bavail; | |||
338 | l_long f_files; | |||
339 | l_long f_ffree; | |||
340 | l_fsid_t f_fsid; | |||
341 | l_long f_namelen; | |||
342 | l_long f_spare[6]; | |||
343 | }; | |||
344 | ||||
345 | #define LINUX_CODA_SUPER_MAGIC0x73757245L 0x73757245L | |||
346 | #define LINUX_EXT2_SUPER_MAGIC0xEF53L 0xEF53L | |||
347 | #define LINUX_HPFS_SUPER_MAGIC0xf995e849L 0xf995e849L | |||
348 | #define LINUX_ISOFS_SUPER_MAGIC0x9660L 0x9660L | |||
349 | #define LINUX_MSDOS_SUPER_MAGIC0x4d44L 0x4d44L | |||
350 | #define LINUX_NCP_SUPER_MAGIC0x564cL 0x564cL | |||
351 | #define LINUX_NFS_SUPER_MAGIC0x6969L 0x6969L | |||
352 | #define LINUX_NTFS_SUPER_MAGIC0x5346544EL 0x5346544EL | |||
353 | #define LINUX_PROC_SUPER_MAGIC0x9fa0L 0x9fa0L | |||
354 | #define LINUX_UFS_SUPER_MAGIC0x00011954L 0x00011954L /* XXX - UFS_MAGIC in Linux */ | |||
355 | #define LINUX_DEVFS_SUPER_MAGIC0x1373L 0x1373L | |||
356 | #define LINUX_SHMFS_MAGIC0x01021994 0x01021994 | |||
357 | ||||
358 | static long | |||
359 | bsd_to_linux_ftype(const char *fstypename) | |||
360 | { | |||
361 | int i; | |||
362 | static struct {const char *bsd_name; long linux_type;} b2l_tbl[] = { | |||
363 | {"ufs", LINUX_UFS_SUPER_MAGIC0x00011954L}, | |||
364 | {"cd9660", LINUX_ISOFS_SUPER_MAGIC0x9660L}, | |||
365 | {"nfs", LINUX_NFS_SUPER_MAGIC0x6969L}, | |||
366 | {"ext2fs", LINUX_EXT2_SUPER_MAGIC0xEF53L}, | |||
367 | {"procfs", LINUX_PROC_SUPER_MAGIC0x9fa0L}, | |||
368 | {"msdosfs", LINUX_MSDOS_SUPER_MAGIC0x4d44L}, | |||
369 | {"ntfs", LINUX_NTFS_SUPER_MAGIC0x5346544EL}, | |||
370 | {"nwfs", LINUX_NCP_SUPER_MAGIC0x564cL}, | |||
371 | {"hpfs", LINUX_HPFS_SUPER_MAGIC0xf995e849L}, | |||
372 | {"coda", LINUX_CODA_SUPER_MAGIC0x73757245L}, | |||
373 | {"devfs", LINUX_DEVFS_SUPER_MAGIC0x1373L}, | |||
374 | {"tmpfs", LINUX_SHMFS_MAGIC0x01021994}, | |||
375 | {NULL((void *)0), 0L}}; | |||
376 | ||||
377 | for (i = 0; b2l_tbl[i].bsd_name != NULL((void *)0); i++) | |||
378 | if (strcmp(b2l_tbl[i].bsd_name, fstypename) == 0) | |||
379 | return (b2l_tbl[i].linux_type); | |||
380 | ||||
381 | return (0L); | |||
382 | } | |||
383 | ||||
384 | static int | |||
385 | bsd_to_linux_statfs(struct statfs *bsd_statfs, struct l_statfs *linux_statfs) | |||
386 | { | |||
387 | #if defined(__i386__) || (defined(__amd64__1) && defined(COMPAT_LINUX321)) | |||
388 | uint64_t tmp; | |||
389 | ||||
390 | #define LINUX_HIBITS 0xffffffff00000000ULL | |||
391 | ||||
392 | tmp = bsd_statfs->f_blocks | bsd_statfs->f_bfree | bsd_statfs->f_files | | |||
393 | bsd_statfs->f_bsize; | |||
394 | if ((bsd_statfs->f_bavail != -1 && (bsd_statfs->f_bavail & LINUX_HIBITS)) || | |||
395 | (bsd_statfs->f_ffree != -1 && (bsd_statfs->f_ffree & LINUX_HIBITS)) || | |||
396 | (tmp & LINUX_HIBITS)) | |||
397 | return (EOVERFLOW84); | |||
398 | #undef LINUX_HIBITS | |||
399 | #endif | |||
400 | linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename); | |||
401 | linux_statfs->f_bsize = bsd_statfs->f_bsize; | |||
402 | linux_statfs->f_blocks = bsd_statfs->f_blocks; | |||
403 | linux_statfs->f_bfree = bsd_statfs->f_bfree; | |||
404 | linux_statfs->f_bavail = bsd_statfs->f_bavail; | |||
405 | linux_statfs->f_ffree = bsd_statfs->f_ffree; | |||
406 | linux_statfs->f_files = bsd_statfs->f_files; | |||
407 | linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0]; | |||
408 | linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1]; | |||
409 | linux_statfs->f_namelen = MAXNAMLEN255; | |||
410 | ||||
411 | return (0); | |||
412 | } | |||
413 | ||||
414 | int | |||
415 | linux_statfs(struct thread *td, struct linux_statfs_args *args) | |||
416 | { | |||
417 | struct l_statfs linux_statfs; | |||
418 | struct statfs bsd_statfs; | |||
419 | char *path; | |||
420 | int error; | |||
421 | ||||
422 | LCONVPATHEXIST(td, args->path, &path)do { int _error; _error = linux_emul_convpath(td, args->path , UIO_USERSPACE, &path, 0, -100); if (*(&path) == ((void *)0)) return (_error); } while (0); | |||
423 | ||||
424 | #ifdef DEBUG | |||
425 | if (ldebug(statfs)((((const unsigned char *)(linux_debug_map))[(99)/8] & (1 <<((99)%8))) == 0)) | |||
426 | printf(ARGS(statfs, "%s, *")"linux(%ld/%ld): ""statfs""(""%s, *"")\n", (long)td->td_proc ->p_pid, (long)td->td_tid, path); | |||
427 | #endif | |||
428 | error = kern_statfs(td, path, UIO_SYSSPACE, &bsd_statfs); | |||
429 | LFREEPATH(path)free(path, M_TEMP); | |||
430 | if (error) | |||
431 | return (error); | |||
432 | error = bsd_to_linux_statfs(&bsd_statfs, &linux_statfs); | |||
433 | if (error) | |||
434 | return (error); | |||
435 | return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs))); | |||
436 | } | |||
437 | ||||
438 | #if defined(__i386__) || (defined(__amd64__1) && defined(COMPAT_LINUX321)) | |||
439 | static void | |||
440 | bsd_to_linux_statfs64(struct statfs *bsd_statfs, struct l_statfs64 *linux_statfs) | |||
441 | { | |||
442 | ||||
443 | linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename); | |||
444 | linux_statfs->f_bsize = bsd_statfs->f_bsize; | |||
445 | linux_statfs->f_blocks = bsd_statfs->f_blocks; | |||
446 | linux_statfs->f_bfree = bsd_statfs->f_bfree; | |||
447 | linux_statfs->f_bavail = bsd_statfs->f_bavail; | |||
448 | linux_statfs->f_ffree = bsd_statfs->f_ffree; | |||
449 | linux_statfs->f_files = bsd_statfs->f_files; | |||
450 | linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0]; | |||
451 | linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1]; | |||
452 | linux_statfs->f_namelen = MAXNAMLEN255; | |||
453 | } | |||
454 | ||||
455 | int | |||
456 | linux_statfs64(struct thread *td, struct linux_statfs64_args *args) | |||
457 | { | |||
458 | struct l_statfs64 linux_statfs; | |||
459 | struct statfs bsd_statfs; | |||
460 | char *path; | |||
461 | int error; | |||
462 | ||||
463 | if (args->bufsize != sizeof(struct l_statfs64)) | |||
464 | return EINVAL22; | |||
465 | ||||
466 | LCONVPATHEXIST(td, args->path, &path)do { int _error; _error = linux_emul_convpath(td, args->path , UIO_USERSPACE, &path, 0, -100); if (*(&path) == ((void *)0)) return (_error); } while (0); | |||
467 | ||||
468 | #ifdef DEBUG | |||
469 | if (ldebug(statfs64)((((const unsigned char *)(linux_debug_map))[(268)/8] & ( 1<<((268)%8))) == 0)) | |||
470 | printf(ARGS(statfs64, "%s, *")"linux(%ld/%ld): ""statfs64""(""%s, *"")\n", (long)td->td_proc ->p_pid, (long)td->td_tid, path); | |||
471 | #endif | |||
472 | error = kern_statfs(td, path, UIO_SYSSPACE, &bsd_statfs); | |||
473 | LFREEPATH(path)free(path, M_TEMP); | |||
474 | if (error) | |||
475 | return (error); | |||
476 | bsd_to_linux_statfs64(&bsd_statfs, &linux_statfs); | |||
477 | return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs))); | |||
478 | } | |||
479 | ||||
480 | int | |||
481 | linux_fstatfs64(struct thread *td, struct linux_fstatfs64_args *args) | |||
482 | { | |||
483 | struct l_statfs64 linux_statfs; | |||
484 | struct statfs bsd_statfs; | |||
485 | int error; | |||
486 | ||||
487 | #ifdef DEBUG | |||
488 | if (ldebug(fstatfs64)((((const unsigned char *)(linux_debug_map))[(269)/8] & ( 1<<((269)%8))) == 0)) | |||
489 | printf(ARGS(fstatfs64, "%d, *")"linux(%ld/%ld): ""fstatfs64""(""%d, *"")\n", (long)td->td_proc ->p_pid, (long)td->td_tid, args->fd); | |||
490 | #endif | |||
491 | if (args->bufsize != sizeof(struct l_statfs64)) | |||
492 | return (EINVAL22); | |||
493 | ||||
494 | error = kern_fstatfs(td, args->fd, &bsd_statfs); | |||
495 | if (error) | |||
496 | return error; | |||
497 | bsd_to_linux_statfs64(&bsd_statfs, &linux_statfs); | |||
498 | return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs))); | |||
499 | } | |||
500 | #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ | |||
501 | ||||
502 | int | |||
503 | linux_fstatfs(struct thread *td, struct linux_fstatfs_args *args) | |||
504 | { | |||
505 | struct l_statfs linux_statfs; | |||
506 | struct statfs bsd_statfs; | |||
507 | int error; | |||
508 | ||||
509 | #ifdef DEBUG | |||
510 | if (ldebug(fstatfs)((((const unsigned char *)(linux_debug_map))[(100)/8] & ( 1<<((100)%8))) == 0)) | |||
511 | printf(ARGS(fstatfs, "%d, *")"linux(%ld/%ld): ""fstatfs""(""%d, *"")\n", (long)td->td_proc ->p_pid, (long)td->td_tid, args->fd); | |||
512 | #endif | |||
513 | error = kern_fstatfs(td, args->fd, &bsd_statfs); | |||
514 | if (error) | |||
| ||||
515 | return (error); | |||
516 | error = bsd_to_linux_statfs(&bsd_statfs, &linux_statfs); | |||
517 | if (error) | |||
518 | return (error); | |||
519 | return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs))); | |||
| ||||
520 | } | |||
521 | ||||
522 | struct l_ustat | |||
523 | { | |||
524 | l_daddr_t f_tfree; | |||
525 | l_ino_t f_tinode; | |||
526 | char f_fname[6]; | |||
527 | char f_fpack[6]; | |||
528 | }; | |||
529 | ||||
530 | int | |||
531 | linux_ustat(struct thread *td, struct linux_ustat_args *args) | |||
532 | { | |||
533 | #ifdef DEBUG | |||
534 | if (ldebug(ustat)((((const unsigned char *)(linux_debug_map))[(62)/8] & (1 <<((62)%8))) == 0)) | |||
535 | printf(ARGS(ustat, "%ju, *")"linux(%ld/%ld): ""ustat""(""%ju, *"")\n", (long)td->td_proc ->p_pid, (long)td->td_tid, (uintmax_t)args->dev); | |||
536 | #endif | |||
537 | ||||
538 | return (EOPNOTSUPP45); | |||
539 | } | |||
540 | ||||
541 | #if defined(__i386__) || (defined(__amd64__1) && defined(COMPAT_LINUX321)) | |||
542 | ||||
543 | static int | |||
544 | stat64_copyout(struct stat *buf, void *ubuf) | |||
545 | { | |||
546 | struct l_stat64 lbuf; | |||
547 | ||||
548 | bzero(&lbuf, sizeof(lbuf)); | |||
549 | lbuf.st_dev = minor(buf->st_dev)((int)((buf->st_dev)&0xffff00ff)) | (major(buf->st_dev)((int)(((u_int)(buf->st_dev) >> 8)&0xff)) << 8); | |||
550 | lbuf.st_ino = buf->st_ino; | |||
551 | lbuf.st_mode = buf->st_mode; | |||
552 | lbuf.st_nlink = buf->st_nlink; | |||
553 | lbuf.st_uid = buf->st_uid; | |||
554 | lbuf.st_gid = buf->st_gid; | |||
555 | lbuf.st_rdev = buf->st_rdev; | |||
556 | lbuf.st_size = buf->st_size; | |||
557 | lbuf.st_atim.tv_sec = buf->st_atim.tv_sec; | |||
558 | lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec; | |||
559 | lbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec; | |||
560 | lbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec; | |||
561 | lbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec; | |||
562 | lbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec; | |||
563 | lbuf.st_blksize = buf->st_blksize; | |||
564 | lbuf.st_blocks = buf->st_blocks; | |||
565 | ||||
566 | /* | |||
567 | * The __st_ino field makes all the difference. In the Linux kernel | |||
568 | * it is conditionally compiled based on STAT64_HAS_BROKEN_ST_INO, | |||
569 | * but without the assignment to __st_ino the runtime linker refuses | |||
570 | * to mmap(2) any shared libraries. I guess it's broken alright :-) | |||
571 | */ | |||
572 | lbuf.__st_ino = buf->st_ino; | |||
573 | ||||
574 | return (copyout(&lbuf, ubuf, sizeof(lbuf))); | |||
575 | } | |||
576 | ||||
577 | int | |||
578 | linux_stat64(struct thread *td, struct linux_stat64_args *args) | |||
579 | { | |||
580 | struct stat buf; | |||
581 | char *filename; | |||
582 | int error; | |||
583 | ||||
584 | LCONVPATHEXIST(td, args->filename, &filename)do { int _error; _error = linux_emul_convpath(td, args->filename , UIO_USERSPACE, &filename, 0, -100); if (*(&filename ) == ((void *)0)) return (_error); } while (0); | |||
585 | ||||
586 | #ifdef DEBUG | |||
587 | if (ldebug(stat64)((((const unsigned char *)(linux_debug_map))[(195)/8] & ( 1<<((195)%8))) == 0)) | |||
588 | printf(ARGS(stat64, "%s, *")"linux(%ld/%ld): ""stat64""(""%s, *"")\n", (long)td->td_proc ->p_pid, (long)td->td_tid, filename); | |||
589 | #endif | |||
590 | ||||
591 | error = linux_kern_stat(td, filename, UIO_SYSSPACE, &buf); | |||
592 | LFREEPATH(filename)free(filename, M_TEMP); | |||
593 | if (error) | |||
594 | return (error); | |||
595 | return (stat64_copyout(&buf, args->statbuf)); | |||
596 | } | |||
597 | ||||
598 | int | |||
599 | linux_lstat64(struct thread *td, struct linux_lstat64_args *args) | |||
600 | { | |||
601 | struct stat sb; | |||
602 | char *filename; | |||
603 | int error; | |||
604 | ||||
605 | LCONVPATHEXIST(td, args->filename, &filename)do { int _error; _error = linux_emul_convpath(td, args->filename , UIO_USERSPACE, &filename, 0, -100); if (*(&filename ) == ((void *)0)) return (_error); } while (0); | |||
606 | ||||
607 | #ifdef DEBUG | |||
608 | if (ldebug(lstat64)((((const unsigned char *)(linux_debug_map))[(196)/8] & ( 1<<((196)%8))) == 0)) | |||
609 | printf(ARGS(lstat64, "%s, *")"linux(%ld/%ld): ""lstat64""(""%s, *"")\n", (long)td->td_proc ->p_pid, (long)td->td_tid, args->filename); | |||
610 | #endif | |||
611 | ||||
612 | error = linux_kern_lstat(td, filename, UIO_SYSSPACE, &sb); | |||
613 | LFREEPATH(filename)free(filename, M_TEMP); | |||
614 | if (error) | |||
615 | return (error); | |||
616 | return (stat64_copyout(&sb, args->statbuf)); | |||
617 | } | |||
618 | ||||
619 | int | |||
620 | linux_fstat64(struct thread *td, struct linux_fstat64_args *args) | |||
621 | { | |||
622 | struct stat buf; | |||
623 | int error; | |||
624 | ||||
625 | #ifdef DEBUG | |||
626 | if (ldebug(fstat64)((((const unsigned char *)(linux_debug_map))[(197)/8] & ( 1<<((197)%8))) == 0)) | |||
627 | printf(ARGS(fstat64, "%d, *")"linux(%ld/%ld): ""fstat64""(""%d, *"")\n", (long)td->td_proc ->p_pid, (long)td->td_tid, args->fd); | |||
628 | #endif | |||
629 | ||||
630 | error = kern_fstat(td, args->fd, &buf); | |||
631 | translate_fd_major_minor(td, args->fd, &buf); | |||
632 | if (!error) | |||
633 | error = stat64_copyout(&buf, args->statbuf); | |||
634 | ||||
635 | return (error); | |||
636 | } | |||
637 | ||||
638 | int | |||
639 | linux_fstatat64(struct thread *td, struct linux_fstatat64_args *args) | |||
640 | { | |||
641 | char *path; | |||
642 | int error, dfd, flag; | |||
643 | struct stat buf; | |||
644 | ||||
645 | if (args->flag & ~LINUX_AT_SYMLINK_NOFOLLOW0x100) | |||
646 | return (EINVAL22); | |||
647 | flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW0x100) ? | |||
648 | AT_SYMLINK_NOFOLLOW0x200 : 0; | |||
649 | ||||
650 | dfd = (args->dfd == LINUX_AT_FDCWD-100) ? AT_FDCWD-100 : args->dfd; | |||
651 | LCONVPATHEXIST_AT(td, args->pathname, &path, dfd)do { int _error; _error = linux_emul_convpath(td, args->pathname , UIO_USERSPACE, &path, 0, dfd); if (*(&path) == ((void *)0)) return (_error); } while (0); | |||
652 | ||||
653 | #ifdef DEBUG | |||
654 | if (ldebug(fstatat64)((((const unsigned char *)(linux_debug_map))[(300)/8] & ( 1<<((300)%8))) == 0)) | |||
655 | printf(ARGS(fstatat64, "%i, %s, %i")"linux(%ld/%ld): ""fstatat64""(""%i, %s, %i"")\n", (long)td-> td_proc->p_pid, (long)td->td_tid, args->dfd, path, args->flag); | |||
656 | #endif | |||
657 | ||||
658 | error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf); | |||
659 | if (!error) | |||
660 | error = stat64_copyout(&buf, args->statbuf); | |||
661 | LFREEPATH(path)free(path, M_TEMP); | |||
662 | ||||
663 | return (error); | |||
664 | } | |||
665 | ||||
666 | #else /* __amd64__ && !COMPAT_LINUX32 */ | |||
667 | ||||
668 | int | |||
669 | linux_newfstatat(struct thread *td, struct linux_newfstatat_args *args) | |||
670 | { | |||
671 | char *path; | |||
672 | int error, dfd, flag; | |||
673 | struct stat buf; | |||
674 | ||||
675 | if (args->flag & ~LINUX_AT_SYMLINK_NOFOLLOW0x100) | |||
676 | return (EINVAL22); | |||
677 | flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW0x100) ? | |||
678 | AT_SYMLINK_NOFOLLOW0x200 : 0; | |||
679 | ||||
680 | dfd = (args->dfd == LINUX_AT_FDCWD-100) ? AT_FDCWD-100 : args->dfd; | |||
681 | LCONVPATHEXIST_AT(td, args->pathname, &path, dfd)do { int _error; _error = linux_emul_convpath(td, args->pathname , UIO_USERSPACE, &path, 0, dfd); if (*(&path) == ((void *)0)) return (_error); } while (0); | |||
682 | ||||
683 | #ifdef DEBUG | |||
684 | if (ldebug(newfstatat)((((const unsigned char *)(linux_debug_map))[(LINUX32_SYS_linux_newfstatat )/8] & (1<<((LINUX32_SYS_linux_newfstatat)%8))) == 0 )) | |||
685 | printf(ARGS(newfstatat, "%i, %s, %i")"linux(%ld/%ld): ""newfstatat""(""%i, %s, %i"")\n", (long)td-> td_proc->p_pid, (long)td->td_tid, args->dfd, path, args->flag); | |||
686 | #endif | |||
687 | ||||
688 | error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf); | |||
689 | if (error == 0) | |||
690 | error = newstat_copyout(&buf, args->statbuf); | |||
691 | LFREEPATH(path)free(path, M_TEMP); | |||
692 | ||||
693 | return (error); | |||
694 | } | |||
695 | ||||
696 | #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ | |||
697 | ||||
698 | int | |||
699 | linux_syncfs(struct thread *td, struct linux_syncfs_args *args) | |||
700 | { | |||
701 | cap_rights_t rights; | |||
702 | struct mount *mp; | |||
703 | struct vnode *vp; | |||
704 | int error, save; | |||
705 | ||||
706 | error = fgetvp(td, args->fd, cap_rights_init(&rights, CAP_FSYNC)__cap_rights_init(0, &rights, ((1ULL << (57 + (0))) | (0x0000000000000100ULL)), 0ULL), &vp); | |||
707 | if (error != 0) | |||
708 | /* | |||
709 | * Linux syncfs() returns only EBADF, however fgetvp() | |||
710 | * can return EINVAL in case of file descriptor does | |||
711 | * not represent a vnode. XXX. | |||
712 | */ | |||
713 | return (error); | |||
714 | ||||
715 | mp = vp->v_mount; | |||
716 | mtx_lock(&mountlist_mtx)__mtx_lock_flags(&((((&mountlist_mtx))))->mtx_lock , ((0)), ("/usr/src/sys/modules/linux/../../compat/linux/linux_stats.c" ), (716)); | |||
717 | error = vfs_busy(mp, MBF_MNTLSTLOCK0x02); | |||
718 | if (error != 0) { | |||
719 | /* See comment above. */ | |||
720 | mtx_unlock(&mountlist_mtx)__mtx_unlock_flags(&((((&mountlist_mtx))))->mtx_lock , ((0)), ("/usr/src/sys/modules/linux/../../compat/linux/linux_stats.c" ), (720)); | |||
721 | goto out; | |||
722 | } | |||
723 | if ((mp->mnt_flag & MNT_RDONLY0x0000000000000001ULL) == 0 && | |||
724 | vn_start_write(NULL((void *)0), &mp, V_NOWAIT0x0002) == 0) { | |||
725 | save = curthread_pflags_set(TDP_SYNCIO0x00000800); | |||
726 | vfs_msync(mp, MNT_NOWAIT2); | |||
727 | VFS_SYNC(mp, MNT_NOWAIT)({ int _rc; do { struct mount *mp__; int _prev_stops; mp__ = ( mp); _prev_stops = sigdeferstop((mp__ != ((void *)0) && (mp__->mnt_vfc->vfc_flags & 0x01000000) != 0) ? 2 : 0);; _rc = (*(mp)->mnt_op->vfs_sync)(mp, 2); sigallowstop (_prev_stops); } while (0); _rc; }); | |||
728 | curthread_pflags_restore(save); | |||
729 | vn_finished_write(mp); | |||
730 | } | |||
731 | vfs_unbusy(mp); | |||
732 | ||||
733 | out: | |||
734 | vrele(vp); | |||
735 | return (error); | |||
736 | } |