update with latest fdesc file system from jsp@sequent.com

This commit is contained in:
cgd 1994-01-05 09:00:57 +00:00
parent acdf74915d
commit 4942f8a8bc
3 changed files with 591 additions and 216 deletions

View File

@ -1,8 +1,9 @@
/*
* Copyright (c) 1992 The Regents of the University of California
* Copyright (c) 1990, 1992 Jan-Simon Pendry
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* This code is derived from software donated to Berkeley by
* Jan-Simon Pendry.
*
* Redistribution and use in source and binary forms, with or without
@ -15,8 +16,8 @@
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
@ -33,7 +34,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: fdesc.h,v 1.2 1993/03/25 06:00:17 cgd Exp $
* From:
* Id: fdesc.h,v 4.1 1993/12/17 10:47:45 jsp Rel
*
* $Id: fdesc.h,v 1.3 1994/01/05 09:00:57 cgd Exp $
*/
#ifdef KERNEL
@ -41,14 +45,35 @@ struct fdescmount {
struct vnode *f_root; /* Root node */
};
#define FD_ROOT 2
#define FD_DEVFD 3
#define FD_STDIN 4
#define FD_STDOUT 5
#define FD_STDERR 6
#define FD_CTTY 7
#define FD_DESC 8
#define FD_MAX 12
typedef enum {
Froot,
Fdevfd,
Fdesc,
Flink,
Fctty
} fdntype;
struct fdescnode {
unsigned f_fd; /* Fd to be dup'ed */
/*int f_isroot;*/ /* Is this the root */
fdntype fd_type; /* Type of this node */
unsigned fd_fd; /* Fd to be dup'ed */
char *fd_link; /* Link to fd/n */
int fd_ix; /* filesystem index */
};
#define VFSTOFDESC(mp) ((struct fdescmount *)((mp)->mnt_data))
#define VTOFDESC(vp) ((struct fdescnode *)(vp)->v_data)
extern dev_t devctty;
extern int fdesc_allocvp __P((fdntype, int, struct mount *, struct vnode **));
extern struct vnodeops fdesc_vnodeops;
extern struct vfsops fdesc_vfsops;
#endif /* KERNEL */

View File

@ -1,8 +1,9 @@
/*
* Copyright (c) 1992 The Regents of the University of California
* Copyright (c) 1990, 1992 Jan-Simon Pendry
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* This code is derived from software donated to Berkeley by
* Jan-Simon Pendry.
*
* Redistribution and use in source and binary forms, with or without
@ -15,8 +16,8 @@
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
@ -33,33 +34,37 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: fdesc_vfsops.c,v 1.5 1993/08/23 16:02:46 mycroft Exp $
* From:
* Id: fdesc_vfsops.c,v 4.1 1993/12/17 10:47:45 jsp Rel
*
* $Id: fdesc_vfsops.c,v 1.6 1994/01/05 09:01:00 cgd Exp $
*/
/*
* /dev/fd Filesystem
*/
#include "param.h"
#include "systm.h"
#include "time.h"
#include "types.h"
#include "proc.h"
#include "resourcevar.h"
#include "filedesc.h"
#include "vnode.h"
#include "mount.h"
#include "namei.h"
#include "malloc.h"
#include "miscfs/fdesc/fdesc.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/proc.h>
#include <sys/resourcevar.h>
#include <sys/filedesc.h>
#include <sys/vnode.h>
#include <sys/mount.h>
#include <sys/namei.h>
#include <sys/malloc.h>
#include <miscfs/fdesc/fdesc.h>
static u_short fdesc_mntid;
dev_t devctty;
fdesc_init()
{
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_init\n"); /* printed during system boot */
#endif
devctty = makedev(nchrdev, 0);
}
/*
@ -87,15 +92,15 @@ fdesc_mount(mp, path, data, ndp, p)
if (mp->mnt_flag & MNT_UPDATE)
return (EOPNOTSUPP);
error = getnewvnode(VT_FDESC, mp, &fdesc_vnodeops, &rvp);
error = fdesc_allocvp(Froot, FD_ROOT, mp, &rvp);
if (error)
return (error);
fmp = (struct fdescmount *) malloc(sizeof(struct fdescmount),
M_MISCFSMNT, M_WAITOK);
MALLOC(fmp, struct fdescmount *, sizeof(struct fdescmount),
M_UFSMNT, M_WAITOK); /* XXX */
rvp->v_type = VDIR;
rvp->v_flag |= VROOT;
/*VTOFDESC(rvp)->f_isroot = 1;*/
VTOFDESC(rvp)->fd_type = Froot;
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_mount: root vp = %x\n", rvp);
#endif
@ -179,7 +184,7 @@ fdesc_unmount(mp, mntflags, p)
/*
* Finally, throw away the fdescmount structure
*/
free(mp->mnt_data, M_MISCFSMNT);
free(mp->mnt_data, M_UFSMNT); /* XXX */
mp->mnt_data = 0;
return 0;
}

View File

@ -1,8 +1,9 @@
/*
* Copyright (c) 1990, 1992 Jan-Simon Pendry
* Copyright (c) 1992 The Regents of the University of California
* Copyright (c) 1990, 1992, 1993 Jan-Simon Pendry
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* This code is derived from software donated to Berkeley by
* Jan-Simon Pendry.
*
* Redistribution and use in source and binary forms, with or without
@ -15,8 +16,8 @@
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
@ -33,29 +34,98 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: fdesc_vnops.c,v 1.7 1993/12/23 17:37:33 cgd Exp $
* From:
* Id: fdesc_vnops.c,v 4.1 1993/12/17 10:47:45 jsp Rel
*
* $Id: fdesc_vnops.c,v 1.8 1994/01/05 09:01:02 cgd Exp $
*/
/*
* /dev/fd Filesystem
*/
#include "param.h"
#include "systm.h"
#include "types.h"
#include "time.h"
#include "proc.h"
#include "resourcevar.h"
#include "filedesc.h"
#include "vnode.h"
#include "file.h"
#include "stat.h"
#include "mount.h"
#include "namei.h"
#include "buf.h"
#include "miscfs/fdesc/fdesc.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/proc.h>
#include <sys/kernel.h> /* boottime */
#include <sys/resourcevar.h>
#include <sys/filedesc.h>
#include <sys/vnode.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <sys/namei.h>
#include <sys/buf.h>
#include <miscfs/fdesc/fdesc.h>
#include "../ufs/dir.h" /* For readdir() XXX */
#include <ufs/dir.h> /* For readdir() XXX */
#define cttyvp(p) ((p)->p_flag&SCTTY ? (p)->p_session->s_ttyvp : NULL)
#define FDL_WANT 0x01
#define FDL_LOCKED 0x02
static int fdescvplock;
static struct vnode *fdescvp[FD_MAX];
#if (FD_STDIN != FD_STDOUT-1) || (FD_STDOUT != FD_STDERR-1)
FD_STDIN, FD_STDOUT, FD_STDERR must be a sequence n, n+1, n+2
#endif
fdesc_allocvp(ftype, ix, mp, vpp)
fdntype ftype;
int ix;
struct mount *mp;
struct vnode **vpp;
{
struct vnode **nvpp = 0;
int error = 0;
loop:
/* get stashed copy of the vnode */
if (ix >= 0 && ix < FD_MAX) {
nvpp = &fdescvp[ix];
if (*nvpp) {
if (vget(*nvpp))
goto loop;
VOP_UNLOCK(*nvpp);
*vpp = *nvpp;
return (error);
}
}
/*
* otherwise lock the array while we call getnewvnode
* since that can block.
*/
if (fdescvplock & FDL_LOCKED) {
fdescvplock |= FDL_WANT;
sleep((caddr_t) &fdescvplock, PINOD);
goto loop;
}
fdescvplock |= FDL_LOCKED;
error = getnewvnode(VT_UFS, mp, &fdesc_vnodeops, vpp);
if (error)
goto out;
if (nvpp)
*nvpp = *vpp;
VTOFDESC(*vpp)->fd_type = ftype;
VTOFDESC(*vpp)->fd_fd = -1;
VTOFDESC(*vpp)->fd_link = 0;
VTOFDESC(*vpp)->fd_ix = ix;
out:;
fdescvplock &= ~FDL_LOCKED;
if (fdescvplock & FDL_WANT) {
fdescvplock &= ~FDL_WANT;
wakeup((caddr_t) &fdescvplock);
}
return (error);
}
/*
* vp is the current namei directory
@ -71,6 +141,7 @@ fdesc_lookup(dvp, ndp, p)
unsigned fd;
int error;
struct vnode *fvp;
char *ln;
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_lookup(%s)\n", pname);
@ -79,49 +150,142 @@ fdesc_lookup(dvp, ndp, p)
ndp->ni_dvp = dvp;
ndp->ni_vp = dvp;
VREF(dvp);
/*VOP_LOCK(dvp);*/
VOP_LOCK(dvp);
return (0);
}
fd = 0;
while (*pname >= '0' && *pname <= '9') {
fd = 10 * fd + *pname++ - '0';
if (fd >= nfiles)
break;
}
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_lookup: fd = %d, *pname = %x\n", fd, *pname);
#endif
if (*pname == '/') {
switch (VTOFDESC(dvp)->fd_type) {
default:
case Flink:
case Fdesc:
case Fctty:
error = ENOTDIR;
goto bad;
}
if (*pname != '\0') {
error = ENOENT;
goto bad;
}
case Froot:
if (ndp->ni_namelen == 2 && bcmp(pname, "fd", 2) == 0) {
error = fdesc_allocvp(Fdevfd, FD_DEVFD, dvp->v_mount, &fvp);
if (error)
goto bad;
ndp->ni_dvp = dvp;
ndp->ni_vp = fvp;
fvp->v_type = VDIR;
VOP_LOCK(fvp);
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_lookup: newvp = %x\n", fvp);
#endif
return (0);
}
if (fd >= nfiles || p->p_fd->fd_ofiles[fd] == NULL) {
error = EBADF;
goto bad;
}
if (ndp->ni_namelen == 3 && bcmp(pname, "tty", 3) == 0) {
struct vnode *ttyvp = cttyvp(p);
if (ttyvp == NULL) {
error = ENXIO;
goto bad;
}
error = fdesc_allocvp(Fctty, FD_CTTY, dvp->v_mount, &fvp);
if (error)
goto bad;
ndp->ni_dvp = dvp;
ndp->ni_vp = fvp;
fvp->v_type = VFIFO;
VOP_LOCK(fvp);
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_lookup: ttyvp = %x\n", fvp);
#endif
return (0);
}
ln = 0;
switch (ndp->ni_namelen) {
case 5:
if (bcmp(pname, "stdin", 5) == 0) {
ln = "fd/0";
fd = FD_STDIN;
}
break;
case 6:
if (bcmp(pname, "stdout", 6) == 0) {
ln = "fd/1";
fd = FD_STDOUT;
} else
if (bcmp(pname, "stderr", 6) == 0) {
ln = "fd/2";
fd = FD_STDERR;
}
break;
}
if (ln) {
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_lookup: link -> %s\n", ln);
#endif
error = fdesc_allocvp(Flink, fd, dvp->v_mount, &fvp);
if (error)
goto bad;
VTOFDESC(fvp)->fd_link = ln;
ndp->ni_dvp = dvp;
ndp->ni_vp = fvp;
fvp->v_type = VLNK;
VOP_LOCK(fvp);
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_lookup: newvp = %x\n", fvp);
#endif
return (0);
} else {
error = ENOENT;
goto bad;
}
/* fall through */
case Fdevfd:
if (ndp->ni_namelen == 2 && bcmp(pname, "..", 2) == 0) {
ndp->ni_dvp = dvp;
error = fdesc_root(dvp->v_mount, &ndp->ni_vp);
return (error);
}
fd = 0;
while (*pname >= '0' && *pname <= '9') {
fd = 10 * fd + *pname++ - '0';
if (fd >= nfiles)
break;
}
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_lookup: allocate new vnode\n");
printf("fdesc_lookup: fd = %d, *pname = %x\n", fd, *pname);
#endif
error = getnewvnode(VT_FDESC, dvp->v_mount, &fdesc_vnodeops, &fvp);
if (error)
goto bad;
VTOFDESC(fvp)->f_fd = fd;
/*VTOFDESC(fvp)->f_isroot = 0;*/
ndp->ni_dvp = dvp;
ndp->ni_vp = fvp;
if (*pname == '/') {
error = ENOTDIR;
goto bad;
}
if (*pname != '\0') {
error = ENOENT;
goto bad;
}
devfd:
if (fd >= nfiles || p->p_fd->fd_ofiles[fd] == NULL) {
error = EBADF;
goto bad;
}
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_lookup: newvp = %x\n", fvp);
printf("fdesc_lookup: allocate new vnode\n");
#endif
return (0);
error = fdesc_allocvp(Fdesc, FD_DESC+fd, dvp->v_mount, &fvp);
if (error)
goto bad;
VTOFDESC(fvp)->fd_fd = fd;
ndp->ni_dvp = dvp;
ndp->ni_vp = fvp;
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_lookup: newvp = %x\n", fvp);
#endif
return (0);
}
bad:;
ndp->ni_dvp = dvp;
@ -138,28 +302,28 @@ fdesc_open(vp, mode, cred, p)
struct ucred *cred;
struct proc *p;
{
int error;
struct filedesc *fdp;
struct file *fp;
int dfd;
int fd;
int error = 0;
/*
* Can always open the root (modulo perms)
*/
if (vp->v_flag & VROOT)
return (0);
switch (VTOFDESC(vp)->fd_type) {
case Fdesc:
/*
* XXX Kludge: set p->p_dupfd to contain the value of the
* the file descriptor being sought for duplication. The error
* return ensures that the vnode for this device will be
* released by vn_open. Open will detect this special error and
* take the actions in dupfdopen. Other callers of vn_open or
* VOP_OPEN will simply report the error.
*/
p->p_dupfd = VTOFDESC(vp)->fd_fd; /* XXX */
error = ENODEV;
break;
/*
* XXX Kludge: set p->p_dupfd to contain the value of the
* the file descriptor being sought for duplication. The error
* return ensures that the vnode for this device will be released
* by vn_open. Open will detect this special error and take the
* actions in dupfdopen. Other callers of vn_open or VOP_OPEN
* will simply report the error.
*/
p->p_dupfd = VTOFDESC(vp)->f_fd; /* XXX */
return (ENODEV);
case Fctty:
error = cttyopen(devctty, mode, 0, p);
break;
}
return (error);
}
static int
@ -171,6 +335,7 @@ fdesc_attr(fd, vap, cred, p)
{
struct filedesc *fdp = p->p_fd;
struct file *fp;
struct stat stb;
int error;
#ifdef FDESC_DIAGNOSTIC
@ -191,10 +356,39 @@ fdesc_attr(fd, vap, cred, p)
switch (fp->f_type) {
case DTYPE_VNODE:
error = VOP_GETATTR((struct vnode *) fp->f_data, vap, cred, p);
if (error == 0 && vap->va_type == VDIR) {
/*
* don't allow directories to show up because
* that causes loops in the namespace.
*/
vap->va_type = VFIFO;
}
break;
case DTYPE_SOCKET:
error = EOPNOTSUPP;
error = soo_stat((struct socket *)fp->f_data, &stb);
if (error == 0) {
vattr_null(vap);
vap->va_type = VSOCK;
vap->va_mode = stb.st_mode;
vap->va_nlink = stb.st_nlink;
vap->va_uid = stb.st_uid;
vap->va_gid = stb.st_gid;
vap->va_fsid = stb.st_dev;
vap->va_fileid = stb.st_ino;
vap->va_size = stb.st_size;
vap->va_blocksize = stb.st_blksize;
vap->va_atime.tv_sec = stb.st_atime;
vap->va_atime.tv_usec = 0;
vap->va_mtime.tv_sec = stb.st_mtime;
vap->va_mtime.tv_usec = 0;
vap->va_ctime.tv_sec = stb.st_ctime;
vap->va_ctime.tv_usec = 0;
vap->va_gen = stb.st_gen;
vap->va_flags = stb.st_flags;
vap->va_rdev = stb.st_rdev;
vap->va_bytes = stb.st_blocks * stb.st_blksize;
}
break;
default:
@ -215,25 +409,52 @@ fdesc_getattr(vp, vap, cred, p)
struct proc *p;
{
unsigned fd;
int error;
int error = 0;
if (vp->v_flag & VROOT) {
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_getattr: stat rootdir\n");
printf("fdesc_getattr: stat type = %d\n", VTOFDESC(vp)->fd_type);
#endif
switch (VTOFDESC(vp)->fd_type) {
case Froot:
case Fdevfd:
case Flink:
case Fctty:
bzero((caddr_t) vap, sizeof(*vap));
vattr_null(vap);
vap->va_type = VDIR;
vap->va_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
vap->va_nlink = 2;
vap->va_fileid = VTOFDESC(vp)->fd_ix;
switch (VTOFDESC(vp)->fd_type) {
case Flink:
vap->va_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
vap->va_type = VLNK;
vap->va_nlink = 1;
/* vap->va_qsize = strlen(VTOFDESC(vp)->fd_link); */
vap->va_size = strlen(VTOFDESC(vp)->fd_link);
break;
case Fctty:
vap->va_mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
vap->va_type = VFIFO;
vap->va_nlink = 1;
/* vap->va_qsize = 0; */
vap->va_size = 0;
break;
default:
vap->va_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
vap->va_type = VDIR;
vap->va_nlink = 2;
/* vap->va_qsize = 0; */
vap->va_size = DEV_BSIZE;
break;
}
vap->va_uid = 0;
vap->va_gid = 0;
vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
vap->va_fileid = 2;
/* vap->va_qsize = 0; */
vap->va_size = DEV_BSIZE;
vap->va_blocksize = DEV_BSIZE;
microtime(&vap->va_atime);
vap->va_atime.tv_sec = boottime.tv_sec;
vap->va_atime.tv_usec = 0;
vap->va_mtime = vap->va_atime;
vap->va_ctime = vap->va_ctime;
vap->va_gen = 0;
@ -241,13 +462,27 @@ fdesc_getattr(vp, vap, cred, p)
vap->va_rdev = 0;
/* vap->va_qbytes = 0; */
vap->va_bytes = 0;
return (0);
break;
case Fdesc:
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_getattr: stat desc #%d\n", VTOFDESC(vp)->fd_fd);
#endif
fd = VTOFDESC(vp)->fd_fd;
error = fdesc_attr(fd, vap, cred, p);
break;
default:
panic("fdesc_getattr");
break;
}
fd = VTOFDESC(vp)->f_fd;
error = fdesc_attr(fd, vap, cred, p);
if (error == 0)
vp->v_type = vap->va_type;
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_getattr: stat returns 0\n");
#endif
return (error);
}
@ -265,10 +500,18 @@ fdesc_setattr(vp, vap, cred, p)
/*
* Can't mess with the root vnode
*/
if (vp->v_flag & VROOT)
return (EACCES);
switch (VTOFDESC(vp)->fd_type) {
case Fdesc:
break;
fd = VTOFDESC(vp)->f_fd;
case Fctty:
return (0);
default:
return (EACCES);
}
fd = VTOFDESC(vp)->fd_fd;
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_setattr: fd = %d, nfiles = %d\n", fd, fdp->fd_nfiles);
#endif
@ -288,7 +531,7 @@ fdesc_setattr(vp, vap, cred, p)
break;
case DTYPE_SOCKET:
error = EOPNOTSUPP;
error = 0; /* EOPNOTSUPP? */
break;
default:
@ -302,6 +545,22 @@ fdesc_setattr(vp, vap, cred, p)
return (error);
}
#define UIO_MX 16
static struct dirtmp {
u_long d_ino;
u_short d_reclen;
u_short d_namlen;
char d_name[8];
} rootent[] = {
{ FD_DEVFD, UIO_MX, 2, "fd" },
{ FD_STDIN, UIO_MX, 5, "stdin" },
{ FD_STDOUT, UIO_MX, 6, "stdout" },
{ FD_STDERR, UIO_MX, 6, "stderr" },
{ FD_CTTY, UIO_MX, 3, "tty" },
{ 0 }
};
fdesc_readdir(vp, uio, cred, eofflagp, cookies, ncookies)
struct vnode *vp;
struct uio *uio;
@ -311,47 +570,69 @@ fdesc_readdir(vp, uio, cred, eofflagp, cookies, ncookies)
int ncookies;
{
struct filedesc *fdp;
int ind, i;
int i;
int error;
#define UIO_MX 16
switch (VTOFDESC(vp)->fd_type) {
case Fctty:
return (0);
case Fdesc:
return (ENOTDIR);
default:
break;
}
fdp = uio->uio_procp->p_fd;
ind = uio->uio_offset / UIO_MX;
error = 0;
while (uio->uio_resid > 0 && (!cookies || ncookies > 0)) {
if (VTOFDESC(vp)->fd_type == Froot) {
struct direct d;
struct direct *dp = &d;
struct dirtmp *dt;
if (ind < 2) { /* . or .. */
bzero((caddr_t) dp, UIO_MX);
if (ind == 0) {
strcpy(dp->d_name, ".");
dp->d_namlen = 1;
} else if (ind == 1) {
strcpy(dp->d_name, "..");
dp->d_namlen = 2;
} else
panic("fdesc: ind is negative!");
i = uio->uio_offset / UIO_MX;
error = 0;
dp->d_reclen = UIO_MX;
dp->d_ino = 2;
while (uio->uio_resid > 0) {
dt = &rootent[i];
if (dt->d_ino == 0) {
*eofflagp = 1;
break;
}
i++;
switch (dt->d_ino) {
case FD_CTTY:
if (cttyvp(uio->uio_procp) == NULL)
continue;
break;
/*
* And ship to userland
*/
error = uiomove((caddr_t) dp, UIO_MX, uio);
if (error)
break;
ind++;
if (cookies) {
*cookies++ = ind * UIO_MX;
ncookies--;
}
continue;
case FD_STDIN:
case FD_STDOUT:
case FD_STDERR:
if ((dt->d_ino-FD_STDIN) >= fdp->fd_nfiles)
continue;
if (fdp->fd_ofiles[dt->d_ino-FD_STDIN] == NULL)
continue;
break;
}
bzero(dp, UIO_MX);
dp->d_ino = dt->d_ino;
dp->d_namlen = dt->d_namlen;
dp->d_reclen = dt->d_reclen;
bcopy(dt->d_name, dp->d_name, dp->d_namlen+1);
error = uiomove((caddr_t) dp, UIO_MX, uio);
if (error)
break;
}
i = ind - 2;
uio->uio_offset = i * UIO_MX;
return (error);
}
i = uio->uio_offset / UIO_MX;
error = 0;
while (uio->uio_resid > 0) {
if (i >= fdp->fd_nfiles) {
*eofflagp = 1;
break;
@ -359,36 +640,17 @@ fdesc_readdir(vp, uio, cred, eofflagp, cookies, ncookies)
if (fdp->fd_ofiles[i] != NULL) {
struct direct d;
struct direct *dp = &d;
char *cp = dp->d_name;
#ifdef FDESC_FILEID
struct vattr va;
#endif
int j;
bzero((caddr_t) dp, UIO_MX);
/*
* Generate an ASCII representation of the name.
* This can cope with fds in the range 0..99999
*/
cp++;
if (i > 10) cp++;
if (i > 100) cp++;
if (i > 1000) cp++;
if (i > 10000) cp++;
if (i > 100000) panic("fdesc_readdir");
dp->d_namlen = cp - dp->d_name;
*cp = '\0';
j = i;
do {
*--cp = j % 10 + '0';
j /= 10;
} while (j > 0);
dp->d_namlen = sprintf(dp->d_name, "%d", i);
/*
* Fill in the remaining fields
*/
dp->d_reclen = UIO_MX;
dp->d_ino = i + 3;
dp->d_ino = i + FD_STDIN;
#ifdef FDESC_FILEID
/*
* If we want the file ids to match the
@ -406,18 +668,123 @@ fdesc_readdir(vp, uio, cred, eofflagp, cookies, ncookies)
error = uiomove((caddr_t) dp, UIO_MX, uio);
if (error)
break;
if (cookies) {
*cookies++ = (ind + 1) * UIO_MX;
ncookies--;
}
}
ind++;
i++;
}
uio->uio_offset = ind * UIO_MX;
uio->uio_offset = i * UIO_MX;
return (error);
}
fdesc_readlink(vp, uio, cred)
struct vnode *vp;
struct uio *uio;
struct ucred *cred;
{
int error;
if (VTOFDESC(vp)->fd_type == Flink) {
char *ln = VTOFDESC(vp)->fd_link;
error = uiomove(ln, strlen(ln), uio);
} else {
error = EOPNOTSUPP;
}
return (error);
}
fdesc_read(vp, uio, ioflag, cred)
struct vnode *vp;
struct uio *uio;
int ioflag;
struct ucred *cred;
{
int error = EOPNOTSUPP;
switch (VTOFDESC(vp)->fd_type) {
case Fctty:
error = cttyread(devctty, uio, ioflag);
break;
default:
error = EOPNOTSUPP;
break;
}
return (error);
}
fdesc_write(vp, uio, ioflag, cred)
struct vnode *vp;
struct uio *uio;
int ioflag;
struct ucred *cred;
{
int error = EOPNOTSUPP;
switch (VTOFDESC(vp)->fd_type) {
case Fctty:
error = cttywrite(devctty, uio, ioflag);
break;
default:
error = EOPNOTSUPP;
break;
}
return (error);
}
fdesc_ioctl(vp, command, data, fflag, cred, p)
struct vnode *vp;
int command;
caddr_t data;
int fflag;
struct ucred *cred;
struct proc *p;
{
int error = EOPNOTSUPP;
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_ioctl: type = %d, command = %x\n",
VTOFDESC(vp)->fd_type, command);
#endif
switch (VTOFDESC(vp)->fd_type) {
case Fctty:
error = cttyioctl(devctty, command, data, fflag, p);
break;
default:
error = EOPNOTSUPP;
break;
}
return (error);
}
fdesc_select(vp, which, fflags, cred, p)
struct vnode *vp;
int which;
int fflags;
struct ucred *cred;
struct proc *p;
{
int error = EOPNOTSUPP;
switch (VTOFDESC(vp)->fd_type) {
case Fctty:
error = cttyselect(devctty, fflags, p);
break;
default:
error = EOPNOTSUPP;
break;
}
return (error);
}
fdesc_inactive(vp, p)
struct vnode *vp;
struct proc *p;
@ -433,16 +800,32 @@ fdesc_inactive(vp, p)
return (0);
}
int fdesc_reclaim(vp)
struct vnode *vp;
{
int ix;
#ifdef FDESC_DIAGNOSTIC
printf("fdesc_reclaim(%x)\n", vp);
#endif
ix = VTOFDESC(vp)->fd_ix;
if (ix >= 0 && ix < FD_MAX) {
if (fdescvp[ix] != vp)
panic("fdesc_reclaim");
fdescvp[ix] = 0;
}
return (0);
}
/*
* Print out the contents of a /dev/fd vnode.
*/
/* ARGSUSED */
int
fdesc_print(vp)
struct vnode *vp;
{
printf("tag VT_FDESC, fdesc vnode\n");
return (0);
printf("tag VT_NON, fdesc vnode\n");
}
/*
@ -489,29 +872,6 @@ fdesc_nullop()
int mode, \
struct ucred *cred, \
struct proc *p))) nullop)
#define fdesc_read ((int (*) __P(( \
struct vnode *vp, \
struct uio *uio, \
int ioflag, \
struct ucred *cred))) fdesc_enotsupp)
#define fdesc_write ((int (*) __P(( \
struct vnode *vp, \
struct uio *uio, \
int ioflag, \
struct ucred *cred))) fdesc_enotsupp)
#define fdesc_ioctl ((int (*) __P(( \
struct vnode *vp, \
int command, \
caddr_t data, \
int fflag, \
struct ucred *cred, \
struct proc *p))) fdesc_enotsupp)
#define fdesc_select ((int (*) __P(( \
struct vnode *vp, \
int which, \
int fflags, \
struct ucred *cred, \
struct proc *p))) fdesc_enotsupp)
#define fdesc_mmap ((int (*) __P(( \
struct vnode *vp, \
int fflags, \
@ -551,23 +911,8 @@ fdesc_nullop()
struct vattr *vap, \
char *target, \
struct proc *p))) fdesc_enotsupp)
#define fdesc_readlink ((int (*) __P(( \
struct vnode *vp, \
struct uio *uio, \
struct ucred *cred))) fdesc_enotsupp)
#define fdesc_abortop ((int (*) __P(( \
struct nameidata *ndp))) nullop)
#ifdef FDESC_DIAGNOSTIC
int fdesc_reclaim(vp)
struct vnode *vp;
{
printf("fdesc_reclaim(%x)\n", vp);
return (0);
}
#else
#define fdesc_reclaim ((int (*) __P(( \
struct vnode *vp))) nullop)
#endif
#define fdesc_lock ((int (*) __P(( \
struct vnode *vp))) nullop)
#define fdesc_unlock ((int (*) __P(( \