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