1 /* $NetBSD: ibcs2_stat.c,v 1.46 2008/06/24 11:18:15 ad Exp $ */
3 * Copyright (c) 1995, 1998 Scott Bartram
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
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.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: ibcs2_stat.c,v 1.46 2008/06/24 11:18:15 ad Exp $");
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/namei.h>
38 #include <sys/filedesc.h>
39 #include <sys/ioctl.h>
40 #include <sys/kernel.h>
41 #include <sys/mount.h>
42 #include <sys/vnode.h>
43 #include <sys/syscallargs.h>
44 #include <sys/vfs_syscalls.h>
46 #include <compat/ibcs2/ibcs2_types.h>
47 #include <compat/ibcs2/ibcs2_fcntl.h>
48 #include <compat/ibcs2/ibcs2_signal.h>
49 #include <compat/ibcs2/ibcs2_stat.h>
50 #include <compat/ibcs2/ibcs2_statfs.h>
51 #include <compat/ibcs2/ibcs2_syscallargs.h>
52 #include <compat/ibcs2/ibcs2_ustat.h>
53 #include <compat/ibcs2/ibcs2_util.h>
54 #include <compat/ibcs2/ibcs2_utsname.h>
56 static void bsd_stat2ibcs_stat(struct stat
*, struct ibcs2_stat
*);
57 static int cvt_statfs(struct statvfs
*, void *, int);
58 static int cvt_statvfs(struct statvfs
*, void *, int);
61 bsd_stat2ibcs_stat(struct stat
*st
, struct ibcs2_stat
*st4
)
63 memset(st4
, 0, sizeof(*st4
));
64 st4
->st_dev
= (ibcs2_dev_t
)st
->st_dev
;
65 st4
->st_ino
= (ibcs2_ino_t
)st
->st_ino
;
66 st4
->st_mode
= (ibcs2_mode_t
)st
->st_mode
;
67 if (st
->st_nlink
>= (1 << 15))
68 st4
->st_nlink
= (1 << 15) - 1;
70 st4
->st_nlink
= (ibcs2_nlink_t
)st
->st_nlink
;
71 st4
->st_uid
= (ibcs2_uid_t
)st
->st_uid
;
72 st4
->st_gid
= (ibcs2_gid_t
)st
->st_gid
;
73 st4
->st_rdev
= (ibcs2_dev_t
)st
->st_rdev
;
74 st4
->st_size
= (ibcs2_off_t
)st
->st_size
;
75 st4
->st_atim
= (ibcs2_time_t
)st
->st_atime
;
76 st4
->st_mtim
= (ibcs2_time_t
)st
->st_mtime
;
77 st4
->st_ctim
= (ibcs2_time_t
)st
->st_ctime
;
81 cvt_statfs(struct statvfs
*sp
, void *tbuf
, int len
)
83 struct ibcs2_statfs ssfs
;
87 if (len
> sizeof(ssfs
))
90 memset(&ssfs
, 0, sizeof ssfs
);
92 ssfs
.f_bsize
= sp
->f_bsize
;
93 ssfs
.f_frsize
= sp
->f_frsize
;
94 ssfs
.f_blocks
= sp
->f_blocks
;
95 ssfs
.f_bfree
= sp
->f_bfree
;
96 ssfs
.f_files
= sp
->f_files
;
97 ssfs
.f_ffree
= sp
->f_ffree
;
100 return copyout((void *)&ssfs
, tbuf
, len
);
104 cvt_statvfs(struct statvfs
*sp
, void *tbuf
, int len
)
106 struct ibcs2_statvfs ssvfs
;
110 if (len
> sizeof(ssvfs
))
113 memset(&ssvfs
, 0, sizeof ssvfs
);
114 ssvfs
.f_bsize
= sp
->f_bsize
;
115 ssvfs
.f_frsize
= sp
->f_frsize
;
116 ssvfs
.f_blocks
= sp
->f_blocks
;
117 ssvfs
.f_bfree
= sp
->f_bfree
;
118 ssvfs
.f_bavail
= sp
->f_bavail
;
119 ssvfs
.f_files
= sp
->f_files
;
120 ssvfs
.f_ffree
= sp
->f_ffree
;
121 ssvfs
.f_favail
= sp
->f_favail
;
122 ssvfs
.f_fsid
= sp
->f_fsidx
.__fsid_val
[0];
123 strncpy(ssvfs
.f_basetype
, sp
->f_fstypename
, 15);
125 ssvfs
.f_namemax
= PATH_MAX
;
127 return copyout((void *)&ssvfs
, tbuf
, len
);
131 ibcs2_sys_statfs(struct lwp
*l
, const struct ibcs2_sys_statfs_args
*uap
, register_t
*retval
)
134 syscallarg(const char *) path;
135 syscallarg(struct ibcs2_statfs *) buf;
137 syscallarg(int) fstype;
144 error
= namei_simple_user(SCARG(uap
, path
),
145 NSM_FOLLOW_TRYEMULROOT
, &vp
);
151 if ((error
= VFS_STATVFS(mp
, sp
)) != 0)
153 sp
->f_flag
= mp
->mnt_flag
& MNT_VISFLAGMASK
;
154 return cvt_statfs(sp
, (void *)SCARG(uap
, buf
), SCARG(uap
, len
));
158 ibcs2_sys_fstatfs(struct lwp
*l
, const struct ibcs2_sys_fstatfs_args
*uap
, register_t
*retval
)
162 syscallarg(struct ibcs2_statfs *) buf;
164 syscallarg(int) fstype;
171 /* fd_getvnode() will use the descriptor for us */
172 if ((error
= fd_getvnode(SCARG(uap
, fd
), &fp
)) != 0)
174 mp
= ((struct vnode
*)fp
->f_data
)->v_mount
;
176 if ((error
= VFS_STATVFS(mp
, sp
)) != 0)
178 sp
->f_flag
= mp
->mnt_flag
& MNT_VISFLAGMASK
;
179 error
= cvt_statfs(sp
, (void *)SCARG(uap
, buf
), SCARG(uap
, len
));
181 fd_putfile(SCARG(uap
, fd
));
186 ibcs2_sys_statvfs(struct lwp
*l
, const struct ibcs2_sys_statvfs_args
*uap
, register_t
*retval
)
189 syscallarg(const char *) path;
190 syscallarg(struct ibcs2_statvfs *) buf;
197 error
= namei_simple_user(SCARG(uap
, path
),
198 NSM_FOLLOW_TRYEMULROOT
, &vp
);
204 if ((error
= VFS_STATVFS(mp
, sp
)) != 0)
206 sp
->f_flag
= mp
->mnt_flag
& MNT_VISFLAGMASK
;
207 return cvt_statvfs(sp
, (void *)SCARG(uap
, buf
),
208 sizeof(struct ibcs2_statvfs
));
212 ibcs2_sys_fstatvfs(struct lwp
*l
, const struct ibcs2_sys_fstatvfs_args
*uap
, register_t
*retval
)
216 syscallarg(struct ibcs2_statvfs *) buf;
223 /* fd_getvnode() will use the descriptor for us */
224 if ((error
= fd_getvnode(SCARG(uap
, fd
), &fp
)) != 0)
226 mp
= ((struct vnode
*)fp
->f_data
)->v_mount
;
228 if ((error
= VFS_STATVFS(mp
, sp
)) != 0)
230 sp
->f_flag
= mp
->mnt_flag
& MNT_VISFLAGMASK
;
231 error
= cvt_statvfs(sp
, SCARG(uap
, buf
), sizeof(struct ibcs2_statvfs
));
233 fd_putfile(SCARG(uap
, fd
));
238 ibcs2_sys_stat(struct lwp
*l
, const struct ibcs2_sys_stat_args
*uap
, register_t
*retval
)
241 syscallarg(const char *) path;
242 syscallarg(struct ibcs2_stat *) st;
245 struct ibcs2_stat ibcs2_st
;
248 error
= do_sys_stat(SCARG(uap
, path
), FOLLOW
, &sb
);
252 bsd_stat2ibcs_stat(&sb
, &ibcs2_st
);
253 return copyout(&ibcs2_st
, SCARG(uap
, st
), sizeof (ibcs2_st
));
257 ibcs2_sys_lstat(struct lwp
*l
, const struct ibcs2_sys_lstat_args
*uap
, register_t
*retval
)
260 syscallarg(const char *) path;
261 syscallarg(struct ibcs2_stat *) st;
264 struct ibcs2_stat ibcs2_st
;
267 error
= do_sys_stat(SCARG(uap
, path
), NOFOLLOW
, &sb
);
271 bsd_stat2ibcs_stat(&sb
, &ibcs2_st
);
272 return copyout((void *)&ibcs2_st
, (void *)SCARG(uap
, st
),
277 ibcs2_sys_fstat(struct lwp
*l
, const struct ibcs2_sys_fstat_args
*uap
, register_t
*retval
)
281 syscallarg(struct ibcs2_stat *) st;
284 struct ibcs2_stat ibcs2_st
;
287 error
= do_sys_fstat(SCARG(uap
, fd
), &sb
);
291 bsd_stat2ibcs_stat(&sb
, &ibcs2_st
);
292 return copyout(&ibcs2_st
, SCARG(uap
, st
), sizeof (ibcs2_st
));
296 ibcs2_sys_utssys(struct lwp
*l
, const struct ibcs2_sys_utssys_args
*uap
, register_t
*retval
)
301 syscallarg(int) flag;
304 switch (SCARG(uap
, flag
)) {
305 case 0: /* uname(struct utsname *) */
307 struct ibcs2_utsname sut
;
309 memset(&sut
, 0, ibcs2_utsname_len
);
310 memcpy(sut
.sysname
, ostype
, sizeof(sut
.sysname
) - 1);
311 memcpy(sut
.nodename
, hostname
, sizeof(sut
.nodename
));
312 sut
.nodename
[sizeof(sut
.nodename
)-1] = '\0';
313 memcpy(sut
.release
, osrelease
, sizeof(sut
.release
) - 1);
314 strlcpy(sut
.version
, "1", sizeof(sut
.version
));
315 memcpy(sut
.machine
, machine
, sizeof(sut
.machine
) - 1);
317 return copyout((void *)&sut
, (void *)SCARG(uap
, a1
),
321 case 2: /* ustat(dev_t, struct ustat *) */
323 struct ibcs2_ustat xu
;
325 xu
.f_tfree
= 20000; /* XXX fixme */
329 return copyout((void *)&xu
, (void *)SCARG(uap
, a2
),