diff -r db301dea93e8 sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_znode.h --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_znode.h Wed May 27 22:30:09 2009 +0000 +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_znode.h Wed May 27 22:58:17 2009 +0000 @@ -166,7 +166,7 @@ * They are used to protect creates, deletes, and renames. * Each directory znode has a mutex and a list of locked names. */ -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_WANT_ZNODE) typedef struct zfs_dirlock { char *dl_name; /* directory entry being locked */ uint32_t dl_sharecnt; /* 0 if exclusive, > 0 if shared */ @@ -206,8 +206,10 @@ /* FreeBSD-specific field. */ struct task z_task; } znode_t; +#endif +#ifdef _KERNEL /* * Range locking rules * -------------------- diff -r db301dea93e8 sys/sys/taskqueue.h --- a/sys/sys/taskqueue.h Wed May 27 22:30:09 2009 +0000 +++ b/sys/sys/taskqueue.h Wed May 27 22:58:17 2009 +0000 @@ -29,7 +29,7 @@ #ifndef _SYS_TASKQUEUE_H_ #define _SYS_TASKQUEUE_H_ -#ifndef _KERNEL +#if !defined(_KERNEL) && !defined(_WANT_ZNODE) #error "no user-servicable parts inside" #endif diff -r db301dea93e8 usr.bin/fstat/zfs.c --- a/usr.bin/fstat/zfs.c Wed May 27 22:30:09 2009 +0000 +++ b/usr.bin/fstat/zfs.c Wed May 27 22:58:17 2009 +0000 @@ -32,6 +32,8 @@ #undef _KERNEL #include +#define _WANT_ZNODE +#include #undef lbolt #undef lbolt64 #undef gethrestime_sec @@ -62,50 +64,22 @@ int zfs_filestat(struct vnode *vp, struct filestat *fsp) { - + znode_t znode; 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) { - dprintf(stderr, "error getting sysctl\n"); - return (0); - } - znodeptr = malloc(size); - if (znodeptr == NULL) { - dprintf(stderr, "error allocating memory for znode storage\n"); - return (0); - } + void *vnodeptr; /* Since we have problems including vnode.h, we'll use the wrappers. */ vnodeptr = getvnodedata(vp); - if (!KVM_READ(vnodeptr, znodeptr, (size_t)size)) { + if (!KVM_READ(vnodeptr, &znode, sizeof(znode))) { dprintf(stderr, "can't read znode at %p for pid %d\n", (void *)vnodeptr, Pid); - goto bad; + return (0); } - - /* - * 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(zphys_addr, &zphys, sizeof(zphys))) { + if (!KVM_READ(znode.z_phys, &zphys, sizeof(zphys))) { dprintf(stderr, "can't read znode_phys at %p for pid %d\n", - zphys_addr, Pid); - goto bad; + &znode.z_phys, Pid); + return (0); } /* Get the mount pointer, and read from the address. */ @@ -113,11 +87,11 @@ if (!KVM_READ(mountptr, &mount, sizeof(mount))) { dprintf(stderr, "can't read mount at %p for pid %d\n", (void *)mountptr, Pid); - goto bad; + return (0); } fsp->fsid = (long)mount.mnt_stat.f_fsid.val[0]; - fsp->fileid = *zid; + fsp->fileid = znode.z_id; /* * 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 @@ -126,9 +100,5 @@ fsp->mode = (mode_t)zphys.zp_mode; fsp->size = (u_long)zphys.zp_size; fsp->rdev = (dev_t)zphys.zp_rdev; - free(znodeptr); return (1); -bad: - free(znodeptr); - return (0); }