ibcs2_stat.c revision 11394
1/*
2 * Copyright (c) 1995 Scott Bartram
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 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 *    derived from this software without specific prior written permission
15 *
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, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <sys/param.h>
29#include <sys/systm.h>
30#include <sys/namei.h>
31#include <sys/proc.h>
32#include <sys/file.h>
33#include <sys/stat.h>
34#include <sys/filedesc.h>
35#include <sys/ioctl.h>
36#include <sys/kernel.h>
37#include <sys/mount.h>
38#include <sys/malloc.h>
39#include <sys/vnode.h>
40#include <sys/syscallargs.h>
41
42#include <vm/vm.h>
43
44#include <compat/ibcs2/ibcs2_types.h>
45#include <compat/ibcs2/ibcs2_fcntl.h>
46#include <compat/ibcs2/ibcs2_signal.h>
47#include <compat/ibcs2/ibcs2_stat.h>
48#include <compat/ibcs2/ibcs2_statfs.h>
49#include <compat/ibcs2/ibcs2_syscallargs.h>
50#include <compat/ibcs2/ibcs2_ustat.h>
51#include <compat/ibcs2/ibcs2_util.h>
52#include <compat/ibcs2/ibcs2_utsname.h>
53
54
55static void
56bsd_stat2ibcs_stat(st, st4)
57	struct ostat *st;
58	struct ibcs2_stat *st4;
59{
60	bzero(st4, sizeof(*st4));
61	st4->st_dev = (ibcs2_dev_t)st->st_dev;
62	st4->st_ino = (ibcs2_ino_t)st->st_ino;
63	st4->st_mode = (ibcs2_mode_t)st->st_mode;
64	st4->st_nlink = (ibcs2_nlink_t)st->st_nlink;
65	st4->st_uid = (ibcs2_uid_t)st->st_uid;
66	st4->st_gid = (ibcs2_gid_t)st->st_gid;
67	st4->st_rdev = (ibcs2_dev_t)st->st_rdev;
68	st4->st_size = (ibcs2_off_t)st->st_size;
69	st4->st_atim = (ibcs2_time_t)st->st_atime;
70	st4->st_mtim = (ibcs2_time_t)st->st_mtime;
71	st4->st_ctim = (ibcs2_time_t)st->st_ctime;
72}
73
74static int
75cvt_statfs(sp, buf, len)
76	struct statfs *sp;
77	caddr_t buf;
78	int len;
79{
80	struct ibcs2_statfs ssfs;
81
82	bzero(&ssfs, sizeof ssfs);
83	ssfs.f_fstyp = 0;
84	ssfs.f_bsize = sp->f_bsize;
85	ssfs.f_frsize = 0;
86	ssfs.f_blocks = sp->f_blocks;
87	ssfs.f_bfree = sp->f_bfree;
88	ssfs.f_files = sp->f_files;
89	ssfs.f_ffree = sp->f_ffree;
90	ssfs.f_fname[0] = 0;
91	ssfs.f_fpack[0] = 0;
92	return copyout((caddr_t)&ssfs, buf, len);
93}
94
95int
96ibcs2_statfs(p, uap, retval)
97	struct proc *p;
98	struct ibcs2_statfs_args *uap;
99	int *retval;
100{
101	register struct mount *mp;
102	register struct statfs *sp;
103	int error;
104	struct nameidata nd;
105	caddr_t sg = stackgap_init();
106
107	CHECKALTEXIST(p, &sg, SCARG(uap, path));
108	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
109	if (error = namei(&nd))
110		return (error);
111	mp = nd.ni_vp->v_mount;
112	sp = &mp->mnt_stat;
113	vrele(nd.ni_vp);
114	if (error = VFS_STATFS(mp, sp, p))
115		return (error);
116	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
117	return cvt_statfs(sp, (caddr_t)SCARG(uap, buf), SCARG(uap, len));
118}
119
120int
121ibcs2_fstatfs(p, uap, retval)
122	struct proc *p;
123	struct ibcs2_fstatfs_args *uap;
124	int *retval;
125{
126	struct file *fp;
127	struct mount *mp;
128	register struct statfs *sp;
129	int error;
130
131	if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp))
132		return (error);
133	mp = ((struct vnode *)fp->f_data)->v_mount;
134	sp = &mp->mnt_stat;
135	if (error = VFS_STATFS(mp, sp, p))
136		return (error);
137	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
138	return cvt_statfs(sp, (caddr_t)SCARG(uap, buf), SCARG(uap, len));
139}
140
141int
142ibcs2_stat(p, uap, retval)
143	struct proc *p;
144	struct ibcs2_stat_args *uap;
145	int *retval;
146{
147	struct ostat st;
148	struct ibcs2_stat ibcs2_st;
149	struct compat_43_stat_args cup;
150	int error;
151	caddr_t sg = stackgap_init();
152
153	CHECKALTEXIST(p, &sg, SCARG(uap, path));
154	SCARG(&cup, path) = SCARG(uap, path);
155	SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
156	if (error = compat_43_stat(p, &cup, retval))
157		return error;
158	if (error = copyin(SCARG(&cup, ub), &st, sizeof(st)))
159		return error;
160	bsd_stat2ibcs_stat(&st, &ibcs2_st);
161	return copyout((caddr_t)&ibcs2_st, (caddr_t)SCARG(uap, st),
162		       ibcs2_stat_len);
163}
164
165int
166ibcs2_lstat(p, uap, retval)
167	struct proc *p;
168	struct ibcs2_lstat_args *uap;
169	int *retval;
170{
171	struct ostat st;
172	struct ibcs2_stat ibcs2_st;
173	struct compat_43_lstat_args cup;
174	int error;
175	caddr_t sg = stackgap_init();
176
177	CHECKALTEXIST(p, &sg, SCARG(uap, path));
178	SCARG(&cup, path) = SCARG(uap, path);
179	SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
180	if (error = compat_43_lstat(p, &cup, retval))
181		return error;
182	if (error = copyin(SCARG(&cup, ub), &st, sizeof(st)))
183		return error;
184	bsd_stat2ibcs_stat(&st, &ibcs2_st);
185	return copyout((caddr_t)&ibcs2_st, (caddr_t)SCARG(uap, st),
186		       ibcs2_stat_len);
187}
188
189int
190ibcs2_fstat(p, uap, retval)
191	struct proc *p;
192	struct ibcs2_fstat_args *uap;
193	int *retval;
194{
195	struct ostat st;
196	struct ibcs2_stat ibcs2_st;
197	struct compat_43_fstat_args cup;
198	int error;
199	caddr_t sg = stackgap_init();
200
201	SCARG(&cup, fd) = SCARG(uap, fd);
202	SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(st));
203	if (error = compat_43_fstat(p, &cup, retval))
204		return error;
205	if (error = copyin(SCARG(&cup, sb), &st, sizeof(st)))
206		return error;
207	bsd_stat2ibcs_stat(&st, &ibcs2_st);
208	return copyout((caddr_t)&ibcs2_st, (caddr_t)SCARG(uap, st),
209		       ibcs2_stat_len);
210}
211
212int
213ibcs2_utssys(p, uap, retval)
214	struct proc *p;
215	struct ibcs2_utssys_args *uap;
216	int *retval;
217{
218	switch (SCARG(uap, flag)) {
219	case 0:			/* uname(2) */
220	{
221		struct ibcs2_utsname sut;
222		extern char ostype[], machine[], osrelease[];
223
224		bzero(&sut, ibcs2_utsname_len);
225		bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1);
226		bcopy(hostname, sut.nodename, sizeof(sut.nodename));
227		sut.nodename[sizeof(sut.nodename)-1] = '\0';
228		bcopy(osrelease, sut.release, sizeof(sut.release) - 1);
229		bcopy("1", sut.version, sizeof(sut.version) - 1);
230		bcopy(machine, sut.machine, sizeof(sut.machine) - 1);
231
232		return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, a1),
233			       ibcs2_utsname_len);
234	}
235
236	case 2:			/* ustat(2) */
237	{
238		return ENOSYS;	/* XXX - TODO */
239	}
240
241	default:
242		return ENOSYS;
243	}
244}
245