Home | History | Annotate | Line # | Download | only in alpha
linux_osf1.c revision 1.3.6.1
      1 /*	$NetBSD: linux_osf1.c,v 1.3.6.1 2022/08/03 11:11:33 martin Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1999 Christopher G. Demetriou.  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. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *      This product includes software developed by Christopher G. Demetriou
     17  *	for the NetBSD Project.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 __KERNEL_RCSID(0, "$NetBSD: linux_osf1.c,v 1.3.6.1 2022/08/03 11:11:33 martin Exp $");
     35 
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/namei.h>
     39 #include <sys/proc.h>
     40 #include <sys/file.h>
     41 #include <sys/filedesc.h>
     42 #include <sys/kernel.h>
     43 #include <sys/mount.h>
     44 #include <sys/vnode.h>
     45 #include <sys/wait.h>
     46 #include <sys/select.h>
     47 #include <sys/syscallargs.h>
     48 #include <sys/vfs_syscalls.h>
     49 
     50 #include <machine/alpha.h>
     51 #include <machine/cpuconf.h>
     52 #include <machine/rpb.h>
     53 #include <machine/fpu.h>
     54 
     55 #include <compat/common/compat_util.h>
     56 #include <compat/linux/common/linux_types.h>
     57 #include <compat/linux/common/linux_signal.h>
     58 #include <compat/linux/arch/alpha/linux_signal.h>
     59 #include <compat/linux/arch/alpha/linux_osf1.h>
     60 #include <compat/linux/linux_syscallargs.h>
     61 
     62 #include <net/if.h>
     63 #include <netinet/in.h>
     64 
     65 #include <nfs/rpcv2.h>
     66 #include <nfs/nfsproto.h>
     67 #include <nfs/nfs.h>
     68 #include <nfs/nfsmount.h>
     69 
     70 #include <ufs/ufs/quota.h>
     71 #include <ufs/ufs/ufsmount.h>
     72 
     73 #include <machine/vmparam.h>
     74 
     75 const struct emul_flags_xtab osf1_wait_options_xtab[] = {
     76     {	OSF1_WNOHANG,		OSF1_WNOHANG,		WNOHANG		},
     77     {	OSF1_WUNTRACED,		OSF1_WUNTRACED,		WUNTRACED	},
     78     {	0								}
     79 };
     80 
     81 const struct emul_flags_xtab osf1_nfs_mount_flags_xtab[] = {
     82     {	OSF1_NFSMNT_SOFT,	OSF1_NFSMNT_SOFT,	NFSMNT_SOFT,	},
     83     {	OSF1_NFSMNT_WSIZE,	OSF1_NFSMNT_WSIZE,	NFSMNT_WSIZE,	},
     84     {	OSF1_NFSMNT_RSIZE,	OSF1_NFSMNT_RSIZE,	NFSMNT_RSIZE,	},
     85     {	OSF1_NFSMNT_TIMEO,	OSF1_NFSMNT_TIMEO,	NFSMNT_TIMEO,	},
     86     {	OSF1_NFSMNT_RETRANS,	OSF1_NFSMNT_RETRANS,	NFSMNT_RETRANS,	},
     87 #if 0 /* no equivalent; needs special handling, see below */
     88     {	OSF1_NFSMNT_HOSTNAME,	OSF1_NFSMNT_HOSTNAME,	???,		},
     89 #endif
     90     {	OSF1_NFSMNT_INT,	OSF1_NFSMNT_INT,	NFSMNT_INT,	},
     91     {	OSF1_NFSMNT_NOCONN,	OSF1_NFSMNT_NOCONN,	NFSMNT_NOCONN,	},
     92 #if 0 /* no equivalents */
     93     {	OSF1_NFSMNT_NOAC,	OSF1_NFSMNT_NOAC,	???,		},
     94     {	OSF1_NFSMNT_ACREGMIN,	OSF1_NFSMNT_ACREGMIN,	???,		},
     95     {	OSF1_NFSMNT_ACREGMAX,	OSF1_NFSMNT_ACREGMAX,	???,		},
     96     {	OSF1_NFSMNT_ACDIRMIN,	OSF1_NFSMNT_ACDIRMIN,	???,		},
     97     {	OSF1_NFSMNT_ACDIRMAX,	OSF1_NFSMNT_ACDIRMAX,	???,		},
     98     {	OSF1_NFSMNT_NOCTO,	OSF1_NFSMNT_NOCTO,	???,		},
     99     {	OSF1_NFSMNT_POSIX,	OSF1_NFSMNT_POSIX,	???,		},
    100     {	OSF1_NFSMNT_AUTO,	OSF1_NFSMNT_AUTO,	???,		},
    101     {	OSF1_NFSMNT_SEC,	OSF1_NFSMNT_SEC,	???,		},
    102     {	OSF1_NFSMNT_TCP,	OSF1_NFSMNT_TCP,	???,		},
    103     {	OSF1_NFSMNT_PROPLIST,	OSF1_NFSMNT_PROPLIST,	???,		},
    104 #endif
    105     {	0								}
    106 };
    107 
    108 static void
    109 osf1_cvt_rusage_from_native(const struct rusage *ru, struct osf1_rusage *oru)
    110 {
    111 
    112 	memset(oru, 0, sizeof(*oru));
    113 
    114 	oru->ru_utime.tv_sec = ru->ru_utime.tv_sec;
    115 	oru->ru_utime.tv_usec = ru->ru_utime.tv_usec;
    116 
    117 	oru->ru_stime.tv_sec = ru->ru_stime.tv_sec;
    118 	oru->ru_stime.tv_usec = ru->ru_stime.tv_usec;
    119 
    120 	oru->ru_maxrss = ru->ru_maxrss;
    121 	oru->ru_ixrss = ru->ru_ixrss;
    122 	oru->ru_idrss = ru->ru_idrss;
    123 	oru->ru_isrss = ru->ru_isrss;
    124 	oru->ru_minflt = ru->ru_minflt;
    125 	oru->ru_majflt = ru->ru_majflt;
    126 	oru->ru_nswap = ru->ru_nswap;
    127 	oru->ru_inblock = ru->ru_inblock;
    128 	oru->ru_oublock = ru->ru_oublock;
    129 	oru->ru_msgsnd = ru->ru_msgsnd;
    130 	oru->ru_msgrcv = ru->ru_msgrcv;
    131 	oru->ru_nsignals = ru->ru_nsignals;
    132 	oru->ru_nvcsw = ru->ru_nvcsw;
    133 	oru->ru_nivcsw = ru->ru_nivcsw;
    134 }
    135 
    136 static void
    137 osf1_cvt_statfs_from_native(const struct statvfs *bsfs, struct osf1_statfs *osfs)
    138 {
    139 
    140 	memset(osfs, 0, sizeof(*osfs));
    141 	if (!strncmp(MOUNT_FFS, bsfs->f_fstypename, sizeof(bsfs->f_fstypename)))
    142 		osfs->f_type = OSF1_MOUNT_UFS;
    143 	else if (!strncmp(MOUNT_NFS, bsfs->f_fstypename, sizeof(bsfs->f_fstypename)))
    144 		osfs->f_type = OSF1_MOUNT_NFS;
    145 	else if (!strncmp(MOUNT_MFS, bsfs->f_fstypename, sizeof(bsfs->f_fstypename)))
    146 		osfs->f_type = OSF1_MOUNT_MFS;
    147 	else
    148 		/* uh oh...  XXX = PC, CDFS, PROCFS, etc. */
    149 		osfs->f_type = OSF1_MOUNT_ADDON;
    150 	osfs->f_flags = bsfs->f_flag;		/* XXX translate */
    151 	osfs->f_fsize = bsfs->f_frsize;
    152 	osfs->f_bsize = bsfs->f_bsize;
    153 	osfs->f_blocks = bsfs->f_blocks;
    154 	osfs->f_bfree = bsfs->f_bfree;
    155 	osfs->f_bavail = bsfs->f_bavail;
    156 	osfs->f_files = bsfs->f_files;
    157 	osfs->f_ffree = bsfs->f_ffree;
    158 	memcpy(&osfs->f_fsid, &bsfs->f_fsidx, sizeof osfs->f_fsid);
    159 	/* osfs->f_spare zeroed above */
    160 	memcpy(osfs->f_mntonname, bsfs->f_mntonname, sizeof osfs->f_mntonname);
    161 	memcpy(osfs->f_mntfromname, bsfs->f_mntfromname,
    162 	    sizeof osfs->f_mntfromname);
    163 	/* XXX osfs->f_xxx should be filled in... */
    164 }
    165 
    166 /* --------------------------------------------------------------------- */
    167 
    168 int
    169 linux_sys_osf1_wait4(struct lwp *l, const struct linux_sys_osf1_wait4_args *uap, register_t *retval)
    170 {
    171 	struct osf1_rusage osf1_rusage;
    172 	struct rusage netbsd_rusage;
    173 	unsigned long leftovers;
    174 	int error, status;
    175 	int options = SCARG(uap, options);
    176 	int pid = SCARG(uap, pid);
    177 
    178 	/* translate options */
    179 	options = emul_flags_translate(osf1_wait_options_xtab,
    180 	    options, &leftovers);
    181 	if (leftovers != 0)
    182 		return (EINVAL);
    183 
    184 	error = do_sys_wait(&pid, &status, options,
    185 	    SCARG(uap, rusage) != NULL ? &netbsd_rusage : NULL);
    186 
    187 	retval[0] = pid;
    188 	if (pid == 0)
    189 		return error;
    190 
    191 	if (SCARG(uap, rusage)) {
    192 		osf1_cvt_rusage_from_native(&netbsd_rusage, &osf1_rusage);
    193 		error = copyout(&osf1_rusage, SCARG(uap, rusage),
    194 		    sizeof osf1_rusage);
    195 	}
    196 
    197 	if (error == 0 && SCARG(uap, status))
    198 		error = copyout(&status, SCARG(uap, status), sizeof(status));
    199 
    200 	return error;
    201 }
    202 
    203 #define	OSF1_MNT_WAIT		0x1
    204 #define	OSF1_MNT_NOWAIT		0x2
    205 
    206 #define	OSF1_MNT_FORCE		0x1
    207 #define	OSF1_MNT_NOFORCE	0x2
    208 
    209 /* acceptable flags for various calls */
    210 #define	OSF1_GETFSSTAT_FLAGS	(OSF1_MNT_WAIT|OSF1_MNT_NOWAIT)
    211 #define	OSF1_MOUNT_FLAGS	0xffffffff			/* XXX */
    212 #define	OSF1_UNMOUNT_FLAGS	(OSF1_MNT_FORCE|OSF1_MNT_NOFORCE)
    213 
    214 static int
    215 osf1_mount_mfs(struct lwp *l, const struct linux_sys_osf1_mount_args *uap)
    216 {
    217 	struct osf1_mfs_args osf_ma;
    218 	struct mfs_args bsd_ma;
    219 	int error;
    220 	register_t dummy;
    221 
    222 	if ((error = copyin(SCARG(uap, data), &osf_ma, sizeof osf_ma)))
    223 		return error;
    224 
    225 	memset(&bsd_ma, 0, sizeof bsd_ma);
    226 	bsd_ma.fspec = osf_ma.name;
    227 	/* XXX export args */
    228 	bsd_ma.base = osf_ma.base;
    229 	bsd_ma.size = osf_ma.size;
    230 
    231 	return do_sys_mount(l, "mfs", UIO_SYSSPACE, SCARG(uap, path),
    232 	    SCARG(uap, flags), &bsd_ma, UIO_SYSSPACE, sizeof bsd_ma, &dummy);
    233 }
    234 
    235 static int
    236 osf1_mount_nfs(struct lwp *l, const struct linux_sys_osf1_mount_args *uap)
    237 {
    238 	struct osf1_nfs_args osf_na;
    239 	struct nfs_args bsd_na;
    240 	int error;
    241 	unsigned long leftovers;
    242 	register_t dummy;
    243 
    244 	if ((error = copyin(SCARG(uap, data), &osf_na, sizeof osf_na)))
    245 		return error;
    246 
    247 	memset(&bsd_na, 0, sizeof bsd_na);
    248 	bsd_na.addr = (struct sockaddr *)osf_na.addr;
    249 	bsd_na.addrlen = sizeof (struct sockaddr_in);
    250 	bsd_na.fh = osf_na.fh;
    251 
    252         /* translate flags */
    253         bsd_na.flags = emul_flags_translate(osf1_nfs_mount_flags_xtab,
    254             osf_na.flags, &leftovers);
    255 	if (leftovers & OSF1_NFSMNT_HOSTNAME) {
    256 		leftovers &= ~OSF1_NFSMNT_HOSTNAME;
    257 		bsd_na.hostname = osf_na.hostname;
    258 	} else {
    259 		/* XXX FILL IN HOST NAME WITH IPADDR? */
    260 	}
    261 	if (leftovers & OSF1_NFSMNT_TCP) {
    262 		leftovers &= ~OSF1_NFSMNT_TCP;
    263 		bsd_na.sotype = SOCK_DGRAM;
    264 		bsd_na.proto = 0;
    265 	} else {
    266 		bsd_na.sotype = SOCK_STREAM;
    267 		bsd_na.proto = 0;
    268 	}
    269         if (leftovers != 0)
    270                 return (EINVAL);
    271 
    272 	/* copy structure elements based on flags */
    273 	if (bsd_na.flags & NFSMNT_WSIZE)
    274 		bsd_na.wsize = osf_na.wsize;
    275 	if (bsd_na.flags & NFSMNT_RSIZE)
    276 		bsd_na.rsize = osf_na.rsize;
    277 	if (bsd_na.flags & NFSMNT_TIMEO)
    278 		bsd_na.timeo = osf_na.timeo;
    279 	if (bsd_na.flags & NFSMNT_RETRANS)
    280 		bsd_na.retrans = osf_na.retrans;
    281 
    282 	return do_sys_mount(l, "nfs", UIO_SYSSPACE, SCARG(uap, path),
    283 	    SCARG(uap, flags), &bsd_na, UIO_SYSSPACE, sizeof bsd_na, &dummy);
    284 }
    285 
    286 int
    287 linux_sys_osf1_mount(struct lwp *l, const struct linux_sys_osf1_mount_args *uap, register_t *retval)
    288 {
    289 
    290 	if (SCARG(uap, flags) & ~OSF1_MOUNT_FLAGS)
    291 		return (EINVAL);
    292 
    293 	/* XXX - xlate flags */
    294 
    295 	switch (SCARG(uap, type)) {
    296 	case OSF1_MOUNT_NFS:
    297 		return osf1_mount_nfs(l, uap);
    298 		break;
    299 
    300 	case OSF1_MOUNT_MFS:
    301 		return osf1_mount_mfs(l, uap);
    302 
    303 	default:
    304 		return (EINVAL);
    305 	}
    306 }
    307 
    308 int
    309 linux_sys_osf1_set_program_attributes(struct lwp *l, const struct linux_sys_osf1_set_program_attributes_args *uap, register_t *retval)
    310 {
    311 	struct proc *p = l->l_proc;
    312 	segsz_t tsize, dsize;
    313 
    314 	tsize = btoc(SCARG(uap, tsize));
    315 	dsize = btoc(SCARG(uap, dsize));
    316 
    317 	if (dsize > p->p_rlimit[RLIMIT_DATA].rlim_cur)
    318 		return (ENOMEM);
    319 	if (tsize > MAXTSIZ)
    320 		return (ENOMEM);
    321 
    322 	/* XXXSMP unlocked */
    323 	p->p_vmspace->vm_taddr = SCARG(uap, taddr);
    324 	p->p_vmspace->vm_tsize = tsize;
    325 	p->p_vmspace->vm_daddr = SCARG(uap, daddr);
    326 	p->p_vmspace->vm_dsize = dsize;
    327 
    328 	return (0);
    329 }
    330 
    331 int
    332 linux_sys_osf1_setitimer(struct lwp *l, const struct linux_sys_osf1_setitimer_args *uap, register_t *retval)
    333 {
    334 	struct osf1_itimerval o_itv, o_oitv;
    335 	struct itimerval b_itv, b_oitv;
    336 	int which;
    337 	int error;
    338 
    339 	switch (SCARG(uap, which)) {
    340 	case OSF1_ITIMER_REAL:
    341 		which = ITIMER_REAL;
    342 		break;
    343 
    344 	case OSF1_ITIMER_VIRTUAL:
    345 		which = ITIMER_VIRTUAL;
    346 		break;
    347 
    348 	case OSF1_ITIMER_PROF:
    349 		which = ITIMER_PROF;
    350 		break;
    351 
    352 	default:
    353 		return (EINVAL);
    354 	}
    355 
    356 	/* get the OSF/1 itimerval argument */
    357 	error = copyin(SCARG(uap, itv), &o_itv, sizeof o_itv);
    358 	if (error != 0)
    359 		return error;
    360 
    361 	/* fill in and the NetBSD timeval */
    362 	memset(&b_itv, 0, sizeof b_itv);
    363 	b_itv.it_interval.tv_sec = o_itv.it_interval.tv_sec;
    364 	b_itv.it_interval.tv_usec = o_itv.it_interval.tv_usec;
    365 	b_itv.it_value.tv_sec = o_itv.it_value.tv_sec;
    366 	b_itv.it_value.tv_usec = o_itv.it_value.tv_usec;
    367 
    368 	if (SCARG(uap, oitv) != NULL) {
    369 		dogetitimer(l->l_proc, which, &b_oitv);
    370 		if (error)
    371 			return error;
    372 	}
    373 
    374 	error = dosetitimer(l->l_proc, which, &b_itv);
    375 
    376 	if (error == 0 || SCARG(uap, oitv) == NULL)
    377 		return error;
    378 
    379 	/* fill in and copy out the old timeval */
    380 	memset(&o_oitv, 0, sizeof o_oitv);
    381 	o_oitv.it_interval.tv_sec = b_oitv.it_interval.tv_sec;
    382 	o_oitv.it_interval.tv_usec = b_oitv.it_interval.tv_usec;
    383 	o_oitv.it_value.tv_sec = b_oitv.it_value.tv_sec;
    384 	o_oitv.it_value.tv_usec = b_oitv.it_value.tv_usec;
    385 
    386 	return copyout(&o_oitv, SCARG(uap, oitv), sizeof o_oitv);
    387 }
    388 
    389 int
    390 linux_sys_osf1_select(struct lwp *l, const struct linux_sys_osf1_select_args *uap,
    391     register_t *retval)
    392 {
    393 	struct osf1_timeval otv;
    394 	struct timespec ats, *ts = NULL;
    395 	int error;
    396 
    397 	if (SCARG(uap, tv)) {
    398 		/* get the OSF/1 timeval argument */
    399 		error = copyin(SCARG(uap, tv), &otv, sizeof otv);
    400 		if (error != 0)
    401 			return error;
    402 
    403 		ats.tv_sec = otv.tv_sec;
    404 		ats.tv_nsec = otv.tv_usec * 1000;
    405 		ts = &ats;
    406 	}
    407 
    408 	return selcommon(retval, SCARG(uap, nd), SCARG(uap, in),
    409 	    SCARG(uap, ou), SCARG(uap, ex), ts, NULL);
    410 }
    411 
    412 int
    413 linux_sys_osf1_gettimeofday(struct lwp *l, const struct linux_sys_osf1_gettimeofday_args *uap, register_t *retval)
    414 {
    415 	struct osf1_timeval otv;
    416 	struct osf1_timezone otz;
    417 	struct timeval tv;
    418 	int error;
    419 
    420 	microtime(&tv);
    421 	memset(&otv, 0, sizeof otv);
    422 	otv.tv_sec = tv.tv_sec;
    423 	otv.tv_usec = tv.tv_usec;
    424 	error = copyout(&otv, SCARG(uap, tv), sizeof otv);
    425 
    426 	if (error == 0 && SCARG(uap, tzp) != NULL) {
    427 		memset(&otz, 0, sizeof otz);
    428 		error = copyout(&otz, SCARG(uap, tzp), sizeof otz);
    429 	}
    430 	return (error);
    431 }
    432 
    433 int
    434 linux_sys_osf1_getrusage(struct lwp *l, const struct linux_sys_osf1_getrusage_args *uap, register_t *retval)
    435 {
    436 	int error, who;
    437 	struct osf1_rusage osf1_rusage;
    438 	struct rusage ru;
    439 	struct proc *p = l->l_proc;
    440 
    441 
    442 	switch (SCARG(uap, who)) {
    443 	case OSF1_RUSAGE_SELF:
    444 		who = RUSAGE_SELF;
    445 		break;
    446 
    447 	case OSF1_RUSAGE_CHILDREN:
    448 		who = RUSAGE_CHILDREN;
    449 		break;
    450 
    451 	case OSF1_RUSAGE_THREAD:		/* XXX not supported */
    452 	default:
    453 		return EINVAL;
    454 	}
    455 
    456 	error = getrusage1(p, who, &ru);
    457 	if (error != 0)
    458 		return error;
    459 
    460 	osf1_cvt_rusage_from_native(&ru, &osf1_rusage);
    461 
    462 	return copyout(&osf1_rusage, SCARG(uap, rusage), sizeof osf1_rusage);
    463 }
    464 
    465 int
    466 linux_sys_osf1_settimeofday(struct lwp *l, const struct linux_sys_osf1_settimeofday_args *uap, register_t *retval)
    467 {
    468 	struct osf1_timeval otv;
    469 	struct timeval tv, *tvp;
    470 	int error = 0;
    471 
    472 	if (SCARG(uap, tv) == NULL)
    473 		tvp = NULL;
    474 	else {
    475 		/* get the OSF/1 timeval argument */
    476 		error = copyin(SCARG(uap, tv), &otv, sizeof otv);
    477 		if (error != 0)
    478 			return error;
    479 
    480 		tv.tv_sec = otv.tv_sec;
    481 		tv.tv_usec = otv.tv_usec;
    482 		tvp = &tv;
    483 	}
    484 
    485 	/* NetBSD ignores the timezone field */
    486 
    487 	return settimeofday1(tvp, false, (const void *)SCARG(uap, tzp), l, true);
    488 }
    489 
    490 int
    491 linux_sys_osf1_utimes(struct lwp *l, const struct linux_sys_osf1_utimes_args *uap, register_t *retval)
    492 {
    493 	struct osf1_timeval otv;
    494 	struct timeval tv[2], *tvp;
    495 	int error;
    496 
    497 	if (SCARG(uap, tptr) == NULL)
    498 		tvp = NULL;
    499 	else {
    500 		/* get the OSF/1 timeval argument */
    501 		error = copyin(SCARG(uap, tptr), &otv, sizeof otv);
    502 		if (error != 0)
    503 			return error;
    504 
    505 		/* fill in and copy out the NetBSD timeval */
    506 		tv[0].tv_sec = otv.tv_sec;
    507 		tv[0].tv_usec = otv.tv_usec;
    508 		/* Set access and modified to the same time */
    509 		tv[1].tv_sec = otv.tv_sec;
    510 		tv[1].tv_usec = otv.tv_usec;
    511 		tvp = tv;
    512 	}
    513 
    514 	return do_sys_utimes(l, NULL, SCARG(uap, path), FOLLOW,
    515 			    tvp, UIO_SYSSPACE);
    516 }
    517 
    518 int
    519 linux_sys_osf1_statfs(struct lwp *l, const struct linux_sys_osf1_statfs_args *uap, register_t *retval)
    520 {
    521 	struct mount *mp;
    522 	struct statvfs *sp;
    523 	struct osf1_statfs osfs;
    524 	int error;
    525 	struct vnode *vp;
    526 
    527 	error = namei_simple_user(SCARG(uap, path),
    528 				NSM_FOLLOW_TRYEMULROOT, &vp);
    529 	if (error != 0)
    530 		return (error);
    531 	mp = vp->v_mount;
    532 	sp = &mp->mnt_stat;
    533 	vrele(vp);
    534 	if ((error = VFS_STATVFS(mp, sp)))
    535 		return (error);
    536 	sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
    537 	osf1_cvt_statfs_from_native(sp, &osfs);
    538 	return copyout(&osfs, SCARG(uap, buf), uimin(sizeof osfs,
    539 	    SCARG(uap, len)));
    540 }
    541 
    542 int
    543 linux_sys_osf1_fstatfs(struct lwp *l, const struct linux_sys_osf1_fstatfs_args *uap, register_t *retval)
    544 {
    545 	file_t *fp;
    546 	struct mount *mp;
    547 	struct statvfs *sp;
    548 	struct osf1_statfs osfs;
    549 	int error;
    550 
    551 	/* fd_getvnode() will use the descriptor for us */
    552 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)))
    553 		return (error);
    554 	mp = fp->f_vnode->v_mount;
    555 	sp = &mp->mnt_stat;
    556 	if ((error = VFS_STATVFS(mp, sp)))
    557 		goto out;
    558 	sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
    559 	osf1_cvt_statfs_from_native(sp, &osfs);
    560 	error = copyout(&osfs, SCARG(uap, buf), uimin(sizeof osfs,
    561 	    SCARG(uap, len)));
    562  out:
    563  	fd_putfile(SCARG(uap, fd));
    564 	return (error);
    565 }
    566 
    567 int
    568 linux_sys_osf1_sysinfo(struct lwp *l, const struct linux_sys_osf1_sysinfo_args *uap, register_t *retval)
    569 {
    570 	const char *string;
    571 	size_t slen;
    572 	int error;
    573 
    574 	error = 0;
    575 	switch (SCARG(uap, cmd)) {
    576 	case OSF1_SI_SYSNAME:
    577 		string = ostype;
    578 		break;
    579 
    580 	case OSF1_SI_HOSTNAME:
    581 		string = hostname;
    582 		break;
    583 
    584 	case OSF1_SI_RELEASE:
    585 		string = osrelease;
    586 		break;
    587 
    588 	case OSF1_SI_VERSION:
    589 		goto should_handle;
    590 
    591 	case OSF1_SI_MACHINE:
    592 		string = MACHINE;
    593 		break;
    594 
    595 	case OSF1_SI_ARCHITECTURE:
    596 		string = MACHINE_ARCH;
    597 		break;
    598 
    599 	case OSF1_SI_HW_SERIAL:
    600 		string = "666";			/* OSF/1 emulation?  YES! */
    601 		break;
    602 
    603 	case OSF1_SI_HW_PROVIDER:
    604 		string = "unknown";
    605 		break;
    606 
    607 	case OSF1_SI_SRPC_DOMAIN:
    608 		goto dont_care;
    609 
    610 	case OSF1_SI_SET_HOSTNAME:
    611 		goto should_handle;
    612 
    613 	case OSF1_SI_SET_SYSNAME:
    614 		goto should_handle;
    615 
    616 	case OSF1_SI_SET_SRPC_DOMAIN:
    617 		goto dont_care;
    618 
    619 	default:
    620 should_handle:
    621 		printf("osf1_sys_sysinfo(%d, %p, 0x%lx)\n", SCARG(uap, cmd),
    622 		    SCARG(uap, buf), SCARG(uap,len));
    623 dont_care:
    624 		return (EINVAL);
    625 	};
    626 
    627 	slen = strlen(string) + 1;
    628 	if (SCARG(uap, buf)) {
    629 		error = copyout(string, SCARG(uap, buf),
    630 				uimin(slen, SCARG(uap, len)));
    631 		if (!error && (SCARG(uap, len) > 0) && (SCARG(uap, len) < slen))
    632 			error = ustore_char(SCARG(uap, buf)
    633 					    + SCARG(uap, len) - 1, 0);
    634 	}
    635 	if (!error)
    636 		retval[0] = slen;
    637 
    638 	return (error);
    639 }
    640 
    641 int
    642 linux_sys_osf1_usleep_thread(struct lwp *l, const struct linux_sys_osf1_usleep_thread_args *uap, register_t *retval)
    643 {
    644 	struct osf1_timeval otv, endotv;
    645 	struct timeval tv, ntv, endtv;
    646 	u_long ticks;
    647 	int error;
    648 
    649 	if ((error = copyin(SCARG(uap, sleep), &otv, sizeof otv)))
    650 		return (error);
    651 	tv.tv_sec = otv.tv_sec;
    652 	tv.tv_usec = otv.tv_usec;
    653 
    654 	ticks = howmany((u_long)tv.tv_sec * 1000000 + tv.tv_usec, tick);
    655 	if (ticks == 0)
    656 		ticks = 1;
    657 
    658 	getmicrotime(&tv);
    659 
    660 	tsleep(l, PUSER|PCATCH, "uslpthrd", ticks);	/* XXX */
    661 
    662 	if (SCARG(uap, slept) != NULL) {
    663 		getmicrotime(&ntv);
    664 		timersub(&ntv, &tv, &endtv);
    665 		if (endtv.tv_sec < 0 || endtv.tv_usec < 0)
    666 			endtv.tv_sec = endtv.tv_usec = 0;
    667 
    668 		memset(&endotv, 0, sizeof(endotv));
    669 		endotv.tv_sec = endtv.tv_sec;
    670 		endotv.tv_usec = endtv.tv_usec;
    671 		error = copyout(&endotv, SCARG(uap, slept), sizeof endotv);
    672 	}
    673 	return (error);
    674 }
    675 
    676 int
    677 linux_sys_osf1_getsysinfo(struct lwp *l, const struct linux_sys_osf1_getsysinfo_args *uap, register_t *retval)
    678 {
    679 	extern int ncpus;
    680 	int error;
    681 	int unit;
    682 	long percpu;
    683 	long proctype;
    684 	u_int64_t fpflags;
    685 	struct osf1_cpu_info cpuinfo;
    686 	const void *data;
    687 	size_t datalen;
    688 
    689 	error = 0;
    690 
    691 	switch(SCARG(uap, op))
    692 	{
    693 	case OSF_GET_MAX_UPROCS:
    694 		data = &maxproc;
    695 		datalen = sizeof(maxproc);
    696 		break;
    697 	case OSF_GET_PHYSMEM:
    698 		data = &physmem;
    699 		datalen = sizeof(physmem);
    700 		break;
    701 	case OSF_GET_MAX_CPU:
    702 	case OSF_GET_CPUS_IN_BOX:
    703 		data = &ncpus;
    704 		datalen = sizeof(ncpus);
    705 		break;
    706 	case OSF_GET_IEEE_FP_CONTROL:
    707 		if (((fpflags = alpha_read_fp_c(l)) & IEEE_INHERIT) != 0) {
    708 			fpflags |= 1ULL << 63;
    709 			fpflags &= ~IEEE_INHERIT;
    710 		}
    711 		data = &fpflags;
    712 		datalen = sizeof(fpflags);
    713 		break;
    714 	case OSF_GET_CPU_INFO:
    715 		memset(&cpuinfo, 0, sizeof(cpuinfo));
    716 #ifdef __alpha__
    717 		unit = alpha_pal_whami();
    718 #else
    719 		unit = 0; /* XXX */
    720 #endif
    721 		cpuinfo.current_cpu = unit;
    722 		cpuinfo.cpus_in_box = ncpus;
    723 		cpuinfo.cpu_type = LOCATE_PCS(hwrpb, unit)->pcs_proc_type;
    724 		cpuinfo.ncpus = ncpus;
    725 		cpuinfo.cpus_present = ncpus;
    726 		cpuinfo.cpus_running = ncpus;
    727 		cpuinfo.cpu_binding = 1;
    728 		cpuinfo.cpu_ex_binding = 0;
    729 		cpuinfo.mhz = hwrpb->rpb_cc_freq / 1000000;
    730 		data = &cpuinfo;
    731 		datalen = sizeof(cpuinfo);
    732 		break;
    733 	case OSF_GET_PROC_TYPE:
    734 #ifdef __alpha__
    735 		unit = alpha_pal_whami();
    736 		proctype = LOCATE_PCS(hwrpb, unit)->pcs_proc_type;
    737 #else
    738 		proctype = 0;	/* XXX */
    739 #endif
    740 		data = &proctype;
    741 		datalen = sizeof(percpu);
    742 		break;
    743 	case OSF_GET_HWRPB: /* note -- osf/1 doesn't have rpb_tbhint[8] */
    744 		data = hwrpb;
    745 		datalen = hwrpb->rpb_size;
    746 		break;
    747 	case OSF_GET_PLATFORM_NAME:
    748 		data = platform.model;
    749 		datalen = strlen(platform.model) + 1;
    750 		break;
    751 	default:
    752 		printf("osf1_getsysinfo called with unknown op=%ld\n",
    753 		       SCARG(uap, op));
    754 		/* return EINVAL; */
    755 		return 0;
    756 	}
    757 
    758 	if (SCARG(uap, nbytes) < datalen)
    759 		return (EINVAL);
    760 	error = copyout(data, SCARG(uap, buffer), datalen);
    761 	if (!error)
    762 		retval[0] = 1;
    763 	return (error);
    764 }
    765 
    766 int
    767 linux_sys_osf1_setsysinfo(struct lwp *l, const struct linux_sys_osf1_setsysinfo_args *uap, register_t *retval)
    768 {
    769 	u_int64_t temp;
    770 	int error;
    771 
    772 	error = 0;
    773 
    774 	switch(SCARG(uap, op)) {
    775 	case OSF_SET_IEEE_FP_CONTROL:
    776 
    777 		if ((error = copyin(SCARG(uap, buffer), &temp, sizeof(temp))))
    778 			break;
    779 		if (temp >> 63 != 0)
    780 			temp |= IEEE_INHERIT;
    781 		alpha_write_fp_c(l, temp);
    782 		break;
    783 	default:
    784 		uprintf("osf1_setsysinfo called with op=%ld\n", SCARG(uap, op));
    785 		//error = EINVAL;
    786 	}
    787 	retval[0] = 0;
    788 	return (error);
    789 }
    790