cxgbe/t4_tom: Read the chip's DDP page sizes and save them in a
[freebsd-src.git] / sys / i386 / ibcs2 / ibcs2_stat.c
blob55d14af99b52290662bf71b31e08acc5917fbc7d
1 /*-
2 * Copyright (c) 1995 Scott Bartram
3 * Copyright (c) 1995 Steven Wallace
4 * All rights reserved.
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
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 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/namei.h>
35 #include <sys/fcntl.h>
36 #include <sys/file.h>
37 #include <sys/stat.h>
38 #include <sys/filedesc.h>
39 #include <sys/jail.h>
40 #include <sys/kernel.h>
41 #include <sys/mount.h>
42 #include <sys/malloc.h>
43 #include <sys/vnode.h>
44 #include <sys/syscallsubr.h>
45 #include <sys/sysctl.h>
46 #include <sys/sysproto.h>
48 #include <i386/ibcs2/ibcs2_signal.h>
49 #include <i386/ibcs2/ibcs2_stat.h>
50 #include <i386/ibcs2/ibcs2_statfs.h>
51 #include <i386/ibcs2/ibcs2_proto.h>
52 #include <i386/ibcs2/ibcs2_util.h>
53 #include <i386/ibcs2/ibcs2_utsname.h>
56 static void bsd_stat2ibcs_stat(struct stat *, struct ibcs2_stat *);
57 static int cvt_statfs(struct statfs *, caddr_t, int);
59 static void
60 bsd_stat2ibcs_stat(st, st4)
61 struct stat *st;
62 struct ibcs2_stat *st4;
64 bzero(st4, sizeof(*st4));
65 st4->st_dev = (ibcs2_dev_t)st->st_dev;
66 st4->st_ino = (ibcs2_ino_t)st->st_ino;
67 st4->st_mode = (ibcs2_mode_t)st->st_mode;
68 st4->st_nlink= (ibcs2_nlink_t)st->st_nlink;
69 st4->st_uid = (ibcs2_uid_t)st->st_uid;
70 st4->st_gid = (ibcs2_gid_t)st->st_gid;
71 st4->st_rdev = (ibcs2_dev_t)st->st_rdev;
72 if (st->st_size < (quad_t)1 << 32)
73 st4->st_size = (ibcs2_off_t)st->st_size;
74 else
75 st4->st_size = -2;
76 st4->st_atim = (ibcs2_time_t)st->st_atim.tv_sec;
77 st4->st_mtim = (ibcs2_time_t)st->st_mtim.tv_sec;
78 st4->st_ctim = (ibcs2_time_t)st->st_ctim.tv_sec;
81 static int
82 cvt_statfs(sp, buf, len)
83 struct statfs *sp;
84 caddr_t buf;
85 int len;
87 struct ibcs2_statfs ssfs;
89 if (len < 0)
90 return (EINVAL);
91 else if (len > sizeof(ssfs))
92 len = sizeof(ssfs);
93 bzero(&ssfs, sizeof ssfs);
94 ssfs.f_fstyp = 0;
95 ssfs.f_bsize = sp->f_bsize;
96 ssfs.f_frsize = 0;
97 ssfs.f_blocks = sp->f_blocks;
98 ssfs.f_bfree = sp->f_bfree;
99 ssfs.f_files = sp->f_files;
100 ssfs.f_ffree = sp->f_ffree;
101 ssfs.f_fname[0] = 0;
102 ssfs.f_fpack[0] = 0;
103 return copyout((caddr_t)&ssfs, buf, len);
107 ibcs2_statfs(td, uap)
108 struct thread *td;
109 struct ibcs2_statfs_args *uap;
111 struct statfs sf;
112 char *path;
113 int error;
115 CHECKALTEXIST(td, uap->path, &path);
116 error = kern_statfs(td, path, UIO_SYSSPACE, &sf);
117 free(path, M_TEMP);
118 if (error)
119 return (error);
120 return cvt_statfs(&sf, (caddr_t)uap->buf, uap->len);
124 ibcs2_fstatfs(td, uap)
125 struct thread *td;
126 struct ibcs2_fstatfs_args *uap;
128 struct statfs sf;
129 int error;
131 error = kern_fstatfs(td, uap->fd, &sf);
132 if (error)
133 return (error);
134 return cvt_statfs(&sf, (caddr_t)uap->buf, uap->len);
138 ibcs2_stat(td, uap)
139 struct thread *td;
140 struct ibcs2_stat_args *uap;
142 struct ibcs2_stat ibcs2_st;
143 struct stat st;
144 char *path;
145 int error;
147 CHECKALTEXIST(td, uap->path, &path);
149 error = kern_statat(td, 0, AT_FDCWD, path, UIO_SYSSPACE, &st, NULL);
150 free(path, M_TEMP);
151 if (error)
152 return (error);
153 bsd_stat2ibcs_stat(&st, &ibcs2_st);
154 return copyout((caddr_t)&ibcs2_st, (caddr_t)uap->st,
155 ibcs2_stat_len);
159 ibcs2_lstat(td, uap)
160 struct thread *td;
161 struct ibcs2_lstat_args *uap;
163 struct ibcs2_stat ibcs2_st;
164 struct stat st;
165 char *path;
166 int error;
168 CHECKALTEXIST(td, uap->path, &path);
170 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, path,
171 UIO_SYSSPACE, &st, NULL);
172 free(path, M_TEMP);
173 if (error)
174 return (error);
175 bsd_stat2ibcs_stat(&st, &ibcs2_st);
176 return copyout((caddr_t)&ibcs2_st, (caddr_t)uap->st,
177 ibcs2_stat_len);
181 ibcs2_fstat(td, uap)
182 struct thread *td;
183 struct ibcs2_fstat_args *uap;
185 struct ibcs2_stat ibcs2_st;
186 struct stat st;
187 int error;
189 error = kern_fstat(td, uap->fd, &st);
190 if (error)
191 return (error);
192 bsd_stat2ibcs_stat(&st, &ibcs2_st);
193 return copyout((caddr_t)&ibcs2_st, (caddr_t)uap->st,
194 ibcs2_stat_len);
198 ibcs2_utssys(td, uap)
199 struct thread *td;
200 struct ibcs2_utssys_args *uap;
202 switch (uap->flag) {
203 case 0: /* uname(2) */
205 char machine_name[9], *p;
206 struct ibcs2_utsname sut;
207 bzero(&sut, ibcs2_utsname_len);
209 strncpy(sut.sysname,
210 IBCS2_UNAME_SYSNAME, sizeof(sut.sysname) - 1);
211 strncpy(sut.release,
212 IBCS2_UNAME_RELEASE, sizeof(sut.release) - 1);
213 strncpy(sut.version,
214 IBCS2_UNAME_VERSION, sizeof(sut.version) - 1);
215 getcredhostname(td->td_ucred, machine_name,
216 sizeof(machine_name) - 1);
217 p = strchr(machine_name, '.');
218 if ( p )
219 *p = '\0';
220 strncpy(sut.nodename, machine_name, sizeof(sut.nodename) - 1);
221 strncpy(sut.machine, machine, sizeof(sut.machine) - 1);
223 DPRINTF(("IBCS2 uname: sys=%s rel=%s ver=%s node=%s mach=%s\n",
224 sut.sysname, sut.release, sut.version, sut.nodename,
225 sut.machine));
226 return copyout((caddr_t)&sut, (caddr_t)uap->a1,
227 ibcs2_utsname_len);
230 case 2: /* ustat(2) */
232 return ENOSYS; /* XXX - TODO */
235 default:
236 return ENOSYS;