Deleted Added
full compact
pseudofs_vnops.c (159996) pseudofs_vnops.c (168720)
1/*-
2 * Copyright (c) 2001 Dag-Erling Co�dan Sm�rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001 Dag-Erling Co�dan Sm�rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/fs/pseudofs/pseudofs_vnops.c 159996 2006-06-27 20:21:38Z netchild $");
30__FBSDID("$FreeBSD: head/sys/fs/pseudofs/pseudofs_vnops.c 168720 2007-04-14 14:08:30Z des $");
31
32#include "opt_pseudofs.h"
33
34#include <sys/param.h>
35#include <sys/kernel.h>
36#include <sys/systm.h>
37#include <sys/ctype.h>
38#include <sys/dirent.h>

--- 37 unchanged lines hidden (view full) ---

76#else
77#define PFS_TRACE(foo) \
78 do { /* nothing */ } while (0)
79#define PFS_RETURN(err) \
80 return (err)
81#endif
82
83/*
31
32#include "opt_pseudofs.h"
33
34#include <sys/param.h>
35#include <sys/kernel.h>
36#include <sys/systm.h>
37#include <sys/ctype.h>
38#include <sys/dirent.h>

--- 37 unchanged lines hidden (view full) ---

76#else
77#define PFS_TRACE(foo) \
78 do { /* nothing */ } while (0)
79#define PFS_RETURN(err) \
80 return (err)
81#endif
82
83/*
84 *
85 */
86static uint32_t
87pfs_fileno(struct pfs_node *pn, pid_t pid)
88{
89 if (!pn->pn_fileno)
90 pfs_fileno_alloc(pn);
91 if (pid != NO_PID)
92 return (pn->pn_fileno * NO_PID + pid);
93 return (pn->pn_fileno);
94}
95
96/*
84 * Returns non-zero if given file is visible to given process. If the 'p'
85 * parameter is non-NULL, then it will hold a pointer to the process the
86 * given file belongs to on return and the process will be locked.
87 */
88static int
89pfs_visible(struct thread *td, struct pfs_node *pn, pid_t pid, struct proc **p)
90{
91 struct proc *proc;

--- 96 unchanged lines hidden (view full) ---

188
189 PFS_TRACE((pn->pn_name));
190
191 if (!pfs_visible(curthread, pn, pvd->pvd_pid, &proc))
192 PFS_RETURN (ENOENT);
193
194 VATTR_NULL(vap);
195 vap->va_type = vn->v_type;
97 * Returns non-zero if given file is visible to given process. If the 'p'
98 * parameter is non-NULL, then it will hold a pointer to the process the
99 * given file belongs to on return and the process will be locked.
100 */
101static int
102pfs_visible(struct thread *td, struct pfs_node *pn, pid_t pid, struct proc **p)
103{
104 struct proc *proc;

--- 96 unchanged lines hidden (view full) ---

201
202 PFS_TRACE((pn->pn_name));
203
204 if (!pfs_visible(curthread, pn, pvd->pvd_pid, &proc))
205 PFS_RETURN (ENOENT);
206
207 VATTR_NULL(vap);
208 vap->va_type = vn->v_type;
196 vap->va_fileid = pn->pn_fileno;
209 vap->va_fileid = pfs_fileno(pn, pvd->pvd_pid);
197 vap->va_flags = 0;
198 vap->va_blocksize = PAGE_SIZE;
199 vap->va_bytes = vap->va_size = 0;
200 vap->va_fsid = vn->v_mount->mnt_stat.f_fsid.val[0];
201 vap->va_nlink = 1;
202 nanotime(&vap->va_ctime);
203 vap->va_atime = vap->va_mtime = vap->va_ctime;
204

--- 381 unchanged lines hidden (view full) ---

586
587/*
588 * Return directory entries.
589 */
590static int
591pfs_readdir(struct vop_readdir_args *va)
592{
593 struct vnode *vn = va->a_vp;
210 vap->va_flags = 0;
211 vap->va_blocksize = PAGE_SIZE;
212 vap->va_bytes = vap->va_size = 0;
213 vap->va_fsid = vn->v_mount->mnt_stat.f_fsid.val[0];
214 vap->va_nlink = 1;
215 nanotime(&vap->va_ctime);
216 vap->va_atime = vap->va_mtime = vap->va_ctime;
217

--- 381 unchanged lines hidden (view full) ---

599
600/*
601 * Return directory entries.
602 */
603static int
604pfs_readdir(struct vop_readdir_args *va)
605{
606 struct vnode *vn = va->a_vp;
594 struct pfs_info *pi = (struct pfs_info *)vn->v_mount->mnt_data;
595 struct pfs_vdata *pvd = (struct pfs_vdata *)vn->v_data;
596 struct pfs_node *pd = pvd->pvd_pn;
597 pid_t pid = pvd->pvd_pid;
598 struct pfs_node *pn;
599 struct dirent *entry;
600 struct uio *uio;
601 struct proc *p;
602 off_t offset;
603 int error, i, resid;
604 char *buf, *ent;
605
607 struct pfs_vdata *pvd = (struct pfs_vdata *)vn->v_data;
608 struct pfs_node *pd = pvd->pvd_pn;
609 pid_t pid = pvd->pvd_pid;
610 struct pfs_node *pn;
611 struct dirent *entry;
612 struct uio *uio;
613 struct proc *p;
614 off_t offset;
615 int error, i, resid;
616 char *buf, *ent;
617
618 KASSERT(pd->pn_info == vn->v_mount->mnt_data,
619 ("directory's pn_info does not match mountpoint's mnt_data"));
606 PFS_TRACE((pd->pn_name));
607
608 if (vn->v_type != VDIR)
609 PFS_RETURN (ENOTDIR);
610 uio = va->a_uio;
611
612 /* check if the directory is visible to the caller */
613 if (!pfs_visible(curthread, pd, pid, NULL))

--- 20 unchanged lines hidden (view full) ---

634 /* fill in entries */
635 ent = buf = malloc(resid, M_IOV, M_WAITOK | M_ZERO);
636 while (pfs_iterate(curthread, pid, pd, &pn, &p) != -1 &&
637 resid >= PFS_DELEN) {
638 entry = (struct dirent *)ent;
639 entry->d_reclen = PFS_DELEN;
640 if (!pn->pn_parent)
641 pn->pn_parent = pd;
620 PFS_TRACE((pd->pn_name));
621
622 if (vn->v_type != VDIR)
623 PFS_RETURN (ENOTDIR);
624 uio = va->a_uio;
625
626 /* check if the directory is visible to the caller */
627 if (!pfs_visible(curthread, pd, pid, NULL))

--- 20 unchanged lines hidden (view full) ---

648 /* fill in entries */
649 ent = buf = malloc(resid, M_IOV, M_WAITOK | M_ZERO);
650 while (pfs_iterate(curthread, pid, pd, &pn, &p) != -1 &&
651 resid >= PFS_DELEN) {
652 entry = (struct dirent *)ent;
653 entry->d_reclen = PFS_DELEN;
654 if (!pn->pn_parent)
655 pn->pn_parent = pd;
642 if (!pn->pn_fileno)
643 pfs_fileno_alloc(pi, pn);
644 if (pid != NO_PID)
645 entry->d_fileno = pn->pn_fileno * NO_PID + pid;
646 else
647 entry->d_fileno = pn->pn_fileno;
656 entry->d_fileno = pfs_fileno(pn, pid);
648 /* PFS_DELEN was picked to fit PFS_NAMLEN */
649 for (i = 0; i < PFS_NAMELEN - 1 && pn->pn_name[i] != '\0'; ++i)
650 entry->d_name[i] = pn->pn_name[i];
651 entry->d_name[i] = 0;
652 entry->d_namlen = i;
653 switch (pn->pn_type) {
654 case pfstype_procdir:
655 KASSERT(p != NULL,
656 ("reached procdir node with p == NULL"));
657 /* PFS_DELEN was picked to fit PFS_NAMLEN */
658 for (i = 0; i < PFS_NAMELEN - 1 && pn->pn_name[i] != '\0'; ++i)
659 entry->d_name[i] = pn->pn_name[i];
660 entry->d_name[i] = 0;
661 entry->d_namlen = i;
662 switch (pn->pn_type) {
663 case pfstype_procdir:
664 KASSERT(p != NULL,
665 ("reached procdir node with p == NULL"));
657 entry->d_fileno = pn->pn_fileno * NO_PID + p->p_pid;
658 entry->d_namlen = snprintf(entry->d_name,
659 PFS_NAMELEN, "%d", p->p_pid);
660 /* fall through */
661 case pfstype_root:
662 case pfstype_dir:
663 case pfstype_this:
664 case pfstype_parent:
665 entry->d_type = DT_DIR;

--- 183 unchanged lines hidden ---
666 entry->d_namlen = snprintf(entry->d_name,
667 PFS_NAMELEN, "%d", p->p_pid);
668 /* fall through */
669 case pfstype_root:
670 case pfstype_dir:
671 case pfstype_this:
672 case pfstype_parent:
673 entry->d_type = DT_DIR;

--- 183 unchanged lines hidden ---