1 /*
2 * Copyright (c) 1995 Scott Bartram
3 * Copyright (c) 1995 Steven Wallace
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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
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/5.3/sys/i386/ibcs2/ibcs2_stat.c 118754 2003-08-10 23:26:16Z nectar $");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/namei.h>
35 #include <sys/file.h>
36 #include <sys/stat.h>
37 #include <sys/filedesc.h>
38 #include <sys/jail.h>
39 #include <sys/kernel.h>
40 #include <sys/mount.h>
41 #include <sys/vnode.h>
42 #include <sys/sysctl.h>
43 #include <sys/sysproto.h>
44
45 #include <i386/ibcs2/ibcs2_signal.h>
46 #include <i386/ibcs2/ibcs2_stat.h>
47 #include <i386/ibcs2/ibcs2_statfs.h>
48 #include <i386/ibcs2/ibcs2_proto.h>
49 #include <i386/ibcs2/ibcs2_util.h>
50 #include <i386/ibcs2/ibcs2_utsname.h>
51
52
53 static void bsd_stat2ibcs_stat(struct stat *, struct ibcs2_stat *);
54 static int cvt_statfs(struct statfs *, caddr_t, int);
55
56 static void
57 bsd_stat2ibcs_stat(st, st4)
58 struct stat *st;
59 struct ibcs2_stat *st4;
60 {
61 bzero(st4, sizeof(*st4));
62 st4->st_dev = (ibcs2_dev_t)st->st_dev;
63 st4->st_ino = (ibcs2_ino_t)st->st_ino;
64 st4->st_mode = (ibcs2_mode_t)st->st_mode;
65 st4->st_nlink= (ibcs2_nlink_t)st->st_nlink;
66 st4->st_uid = (ibcs2_uid_t)st->st_uid;
67 st4->st_gid = (ibcs2_gid_t)st->st_gid;
68 st4->st_rdev = (ibcs2_dev_t)st->st_rdev;
69 if (st->st_size < (quad_t)1 << 32)
70 st4->st_size = (ibcs2_off_t)st->st_size;
71 else
72 st4->st_size = -2;
73 st4->st_atim = (ibcs2_time_t)st->st_atime;
74 st4->st_mtim = (ibcs2_time_t)st->st_mtime;
75 st4->st_ctim = (ibcs2_time_t)st->st_ctime;
76 }
77
78 static int
79 cvt_statfs(sp, buf, len)
80 struct statfs *sp;
81 caddr_t buf;
82 int len;
83 {
84 struct ibcs2_statfs ssfs;
85
86 if (len < 0)
87 return (EINVAL);
88 else if (len > sizeof(ssfs))
89 len = sizeof(ssfs);
90 bzero(&ssfs, sizeof ssfs);
91 ssfs.f_fstyp = 0;
92 ssfs.f_bsize = sp->f_bsize;
93 ssfs.f_frsize = 0;
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;
98 ssfs.f_fname[0] = 0;
99 ssfs.f_fpack[0] = 0;
100 return copyout((caddr_t)&ssfs, buf, len);
101 }
102
103 int
104 ibcs2_statfs(td, uap)
105 struct thread *td;
106 struct ibcs2_statfs_args *uap;
107 {
108 register struct mount *mp;
109 register struct statfs *sp;
110 int error;
111 struct nameidata nd;
112 caddr_t sg = stackgap_init();
113
114 CHECKALTEXIST(td, &sg, uap->path);
115 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td);
116 if ((error = namei(&nd)) != 0)
117 return (error);
118 NDFREE(&nd, NDF_ONLY_PNBUF);
119 mp = nd.ni_vp->v_mount;
120 sp = &mp->mnt_stat;
121 vrele(nd.ni_vp);
122 if ((error = VFS_STATFS(mp, sp, td)) != 0)
123 return (error);
124 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
125 return cvt_statfs(sp, (caddr_t)uap->buf, uap->len);
126 }
127
128 int
129 ibcs2_fstatfs(td, uap)
130 struct thread *td;
131 struct ibcs2_fstatfs_args *uap;
132 {
133 struct file *fp;
134 struct mount *mp;
135 register struct statfs *sp;
136 int error;
137
138 if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0)
139 return (error);
140 mp = fp->f_vnode->v_mount;
141 sp = &mp->mnt_stat;
142 error = VFS_STATFS(mp, sp, td);
143 fdrop(fp, td);
144 if (error != 0)
145 return (error);
146 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
147 return cvt_statfs(sp, (caddr_t)uap->buf, uap->len);
148 }
149
150 int
151 ibcs2_stat(td, uap)
152 struct thread *td;
153 struct ibcs2_stat_args *uap;
154 {
155 struct stat st;
156 struct ibcs2_stat ibcs2_st;
157 struct stat_args cup;
158 int error;
159 caddr_t sg = stackgap_init();
160
161 CHECKALTEXIST(td, &sg, uap->path);
162 cup.path = uap->path;
163 cup.ub = stackgap_alloc(&sg, sizeof(st));
164
165 if ((error = stat(td, &cup)) != 0)
166 return error;
167
168 if ((error = copyin(cup.ub, &st, sizeof(st))) != 0)
169 return error;
170 bsd_stat2ibcs_stat(&st, &ibcs2_st);
171 return copyout((caddr_t)&ibcs2_st, (caddr_t)uap->st,
172 ibcs2_stat_len);
173 }
174
175 int
176 ibcs2_lstat(td, uap)
177 struct thread *td;
178 struct ibcs2_lstat_args *uap;
179 {
180 struct stat st;
181 struct ibcs2_stat ibcs2_st;
182 struct lstat_args cup;
183 int error;
184 caddr_t sg = stackgap_init();
185
186 CHECKALTEXIST(td, &sg, uap->path);
187 cup.path = uap->path;
188 cup.ub = stackgap_alloc(&sg, sizeof(st));
189
190 if ((error = lstat(td, &cup)) != 0)
191 return error;
192
193 if ((error = copyin(cup.ub, &st, sizeof(st))) != 0)
194 return error;
195 bsd_stat2ibcs_stat(&st, &ibcs2_st);
196 return copyout((caddr_t)&ibcs2_st, (caddr_t)uap->st,
197 ibcs2_stat_len);
198 }
199
200 int
201 ibcs2_fstat(td, uap)
202 struct thread *td;
203 struct ibcs2_fstat_args *uap;
204 {
205 struct stat st;
206 struct ibcs2_stat ibcs2_st;
207 struct fstat_args cup;
208 int error;
209 caddr_t sg = stackgap_init();
210
211 cup.fd = uap->fd;
212 cup.sb = stackgap_alloc(&sg, sizeof(st));
213
214 if ((error = fstat(td, &cup)) != 0)
215 return error;
216
217 if ((error = copyin(cup.sb, &st, sizeof(st))) != 0)
218 return error;
219 bsd_stat2ibcs_stat(&st, &ibcs2_st);
220 return copyout((caddr_t)&ibcs2_st, (caddr_t)uap->st,
221 ibcs2_stat_len);
222 }
223
224 int
225 ibcs2_utssys(td, uap)
226 struct thread *td;
227 struct ibcs2_utssys_args *uap;
228 {
229 switch (uap->flag) {
230 case 0: /* uname(2) */
231 {
232 char machine_name[9], *p;
233 struct ibcs2_utsname sut;
234 bzero(&sut, ibcs2_utsname_len);
235
236 strncpy(sut.sysname,
237 IBCS2_UNAME_SYSNAME, sizeof(sut.sysname) - 1);
238 strncpy(sut.release,
239 IBCS2_UNAME_RELEASE, sizeof(sut.release) - 1);
240 strncpy(sut.version,
241 IBCS2_UNAME_VERSION, sizeof(sut.version) - 1);
242 getcredhostname(td->td_ucred, machine_name,
243 sizeof(machine_name) - 1);
244 p = index(machine_name, '.');
245 if ( p )
246 *p = '\0';
247 strncpy(sut.nodename, machine_name, sizeof(sut.nodename) - 1);
248 strncpy(sut.machine, machine, sizeof(sut.machine) - 1);
249
250 DPRINTF(("IBCS2 uname: sys=%s rel=%s ver=%s node=%s mach=%s\n",
251 sut.sysname, sut.release, sut.version, sut.nodename,
252 sut.machine));
253 return copyout((caddr_t)&sut, (caddr_t)uap->a1,
254 ibcs2_utsname_len);
255 }
256
257 case 2: /* ustat(2) */
258 {
259 return ENOSYS; /* XXX - TODO */
260 }
261
262 default:
263 return ENOSYS;
264 }
265 }
Cache object: 843c52d802d45979208a32945c7059aa
|