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 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); }