int smbfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) { struct smbnode node; struct mount mnt; int error; assert(kd); assert(vn); error = kvm_read_all(kd, (unsigned long)VTOSMB(vp), &node, sizeof(node)); if (error != 0) { warnx("can't read smbfs fnode at %p", (void *)VTOSMB(vp)); return (1); } error = kvm_read_all(kd, (unsigned long)getvnodemount(vp), &mnt, sizeof(mnt)); if (error != 0) { warnx("can't read mount at %p for vnode %p", (void *)getvnodemount(vp), vp); return (1); } vn->vn_fileid = node.n_ino; if (vn->vn_fileid == 0) vn->vn_fileid = 2; vn->vn_fsid = mnt.mnt_stat.f_fsid.val[0]; return (0); }
int isofs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) { struct iso_node isonode; struct iso_mnt mnt; if (!kvm_read_all(kd, (unsigned long)VTOI(vp), &isonode, sizeof(isonode))) { warnx("can't read iso_node at %p", (void *)VTOI(vp)); return (1); } if (!kvm_read_all(kd, (unsigned long)isonode.i_mnt, &mnt, sizeof(mnt))) { warnx("can't read iso_mnt at %p", (void *)VTOI(vp)); return (1); } vn->vn_fsid = dev2udev(kd, mnt.im_dev); vn->vn_mode = (mode_t)isonode.inode.iso_mode; vn->vn_fileid = isonode.i_number; vn->vn_size = isonode.i_size; return (0); }
int udf_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) { struct udf_node node; struct udf_mnt mnt; int error; assert(kd); assert(vn); error = kvm_read_all(kd, (unsigned long)VTON(vp), &node, sizeof(node)); if (error != 0) { warnx("can't read udf fnode at %p", (void *)VTON(vp)); return (1); } error = kvm_read_all(kd, (unsigned long)node.udfmp, &mnt, sizeof(mnt)); if (error != 0) { warnx("can't read udf_mnt at %p for vnode %p", (void *)node.udfmp, vp); return (1); } vn->vn_fileid = node.hash_id; vn->vn_fsid = dev2udev(kd, mnt.im_dev); return (0); }
int zfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) { znode_phys_t zphys; struct mount mount, *mountptr; uint64_t *zid; void *znodeptr, *vnodeptr; char *dataptr; void *zphys_addr; size_t len; int size; len = sizeof(size); if (sysctlbyname("debug.sizeof.znode", &size, &len, NULL, 0) == -1) { warnx("error getting sysctl"); return (1); } znodeptr = malloc(size); if (znodeptr == NULL) { warnx("error allocating memory for znode storage"); return (1); } /* Since we have problems including vnode.h, we'll use the wrappers. */ vnodeptr = getvnodedata(vp); if (!kvm_read_all(kd, (unsigned long)vnodeptr, znodeptr, (size_t)size)) { warnx("can't read znode at %p", (void *)vnodeptr); goto bad; } /* * z_id field is stored in the third pointer. We therefore skip the two * first bytes. * * Pointer to the z_phys structure is the next last pointer. Therefore * go back two bytes from the end. */ dataptr = znodeptr; zid = (uint64_t *)(dataptr + LOCATION_ZID); zphys_addr = *(void **)(dataptr + LOCATION_ZPHYS(size)); if (!kvm_read_all(kd, (unsigned long)zphys_addr, &zphys, sizeof(zphys))) { warnx("can't read znode_phys at %p", zphys_addr); goto bad; } /* Get the mount pointer, and read from the address. */ mountptr = getvnodemount(vp); if (!kvm_read_all(kd, (unsigned long)mountptr, &mount, sizeof(mount))) { warnx("can't read mount at %p", (void *)mountptr); goto bad; } vn->vn_fsid = mount.mnt_stat.f_fsid.val[0]; vn->vn_fileid = *zid; /* * XXX: Shows up wrong in output, but UFS has this error too. Could * be that we're casting mode-variables from 64-bit to 8-bit or simply * error in the mode-to-string function. */ vn->vn_mode = (mode_t)zphys.zp_mode; vn->vn_size = (u_long)zphys.zp_size; free(znodeptr); return (0); bad: free(znodeptr); return (1); }
int msdosfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) { struct denode denode; static struct dosmount *mounts; struct dosmount *mnt; u_long dirsperblk; int fileid; if (!kvm_read_all(kd, (unsigned long)VTODE(vp), &denode, sizeof(denode))) { warnx("can't read denode at %p", (void *)VTODE(vp)); return (1); } /* * Find msdosfsmount structure for the vnode's filesystem. Needed * for some filesystem parameters */ for (mnt = mounts; mnt; mnt = mnt->next) if (mnt->kptr == denode.de_pmp) break; if (!mnt) { if ((mnt = malloc(sizeof(struct dosmount))) == NULL) { warn("malloc()"); return (1); } if (!kvm_read_all(kd, (unsigned long)denode.de_pmp, &mnt->data, sizeof(mnt->data))) { free(mnt); warnx("can't read mount info at %p", (void *)denode.de_pmp); return (1); } mnt->next = mounts; mounts = mnt; mnt->kptr = denode.de_pmp; } vn->vn_fsid = dev2udev(kd, mnt->data.pm_dev); vn->vn_mode = 0555; vn->vn_mode |= denode.de_Attributes & ATTR_READONLY ? 0 : 0222; vn->vn_mode &= mnt->data.pm_mask; /* Distinguish directories and files. No "special" files in FAT. */ vn->vn_mode |= denode.de_Attributes & ATTR_DIRECTORY ? S_IFDIR : S_IFREG; vn->vn_size = denode.de_FileSize; /* * XXX - * Culled from msdosfs_vnops.c. There appears to be a problem * here, in that a directory has the same inode number as the first * file in the directory. stat(2) suffers from this problem also, so * I won't try to fix it here. * * The following computation of the fileid must be the same as that * used in msdosfs_readdir() to compute d_fileno. If not, pwd * doesn't work. */ dirsperblk = mnt->data.pm_BytesPerSec / sizeof(struct direntry); if (denode.de_Attributes & ATTR_DIRECTORY) { fileid = cntobn(&mnt->data, denode.de_StartCluster) * dirsperblk; if (denode.de_StartCluster == MSDOSFSROOT) fileid = 1; } else { fileid = cntobn(&mnt->data, denode.de_dirclust) * dirsperblk; if (denode.de_dirclust == MSDOSFSROOT) fileid = roottobn(&mnt->data, 0) * dirsperblk; fileid += denode.de_diroffset / sizeof(struct direntry); } vn->vn_fileid = fileid; return (0); }