Exemplo n.º 1
0
Arquivo: fstat.c Projeto: MarginC/kame
void
vtrans(struct vnode *vp, int i, int flag, off_t offset)
{
	struct vnode vn;
	struct filestat fst;
	char rw[3], mode[17];
	char *badtype = NULL, *filename;

	filename = badtype = NULL;
	if (!KVM_READ(vp, &vn, sizeof (struct vnode))) {
		dprintf("can't read vnode at %p for pid %ld", vp, (long)Pid);
		return;
	}
	if (vn.v_type == VNON || vn.v_tag == VT_NON)
		badtype = "none";
	else if (vn.v_type == VBAD)
		badtype = "bad";
	else
		switch (vn.v_tag) {
		case VT_UFS:
		case VT_MFS:
			if (!ufs_filestat(&vn, &fst))
				badtype = "error";
			break;
		case VT_NFS:
			if (!nfs_filestat(&vn, &fst))
				badtype = "error";
			break;
		case VT_EXT2FS:
			if (!ext2fs_filestat(&vn, &fst))
				badtype = "error";
			break;
		case VT_ISOFS:
			if (!isofs_filestat(&vn, &fst))
				badtype = "error";
			break;
		case VT_MSDOSFS:
			if (!msdos_filestat(&vn, &fst))
				badtype = "error";
			break;
		case VT_XFS:
			if (!xfs_filestat(&vn, &fst))
				badtype = "error";
			break;
		case VT_NULL:
			if (!null_filestat(&vn, &fst))
				badtype = "error";
			break;
		default: {
			static char unknown[30];
			snprintf(badtype = unknown, sizeof unknown,
			    "?(%x)", vn.v_tag);
			break;
		}
	}
	if (checkfile) {
		int fsmatch = 0;
		DEVS *d;

		if (badtype)
			return;
		for (d = devs; d != NULL; d = d->next)
			if (d->fsid == fst.fsid) {
				fsmatch = 1;
				if (d->ino == fst.fileid) {
					filename = d->name;
					break;
				}
			}
		if (fsmatch == 0 || (filename == NULL && fsflg == 0))
			return;
	}
	PREFIX(i);
	if (badtype) {
		(void)printf(" -         -  %10s    -\n", badtype);
		return;
	}
	if (nflg)
		(void)printf(" %2ld,%-2ld", (long)major(fst.fsid),
		    (long)minor(fst.fsid));
	else
		(void)printf(" %-8s", getmnton(vn.v_mount));
	if (nflg)
		(void)snprintf(mode, sizeof mode, "%o", fst.mode);
	else
		strmode(fst.mode, mode);
	(void)printf(" %6ld %11s", fst.fileid, mode);
	rw[0] = '\0';
	if (flag & FREAD)
		strlcat(rw, "r", sizeof rw);
	if (flag & FWRITE)
		strlcat(rw, "w", sizeof rw);
	printf(" %2s", rw);
	switch (vn.v_type) {
	case VBLK:
	case VCHR: {
		char *name;

		if (nflg || ((name = devname(fst.rdev, vn.v_type == VCHR ?
		    S_IFCHR : S_IFBLK)) == NULL))
			printf("   %2d,%-3d", major(fst.rdev), minor(fst.rdev));
		else
			printf("  %7s", name);
		if (oflg)
			printf("         ");
		break;
	}
	default:
		printf(" %8lld", (long long)fst.size);
		if (oflg)
			printf(":%-8lld", (long long)offset);
	}
	if (filename && !fsflg)
		printf(" %s", filename);
	putchar('\n');
}
Exemplo n.º 2
0
void
vtrans(struct vnode *vp, struct nchandle *ncr, int i, int flag, off_t off)
{
    struct vnode vn;
    struct filestat fst;
    char rw[3], mode[15];
    const char *badtype = NULL, *filename;
    char *name;

    fst.offset = off;
    filename = badtype = NULL;
    if (!kread(vp, &vn, sizeof (struct vnode))) {
        dprintf(stderr, "can't read vnode at %p for pid %d\n",
                (void *)vp, Pid);
        return;
    }
    if (vn.v_type == VNON || vn.v_tag == VT_NON)
        badtype = "none";
    else if (vn.v_type == VBAD)
        badtype = "bad";
    else
        switch (vn.v_tag) {
        case VT_UFS:
            if (!ufs_filestat(&vn, &fst))
                badtype = "error";
            break;
        case VT_MFS:
            if (!ufs_filestat(&vn, &fst))
                badtype = "error";
            break;
        case VT_NFS:
            if (!nfs_filestat(&vn, &fst))
                badtype = "error";
            break;

        case VT_MSDOSFS:
            if (!msdosfs_filestat(&vn, &fst))
                badtype = "error";
            break;

        case VT_ISOFS:
            if (!isofs_filestat(&vn, &fst))
                badtype = "error";
            break;

        case VT_DEVFS:
            if (!devfs_filestat(&vn, &fst))
                badtype = "error";
            break;

        default: {
            static char unknown[10];
            sprintf(unknown, "?(%x)", vn.v_tag);
            badtype=unknown;
            break;
        }
        }
    if (checkfile) {
        int fsmatch = 0;
        DEVS *d;

        if (badtype)
            return;
        for (d = devs; d != NULL; d = d->next)
            if (d->fsid == fst.fsid) {
                fsmatch = 1;
                if (d->ino == (ino_t)fst.fileid) {
                    filename = d->name;
                    break;
                }
            }
        if (fsmatch == 0 || (filename == NULL && fsflg == 0))
            return;
    }
    PREFIX(i);
    if (badtype) {
        (void)printf(" %-*s  %10s    %jd\n",
                     wflg_mnt,
                     getmnton(vn.v_mount, &vn.v_namecache, ncr),
                     badtype,
                     (intmax_t)off);
        return;
    }
    if (nflg)
        (void)printf(" %3d,%-9d   ", major(fst.fsid), minor(fst.fsid));
    else
        (void)printf(" %-*s", wflg_mnt, getmnton(vn.v_mount, &vn.v_namecache, ncr));
    if (nflg)
        (void)sprintf(mode, "%o", fst.mode);
    else
        strmode(fst.mode, mode);
    (void)printf(" %*ld %10s", ino_width, fst.fileid, mode);
    switch (vn.v_type) {
    case VBLK:
    case VCHR:
        if (nflg || ((name = devname(fst.rdev, vn.v_type == VCHR ?
                                     S_IFCHR : S_IFBLK)) == NULL))
            printf(" %3d,%-4d", major(fst.rdev), minor(fst.rdev));
        else
            printf(" %8s", name);
        break;
    case VREG:
        printf(" %jd", (intmax_t)fst.offset);
        break;
    default:
        printf(" %8ju", (uintmax_t)fst.size);
    }
    rw[0] = '\0';
    if (flag & FREAD)
        strcat(rw, "r");
    if (flag & FWRITE)
        strcat(rw, "w");
    printf(" %2s", rw);
    if (filename && !fsflg)
        printf("  %s", filename);
    putchar('\n');
}
Exemplo n.º 3
0
void
vtrans(struct vnode *vp, int i, int flag)
{
	struct vnode vn;
	struct filestat fst;
	char rw[3], mode[15], tagstr[12], *tagptr;
	const char *badtype, *filename;

	filename = badtype = NULL;
	if (!KVM_READ(vp, &vn, sizeof (struct vnode))) {
		dprintf(stderr, "can't read vnode at %p for pid %d\n",
		    (void *)vp, Pid);
		return;
	}
	if (!KVM_READ(&vp->v_tag, &tagptr, sizeof tagptr) ||
	    !KVM_READ(tagptr, tagstr, sizeof tagstr)) {
		dprintf(stderr, "can't read v_tag at %p for pid %d\n",
		    (void *)vp, Pid);
		return;
	}
	tagstr[sizeof(tagstr) - 1] = '\0';
	if (vn.v_type == VNON)
		badtype = "none";
	else if (vn.v_type == VBAD)
		badtype = "bad";
	else {
		if (!strcmp("ufs", tagstr)) {
			if (!ufs_filestat(&vn, &fst))
				badtype = "error";
		} else if (!strcmp("devfs", tagstr)) {
			if (!devfs_filestat(&vn, &fst))
				badtype = "error";
		} else if (!strcmp("nfs", tagstr)) {
			if (!nfs_filestat(&vn, &fst))
				badtype = "error";
		} else if (!strcmp("msdosfs", tagstr)) {
			if (!msdosfs_filestat(&vn, &fst))
				badtype = "error";
		} else if (!strcmp("isofs", tagstr)) {
			if (!isofs_filestat(&vn, &fst))
				badtype = "error";
#ifdef ZFS
		} else if (!strcmp("zfs", tagstr)) {
			if (!zfs_filestat(&vn, &fst))
				badtype = "error";
#endif
		} else {
			static char unknown[32];
			snprintf(unknown, sizeof unknown, "?(%s)", tagstr);
			badtype = unknown;
		}
	}
	if (checkfile) {
		int fsmatch = 0;
		DEVS *d;

		if (badtype)
			return;
		for (d = devs; d != NULL; d = d->next)
			if (d->fsid == fst.fsid) {
				fsmatch = 1;
				if (d->ino == fst.fileid) {
					filename = d->name;
					break;
				}
			}
		if (fsmatch == 0 || (filename == NULL && fsflg == 0))
			return;
	}
	PREFIX(i);
	if (badtype) {
		(void)printf(" -         -  %10s    -\n", badtype);
		return;
	}
	if (nflg)
		(void)printf(" %2d,%-2d", major(fst.fsid), minor(fst.fsid));
	else
		(void)printf(" %-8s", getmnton(vn.v_mount));
	if (nflg)
		(void)sprintf(mode, "%o", fst.mode);
	else
		strmode(fst.mode, mode);
	(void)printf(" %6ld %10s", fst.fileid, mode);
	switch (vn.v_type) {
	case VBLK:
	case VCHR: {
		char *name;

		name = kdevtoname(vn.v_rdev);
		if (nflg || !name)
			printf("  %2d,%-2d", major(fst.rdev), minor(fst.rdev));
		else {
			printf(" %6s", name);
			free(name);
		}
		break;
	}
	default:
		printf(" %6lu", fst.size);
	}
	rw[0] = '\0';
	if (flag & FREAD)
		strcat(rw, "r");
	if (flag & FWRITE)
		strcat(rw, "w");
	printf(" %2s", rw);
	if (filename && !fsflg)
		printf("  %s", filename);
	putchar('\n');
}