diff options
author | ck153898 <none@none> | 2007-02-12 11:30:24 -0800 |
---|---|---|
committer | ck153898 <none@none> | 2007-02-12 11:30:24 -0800 |
commit | 5aba80db367b061758a29154d304977d00d8e4f4 (patch) | |
tree | 80dfd26b7701f87bd0d278f10812ec7c71b38ead /usr/src/lib/libzfs/common/libzfs_util.c | |
parent | 52d8a8f99665c68b55f5343b8158e0496c889707 (diff) | |
download | illumos-joyent-5aba80db367b061758a29154d304977d00d8e4f4.tar.gz |
PSARC 2007/050 zfs list -d
6260523 want 'zfs list <path>'
Diffstat (limited to 'usr/src/lib/libzfs/common/libzfs_util.c')
-rw-r--r-- | usr/src/lib/libzfs/common/libzfs_util.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/usr/src/lib/libzfs/common/libzfs_util.c b/usr/src/lib/libzfs/common/libzfs_util.c index 48ee3f509e..a16202534b 100644 --- a/usr/src/lib/libzfs/common/libzfs_util.c +++ b/usr/src/lib/libzfs/common/libzfs_util.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -38,6 +38,8 @@ #include <strings.h> #include <unistd.h> #include <sys/mnttab.h> +#include <sys/mntent.h> +#include <sys/types.h> #include <libzfs.h> @@ -521,6 +523,51 @@ zfs_get_handle(zfs_handle_t *zhp) } /* + * Given a name, determine whether or not it's a valid path + * (starts with '/' or "./"). If so, walk the mnttab trying + * to match the device number. If not, treat the path as an + * fs/vol/snap name. + */ +zfs_handle_t * +zfs_path_to_zhandle(libzfs_handle_t *hdl, char *path, zfs_type_t argtype) +{ + struct stat64 statbuf; + struct extmnttab entry; + int ret; + + if (path[0] != '/' && strncmp(path, "./", strlen("./")) != 0) { + /* + * It's not a valid path, assume it's a name of type 'argtype'. + */ + return (zfs_open(hdl, path, argtype)); + } + + if (stat64(path, &statbuf) != 0) { + (void) fprintf(stderr, "%s: %s\n", path, strerror(errno)); + return (NULL); + } + + rewind(hdl->libzfs_mnttab); + while ((ret = getextmntent(hdl->libzfs_mnttab, &entry, 0)) == 0) { + if (makedevice(entry.mnt_major, entry.mnt_minor) == + statbuf.st_dev) { + break; + } + } + if (ret != 0) { + return (NULL); + } + + if (strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0) { + (void) fprintf(stderr, gettext("'%s': not a ZFS filesystem\n"), + path); + return (NULL); + } + + return (zfs_open(hdl, entry.mnt_special, ZFS_TYPE_FILESYSTEM)); +} + +/* * Initialize the zc_nvlist_dst member to prepare for receiving an nvlist from * an ioctl(). */ |