1 /* $NetBSD: darwin_mount.c,v 1.19 2009/01/11 02:45:47 christos Exp $ */
4 * Copyright (c) 2003, 2008 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: darwin_mount.c,v 1.19 2009/01/11 02:45:47 christos Exp $");
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/mount.h>
40 #include <sys/vnode.h>
41 #include <sys/namei.h>
43 #include <sys/filedesc.h>
44 #include <sys/syscallargs.h>
46 #include <compat/sys/signal.h>
48 #include <compat/mach/mach_types.h>
49 #include <compat/mach/mach_vm.h>
51 #include <compat/darwin/darwin_types.h>
52 #include <compat/darwin/darwin_audit.h>
53 #include <compat/darwin/darwin_mount.h>
54 #include <compat/darwin/darwin_syscallargs.h>
56 static void native_to_darwin_statvfs(const struct statvfs
*,
57 struct darwin_statfs
*);
60 darwin_sys_fstatfs(struct lwp
*l
, const struct darwin_sys_fstatfs_args
*uap
, register_t
*retval
)
64 syscallarg(struct darwin_statfs *) buf;
69 struct darwin_statfs ds
;
72 /* fd_getvnode() will use the descriptor for us */
73 if ((error
= fd_getvnode(SCARG(uap
, fd
), &fp
)))
76 mp
= ((struct vnode
*)fp
->f_data
)->v_mount
;
79 if ((error
= VFS_STATVFS(mp
, bs
)) != 0)
82 native_to_darwin_statvfs(bs
, &ds
);
84 error
= copyout(&ds
, SCARG(uap
, buf
), sizeof(ds
));
87 fd_putfile(SCARG(uap
, fd
));
92 darwin_sys_getfsstat(struct lwp
*l
, const struct darwin_sys_getfsstat_args
*uap
, register_t
*retval
)
95 syscallarg(struct darwin_statfs *) buf;
96 syscallarg(long) bufsize;
97 syscallarg(int) flags;
99 struct mount
*mp
, *nmp
;
101 struct darwin_statfs ds
;
102 struct darwin_statfs
*uds
;
103 long count
, maxcount
, error
;
105 maxcount
= SCARG(uap
, bufsize
) / sizeof(struct darwin_statfs
);
106 uds
= SCARG(uap
, buf
);
108 for (count
= 0, mp
= mountlist
.cqh_first
;
109 mp
!= (void *)&mountlist
; mp
= nmp
) {
110 nmp
= mp
->mnt_list
.cqe_next
;
112 if ((uds
!= NULL
) && (count
< maxcount
)) {
115 if (((SCARG(uap
, flags
) & MNT_NOWAIT
) == 0 ||
116 (SCARG(uap
, flags
) & MNT_WAIT
)) &&
117 (error
= VFS_STATVFS(mp
, bs
)))
120 native_to_darwin_statvfs(bs
, &ds
);
122 if ((error
= copyout(&ds
, uds
, sizeof(*uds
))) != 0)
129 if ((uds
!= NULL
) && (count
> maxcount
))
138 darwin_sys_statfs(struct lwp
*l
, const struct darwin_sys_statfs_args
*uap
, register_t
*retval
)
141 syscallarg(char *) path;
142 syscallarg(struct statfs *) buf;
146 struct darwin_statfs ds
;
150 error
= namei_simple_user(SCARG(uap
, path
),
151 NSM_FOLLOW_TRYEMULROOT
, &vp
);
159 if ((error
= VFS_STATVFS(mp
, bs
)) != 0)
162 native_to_darwin_statvfs(bs
, &ds
);
164 error
= copyout(&ds
, SCARG(uap
, buf
), sizeof(ds
));
171 native_to_darwin_statvfs(const struct statvfs
*bs
, struct darwin_statfs
*ds
)
174 long sflags
= bs
->f_flag
& MNT_VISFLAGMASK
;
176 if (sflags
|MNT_RDONLY
)
177 dflags
|= DARWIN_MNT_RDONLY
;
178 if (sflags
|MNT_SYNCHRONOUS
)
179 dflags
|= DARWIN_MNT_SYNCHRONOUS
;
180 if (sflags
|MNT_NOEXEC
)
181 dflags
|= DARWIN_MNT_NOEXEC
;
182 if (sflags
|MNT_NOSUID
)
183 dflags
|= DARWIN_MNT_NOSUID
;
184 if (sflags
|MNT_NODEV
)
185 dflags
|= DARWIN_MNT_NODEV
;
186 if (sflags
|MNT_UNION
)
187 dflags
|= DARWIN_MNT_UNION
;
188 if (sflags
|MNT_ASYNC
)
189 dflags
|= DARWIN_MNT_ASYNC
;
190 if (sflags
|MNT_IGNORE
)
191 dflags
|= DARWIN_MNT_DONTBROWSE
;
194 ds
->f_oflags
= dflags
& 0xffff;
195 ds
->f_bsize
= bs
->f_bsize
;
196 ds
->f_iosize
= bs
->f_iosize
;
197 ds
->f_blocks
= bs
->f_blocks
;
198 ds
->f_bfree
= bs
->f_bfree
;
199 ds
->f_bavail
= bs
->f_bavail
;
200 ds
->f_files
= bs
->f_files
;
201 ds
->f_ffree
= bs
->f_ffree
;
202 (void)memcpy(&ds
->f_fsid
, &bs
->f_fsidx
, sizeof(ds
->f_fsid
));
203 ds
->f_owner
= bs
->f_owner
;
206 ds
->f_flags
= dflags
;
207 (void)strlcpy(ds
->f_fstypename
, bs
->f_fstypename
, DARWIN_MFSNAMELEN
);
208 (void)strlcpy(ds
->f_mntonname
, bs
->f_mntonname
, DARWIN_MNAMELEN
);
209 (void)strlcpy(ds
->f_mntfromname
, bs
->f_mntfromname
, DARWIN_MNAMELEN
);