1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software donated to Berkeley by
|
|
|
|
* Jan-Simon Pendry.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)fdesc_vnops.c 8.9 (Berkeley) 1/21/94
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* /dev/fd Filesystem
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/dirent.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/filedesc.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/kernel.h> /* boottime */
|
|
|
|
#include <sys/lock.h>
|
2002-01-13 21:37:49 +00:00
|
|
|
#include <sys/mutex.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/malloc.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/file.h> /* Must come after sys/malloc.h */
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/namei.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
|
2001-05-23 09:42:29 +00:00
|
|
|
#include <fs/fdescfs/fdesc.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
#define FDL_WANT 0x01
|
|
|
|
#define FDL_LOCKED 0x02
|
|
|
|
static int fdcache_lock;
|
|
|
|
|
1997-09-07 05:27:26 +00:00
|
|
|
static vop_t **fdesc_vnodeop_p;
|
|
|
|
|
1994-09-09 13:23:20 +00:00
|
|
|
#define NFDCACHE 4
|
1997-02-10 02:22:35 +00:00
|
|
|
#define FD_NHASH(ix) \
|
|
|
|
(&fdhashtbl[(ix) & fdhash])
|
2000-05-26 02:09:24 +00:00
|
|
|
static LIST_HEAD(fdhashhead, fdescnode) *fdhashtbl;
|
1998-02-09 06:11:36 +00:00
|
|
|
static u_long fdhash;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2002-03-19 22:20:14 +00:00
|
|
|
static int fdesc_getattr(struct vop_getattr_args *ap);
|
|
|
|
static int fdesc_inactive(struct vop_inactive_args *ap);
|
|
|
|
static int fdesc_lookup(struct vop_lookup_args *ap);
|
|
|
|
static int fdesc_open(struct vop_open_args *ap);
|
|
|
|
static int fdesc_readdir(struct vop_readdir_args *ap);
|
|
|
|
static int fdesc_reclaim(struct vop_reclaim_args *ap);
|
|
|
|
static int fdesc_poll(struct vop_poll_args *ap);
|
|
|
|
static int fdesc_setattr(struct vop_setattr_args *ap);
|
1995-12-03 14:54:48 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Initialise cache headers
|
|
|
|
*/
|
1994-05-25 09:21:21 +00:00
|
|
|
int
|
1997-02-10 02:22:35 +00:00
|
|
|
fdesc_init(vfsp)
|
|
|
|
struct vfsconf *vfsp;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
fdhashtbl = hashinit(NFDCACHE, M_CACHE, &fdhash);
|
1994-05-25 09:21:21 +00:00
|
|
|
return (0);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
fdesc_allocvp(ftype, ix, mp, vpp, td)
|
1994-05-24 10:09:53 +00:00
|
|
|
fdntype ftype;
|
|
|
|
int ix;
|
|
|
|
struct mount *mp;
|
|
|
|
struct vnode **vpp;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
1997-02-10 02:22:35 +00:00
|
|
|
struct fdhashhead *fc;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct fdescnode *fd;
|
|
|
|
int error = 0;
|
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
fc = FD_NHASH(ix);
|
1994-05-24 10:09:53 +00:00
|
|
|
loop:
|
2001-02-04 13:13:25 +00:00
|
|
|
LIST_FOREACH(fd, fc, fd_hash) {
|
1994-05-24 10:09:53 +00:00
|
|
|
if (fd->fd_ix == ix && fd->fd_vnode->v_mount == mp) {
|
2001-09-12 08:38:13 +00:00
|
|
|
if (vget(fd->fd_vnode, 0, td))
|
1994-05-24 10:09:53 +00:00
|
|
|
goto loop;
|
|
|
|
*vpp = fd->fd_vnode;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* otherwise lock the array while we call getnewvnode
|
|
|
|
* since that can block.
|
1995-05-30 08:16:23 +00:00
|
|
|
*/
|
1994-05-24 10:09:53 +00:00
|
|
|
if (fdcache_lock & FDL_LOCKED) {
|
|
|
|
fdcache_lock |= FDL_WANT;
|
2003-03-02 16:54:40 +00:00
|
|
|
(void) tsleep( &fdcache_lock, PINOD, "fdalvp", 0);
|
1994-05-24 10:09:53 +00:00
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
fdcache_lock |= FDL_LOCKED;
|
|
|
|
|
1996-06-12 03:37:57 +00:00
|
|
|
/*
|
|
|
|
* Do the MALLOC before the getnewvnode since doing so afterward
|
|
|
|
* might cause a bogus v_data pointer to get dereferenced
|
|
|
|
* elsewhere if MALLOC should block.
|
|
|
|
*/
|
2003-02-19 05:47:46 +00:00
|
|
|
MALLOC(fd, struct fdescnode *, sizeof(struct fdescnode), M_TEMP, M_WAITOK);
|
1996-06-12 03:37:57 +00:00
|
|
|
|
2002-09-14 09:02:28 +00:00
|
|
|
error = getnewvnode("fdesc", mp, fdesc_vnodeop_p, vpp);
|
1996-06-12 03:37:57 +00:00
|
|
|
if (error) {
|
|
|
|
FREE(fd, M_TEMP);
|
1994-05-24 10:09:53 +00:00
|
|
|
goto out;
|
1996-06-12 03:37:57 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
(*vpp)->v_data = fd;
|
|
|
|
fd->fd_vnode = *vpp;
|
|
|
|
fd->fd_type = ftype;
|
|
|
|
fd->fd_fd = -1;
|
|
|
|
fd->fd_ix = ix;
|
1997-02-10 02:22:35 +00:00
|
|
|
LIST_INSERT_HEAD(fc, fd, fd_hash);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
out:
|
1994-05-24 10:09:53 +00:00
|
|
|
fdcache_lock &= ~FDL_LOCKED;
|
|
|
|
|
|
|
|
if (fdcache_lock & FDL_WANT) {
|
|
|
|
fdcache_lock &= ~FDL_WANT;
|
2003-03-02 16:54:40 +00:00
|
|
|
wakeup( &fdcache_lock);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vp is the current namei directory
|
|
|
|
* ndp is the name to locate in that directory...
|
|
|
|
*/
|
1995-11-07 13:39:31 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
fdesc_lookup(ap)
|
|
|
|
struct vop_lookup_args /* {
|
|
|
|
struct vnode * a_dvp;
|
|
|
|
struct vnode ** a_vpp;
|
|
|
|
struct componentname * a_cnp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode **vpp = ap->a_vpp;
|
|
|
|
struct vnode *dvp = ap->a_dvp;
|
1997-02-10 02:22:35 +00:00
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
char *pname = cnp->cn_nameptr;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td = cnp->cn_thread;
|
2002-01-13 11:58:06 +00:00
|
|
|
struct file *fp;
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
int nlen = cnp->cn_namelen;
|
|
|
|
u_int fd;
|
1994-05-24 10:09:53 +00:00
|
|
|
int error;
|
|
|
|
struct vnode *fvp;
|
|
|
|
|
2002-10-26 18:16:19 +00:00
|
|
|
if ((cnp->cn_flags & ISLASTCN) &&
|
|
|
|
(cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) {
|
1995-09-02 20:19:12 +00:00
|
|
|
error = EROFS;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
VOP_UNLOCK(dvp, 0, td);
|
1997-02-10 02:22:35 +00:00
|
|
|
if (cnp->cn_namelen == 1 && *pname == '.') {
|
1994-05-24 10:09:53 +00:00
|
|
|
*vpp = dvp;
|
2003-03-02 15:56:49 +00:00
|
|
|
VREF(dvp);
|
2002-07-09 19:43:39 +00:00
|
|
|
vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
if (VTOFDESC(dvp)->fd_type != Froot) {
|
1994-05-24 10:09:53 +00:00
|
|
|
error = ENOTDIR;
|
|
|
|
goto bad;
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
fd = 0;
|
2000-06-27 21:37:17 +00:00
|
|
|
/* the only time a leading 0 is acceptable is if it's "0" */
|
|
|
|
if (*pname == '0' && nlen != 1) {
|
|
|
|
error = ENOENT;
|
|
|
|
goto bad;
|
|
|
|
}
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
while (nlen--) {
|
|
|
|
if (*pname < '0' || *pname > '9') {
|
1994-05-24 10:09:53 +00:00
|
|
|
error = ENOENT;
|
|
|
|
goto bad;
|
|
|
|
}
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
fd = 10 * fd + *pname++ - '0';
|
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2002-01-14 00:13:45 +00:00
|
|
|
if ((error = fget(td, fd, &fp)) != 0)
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
goto bad;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = fdesc_allocvp(Fdesc, FD_DESC+fd, dvp->v_mount, &fvp, td);
|
2002-01-13 11:58:06 +00:00
|
|
|
fdrop(fp, td);
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
VTOFDESC(fvp)->fd_fd = fd;
|
2002-07-09 19:43:39 +00:00
|
|
|
vn_lock(fvp, LK_EXCLUSIVE | LK_RETRY, td);
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
*vpp = fvp;
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
bad:
|
2002-07-09 19:43:39 +00:00
|
|
|
vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
|
1994-05-24 10:09:53 +00:00
|
|
|
*vpp = NULL;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1995-11-07 13:39:31 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
fdesc_open(ap)
|
|
|
|
struct vop_open_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_mode;
|
|
|
|
struct ucred *a_cred;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *a_td;
|
1994-05-24 10:09:53 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
if (VTOFDESC(vp)->fd_type == Froot)
|
|
|
|
return (0);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
/*
|
2001-09-12 08:38:13 +00:00
|
|
|
* XXX Kludge: set td->td_proc->p_dupfd to contain the value of the the file
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
ap->a_td->td_dupfd = VTOFDESC(vp)->fd_fd; /* XXX */
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
return (ENODEV);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1995-11-07 13:39:31 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
fdesc_getattr(ap)
|
|
|
|
struct vop_getattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
struct ucred *a_cred;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *a_td;
|
1994-05-24 10:09:53 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct vattr *vap = ap->a_vap;
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
struct file *fp;
|
|
|
|
struct stat stb;
|
|
|
|
u_int fd;
|
1994-05-24 10:09:53 +00:00
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (VTOFDESC(vp)->fd_type) {
|
|
|
|
case Froot:
|
2000-06-15 17:19:22 +00:00
|
|
|
VATTR_NULL(vap);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
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_size = DEV_BSIZE;
|
|
|
|
vap->va_fileid = VTOFDESC(vp)->fd_ix;
|
1994-05-24 10:09:53 +00:00
|
|
|
vap->va_uid = 0;
|
|
|
|
vap->va_gid = 0;
|
|
|
|
vap->va_blocksize = DEV_BSIZE;
|
1996-09-20 05:56:36 +00:00
|
|
|
vap->va_atime.tv_sec = boottime.tv_sec;
|
|
|
|
vap->va_atime.tv_nsec = 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
vap->va_mtime = vap->va_atime;
|
|
|
|
vap->va_ctime = vap->va_mtime;
|
|
|
|
vap->va_gen = 0;
|
|
|
|
vap->va_flags = 0;
|
|
|
|
vap->va_rdev = 0;
|
|
|
|
vap->va_bytes = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Fdesc:
|
|
|
|
fd = VTOFDESC(vp)->fd_fd;
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
|
2002-01-14 00:13:45 +00:00
|
|
|
if ((error = fget(ap->a_td, fd, &fp)) != 0)
|
|
|
|
return (error);
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
|
2000-10-09 20:06:13 +00:00
|
|
|
bzero(&stb, sizeof(stb));
|
Make similar changes to fo_stat() and fo_poll() as made earlier to
fo_read() and fo_write(): explicitly use the cred argument to fo_poll()
as "active_cred" using the passed file descriptor's f_cred reference
to provide access to the file credential. Add an active_cred
argument to fo_stat() so that implementers have access to the active
credential as well as the file credential. Generally modify callers
of fo_stat() to pass in td->td_ucred rather than fp->f_cred, which
was redundantly provided via the fp argument. This set of modifications
also permits threads to perform these operations on behalf of another
thread without modifying their credential.
Trickle this change down into fo_stat/poll() implementations:
- badfo_poll(), badfo_stat(): modify/add arguments.
- kqueue_poll(), kqueue_stat(): modify arguments.
- pipe_poll(), pipe_stat(): modify/add arguments, pass active_cred to
MAC checks rather than td->td_ucred.
- soo_poll(), soo_stat(): modify/add arguments, pass fp->f_cred rather
than cred to pru_sopoll() to maintain current semantics.
- sopoll(): moidfy arguments.
- vn_poll(), vn_statfile(): modify/add arguments, pass new arguments
to vn_stat(). Pass active_cred to MAC and fp->f_cred to VOP_POLL()
to maintian current semantics.
- vn_close(): rename cred to file_cred to reflect reality while I'm here.
- vn_stat(): Add active_cred and file_cred arguments to vn_stat()
and consumers so that this distinction is maintained at the VFS
as well as 'struct file' layer. Pass active_cred instead of
td->td_ucred to MAC and to VOP_GETATTR() to maintain current semantics.
- fifofs: modify the creation of a "filetemp" so that the file
credential is properly initialized and can be used in the socket
code if desired. Pass ap->a_td->td_ucred as the active
credential to soo_poll(). If we teach the vnop interface about
the distinction between file and active credentials, we would use
the active credential here.
Note that current inconsistent passing of active_cred vs. file_cred to
VOP's is maintained. It's not clear why GETATTR would be authorized
using active_cred while POLL would be authorized using file_cred at
the file system level.
Obtained from: TrustedBSD Project
Sponsored by: DARPA, NAI Labs
2002-08-16 12:52:03 +00:00
|
|
|
error = fo_stat(fp, &stb, ap->a_td->td_ucred, ap->a_td);
|
2002-01-13 11:58:06 +00:00
|
|
|
fdrop(fp, ap->a_td);
|
2000-10-09 20:06:13 +00:00
|
|
|
if (error == 0) {
|
|
|
|
VATTR_NULL(vap);
|
|
|
|
vap->va_type = IFTOVT(stb.st_mode);
|
|
|
|
vap->va_mode = stb.st_mode;
|
2000-06-20 20:34:11 +00:00
|
|
|
#define FDRX (VREAD|VEXEC)
|
2000-10-09 20:06:13 +00:00
|
|
|
if (vap->va_type == VDIR)
|
2000-06-20 20:34:11 +00:00
|
|
|
vap->va_mode &= ~((FDRX)|(FDRX>>3)|(FDRX>>6));
|
|
|
|
#undef FDRX
|
2000-10-09 20:06:13 +00:00
|
|
|
vap->va_nlink = 1;
|
|
|
|
vap->va_flags = 0;
|
|
|
|
vap->va_bytes = stb.st_blocks * stb.st_blksize;
|
|
|
|
vap->va_fileid = VTOFDESC(vp)->fd_ix;
|
|
|
|
vap->va_size = stb.st_size;
|
|
|
|
vap->va_blocksize = stb.st_blksize;
|
|
|
|
vap->va_rdev = stb.st_rdev;
|
|
|
|
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
/*
|
2000-10-09 20:06:13 +00:00
|
|
|
* If no time data is provided, use the current time.
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
*/
|
2000-10-09 20:06:13 +00:00
|
|
|
if (stb.st_atimespec.tv_sec == 0 &&
|
|
|
|
stb.st_atimespec.tv_nsec == 0)
|
|
|
|
nanotime(&stb.st_atimespec);
|
|
|
|
|
|
|
|
if (stb.st_ctimespec.tv_sec == 0 &&
|
|
|
|
stb.st_ctimespec.tv_nsec == 0)
|
|
|
|
nanotime(&stb.st_ctimespec);
|
|
|
|
|
|
|
|
if (stb.st_mtimespec.tv_sec == 0 &&
|
|
|
|
stb.st_mtimespec.tv_nsec == 0)
|
|
|
|
nanotime(&stb.st_mtimespec);
|
|
|
|
|
|
|
|
vap->va_atime = stb.st_atimespec;
|
|
|
|
vap->va_mtime = stb.st_mtimespec;
|
|
|
|
vap->va_ctime = stb.st_ctimespec;
|
|
|
|
vap->va_uid = stb.st_uid;
|
|
|
|
vap->va_gid = stb.st_gid;
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic("fdesc_getattr");
|
1995-05-30 08:16:23 +00:00
|
|
|
break;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (error == 0)
|
|
|
|
vp->v_type = vap->va_type;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1995-11-07 13:39:31 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
fdesc_setattr(ap)
|
|
|
|
struct vop_setattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
struct ucred *a_cred;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *a_td;
|
1994-05-24 10:09:53 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
1998-06-10 21:21:31 +00:00
|
|
|
struct vattr *vap = ap->a_vap;
|
2000-07-11 22:07:57 +00:00
|
|
|
struct vnode *vp;
|
|
|
|
struct mount *mp;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct file *fp;
|
|
|
|
unsigned fd;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Can't mess with the root vnode
|
|
|
|
*/
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
if (VTOFDESC(ap->a_vp)->fd_type == Froot)
|
1994-05-24 10:09:53 +00:00
|
|
|
return (EACCES);
|
|
|
|
|
|
|
|
fd = VTOFDESC(ap->a_vp)->fd_fd;
|
|
|
|
|
|
|
|
/*
|
2000-06-06 00:35:39 +00:00
|
|
|
* Allow setattr where there is an underlying vnode.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
error = getvnode(ap->a_td->td_proc->p_fd, fd, &fp);
|
2000-10-09 20:06:13 +00:00
|
|
|
if (error) {
|
|
|
|
/*
|
|
|
|
* getvnode() returns EINVAL if the file descriptor is not
|
|
|
|
* backed by a vnode. Silently drop all changes except
|
|
|
|
* chflags(2) in this case.
|
|
|
|
*/
|
|
|
|
if (error == EINVAL) {
|
|
|
|
if (vap->va_flags != VNOVAL)
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
else
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
return (error);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2003-06-22 08:41:43 +00:00
|
|
|
vp = fp->f_vnode;
|
2002-01-13 11:58:06 +00:00
|
|
|
if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) {
|
|
|
|
fdrop(fp, ap->a_td);
|
2000-10-09 20:06:13 +00:00
|
|
|
return (error);
|
2002-01-13 11:58:06 +00:00
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
error = VOP_SETATTR(vp, ap->a_vap, ap->a_cred, ap->a_td);
|
2000-10-09 20:06:13 +00:00
|
|
|
vn_finished_write(mp);
|
2002-01-13 11:58:06 +00:00
|
|
|
fdrop(fp, ap->a_td);
|
1994-05-24 10:09:53 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define UIO_MX 16
|
|
|
|
|
1995-11-07 13:39:31 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
fdesc_readdir(ap)
|
|
|
|
struct vop_readdir_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
struct ucred *a_cred;
|
1997-02-10 02:22:35 +00:00
|
|
|
int *a_eofflag;
|
|
|
|
u_long *a_cookies;
|
|
|
|
int a_ncookies;
|
1994-05-24 10:09:53 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct uio *uio = ap->a_uio;
|
|
|
|
struct filedesc *fdp;
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
struct dirent d;
|
|
|
|
struct dirent *dp = &d;
|
|
|
|
int error, i, off, fcnt;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
/*
|
|
|
|
* We don't allow exporting fdesc mounts, and currently local
|
|
|
|
* requests do not need cookies.
|
|
|
|
*/
|
|
|
|
if (ap->a_ncookies)
|
|
|
|
panic("fdesc_readdir: not hungry");
|
|
|
|
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
if (VTOFDESC(ap->a_vp)->fd_type != Froot)
|
1998-06-14 08:46:41 +00:00
|
|
|
panic("fdesc_readdir: not dir");
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1998-06-14 08:46:41 +00:00
|
|
|
off = (int)uio->uio_offset;
|
|
|
|
if (off != uio->uio_offset || off < 0 || (u_int)off % UIO_MX != 0 ||
|
|
|
|
uio->uio_resid < UIO_MX)
|
|
|
|
return (EINVAL);
|
|
|
|
i = (u_int)off / UIO_MX;
|
2001-09-12 08:38:13 +00:00
|
|
|
fdp = uio->uio_td->td_proc->p_fd;
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
error = 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
fcnt = i - 2; /* The first two nodes are `.' and `..' */
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2002-01-13 11:58:06 +00:00
|
|
|
FILEDESC_LOCK(fdp);
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
while (i < fdp->fd_nfiles + 2 && uio->uio_resid >= UIO_MX) {
|
|
|
|
switch (i) {
|
|
|
|
case 0: /* `.' */
|
|
|
|
case 1: /* `..' */
|
|
|
|
bzero((caddr_t)dp, UIO_MX);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
dp->d_fileno = i + FD_ROOT;
|
|
|
|
dp->d_namlen = i + 1;
|
|
|
|
dp->d_reclen = UIO_MX;
|
|
|
|
bcopy("..", dp->d_name, dp->d_namlen);
|
|
|
|
dp->d_name[i + 1] = '\0';
|
|
|
|
dp->d_type = DT_DIR;
|
|
|
|
break;
|
|
|
|
default:
|
2002-01-13 11:58:06 +00:00
|
|
|
if (fdp->fd_ofiles[fcnt] == NULL) {
|
|
|
|
FILEDESC_UNLOCK(fdp);
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
goto done;
|
2002-01-13 11:58:06 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
bzero((caddr_t) dp, UIO_MX);
|
|
|
|
dp->d_namlen = sprintf(dp->d_name, "%d", fcnt);
|
1994-05-24 10:09:53 +00:00
|
|
|
dp->d_reclen = UIO_MX;
|
|
|
|
dp->d_type = DT_UNKNOWN;
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
dp->d_fileno = i + FD_DESC;
|
|
|
|
break;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
/*
|
|
|
|
* And ship to userland
|
|
|
|
*/
|
2002-01-13 11:58:06 +00:00
|
|
|
FILEDESC_UNLOCK(fdp);
|
2003-03-02 15:50:23 +00:00
|
|
|
error = uiomove(dp, UIO_MX, uio);
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
if (error)
|
2002-01-13 11:58:06 +00:00
|
|
|
goto done;
|
|
|
|
FILEDESC_LOCK(fdp);
|
1994-05-24 10:09:53 +00:00
|
|
|
i++;
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
fcnt++;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2002-01-13 11:58:06 +00:00
|
|
|
FILEDESC_UNLOCK(fdp);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
Adapt fdesc to be mounted on /dev/fd and remove fd, stdin, stdout and
stderr nodes. More specific items of this patch:
o Removed support for symbolic links, and the need for
fdesc_readlink().
o Put all the code from fdesc_attr() into fdesc_getattr() and removed
fdesc_attr(). This also made it easier to properly give all nodes
unique inode numbers.
o The removal of all non-fd nodes allowed the removal of the fdesc_read(),
fdesc_write(), and fdesc_ioctl() nodes, since we no longer have nodes
that get special handling.
o Correct the component name validity-checking in fdesc_lookup(). It
previously detected the end of the string by checking for a terminating
NUL, now it uses cnp->cn_namelen.
o Handle kqueue files as FIFOs. This is probably the closest file type
to represent this type of file there is, and it is unfortunately not
very representative of a kqueue. Creation time is not supported by
kqueue, so ctime, mtime and atime are all set to the current time when
getattr() was called.
o Also set st_[mca]time to the current time since there's no data in
socket structures that can be used to fill this in (FIFOs).
o Simplify fdesc_readdir() since it only has to report the numbered
fd nodes. Add `.' and `..' directory links as well.
o Remove read bits from directories as they tend to confuse programs
like tar(1).
Reviewed by: phk
Discussed with: bde (earlier on, not quite review)
2000-05-11 22:10:51 +00:00
|
|
|
done:
|
1994-05-24 10:09:53 +00:00
|
|
|
uio->uio_offset = i * UIO_MX;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1995-11-07 13:39:31 +00:00
|
|
|
static int
|
1997-09-14 02:58:12 +00:00
|
|
|
fdesc_poll(ap)
|
|
|
|
struct vop_poll_args /* {
|
1994-05-24 10:09:53 +00:00
|
|
|
struct vnode *a_vp;
|
1997-09-14 02:58:12 +00:00
|
|
|
int a_events;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct ucred *a_cred;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *a_td;
|
1994-05-24 10:09:53 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
return seltrue(0, ap->a_events, ap->a_td);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1995-11-07 13:39:31 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
fdesc_inactive(ap)
|
|
|
|
struct vop_inactive_args /* {
|
|
|
|
struct vnode *a_vp;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *a_td;
|
1994-05-24 10:09:53 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear out the v_type field to avoid
|
|
|
|
* nasty things happening in vgone().
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
VOP_UNLOCK(vp, 0, ap->a_td);
|
1994-05-24 10:09:53 +00:00
|
|
|
vp->v_type = VNON;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-11-07 13:39:31 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
fdesc_reclaim(ap)
|
|
|
|
struct vop_reclaim_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
1997-02-10 02:22:35 +00:00
|
|
|
struct fdescnode *fd = VTOFDESC(vp);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
LIST_REMOVE(fd, fd_hash);
|
1994-05-24 10:09:53 +00:00
|
|
|
FREE(vp->v_data, M_TEMP);
|
|
|
|
vp->v_data = 0;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-11-07 13:39:31 +00:00
|
|
|
static struct vnodeopv_entry_desc fdesc_vnodeop_entries[] = {
|
1997-10-26 20:55:39 +00:00
|
|
|
{ &vop_default_desc, (vop_t *) vop_defaultop },
|
|
|
|
{ &vop_access_desc, (vop_t *) vop_null },
|
1997-10-15 09:22:02 +00:00
|
|
|
{ &vop_getattr_desc, (vop_t *) fdesc_getattr },
|
1997-10-15 10:05:29 +00:00
|
|
|
{ &vop_inactive_desc, (vop_t *) fdesc_inactive },
|
1997-10-15 09:22:02 +00:00
|
|
|
{ &vop_lookup_desc, (vop_t *) fdesc_lookup },
|
|
|
|
{ &vop_open_desc, (vop_t *) fdesc_open },
|
1997-10-16 20:32:40 +00:00
|
|
|
{ &vop_pathconf_desc, (vop_t *) vop_stdpathconf },
|
1997-10-15 09:22:02 +00:00
|
|
|
{ &vop_poll_desc, (vop_t *) fdesc_poll },
|
|
|
|
{ &vop_readdir_desc, (vop_t *) fdesc_readdir },
|
|
|
|
{ &vop_reclaim_desc, (vop_t *) fdesc_reclaim },
|
|
|
|
{ &vop_setattr_desc, (vop_t *) fdesc_setattr },
|
1995-11-09 08:17:23 +00:00
|
|
|
{ NULL, NULL }
|
1994-05-24 10:09:53 +00:00
|
|
|
};
|
1995-11-07 13:39:31 +00:00
|
|
|
static struct vnodeopv_desc fdesc_vnodeop_opv_desc =
|
1994-05-24 10:09:53 +00:00
|
|
|
{ &fdesc_vnodeop_p, fdesc_vnodeop_entries };
|
1994-09-21 03:47:43 +00:00
|
|
|
|
|
|
|
VNODEOP_SET(fdesc_vnodeop_opv_desc);
|