2005-01-06 18:10:42 +00:00
|
|
|
/*-
|
2017-11-20 19:43:44 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
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.
|
2016-04-30 16:01:37 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-24 10:09:53 +00:00
|
|
|
* 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>
|
2014-03-16 10:55:57 +00:00
|
|
|
#include <sys/capsicum.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>
|
2017-12-19 18:20:38 +00:00
|
|
|
#include <sys/syscallsubr.h>
|
|
|
|
#include <sys/unistd.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#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
|
|
|
|
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
|
|
|
|
2008-05-24 14:51:30 +00:00
|
|
|
struct mtx fdesc_hashmtx;
|
|
|
|
|
2004-12-01 12:24:41 +00:00
|
|
|
static vop_getattr_t fdesc_getattr;
|
|
|
|
static vop_lookup_t fdesc_lookup;
|
|
|
|
static vop_open_t fdesc_open;
|
2017-12-19 18:20:38 +00:00
|
|
|
static vop_pathconf_t fdesc_pathconf;
|
2004-12-01 12:24:41 +00:00
|
|
|
static vop_readdir_t fdesc_readdir;
|
2017-08-01 03:40:19 +00:00
|
|
|
static vop_readlink_t fdesc_readlink;
|
2004-12-01 12:24:41 +00:00
|
|
|
static vop_reclaim_t fdesc_reclaim;
|
|
|
|
static vop_setattr_t fdesc_setattr;
|
1995-12-03 14:54:48 +00:00
|
|
|
|
2005-08-10 07:08:14 +00:00
|
|
|
static struct vop_vector fdesc_vnodeops = {
|
|
|
|
.vop_default = &default_vnodeops,
|
|
|
|
|
|
|
|
.vop_access = VOP_NULL,
|
|
|
|
.vop_getattr = fdesc_getattr,
|
|
|
|
.vop_lookup = fdesc_lookup,
|
|
|
|
.vop_open = fdesc_open,
|
2017-12-19 18:20:38 +00:00
|
|
|
.vop_pathconf = fdesc_pathconf,
|
2005-08-10 07:08:14 +00:00
|
|
|
.vop_readdir = fdesc_readdir,
|
2017-08-01 03:40:19 +00:00
|
|
|
.vop_readlink = fdesc_readlink,
|
2005-08-10 07:08:14 +00:00
|
|
|
.vop_reclaim = fdesc_reclaim,
|
|
|
|
.vop_setattr = fdesc_setattr,
|
|
|
|
};
|
2004-12-01 23:16:38 +00:00
|
|
|
|
2008-05-24 14:51:30 +00:00
|
|
|
static void fdesc_insmntque_dtr(struct vnode *, void *);
|
|
|
|
static void fdesc_remove_entry(struct fdescnode *);
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Initialise cache headers
|
|
|
|
*/
|
1994-05-25 09:21:21 +00:00
|
|
|
int
|
2016-04-30 12:44:03 +00:00
|
|
|
fdesc_init(struct vfsconf *vfsp)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
|
2008-05-24 14:51:30 +00:00
|
|
|
mtx_init(&fdesc_hashmtx, "fdescfs_hash", NULL, MTX_DEF);
|
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
|
|
|
}
|
|
|
|
|
2008-05-24 14:51:30 +00:00
|
|
|
/*
|
|
|
|
* Uninit ready for unload.
|
|
|
|
*/
|
|
|
|
int
|
2016-04-30 12:44:03 +00:00
|
|
|
fdesc_uninit(struct vfsconf *vfsp)
|
2008-05-24 14:51:30 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
hashdestroy(fdhashtbl, M_CACHE, fdhash);
|
|
|
|
mtx_destroy(&fdesc_hashmtx);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If allocating vnode fails, call this.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
fdesc_insmntque_dtr(struct vnode *vp, void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
vgone(vp);
|
|
|
|
vput(vp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove an entry from the hash if it exists.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
fdesc_remove_entry(struct fdescnode *fd)
|
|
|
|
{
|
|
|
|
struct fdhashhead *fc;
|
|
|
|
struct fdescnode *fd2;
|
|
|
|
|
|
|
|
fc = FD_NHASH(fd->fd_ix);
|
|
|
|
mtx_lock(&fdesc_hashmtx);
|
|
|
|
LIST_FOREACH(fd2, fc, fd_hash) {
|
|
|
|
if (fd == fd2) {
|
|
|
|
LIST_REMOVE(fd, fd_hash);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mtx_unlock(&fdesc_hashmtx);
|
|
|
|
}
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
int
|
2016-04-30 12:44:03 +00:00
|
|
|
fdesc_allocvp(fdntype ftype, unsigned fd_fd, int ix, struct mount *mp,
|
|
|
|
struct vnode **vpp)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2008-05-24 14:51:30 +00:00
|
|
|
struct fdescmount *fmp;
|
1997-02-10 02:22:35 +00:00
|
|
|
struct fdhashhead *fc;
|
2008-05-24 14:51:30 +00:00
|
|
|
struct fdescnode *fd, *fd2;
|
|
|
|
struct vnode *vp, *vp2;
|
2009-05-11 15:33:26 +00:00
|
|
|
struct thread *td;
|
2017-07-08 21:15:46 +00:00
|
|
|
int error;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2009-05-11 15:33:26 +00:00
|
|
|
td = curthread;
|
1997-02-10 02:22:35 +00:00
|
|
|
fc = FD_NHASH(ix);
|
1994-05-24 10:09:53 +00:00
|
|
|
loop:
|
2008-05-24 14:51:30 +00:00
|
|
|
mtx_lock(&fdesc_hashmtx);
|
|
|
|
/*
|
|
|
|
* If a forced unmount is progressing, we need to drop it. The flags are
|
|
|
|
* protected by the hashmtx.
|
|
|
|
*/
|
2017-07-09 14:15:51 +00:00
|
|
|
fmp = mp->mnt_data;
|
2008-05-24 14:51:30 +00:00
|
|
|
if (fmp == NULL || fmp->flags & FMNT_UNMOUNTF) {
|
|
|
|
mtx_unlock(&fdesc_hashmtx);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
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) {
|
2008-05-24 14:51:30 +00:00
|
|
|
/* Get reference to vnode in case it's being free'd */
|
|
|
|
vp = fd->fd_vnode;
|
|
|
|
VI_LOCK(vp);
|
|
|
|
mtx_unlock(&fdesc_hashmtx);
|
|
|
|
if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, td))
|
1994-05-24 10:09:53 +00:00
|
|
|
goto loop;
|
2008-05-24 14:51:30 +00:00
|
|
|
*vpp = vp;
|
|
|
|
return (0);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-24 14:51:30 +00:00
|
|
|
mtx_unlock(&fdesc_hashmtx);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2008-10-23 15:53:51 +00:00
|
|
|
fd = malloc(sizeof(struct fdescnode), M_TEMP, M_WAITOK);
|
1996-06-12 03:37:57 +00:00
|
|
|
|
2008-05-24 14:51:30 +00:00
|
|
|
error = getnewvnode("fdescfs", mp, &fdesc_vnodeops, &vp);
|
1996-06-12 03:37:57 +00:00
|
|
|
if (error) {
|
2008-10-23 15:53:51 +00:00
|
|
|
free(fd, M_TEMP);
|
2008-05-24 14:51:30 +00:00
|
|
|
return (error);
|
1996-06-12 03:37:57 +00:00
|
|
|
}
|
2008-05-24 14:51:30 +00:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
vp->v_data = fd;
|
|
|
|
fd->fd_vnode = vp;
|
1994-05-24 10:09:53 +00:00
|
|
|
fd->fd_type = ftype;
|
2008-05-24 14:51:30 +00:00
|
|
|
fd->fd_fd = fd_fd;
|
1994-05-24 10:09:53 +00:00
|
|
|
fd->fd_ix = ix;
|
2017-08-01 03:40:19 +00:00
|
|
|
if (ftype == Fdesc && fmp->flags & FMNT_LINRDLNKF)
|
|
|
|
vp->v_vflag |= VV_READLINK;
|
2008-05-24 14:51:30 +00:00
|
|
|
error = insmntque1(vp, mp, fdesc_insmntque_dtr, NULL);
|
2007-03-13 01:50:27 +00:00
|
|
|
if (error != 0) {
|
|
|
|
*vpp = NULLVP;
|
2008-05-24 14:51:30 +00:00
|
|
|
return (error);
|
2007-03-13 01:50:27 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2008-05-24 14:51:30 +00:00
|
|
|
/* Make sure that someone didn't beat us when inserting the vnode. */
|
|
|
|
mtx_lock(&fdesc_hashmtx);
|
|
|
|
/*
|
|
|
|
* If a forced unmount is progressing, we need to drop it. The flags are
|
|
|
|
* protected by the hashmtx.
|
|
|
|
*/
|
2017-07-09 14:15:51 +00:00
|
|
|
fmp = mp->mnt_data;
|
2008-05-24 14:51:30 +00:00
|
|
|
if (fmp == NULL || fmp->flags & FMNT_UNMOUNTF) {
|
|
|
|
mtx_unlock(&fdesc_hashmtx);
|
|
|
|
vgone(vp);
|
|
|
|
vput(vp);
|
|
|
|
*vpp = NULLVP;
|
|
|
|
return (-1);
|
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2008-05-24 14:51:30 +00:00
|
|
|
LIST_FOREACH(fd2, fc, fd_hash) {
|
|
|
|
if (fd2->fd_ix == ix && fd2->fd_vnode->v_mount == mp) {
|
|
|
|
/* Get reference to vnode in case it's being free'd */
|
|
|
|
vp2 = fd2->fd_vnode;
|
|
|
|
VI_LOCK(vp2);
|
|
|
|
mtx_unlock(&fdesc_hashmtx);
|
|
|
|
error = vget(vp2, LK_EXCLUSIVE | LK_INTERLOCK, td);
|
|
|
|
/* Someone beat us, dec use count and wait for reclaim */
|
|
|
|
vgone(vp);
|
|
|
|
vput(vp);
|
|
|
|
/* If we didn't get it, return no vnode. */
|
|
|
|
if (error)
|
|
|
|
vp2 = NULLVP;
|
|
|
|
*vpp = vp2;
|
|
|
|
return (error);
|
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
2008-05-24 14:51:30 +00:00
|
|
|
/* If we came here, we can insert it safely. */
|
|
|
|
LIST_INSERT_HEAD(fc, fd, fd_hash);
|
|
|
|
mtx_unlock(&fdesc_hashmtx);
|
|
|
|
*vpp = vp;
|
|
|
|
return (0);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
2015-02-28 19:57:22 +00:00
|
|
|
struct fdesc_get_ino_args {
|
|
|
|
fdntype ftype;
|
|
|
|
unsigned fd_fd;
|
|
|
|
int ix;
|
|
|
|
struct file *fp;
|
|
|
|
struct thread *td;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
fdesc_get_ino_alloc(struct mount *mp, void *arg, int lkflags,
|
|
|
|
struct vnode **rvp)
|
|
|
|
{
|
|
|
|
struct fdesc_get_ino_args *a;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
a = arg;
|
|
|
|
error = fdesc_allocvp(a->ftype, a->fd_fd, a->ix, mp, rvp);
|
|
|
|
fdrop(a->fp, a->td);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* 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
|
2016-04-30 12:44:03 +00:00
|
|
|
fdesc_lookup(struct vop_lookup_args *ap)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
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;
|
2015-02-28 19:57:22 +00:00
|
|
|
struct fdesc_get_ino_args arg;
|
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;
|
2009-05-12 09:22:33 +00:00
|
|
|
u_int fd, fd1;
|
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;
|
|
|
|
}
|
|
|
|
|
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);
|
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;
|
|
|
|
}
|
2009-05-12 09:22:33 +00:00
|
|
|
fd1 = 10 * fd + *pname++ - '0';
|
|
|
|
if (fd1 < fd) {
|
|
|
|
error = ENOENT;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
fd = fd1;
|
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
|
|
|
|
2011-08-11 12:30:23 +00:00
|
|
|
/*
|
|
|
|
* No rights to check since 'fp' isn't actually used.
|
|
|
|
*/
|
2018-05-09 18:47:24 +00:00
|
|
|
if ((error = fget(td, fd, &cap_no_rights, &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
|
|
|
|
2008-05-24 14:51:30 +00:00
|
|
|
/* Check if we're looking up ourselves. */
|
|
|
|
if (VTOFDESC(dvp)->fd_ix == FD_DESC + fd) {
|
|
|
|
/*
|
|
|
|
* In case we're holding the last reference to the file, the dvp
|
|
|
|
* will be re-acquired.
|
|
|
|
*/
|
|
|
|
vhold(dvp);
|
|
|
|
VOP_UNLOCK(dvp, 0);
|
|
|
|
fdrop(fp, td);
|
|
|
|
|
|
|
|
/* Re-aquire the lock afterwards. */
|
|
|
|
vn_lock(dvp, LK_RETRY | LK_EXCLUSIVE);
|
|
|
|
vdrop(dvp);
|
|
|
|
fvp = dvp;
|
2015-02-28 19:57:22 +00:00
|
|
|
if ((dvp->v_iflag & VI_DOOMED) != 0)
|
|
|
|
error = ENOENT;
|
2008-05-24 14:51:30 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Unlock our root node (dvp) when doing this, since we might
|
|
|
|
* deadlock since the vnode might be locked by another thread
|
|
|
|
* and the root vnode lock will be obtained afterwards (in case
|
|
|
|
* we're looking up the fd of the root vnode), which will be the
|
|
|
|
* opposite lock order. Vhold the root vnode first so we don't
|
2013-05-12 16:43:26 +00:00
|
|
|
* lose it.
|
2008-05-24 14:51:30 +00:00
|
|
|
*/
|
2015-02-28 19:57:22 +00:00
|
|
|
arg.ftype = Fdesc;
|
|
|
|
arg.fd_fd = fd;
|
|
|
|
arg.ix = FD_DESC + fd;
|
|
|
|
arg.fp = fp;
|
|
|
|
arg.td = td;
|
|
|
|
error = vn_vget_ino_gen(dvp, fdesc_get_ino_alloc, &arg,
|
|
|
|
LK_EXCLUSIVE, &fvp);
|
2008-05-24 14:51:30 +00:00
|
|
|
}
|
2017-07-09 14:18:22 +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
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
*vpp = fvp;
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
bad:
|
1994-05-24 10:09:53 +00:00
|
|
|
*vpp = NULL;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1995-11-07 13:39:31 +00:00
|
|
|
static int
|
2016-04-30 12:44:03 +00:00
|
|
|
fdesc_open(struct vop_open_args *ap)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
/*
|
2011-02-21 09:01:34 +00:00
|
|
|
* XXX Kludge: set td->td_proc->p_dupfd to contain the value of 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
|
|
|
}
|
|
|
|
|
2017-12-19 18:20:38 +00:00
|
|
|
static int
|
|
|
|
fdesc_pathconf(struct vop_pathconf_args *ap)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
switch (ap->a_name) {
|
|
|
|
case _PC_NAME_MAX:
|
|
|
|
*ap->a_retval = NAME_MAX;
|
|
|
|
return (0);
|
|
|
|
case _PC_LINK_MAX:
|
|
|
|
if (VTOFDESC(vp)->fd_type == Froot)
|
|
|
|
*ap->a_retval = 2;
|
|
|
|
else
|
|
|
|
*ap->a_retval = 1;
|
|
|
|
return (0);
|
|
|
|
default:
|
2018-03-09 04:45:24 +00:00
|
|
|
if (VTOFDESC(vp)->fd_type == Froot)
|
|
|
|
return (vop_stdpathconf(ap));
|
2017-12-19 18:20:38 +00:00
|
|
|
vref(vp);
|
|
|
|
VOP_UNLOCK(vp, 0);
|
|
|
|
error = kern_fpathconf(curthread, VTOFDESC(vp)->fd_fd,
|
2018-01-17 22:36:58 +00:00
|
|
|
ap->a_name, ap->a_retval);
|
2017-12-19 18:20:38 +00:00
|
|
|
vn_lock(vp, LK_SHARED | LK_RETRY);
|
|
|
|
vunref(vp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-11-07 13:39:31 +00:00
|
|
|
static int
|
2016-04-30 12:44:03 +00:00
|
|
|
fdesc_getattr(struct vop_getattr_args *ap)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct vattr *vap = ap->a_vap;
|
2016-07-27 11:08:59 +00:00
|
|
|
struct timeval boottime;
|
2009-05-12 09:28:45 +00:00
|
|
|
|
2016-07-27 11:08:59 +00:00
|
|
|
getboottime(&boottime);
|
2009-05-12 09:28:45 +00:00
|
|
|
vap->va_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
|
|
|
|
vap->va_fileid = VTOFDESC(vp)->fd_ix;
|
|
|
|
vap->va_uid = 0;
|
|
|
|
vap->va_gid = 0;
|
|
|
|
vap->va_blocksize = DEV_BSIZE;
|
|
|
|
vap->va_atime.tv_sec = boottime.tv_sec;
|
|
|
|
vap->va_atime.tv_nsec = 0;
|
|
|
|
vap->va_mtime = vap->va_atime;
|
|
|
|
vap->va_ctime = vap->va_mtime;
|
|
|
|
vap->va_gen = 0;
|
|
|
|
vap->va_flags = 0;
|
|
|
|
vap->va_bytes = 0;
|
|
|
|
vap->va_filerev = 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
switch (VTOFDESC(vp)->fd_type) {
|
|
|
|
case Froot:
|
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_type = VDIR;
|
|
|
|
vap->va_nlink = 2;
|
|
|
|
vap->va_size = DEV_BSIZE;
|
2008-09-20 19:49:15 +00:00
|
|
|
vap->va_rdev = NODEV;
|
1994-05-24 10:09:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Fdesc:
|
2017-08-01 03:40:19 +00:00
|
|
|
vap->va_type = (vp->v_vflag & VV_READLINK) == 0 ? VCHR : VLNK;
|
2009-05-12 09:28:45 +00:00
|
|
|
vap->va_nlink = 1;
|
|
|
|
vap->va_size = 0;
|
|
|
|
vap->va_rdev = makedev(0, vap->va_fileid);
|
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
|
|
|
}
|
|
|
|
|
2009-05-12 09:28:45 +00:00
|
|
|
vp->v_type = vap->va_type;
|
|
|
|
return (0);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1995-11-07 13:39:31 +00:00
|
|
|
static int
|
2016-04-30 12:44:03 +00:00
|
|
|
fdesc_setattr(struct vop_setattr_args *ap)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
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;
|
2016-02-07 15:40:01 +00:00
|
|
|
struct mount *mp;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct file *fp;
|
2008-08-28 15:23:18 +00:00
|
|
|
struct thread *td = curthread;
|
Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.
The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.
The structure definition looks like this:
struct cap_rights {
uint64_t cr_rights[CAP_RIGHTS_VERSION + 2];
};
The initial CAP_RIGHTS_VERSION is 0.
The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.
The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.
To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.
#define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL)
We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:
#define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL)
#define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL)
#define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP)
There is new API to manage the new cap_rights_t structure:
cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
void cap_rights_set(cap_rights_t *rights, ...);
void cap_rights_clear(cap_rights_t *rights, ...);
bool cap_rights_is_set(const cap_rights_t *rights, ...);
bool cap_rights_is_valid(const cap_rights_t *rights);
void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);
Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:
cap_rights_t rights;
cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);
There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:
#define cap_rights_set(rights, ...) \
__cap_rights_set((rights), __VA_ARGS__, 0ULL)
void __cap_rights_set(cap_rights_t *rights, ...);
Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:
cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);
Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.
This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.
Sponsored by: The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
|
|
|
cap_rights_t rights;
|
1994-05-24 10:09:53 +00:00
|
|
|
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
|
|
|
*/
|
2015-06-16 13:09:18 +00:00
|
|
|
error = getvnode(td, fd,
|
Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.
The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.
The structure definition looks like this:
struct cap_rights {
uint64_t cr_rights[CAP_RIGHTS_VERSION + 2];
};
The initial CAP_RIGHTS_VERSION is 0.
The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.
The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.
To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.
#define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL)
We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:
#define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL)
#define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL)
#define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP)
There is new API to manage the new cap_rights_t structure:
cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
void cap_rights_set(cap_rights_t *rights, ...);
void cap_rights_clear(cap_rights_t *rights, ...);
bool cap_rights_is_set(const cap_rights_t *rights, ...);
bool cap_rights_is_valid(const cap_rights_t *rights);
void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);
Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:
cap_rights_t rights;
cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);
There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:
#define cap_rights_set(rights, ...) \
__cap_rights_set((rights), __VA_ARGS__, 0ULL)
void __cap_rights_set(cap_rights_t *rights, ...);
Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:
cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);
Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.
This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.
Sponsored by: The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
|
|
|
cap_rights_init(&rights, CAP_EXTATTR_SET), &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;
|
2003-11-19 04:14:42 +00:00
|
|
|
if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) == 0) {
|
2008-01-10 01:10:58 +00:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
2008-08-28 15:23:18 +00:00
|
|
|
error = VOP_SETATTR(vp, ap->a_vap, ap->a_cred);
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
2003-11-19 04:14:42 +00:00
|
|
|
vn_finished_write(mp);
|
2002-01-13 11:58:06 +00:00
|
|
|
}
|
2008-08-28 15:23:18 +00:00
|
|
|
fdrop(fp, td);
|
1994-05-24 10:09:53 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
Commit the 64-bit inode project.
Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify
struct dirent layout to add d_off, increase the size of d_fileno
to 64-bits, increase the size of d_namlen to 16-bits, and change
the required alignment. Increase struct statfs f_mntfromname[] and
f_mntonname[] array length MNAMELEN to 1024.
ABI breakage is mitigated by providing compatibility using versioned
symbols, ingenious use of the existing padding in structures, and
by employing other tricks. Unfortunately, not everything can be
fixed, especially outside the base system. For instance, third-party
APIs which pass struct stat around are broken in backward and
forward incompatible ways.
Kinfo sysctl MIBs ABI is changed in backward-compatible way, but
there is no general mechanism to handle other sysctl MIBS which
return structures where the layout has changed. It was considered
that the breakage is either in the management interfaces, where we
usually allow ABI slip, or is not important.
Struct xvnode changed layout, no compat shims are provided.
For struct xtty, dev_t tty device member was reduced to uint32_t.
It was decided that keeping ABI compat in this case is more useful
than reporting 64-bit dev_t, for the sake of pstat.
Update note: strictly follow the instructions in UPDATING. Build
and install the new kernel with COMPAT_FREEBSD11 option enabled,
then reboot, and only then install new world.
Credits: The 64-bit inode project, also known as ino64, started life
many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick
(mckusick) then picked up and updated the patch, and acted as a
flag-waver. Feedback, suggestions, and discussions were carried
by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles),
and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial
ports investigation followed by an exp-run by Antoine Brodin (antoine).
Essential and all-embracing testing was done by Peter Holm (pho).
The heavy lifting of coordinating all these efforts and bringing the
project to completion were done by Konstantin Belousov (kib).
Sponsored by: The FreeBSD Foundation (emaste, kib)
Differential revision: https://reviews.freebsd.org/D10439
2017-05-23 09:29:05 +00:00
|
|
|
#define UIO_MX _GENERIC_DIRLEN(10) /* number of symbols in INT_MAX printout */
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1995-11-07 13:39:31 +00:00
|
|
|
static int
|
2016-04-30 12:44:03 +00:00
|
|
|
fdesc_readdir(struct vop_readdir_args *ap)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2017-08-01 03:40:19 +00:00
|
|
|
struct fdescmount *fmp;
|
1994-05-24 10:09:53 +00:00
|
|
|
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
|
|
|
|
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
|
|
|
|
2017-08-01 03:40:19 +00:00
|
|
|
fmp = VFSTOFDESC(ap->a_vp->v_mount);
|
2011-04-09 21:40:48 +00:00
|
|
|
if (ap->a_ncookies != NULL)
|
|
|
|
*ap->a_ncookies = 0;
|
|
|
|
|
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
|
|
|
|
Replace custom file descriptor array sleep lock constructed using a mutex
and flags with an sxlock. This leads to a significant and measurable
performance improvement as a result of access to shared locking for
frequent lookup operations, reduced general overhead, and reduced overhead
in the event of contention. All of these are imported for threaded
applications where simultaneous access to a shared file descriptor array
occurs frequently. Kris has reported 2x-4x transaction rate improvements
on 8-core MySQL benchmarks; smaller improvements can be expected for many
workloads as a result of reduced overhead.
- Generally eliminate the distinction between "fast" and regular
acquisisition of the filedesc lock; the plan is that they will now all
be fast. Change all locking instances to either shared or exclusive
locks.
- Correct a bug (pointed out by kib) in fdfree() where previously msleep()
was called without the mutex held; sx_sleep() is now always called with
the sxlock held exclusively.
- Universally hold the struct file lock over changes to struct file,
rather than the filedesc lock or no lock. Always update the f_ops
field last. A further memory barrier is required here in the future
(discussed with jhb).
- Improve locking and reference management in linux_at(), which fails to
properly acquire vnode references before using vnode pointers. Annotate
improper use of vn_fullpath(), which will be replaced at a future date.
In fcntl(), we conservatively acquire an exclusive lock, even though in
some cases a shared lock may be sufficient, which should be revisited.
The dropping of the filedesc lock in fdgrowtable() is no longer required
as the sxlock can be held over the sleep operation; we should consider
removing that (pointed out by attilio).
Tested by: kris
Discussed with: jhb, kris, attilio, jeff
2007-04-04 09:11:34 +00:00
|
|
|
FILEDESC_SLOCK(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) {
|
2010-03-16 19:59:14 +00:00
|
|
|
bzero((caddr_t)dp, UIO_MX);
|
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
|
|
|
switch (i) {
|
|
|
|
case 0: /* `.' */
|
|
|
|
case 1: /* `..' */
|
|
|
|
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_type = DT_DIR;
|
2018-11-23 22:24:59 +00:00
|
|
|
dirent_terminate(dp);
|
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
|
|
|
break;
|
|
|
|
default:
|
Merge Capsicum overhaul:
- Capability is no longer separate descriptor type. Now every descriptor
has set of its own capability rights.
- The cap_new(2) system call is left, but it is no longer documented and
should not be used in new code.
- The new syscall cap_rights_limit(2) should be used instead of
cap_new(2), which limits capability rights of the given descriptor
without creating a new one.
- The cap_getrights(2) syscall is renamed to cap_rights_get(2).
- If CAP_IOCTL capability right is present we can further reduce allowed
ioctls list with the new cap_ioctls_limit(2) syscall. List of allowed
ioctls can be retrived with cap_ioctls_get(2) syscall.
- If CAP_FCNTL capability right is present we can further reduce fcntls
that can be used with the new cap_fcntls_limit(2) syscall and retrive
them with cap_fcntls_get(2).
- To support ioctl and fcntl white-listing the filedesc structure was
heavly modified.
- The audit subsystem, kdump and procstat tools were updated to
recognize new syscalls.
- Capability rights were revised and eventhough I tried hard to provide
backward API and ABI compatibility there are some incompatible changes
that are described in detail below:
CAP_CREATE old behaviour:
- Allow for openat(2)+O_CREAT.
- Allow for linkat(2).
- Allow for symlinkat(2).
CAP_CREATE new behaviour:
- Allow for openat(2)+O_CREAT.
Added CAP_LINKAT:
- Allow for linkat(2). ABI: Reuses CAP_RMDIR bit.
- Allow to be target for renameat(2).
Added CAP_SYMLINKAT:
- Allow for symlinkat(2).
Removed CAP_DELETE. Old behaviour:
- Allow for unlinkat(2) when removing non-directory object.
- Allow to be source for renameat(2).
Removed CAP_RMDIR. Old behaviour:
- Allow for unlinkat(2) when removing directory.
Added CAP_RENAMEAT:
- Required for source directory for the renameat(2) syscall.
Added CAP_UNLINKAT (effectively it replaces CAP_DELETE and CAP_RMDIR):
- Allow for unlinkat(2) on any object.
- Required if target of renameat(2) exists and will be removed by this
call.
Removed CAP_MAPEXEC.
CAP_MMAP old behaviour:
- Allow for mmap(2) with any combination of PROT_NONE, PROT_READ and
PROT_WRITE.
CAP_MMAP new behaviour:
- Allow for mmap(2)+PROT_NONE.
Added CAP_MMAP_R:
- Allow for mmap(PROT_READ).
Added CAP_MMAP_W:
- Allow for mmap(PROT_WRITE).
Added CAP_MMAP_X:
- Allow for mmap(PROT_EXEC).
Added CAP_MMAP_RW:
- Allow for mmap(PROT_READ | PROT_WRITE).
Added CAP_MMAP_RX:
- Allow for mmap(PROT_READ | PROT_EXEC).
Added CAP_MMAP_WX:
- Allow for mmap(PROT_WRITE | PROT_EXEC).
Added CAP_MMAP_RWX:
- Allow for mmap(PROT_READ | PROT_WRITE | PROT_EXEC).
Renamed CAP_MKDIR to CAP_MKDIRAT.
Renamed CAP_MKFIFO to CAP_MKFIFOAT.
Renamed CAP_MKNODE to CAP_MKNODEAT.
CAP_READ old behaviour:
- Allow pread(2).
- Disallow read(2), readv(2) (if there is no CAP_SEEK).
CAP_READ new behaviour:
- Allow read(2), readv(2).
- Disallow pread(2) (CAP_SEEK was also required).
CAP_WRITE old behaviour:
- Allow pwrite(2).
- Disallow write(2), writev(2) (if there is no CAP_SEEK).
CAP_WRITE new behaviour:
- Allow write(2), writev(2).
- Disallow pwrite(2) (CAP_SEEK was also required).
Added convinient defines:
#define CAP_PREAD (CAP_SEEK | CAP_READ)
#define CAP_PWRITE (CAP_SEEK | CAP_WRITE)
#define CAP_MMAP_R (CAP_MMAP | CAP_SEEK | CAP_READ)
#define CAP_MMAP_W (CAP_MMAP | CAP_SEEK | CAP_WRITE)
#define CAP_MMAP_X (CAP_MMAP | CAP_SEEK | 0x0000000000000008ULL)
#define CAP_MMAP_RW (CAP_MMAP_R | CAP_MMAP_W)
#define CAP_MMAP_RX (CAP_MMAP_R | CAP_MMAP_X)
#define CAP_MMAP_WX (CAP_MMAP_W | CAP_MMAP_X)
#define CAP_MMAP_RWX (CAP_MMAP_R | CAP_MMAP_W | CAP_MMAP_X)
#define CAP_RECV CAP_READ
#define CAP_SEND CAP_WRITE
#define CAP_SOCK_CLIENT \
(CAP_CONNECT | CAP_GETPEERNAME | CAP_GETSOCKNAME | CAP_GETSOCKOPT | \
CAP_PEELOFF | CAP_RECV | CAP_SEND | CAP_SETSOCKOPT | CAP_SHUTDOWN)
#define CAP_SOCK_SERVER \
(CAP_ACCEPT | CAP_BIND | CAP_GETPEERNAME | CAP_GETSOCKNAME | \
CAP_GETSOCKOPT | CAP_LISTEN | CAP_PEELOFF | CAP_RECV | CAP_SEND | \
CAP_SETSOCKOPT | CAP_SHUTDOWN)
Added defines for backward API compatibility:
#define CAP_MAPEXEC CAP_MMAP_X
#define CAP_DELETE CAP_UNLINKAT
#define CAP_MKDIR CAP_MKDIRAT
#define CAP_RMDIR CAP_UNLINKAT
#define CAP_MKFIFO CAP_MKFIFOAT
#define CAP_MKNOD CAP_MKNODAT
#define CAP_SOCK_ALL (CAP_SOCK_CLIENT | CAP_SOCK_SERVER)
Sponsored by: The FreeBSD Foundation
Reviewed by: Christoph Mallon <christoph.mallon@gmx.de>
Many aspects discussed with: rwatson, benl, jonathan
ABI compatibility discussed with: kib
2013-03-02 00:53:12 +00:00
|
|
|
if (fdp->fd_ofiles[fcnt].fde_file == NULL)
|
2010-03-16 19:59:14 +00:00
|
|
|
break;
|
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_namlen = sprintf(dp->d_name, "%d", fcnt);
|
1994-05-24 10:09:53 +00:00
|
|
|
dp->d_reclen = UIO_MX;
|
2017-08-01 03:40:19 +00:00
|
|
|
dp->d_type = (fmp->flags & FMNT_LINRDLNKF) == 0 ?
|
|
|
|
DT_CHR : DT_LNK;
|
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;
|
2018-11-23 22:24:59 +00:00
|
|
|
dirent_terminate(dp);
|
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
|
|
|
break;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2018-11-14 14:18:35 +00:00
|
|
|
/* NOTE: d_off is the offset of the *next* entry. */
|
|
|
|
dp->d_off = UIO_MX * (i + 1);
|
2010-03-16 19:59:14 +00:00
|
|
|
if (dp->d_namlen != 0) {
|
|
|
|
/*
|
|
|
|
* And ship to userland
|
|
|
|
*/
|
|
|
|
FILEDESC_SUNLOCK(fdp);
|
|
|
|
error = uiomove(dp, UIO_MX, uio);
|
|
|
|
if (error)
|
|
|
|
goto done;
|
|
|
|
FILEDESC_SLOCK(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
|
|
|
}
|
Replace custom file descriptor array sleep lock constructed using a mutex
and flags with an sxlock. This leads to a significant and measurable
performance improvement as a result of access to shared locking for
frequent lookup operations, reduced general overhead, and reduced overhead
in the event of contention. All of these are imported for threaded
applications where simultaneous access to a shared file descriptor array
occurs frequently. Kris has reported 2x-4x transaction rate improvements
on 8-core MySQL benchmarks; smaller improvements can be expected for many
workloads as a result of reduced overhead.
- Generally eliminate the distinction between "fast" and regular
acquisisition of the filedesc lock; the plan is that they will now all
be fast. Change all locking instances to either shared or exclusive
locks.
- Correct a bug (pointed out by kib) in fdfree() where previously msleep()
was called without the mutex held; sx_sleep() is now always called with
the sxlock held exclusively.
- Universally hold the struct file lock over changes to struct file,
rather than the filedesc lock or no lock. Always update the f_ops
field last. A further memory barrier is required here in the future
(discussed with jhb).
- Improve locking and reference management in linux_at(), which fails to
properly acquire vnode references before using vnode pointers. Annotate
improper use of vn_fullpath(), which will be replaced at a future date.
In fcntl(), we conservatively acquire an exclusive lock, even though in
some cases a shared lock may be sufficient, which should be revisited.
The dropping of the filedesc lock in fdgrowtable() is no longer required
as the sxlock can be held over the sleep operation; we should consider
removing that (pointed out by attilio).
Tested by: kris
Discussed with: jhb, kris, attilio, jeff
2007-04-04 09:11:34 +00:00
|
|
|
FILEDESC_SUNLOCK(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
|
2016-04-30 12:44:03 +00:00
|
|
|
fdesc_reclaim(struct vop_reclaim_args *ap)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2008-05-24 14:51:30 +00:00
|
|
|
struct vnode *vp;
|
|
|
|
struct fdescnode *fd;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2008-05-24 14:51:30 +00:00
|
|
|
vp = ap->a_vp;
|
|
|
|
fd = VTOFDESC(vp);
|
|
|
|
fdesc_remove_entry(fd);
|
2008-10-23 15:53:51 +00:00
|
|
|
free(vp->v_data, M_TEMP);
|
2008-05-24 14:51:30 +00:00
|
|
|
vp->v_data = NULL;
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2017-08-01 03:40:19 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
fdesc_readlink(struct vop_readlink_args *va)
|
|
|
|
{
|
|
|
|
struct vnode *vp, *vn;
|
|
|
|
struct thread *td;
|
|
|
|
struct uio *uio;
|
|
|
|
struct file *fp;
|
|
|
|
char *freepath, *fullpath;
|
|
|
|
size_t pathlen;
|
|
|
|
int lockflags, fd_fd;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
freepath = NULL;
|
|
|
|
vn = va->a_vp;
|
|
|
|
if (VTOFDESC(vn)->fd_type != Fdesc)
|
|
|
|
panic("fdesc_readlink: not fdescfs link");
|
|
|
|
fd_fd = ((struct fdescnode *)vn->v_data)->fd_fd;
|
|
|
|
lockflags = VOP_ISLOCKED(vn);
|
|
|
|
VOP_UNLOCK(vn, 0);
|
|
|
|
|
|
|
|
td = curthread;
|
2018-05-09 18:47:24 +00:00
|
|
|
error = fget_cap(td, fd_fd, &cap_no_rights, &fp, NULL);
|
2017-08-01 03:40:19 +00:00
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
switch (fp->f_type) {
|
|
|
|
case DTYPE_VNODE:
|
|
|
|
vp = fp->f_vnode;
|
|
|
|
error = vn_fullpath(td, vp, &fullpath, &freepath);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fullpath = "anon_inode:[unknown]";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (error == 0) {
|
|
|
|
uio = va->a_uio;
|
|
|
|
pathlen = strlen(fullpath);
|
|
|
|
error = uiomove(fullpath, pathlen, uio);
|
|
|
|
}
|
|
|
|
if (freepath != NULL)
|
|
|
|
free(freepath, M_TEMP);
|
|
|
|
fdrop(fp, td);
|
|
|
|
|
|
|
|
out:
|
|
|
|
vn_lock(vn, lockflags | LK_RETRY);
|
|
|
|
return (error);
|
|
|
|
}
|