1 /* $NetBSD: netbsd32_compat_20.c,v 1.26 2008/06/24 11:18:15 ad Exp $ */
4 * Copyright (c) 1998, 2001 Matthew R. Green
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_20.c,v 1.26 2008/06/24 11:18:15 ad Exp $");
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/malloc.h>
35 #include <sys/mount.h>
38 #include <sys/ktrace.h>
39 #include <sys/vnode.h>
41 #include <sys/filedesc.h>
42 #include <sys/namei.h>
43 #include <sys/syscallargs.h>
45 #include <sys/dirent.h>
47 #include <compat/netbsd32/netbsd32.h>
48 #include <compat/netbsd32/netbsd32_syscallargs.h>
49 #include <compat/netbsd32/netbsd32_conv.h>
51 static inline void compat_20_netbsd32_from_statvfs(struct statvfs
*,
52 struct netbsd32_statfs
*);
55 compat_20_netbsd32_from_statvfs(struct statvfs
*sbp
, struct netbsd32_statfs
*sb32p
)
57 sb32p
->f_flags
= sbp
->f_flag
;
58 sb32p
->f_bsize
= (netbsd32_long
)sbp
->f_bsize
;
59 sb32p
->f_iosize
= (netbsd32_long
)sbp
->f_iosize
;
60 sb32p
->f_blocks
= (netbsd32_long
)sbp
->f_blocks
;
61 sb32p
->f_bfree
= (netbsd32_long
)sbp
->f_bfree
;
62 sb32p
->f_bavail
= (netbsd32_long
)sbp
->f_bavail
;
63 sb32p
->f_files
= (netbsd32_long
)sbp
->f_files
;
64 sb32p
->f_ffree
= (netbsd32_long
)sbp
->f_ffree
;
65 sb32p
->f_fsid
= sbp
->f_fsidx
;
66 sb32p
->f_owner
= sbp
->f_owner
;
67 sb32p
->f_spare
[0] = 0;
68 sb32p
->f_spare
[1] = 0;
69 sb32p
->f_spare
[2] = 0;
70 sb32p
->f_spare
[3] = 0;
72 /* May as well do the whole batch in one go */
73 (void)memcpy(sb32p
->f_fstypename
, sbp
->f_fstypename
,
74 sizeof(sb32p
->f_fstypename
) +
75 sizeof(sb32p
->f_mntonname
) +
76 sizeof(sb32p
->f_mntfromname
));
78 /* If we want to be careful */
79 (void)memcpy(sb32p
->f_fstypename
, sbp
->f_fstypename
,
80 sizeof(sb32p
->f_fstypename
));
81 (void)memcpy(sb32p
->f_mntonname
, sbp
->f_mntonname
,
82 sizeof(sb32p
->f_mntonname
));
83 (void)memcpy(sb32p
->f_mntfromname
, sbp
->f_mntfromname
,
84 sizeof(sb32p
->f_mntfromname
));
89 compat_20_netbsd32_getfsstat(struct lwp
*l
, const struct compat_20_netbsd32_getfsstat_args
*uap
, register_t
*retval
)
92 syscallarg(netbsd32_statfsp_t) buf;
93 syscallarg(netbsd32_long) bufsize;
94 syscallarg(int) flags;
96 struct mount
*mp
, *nmp
;
98 struct netbsd32_statfs sb32
;
100 long count
, maxcount
, error
;
102 maxcount
= SCARG(uap
, bufsize
) / sizeof(struct netbsd32_statfs
);
103 sfsp
= SCARG_P32(uap
, buf
);
104 mutex_enter(&mountlist_lock
);
106 for (mp
= mountlist
.cqh_first
; mp
!= (void *)&mountlist
; mp
= nmp
) {
107 if (vfs_busy(mp
, &nmp
)) {
110 if (sfsp
&& count
< maxcount
) {
113 * If MNT_NOWAIT or MNT_LAZY is specified, do not
114 * refresh the fsstat cache. MNT_WAIT or MNT_LAZY
115 * overrides MNT_NOWAIT.
117 if (SCARG(uap
, flags
) != MNT_NOWAIT
&&
118 SCARG(uap
, flags
) != MNT_LAZY
&&
119 (SCARG(uap
, flags
) == MNT_WAIT
||
120 SCARG(uap
, flags
) == 0) &&
121 (error
= VFS_STATVFS(mp
, sp
)) != 0) {
122 mutex_enter(&mountlist_lock
);
123 vfs_unbusy(mp
, false, &nmp
);
126 sp
->f_flag
= mp
->mnt_flag
& MNT_VISFLAGMASK
;
127 compat_20_netbsd32_from_statvfs(sp
, &sb32
);
128 error
= copyout(&sb32
, sfsp
, sizeof(sb32
));
130 vfs_unbusy(mp
, false, NULL
);
133 sfsp
= (char *)sfsp
+ sizeof(sb32
);
136 mutex_enter(&mountlist_lock
);
137 vfs_unbusy(mp
, false, &nmp
);
139 mutex_exit(&mountlist_lock
);
140 if (sfsp
&& count
> maxcount
)
148 compat_20_netbsd32_statfs(struct lwp
*l
, const struct compat_20_netbsd32_statfs_args
*uap
, register_t
*retval
)
151 syscallarg(const netbsd32_charp) path;
152 syscallarg(netbsd32_statfsp_t) buf;
156 struct netbsd32_statfs s32
;
160 error
= namei_simple_user(SCARG_P32(uap
, path
),
161 NSM_FOLLOW_TRYEMULROOT
, &vp
);
167 if ((error
= VFS_STATVFS(mp
, sp
)) != 0)
169 sp
->f_flag
= mp
->mnt_flag
& MNT_VISFLAGMASK
;
170 compat_20_netbsd32_from_statvfs(sp
, &s32
);
171 return copyout(&s32
, SCARG_P32(uap
, buf
), sizeof(s32
));
175 compat_20_netbsd32_fstatfs(struct lwp
*l
, const struct compat_20_netbsd32_fstatfs_args
*uap
, register_t
*retval
)
179 syscallarg(netbsd32_statfsp_t) buf;
184 struct netbsd32_statfs s32
;
187 /* fd_getvnode() will use the descriptor for us */
188 if ((error
= fd_getvnode(SCARG(uap
, fd
), &fp
)) != 0)
190 mp
= ((struct vnode
*)fp
->f_data
)->v_mount
;
192 if ((error
= VFS_STATVFS(mp
, sp
)) != 0)
194 sp
->f_flag
= mp
->mnt_flag
& MNT_VISFLAGMASK
;
195 compat_20_netbsd32_from_statvfs(sp
, &s32
);
196 error
= copyout(&s32
, SCARG_P32(uap
, buf
), sizeof(s32
));
198 fd_putfile(SCARG(uap
, fd
));
203 compat_20_netbsd32_fhstatfs(struct lwp
*l
, const struct compat_20_netbsd32_fhstatfs_args
*uap
, register_t
*retval
)
206 syscallarg(const netbsd32_fhandlep_t) fhp;
207 syscallarg(struct statvfs *) buf;
209 struct compat_30_sys_fhstatvfs1_args ua
;
211 NETBSD32TOP_UAP(fhp
, const struct compat_30_fhandle
);
212 NETBSD32TOP_UAP(buf
, struct statvfs
);
214 NETBSD32TOP_UAP(flags
, int);
216 return (compat_30_sys_fhstatvfs1(l
, &ua
, retval
));