Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add fhopen, fhstat, fhstatfs syscalls. Also move getfh i...
details: https://anonhg.NetBSD.org/src/rev/70d449e4395b
branches: trunk
changeset: 474153:70d449e4395b
user: wrstuden <wrstuden%NetBSD.org@localhost>
date: Tue Jun 29 22:18:47 1999 +0000
description:
Add fhopen, fhstat, fhstatfs syscalls. Also move getfh in from the nfs
syscall code.
diffstat:
sys/kern/init_sysent.c | 15 +-
sys/kern/vfs_syscalls.c | 238 +++++++++++++++++++++++++++++++++++++++++++++++-
sys/nfs/nfs_syscalls.c | 42 +--------
sys/sys/mount.h | 10 +-
4 files changed, 255 insertions(+), 50 deletions(-)
diffs (truncated from 383 to 300 lines):
diff -r a7189fb45553 -r 70d449e4395b sys/kern/init_sysent.c
--- a/sys/kern/init_sysent.c Tue Jun 29 22:17:39 1999 +0000
+++ b/sys/kern/init_sysent.c Tue Jun 29 22:18:47 1999 +0000
@@ -1,10 +1,10 @@
-/* $NetBSD: init_sysent.c,v 1.107 1999/06/15 23:29:17 thorpej Exp $ */
+/* $NetBSD: init_sysent.c,v 1.108 1999/06/29 22:18:47 wrstuden Exp $ */
/*
* System call switch table.
*
* DO NOT EDIT-- this file is automatically generated.
- * created from NetBSD: syscalls.master,v 1.93 1999/06/15 23:28:16 thorpej Exp
+ * created from NetBSD: syscalls.master,v 1.94 1999/06/29 22:15:31 wrstuden Exp
*/
#include "opt_ktrace.h"
@@ -391,13 +391,8 @@
sys_nosys }, /* 159 = unimplemented */
{ 0, 0,
sys_nosys }, /* 160 = unimplemented */
-#if defined(NFS) || defined(NFSSERVER) || !defined(_KERNEL)
{ 2, s(struct sys_getfh_args),
sys_getfh }, /* 161 = getfh */
-#else
- { 0, 0,
- sys_nosys }, /* 161 = excluded getfh */
-#endif
{ 2, s(struct compat_09_sys_getdomainname_args),
compat_09(sys_getdomainname) }, /* 162 = compat_09 ogetdomainname */
{ 2, s(struct compat_09_sys_setdomainname_args),
@@ -757,5 +752,11 @@
sys___getcwd }, /* 296 = __getcwd */
{ 1, s(struct sys_fchroot_args),
sys_fchroot }, /* 297 = fchroot */
+ { 2, s(struct sys_fhopen_args),
+ sys_fhopen }, /* 298 = fhopen */
+ { 2, s(struct sys_fhstat_args),
+ sys_fhstat }, /* 299 = fhstat */
+ { 2, s(struct sys_fhstatfs_args),
+ sys_fhstatfs }, /* 300 = fhstatfs */
};
diff -r a7189fb45553 -r 70d449e4395b sys/kern/vfs_syscalls.c
--- a/sys/kern/vfs_syscalls.c Tue Jun 29 22:17:39 1999 +0000
+++ b/sys/kern/vfs_syscalls.c Tue Jun 29 22:18:47 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_syscalls.c,v 1.136 1999/05/06 17:11:04 christos Exp $ */
+/* $NetBSD: vfs_syscalls.c,v 1.137 1999/06/29 22:18:47 wrstuden Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -1001,6 +1001,242 @@
}
/*
+ * Get file handle system call
+ */
+int
+sys_getfh(p, v, retval)
+ struct proc *p;
+ register void *v;
+ register_t *retval;
+{
+ register struct sys_getfh_args /* {
+ syscallarg(char *) fname;
+ syscallarg(fhandle_t *) fhp;
+ } */ *uap = v;
+ register struct vnode *vp;
+ fhandle_t fh;
+ int error;
+ struct nameidata nd;
+
+ /*
+ * Must be super user
+ */
+ error = suser(p->p_ucred, &p->p_acflag);
+ if (error)
+ return (error);
+ NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
+ SCARG(uap, fname), p);
+ error = namei(&nd);
+ if (error)
+ return (error);
+ vp = nd.ni_vp;
+ memset((caddr_t)&fh, 0, sizeof(fh));
+ fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid;
+ error = VFS_VPTOFH(vp, &fh.fh_fid);
+ vput(vp);
+ if (error)
+ return (error);
+ error = copyout((caddr_t)&fh, (caddr_t)SCARG(uap, fhp), sizeof (fh));
+ return (error);
+}
+
+/*
+ * Open a file given a file handle.
+ *
+ * Check permissions, allocate an open file structure,
+ * and call the device open routine if any.
+ */
+int
+sys_fhopen(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ register struct sys_fhopen_args /* {
+ syscallarg(const fhandle_t *) fhp;
+ syscallarg(int) flags;
+ } */ *uap = v;
+ struct filedesc *fdp = p->p_fd;
+ struct file *fp;
+ struct vnode *vp;
+ struct mount *mp;
+ struct ucred *cred = p->p_ucred;
+ int flags;
+ struct file *nfp;
+ int type, indx, error=0;
+ struct flock lf;
+ struct vattr va;
+ fhandle_t fh;
+ extern struct fileops vnops;
+
+ /*
+ * Must be super user
+ */
+ if ((error = suser(p->p_ucred, &p->p_acflag)))
+ return (error);
+
+ flags = FFLAGS(SCARG(uap, flags));
+ if ((flags & (FREAD | FWRITE)) == 0)
+ return (EINVAL);
+ if ((flags & O_CREAT))
+ return (EINVAL);
+ if ((error = falloc(p, &nfp, &indx)) != 0)
+ return (error);
+ fp = nfp;
+ if ((error = copyin(SCARG(uap, fhp), &fh, sizeof(fhandle_t))) != 0)
+ return (error);
+
+ if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
+ return (ESTALE);
+ if ((error = VFS_FHTOVP(mp, &fh.fh_fid, &vp)))
+ return (error);
+
+ /* Now do an effective vn_open */
+
+ if (vp->v_type == VSOCK) {
+ error = EOPNOTSUPP;
+ goto bad;
+ }
+ if (flags & FREAD) {
+ if ((error = VOP_ACCESS(vp, VREAD, cred, p)) != 0)
+ goto bad;
+ }
+ if (flags & (FWRITE | O_TRUNC)) {
+ if (vp->v_type == VDIR) {
+ error = EISDIR;
+ goto bad;
+ }
+ if ((error = vn_writechk(vp)) != 0 ||
+ (error = VOP_ACCESS(vp, VWRITE, cred, p)) != 0)
+ goto bad;
+ }
+ if (flags & O_TRUNC) {
+ VOP_UNLOCK(vp, 0); /* XXX */
+ VOP_LEASE(vp, p, cred, LEASE_WRITE);
+ vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); /* XXX */
+ VATTR_NULL(&va);
+ va.va_size = 0;
+ if ((error = VOP_SETATTR(vp, &va, cred, p)) != 0)
+ goto bad;
+ }
+ if ((error = VOP_OPEN(vp, flags, cred, p)) != 0)
+ goto bad;
+ if (flags & FWRITE)
+ vp->v_writecount++;
+
+ /* done with modified vn_open, now finish what sys_open does. */
+
+ fp->f_flag = flags & FMASK;
+ fp->f_type = DTYPE_VNODE;
+ fp->f_ops = &vnops;
+ fp->f_data = (caddr_t)vp;
+ if (flags & (O_EXLOCK | O_SHLOCK)) {
+ lf.l_whence = SEEK_SET;
+ lf.l_start = 0;
+ lf.l_len = 0;
+ if (flags & O_EXLOCK)
+ lf.l_type = F_WRLCK;
+ else
+ lf.l_type = F_RDLCK;
+ type = F_FLOCK;
+ if ((flags & FNONBLOCK) == 0)
+ type |= F_WAIT;
+ VOP_UNLOCK(vp, 0);
+ error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf, type);
+ if (error) {
+ (void) vn_close(vp, fp->f_flag, fp->f_cred, p);
+ ffree(fp);
+ fdp->fd_ofiles[indx] = NULL;
+ return (error);
+ }
+ vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+ fp->f_flag |= FHASLOCK;
+ }
+ VOP_UNLOCK(vp, 0);
+ *retval = indx;
+ return (0);
+bad:
+ vput(vp);
+ return (error);
+}
+
+/* ARGSUSED */
+int
+sys_fhstat(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ register struct sys_fhstat_args /* {
+ syscallarg(const fhandle_t *) fhp;
+ syscallarg(struct stat *) sb;
+ } */ *uap = v;
+ struct stat sb;
+ int error;
+ fhandle_t fh;
+ struct mount *mp;
+ struct vnode *vp;
+
+ /*
+ * Must be super user
+ */
+ if ((error = suser(p->p_ucred, &p->p_acflag)))
+ return (error);
+
+ if ((error = copyin(SCARG(uap, fhp), &fh, sizeof(fhandle_t))) != 0)
+ return (error);
+
+ if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
+ return (ESTALE);
+ if ((error = VFS_FHTOVP(mp, &fh.fh_fid, &vp)))
+ return (error);
+ error = vn_stat(vp, &sb, p);
+ vput(vp);
+ if (error)
+ return (error);
+ error = copyout(&sb, SCARG(uap, sb), sizeof(sb));
+ return (error);
+}
+
+/* ARGSUSED */
+int
+sys_fhstatfs(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ register struct sys_fhstatfs_args /*
+ syscallarg(const fhandle_t *) fhp;
+ syscallarg(struct statfs *) buf;
+ } */ *uap = v;
+ struct statfs sp;
+ fhandle_t fh;
+ struct mount *mp;
+ struct vnode *vp;
+ int error;
+
+ /*
+ * Must be super user
+ */
+ if ((error = suser(p->p_ucred, &p->p_acflag)))
+ return (error);
+
+ if ((error = copyin(SCARG(uap, fhp), &fh, sizeof(fhandle_t))) != 0)
+ return (error);
+
+ if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
+ return (ESTALE);
+ if ((error = VFS_FHTOVP(mp, &fh.fh_fid, &vp)))
+ return (error);
+ mp = vp->v_mount;
+ vput(vp);
+ if ((error = VFS_STATFS(mp, &sp, p)) != 0)
+ return (error);
+ sp.f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
+ return (copyout(&sp, SCARG(uap, buf), sizeof(sp)));
+}
+
+/*
* Create a special file.
*/
/* ARGSUSED */
diff -r a7189fb45553 -r 70d449e4395b sys/nfs/nfs_syscalls.c
--- a/sys/nfs/nfs_syscalls.c Tue Jun 29 22:17:39 1999 +0000
+++ b/sys/nfs/nfs_syscalls.c Tue Jun 29 22:18:47 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nfs_syscalls.c,v 1.35 1999/05/05 20:01:12 thorpej Exp $ */
+/* $NetBSD: nfs_syscalls.c,v 1.36 1999/06/29 22:18:48 wrstuden Exp $ */
Home |
Main Index |
Thread Index |
Old Index