/*
- * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
static int fdesc_attr(int fd, struct vnode_attr *vap, vfs_context_t a_context);
-lck_mtx_t fdesc_mtx;
-lck_grp_t *fdesc_lckgrp;
+static LCK_GRP_DECLARE(fdesc_lckgrp, "fdesc");
+static LCK_MTX_DECLARE(fdesc_mtx, &fdesc_lckgrp);
static void
fdesc_lock(void)
/* XXX Make sure you have the right path... */
fdhashtbl = hashinit(NFDCACHE, M_CACHE, &fdhash);
- fdesc_lckgrp = lck_grp_alloc_init("fdesc", NULL);
- lck_mtx_init(&fdesc_mtx, fdesc_lckgrp, NULL);
DEVFS_LOCK();
dev_add_entry("fd", rootdir, DEV_DEVFD, NULL, NULL, NULL, &direntp);
}
*vpp = fd->fd_vnode;
- (*vpp)->v_type = vtype;
+ (*vpp)->v_type = (uint16_t)vtype;
return error;
}
*vpp = dvp;
if ((error = vnode_get(dvp))) {
- return error;
+ goto bad;
}
return 0;
}
if ((error = fp_lookup(p, fd, &fp, 0))) {
return error;
}
- switch (FILEGLOB_DTYPE(fp->f_fglob)) {
+ switch (FILEGLOB_DTYPE(fp->fp_glob)) {
case DTYPE_VNODE:
- if ((error = vnode_getwithref((struct vnode *) fp->f_fglob->fg_data)) != 0) {
+ if ((error = vnode_getwithref((struct vnode *) fp->fp_glob->fg_data)) != 0) {
break;
}
- if ((error = vnode_authorize((struct vnode *)fp->f_fglob->fg_data,
+ if ((error = vnode_authorize((struct vnode *)fp->fp_glob->fg_data,
NULL,
KAUTH_VNODE_READ_ATTRIBUTES | KAUTH_VNODE_READ_SECURITY,
a_context)) == 0) {
- error = vnode_getattr((struct vnode *)fp->f_fglob->fg_data, vap, a_context);
+ error = vnode_getattr((struct vnode *)fp->fp_glob->fg_data, vap, a_context);
}
if (error == 0 && vap->va_type == VDIR) {
/*
*/
vap->va_mode &= ~((VEXEC) | (VEXEC >> 3) | (VEXEC >> 6));
}
- (void)vnode_put((struct vnode *) fp->f_fglob->fg_data);
+ (void)vnode_put((struct vnode *) fp->fp_glob->fg_data);
break;
case DTYPE_SOCKET:
case DTYPE_PIPE:
#if SOCKETS
- if (FILEGLOB_DTYPE(fp->f_fglob) == DTYPE_SOCKET) {
- error = soo_stat((struct socket *)fp->f_fglob->fg_data, (void *)&stb, 0);
+ if (FILEGLOB_DTYPE(fp->fp_glob) == DTYPE_SOCKET) {
+ error = soo_stat((struct socket *)fp->fp_glob->fg_data, (void *)&stb, 0);
} else
#endif /* SOCKETS */
- error = pipe_stat((struct pipe *)fp->f_fglob->fg_data, (void *)&stb, 0);
+ error = pipe_stat((struct pipe *)fp->fp_glob->fg_data, (void *)&stb, 0);
if (error == 0) {
- if (FILEGLOB_DTYPE(fp->f_fglob) == DTYPE_SOCKET) {
+ if (FILEGLOB_DTYPE(fp->fp_glob) == DTYPE_SOCKET) {
VATTR_RETURN(vap, va_type, VSOCK);
} else {
VATTR_RETURN(vap, va_type, VFIFO);
* a snapshot.
*/
if (error == 0) {
- vp->v_type = vap->va_type;
+ vp->v_type = (uint16_t)vap->va_type;
/* We need an inactive to reset type to VNON */
vnode_setneedinactive(vp);
/*
* Can setattr the underlying vnode, but not sockets!
*/
- switch (FILEGLOB_DTYPE(fp->f_fglob)) {
+ switch (FILEGLOB_DTYPE(fp->fp_glob)) {
case DTYPE_VNODE:
{
- if ((error = vnode_getwithref((struct vnode *) fp->f_fglob->fg_data)) != 0) {
+ if ((error = vnode_getwithref((struct vnode *) fp->fp_glob->fg_data)) != 0) {
break;
}
- error = vnode_setattr((struct vnode *) fp->f_fglob->fg_data, ap->a_vap, ap->a_context);
- (void)vnode_put((struct vnode *) fp->f_fglob->fg_data);
+ error = vnode_setattr((struct vnode *) fp->fp_glob->fg_data, ap->a_vap, ap->a_context);
+ (void)vnode_put((struct vnode *) fp->fp_glob->fg_data);
break;
}
{
struct uio *uio = ap->a_uio;
struct proc *p = current_proc();
- int i, error;
+ off_t i;
+ int error;
/*
* We don't allow exporting fdesc mounts, and currently local
i = uio->uio_offset / UIO_MX;
error = 0;
while (uio_resid(uio) >= UIO_MX) {
- if (i >= p->p_fd->fd_nfiles) {
+ if (i >= p->p_fd->fd_nfiles || i < 0) {
break;
}
bzero((caddr_t) dp, UIO_MX);
- dp->d_namlen = snprintf(dp->d_name, sizeof(dp->d_name),
- "%d", i);
+ dp->d_namlen = (__uint8_t)scnprintf(dp->d_name, sizeof(dp->d_name),
+ "%lld", i);
dp->d_reclen = UIO_MX;
dp->d_type = DT_UNKNOWN;
- dp->d_fileno = i + FD_STDIN;
+ dp->d_fileno = (ino_t)i + FD_STDIN;
/*
* And ship to userland
*/
#define fdesc_blockmap (int (*) (struct vnop_blockmap_args *))eopnotsupp
int(**fdesc_vnodeop_p)(void *);
-struct vnodeopv_entry_desc devfs_fdesc_vnodeop_entries[] = {
- { &vnop_default_desc, (VOPFUNC)vn_default_error },
- { &vnop_lookup_desc, (VOPFUNC)vn_default_error}, /* lookup */
- { &vnop_create_desc, (VOPFUNC)fdesc_create }, /* create */
- { &vnop_mknod_desc, (VOPFUNC)fdesc_mknod }, /* mknod */
- { &vnop_open_desc, (VOPFUNC)fdesc_open }, /* open */
- { &vnop_close_desc, (VOPFUNC)fdesc_close }, /* close */
- { &vnop_access_desc, (VOPFUNC)fdesc_access }, /* access */
- { &vnop_getattr_desc, (VOPFUNC)fdesc_getattr }, /* getattr */
- { &vnop_setattr_desc, (VOPFUNC)fdesc_setattr }, /* setattr */
- { &vnop_read_desc, (VOPFUNC)fdesc_read }, /* read */
- { &vnop_write_desc, (VOPFUNC)fdesc_write }, /* write */
- { &vnop_ioctl_desc, (VOPFUNC)fdesc_ioctl }, /* ioctl */
- { &vnop_select_desc, (VOPFUNC)fdesc_select }, /* select */
- { &vnop_revoke_desc, (VOPFUNC)fdesc_revoke }, /* revoke */
- { &vnop_mmap_desc, (VOPFUNC)fdesc_mmap }, /* mmap */
- { &vnop_fsync_desc, (VOPFUNC)fdesc_fsync }, /* fsync */
- { &vnop_remove_desc, (VOPFUNC)fdesc_remove }, /* remove */
- { &vnop_link_desc, (VOPFUNC)fdesc_link }, /* link */
- { &vnop_rename_desc, (VOPFUNC)fdesc_rename }, /* rename */
- { &vnop_mkdir_desc, (VOPFUNC)fdesc_mkdir }, /* mkdir */
- { &vnop_rmdir_desc, (VOPFUNC)fdesc_rmdir }, /* rmdir */
- { &vnop_symlink_desc, (VOPFUNC)fdesc_symlink }, /* symlink */
- { &vnop_readdir_desc, (VOPFUNC)vn_default_error},/* readdir */
- { &vnop_readlink_desc, (VOPFUNC)err_readlink}, /* readlink */
- { &vnop_inactive_desc, (VOPFUNC)fdesc_inactive },/* inactive */
- { &vnop_reclaim_desc, (VOPFUNC)fdesc_reclaim }, /* reclaim */
- { &vnop_strategy_desc, (VOPFUNC)fdesc_strategy }, /* strategy */
- { &vnop_pathconf_desc, (VOPFUNC)fdesc_pathconf }, /* pathconf */
- { &vnop_advlock_desc, (VOPFUNC)fdesc_advlock }, /* advlock */
- { &vnop_bwrite_desc, (VOPFUNC)fdesc_bwrite }, /* bwrite */
- { &vnop_pagein_desc, (VOPFUNC)err_pagein }, /* pagein */
- { &vnop_pageout_desc, (VOPFUNC)err_pageout }, /* pageout */
- { &vnop_copyfile_desc, (VOPFUNC)err_copyfile }, /* Copyfile */
- { &vnop_blktooff_desc, (VOPFUNC)fdesc_blktooff }, /* blktooff */
- { &vnop_blktooff_desc, (VOPFUNC)fdesc_offtoblk }, /* offtoblk */
- { &vnop_blockmap_desc, (VOPFUNC)fdesc_blockmap }, /* blockmap */
- { (struct vnodeop_desc*)NULL, (VOPFUNC)NULL }
+const struct vnodeopv_entry_desc devfs_fdesc_vnodeop_entries[] = {
+ { .opve_op = &vnop_default_desc, .opve_impl = (VOPFUNC)vn_default_error },
+ { .opve_op = &vnop_lookup_desc, .opve_impl = (VOPFUNC)vn_default_error}, /* lookup */
+ { .opve_op = &vnop_create_desc, .opve_impl = (VOPFUNC)fdesc_create }, /* create */
+ { .opve_op = &vnop_mknod_desc, .opve_impl = (VOPFUNC)fdesc_mknod }, /* mknod */
+ { .opve_op = &vnop_open_desc, .opve_impl = (VOPFUNC)fdesc_open }, /* open */
+ { .opve_op = &vnop_close_desc, .opve_impl = (VOPFUNC)fdesc_close }, /* close */
+ { .opve_op = &vnop_access_desc, .opve_impl = (VOPFUNC)fdesc_access }, /* access */
+ { .opve_op = &vnop_getattr_desc, .opve_impl = (VOPFUNC)fdesc_getattr }, /* getattr */
+ { .opve_op = &vnop_setattr_desc, .opve_impl = (VOPFUNC)fdesc_setattr }, /* setattr */
+ { .opve_op = &vnop_read_desc, .opve_impl = (VOPFUNC)fdesc_read }, /* read */
+ { .opve_op = &vnop_write_desc, .opve_impl = (VOPFUNC)fdesc_write }, /* write */
+ { .opve_op = &vnop_ioctl_desc, .opve_impl = (VOPFUNC)fdesc_ioctl }, /* ioctl */
+ { .opve_op = &vnop_select_desc, .opve_impl = (VOPFUNC)fdesc_select }, /* select */
+ { .opve_op = &vnop_revoke_desc, .opve_impl = (VOPFUNC)fdesc_revoke }, /* revoke */
+ { .opve_op = &vnop_mmap_desc, .opve_impl = (VOPFUNC)fdesc_mmap }, /* mmap */
+ { .opve_op = &vnop_fsync_desc, .opve_impl = (VOPFUNC)fdesc_fsync }, /* fsync */
+ { .opve_op = &vnop_remove_desc, .opve_impl = (VOPFUNC)fdesc_remove }, /* remove */
+ { .opve_op = &vnop_link_desc, .opve_impl = (VOPFUNC)fdesc_link }, /* link */
+ { .opve_op = &vnop_rename_desc, .opve_impl = (VOPFUNC)fdesc_rename }, /* rename */
+ { .opve_op = &vnop_mkdir_desc, .opve_impl = (VOPFUNC)fdesc_mkdir }, /* mkdir */
+ { .opve_op = &vnop_rmdir_desc, .opve_impl = (VOPFUNC)fdesc_rmdir }, /* rmdir */
+ { .opve_op = &vnop_symlink_desc, .opve_impl = (VOPFUNC)fdesc_symlink }, /* symlink */
+ { .opve_op = &vnop_readdir_desc, .opve_impl = (VOPFUNC)vn_default_error},/* readdir */
+ { .opve_op = &vnop_readlink_desc, .opve_impl = (VOPFUNC)err_readlink}, /* readlink */
+ { .opve_op = &vnop_inactive_desc, .opve_impl = (VOPFUNC)fdesc_inactive },/* inactive */
+ { .opve_op = &vnop_reclaim_desc, .opve_impl = (VOPFUNC)fdesc_reclaim }, /* reclaim */
+ { .opve_op = &vnop_strategy_desc, .opve_impl = (VOPFUNC)fdesc_strategy }, /* strategy */
+ { .opve_op = &vnop_pathconf_desc, .opve_impl = (VOPFUNC)fdesc_pathconf }, /* pathconf */
+ { .opve_op = &vnop_advlock_desc, .opve_impl = (VOPFUNC)fdesc_advlock }, /* advlock */
+ { .opve_op = &vnop_bwrite_desc, .opve_impl = (VOPFUNC)fdesc_bwrite }, /* bwrite */
+ { .opve_op = &vnop_pagein_desc, .opve_impl = (VOPFUNC)err_pagein }, /* pagein */
+ { .opve_op = &vnop_pageout_desc, .opve_impl = (VOPFUNC)err_pageout }, /* pageout */
+ { .opve_op = &vnop_copyfile_desc, .opve_impl = (VOPFUNC)err_copyfile }, /* Copyfile */
+ { .opve_op = &vnop_blktooff_desc, .opve_impl = (VOPFUNC)fdesc_blktooff }, /* blktooff */
+ { .opve_op = &vnop_blktooff_desc, .opve_impl = (VOPFUNC)fdesc_offtoblk }, /* offtoblk */
+ { .opve_op = &vnop_blockmap_desc, .opve_impl = (VOPFUNC)fdesc_blockmap }, /* blockmap */
+ { .opve_op = (struct vnodeop_desc*)NULL, .opve_impl = (VOPFUNC)NULL }
};
-struct vnodeopv_desc devfs_fdesc_vnodeop_opv_desc =
-{ &fdesc_vnodeop_p, devfs_fdesc_vnodeop_entries };
+const struct vnodeopv_desc devfs_fdesc_vnodeop_opv_desc =
+{ .opv_desc_vector_p = &fdesc_vnodeop_p, .opv_desc_ops = devfs_fdesc_vnodeop_entries };