From 537eb26ac226d2ada661314dc340a05949ba1cde Mon Sep 17 00:00:00 2001 From: christos Date: Thu, 16 Oct 1997 23:50:36 +0000 Subject: [PATCH] add stat12 compatibility calls and rename ostat to stat43 --- sys/compat/common/vfs_syscalls_12.c | 145 +++++++++++++++++++++++++++- sys/compat/common/vfs_syscalls_43.c | 18 ++-- 2 files changed, 153 insertions(+), 10 deletions(-) diff --git a/sys/compat/common/vfs_syscalls_12.c b/sys/compat/common/vfs_syscalls_12.c index 997eb6fd88c0..742daf915500 100644 --- a/sys/compat/common/vfs_syscalls_12.c +++ b/sys/compat/common/vfs_syscalls_12.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls_12.c,v 1.1 1997/10/10 01:47:02 fvdl Exp $ */ +/* $NetBSD: vfs_syscalls_12.c,v 1.2 1997/10/16 23:50:36 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +57,37 @@ #include +static void cvtstat __P((struct stat *, struct stat12 *)); + +/* + * Convert from an old to a new stat structure. + */ +static void +cvtstat(st, ost) + struct stat *st; + struct stat12 *ost; +{ + + ost->st_dev = st->st_dev; + ost->st_ino = st->st_ino; + ost->st_mode = st->st_mode; + ost->st_nlink = st->st_nlink; + if (st->st_nlink >= (1 << 15)) + ost->st_nlink = (1 << 15) - 1; + else + ost->st_nlink = st->st_nlink; + ost->st_uid = st->st_uid; + ost->st_gid = st->st_gid; + ost->st_rdev = st->st_rdev; + ost->st_size = st->st_size; + ost->st_atime = st->st_atime; + ost->st_mtime = st->st_mtime; + ost->st_ctime = st->st_ctime; + ost->st_blksize = st->st_blksize; + ost->st_blocks = st->st_blocks; + ost->st_flags = st->st_flags; + ost->st_gen = st->st_gen; +} /* * Read a block of directory entries in a file system independent format. */ @@ -89,3 +121,114 @@ compat_12_sys_getdirentries(p, v, retval) *retval = done; return error; } + +/* + * Get file status; this version follows links. + */ +/* ARGSUSED */ +int +compat_12_sys_stat(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct compat_12_sys_stat_args /* { + syscallarg(char *) path; + syscallarg(struct stat12 *) ub; + } */ *uap = v; + struct stat sb; + struct stat12 osb; + int error; + struct nameidata nd; + + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, + SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + error = vn_stat(nd.ni_vp, &sb, p); + vput(nd.ni_vp); + if (error) + return (error); + cvtstat(&sb, &osb); + error = copyout((caddr_t)&osb, (caddr_t)SCARG(uap, ub), sizeof (osb)); + return (error); +} + + +/* + * Get file status; this version does not follow links. + */ +/* ARGSUSED */ +int +compat_12_sys_lstat(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct compat_12_sys_lstat_args /* { + syscallarg(char *) path; + syscallarg(struct stat12 *) ub; + } */ *uap = v; + struct stat sb; + struct stat12 osb; + int error; + struct nameidata nd; + + NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF, UIO_USERSPACE, + SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + error = vn_stat(nd.ni_vp, &sb, p); + vput(nd.ni_vp); + if (error) + return (error); + cvtstat(&sb, &osb); + error = copyout(&osb, SCARG(uap, ub), sizeof (osb)); + return (error); +} + + +/* + * Return status information about a file descriptor. + */ +/* ARGSUSED */ +int +compat_12_sys_fstat(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct compat_12_sys_fstat_args /* { + syscallarg(int) fd; + syscallarg(struct stat12 *) sb; + } */ *uap = v; + int fd = SCARG(uap, fd); + register struct filedesc *fdp = p->p_fd; + register struct file *fp; + struct stat ub; + struct stat12 oub; + int error; + + if ((u_int)fd >= fdp->fd_nfiles || + (fp = fdp->fd_ofiles[fd]) == NULL) + return (EBADF); + switch (fp->f_type) { + + case DTYPE_VNODE: + error = vn_stat((struct vnode *)fp->f_data, &ub, p); + break; + + case DTYPE_SOCKET: + error = soo_stat((struct socket *)fp->f_data, &ub); + break; + + default: + panic("compat_12_sys_fstat"); + /*NOTREACHED*/ + } + cvtstat(&ub, &oub); + if (error == 0) + error = copyout((caddr_t)&oub, (caddr_t)SCARG(uap, sb), + sizeof (oub)); + return (error); +} diff --git a/sys/compat/common/vfs_syscalls_43.c b/sys/compat/common/vfs_syscalls_43.c index 1506f5d45ea1..9d50a2291acc 100644 --- a/sys/compat/common/vfs_syscalls_43.c +++ b/sys/compat/common/vfs_syscalls_43.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls_43.c,v 1.7 1997/10/10 13:03:32 fvdl Exp $ */ +/* $NetBSD: vfs_syscalls_43.c,v 1.8 1997/10/16 23:50:39 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -62,7 +62,7 @@ #include #include -static void cvtstat __P((struct stat *, struct ostat *)); +static void cvtstat __P((struct stat *, struct stat43 *)); /* * Convert from an old to a new stat structure. @@ -70,7 +70,7 @@ static void cvtstat __P((struct stat *, struct ostat *)); static void cvtstat(st, ost) struct stat *st; - struct ostat *ost; + struct stat43 *ost; { ost->st_dev = st->st_dev; @@ -105,10 +105,10 @@ compat_43_sys_stat(p, v, retval) { register struct compat_43_sys_stat_args /* { syscallarg(char *) path; - syscallarg(struct ostat *) ub; + syscallarg(struct stat43 *) ub; } */ *uap = v; struct stat sb; - struct ostat osb; + struct stat43 osb; int error; struct nameidata nd; @@ -138,10 +138,10 @@ compat_43_sys_lstat(p, v, retval) { register struct compat_43_sys_lstat_args /* { syscallarg(char *) path; - syscallarg(struct ostat *) ub; + syscallarg(struct stat43 *) ub; } */ *uap = v; struct stat sb; - struct ostat osb; + struct stat43 osb; int error; struct nameidata nd; @@ -171,13 +171,13 @@ compat_43_sys_fstat(p, v, retval) { register struct compat_43_sys_fstat_args /* { syscallarg(int) fd; - syscallarg(struct ostat *) sb; + syscallarg(struct stat43 *) sb; } */ *uap = v; int fd = SCARG(uap, fd); register struct filedesc *fdp = p->p_fd; register struct file *fp; struct stat ub; - struct ostat oub; + struct stat43 oub; int error; if ((u_int)fd >= fdp->fd_nfiles ||