static char * get_zfs_dataset(sa_handle_impl_t impl_handle, char *path, boolean_t search_mnttab) { size_t i, count = 0; char *dataset = NULL; zfs_handle_t **zlist; char mountpoint[ZFS_MAXPROPLEN]; char canmount[ZFS_MAXPROPLEN]; get_all_filesystems(impl_handle, &zlist, &count); qsort(zlist, count, sizeof (void *), mountpoint_compare); for (i = 0; i < count; i++) { /* must have a mountpoint */ if (zfs_prop_get(zlist[i], ZFS_PROP_MOUNTPOINT, mountpoint, sizeof (mountpoint), NULL, NULL, 0, B_FALSE) != 0) { /* no mountpoint */ continue; } /* mountpoint must be a path */ if (strcmp(mountpoint, ZFS_MOUNTPOINT_NONE) == 0 || strcmp(mountpoint, ZFS_MOUNTPOINT_LEGACY) == 0) { /* * Search mmttab for mountpoint and get dataset. */ if (search_mnttab == B_TRUE && get_legacy_mountpoint(path, mountpoint, sizeof (mountpoint), NULL, 0) == 0) { dataset = mountpoint; break; } continue; } /* canmount must be set */ canmount[0] = '\0'; if (zfs_prop_get(zlist[i], ZFS_PROP_CANMOUNT, canmount, sizeof (canmount), NULL, NULL, 0, B_FALSE) != 0 || strcmp(canmount, "off") == 0) continue; /* * have a mountable handle but want to skip those marked none * and legacy */ if (strcmp(mountpoint, path) == 0) { dataset = (char *)zfs_get_name(zlist[i]); break; } } if (dataset != NULL) dataset = strdup(dataset); return (dataset); }
static char * verify_zfs_handle(zfs_handle_t *hdl, const char *path, boolean_t search_mnttab) { char mountpoint[ZFS_MAXPROPLEN]; char canmount[ZFS_MAXPROPLEN] = { 0 }; /* must have a mountpoint */ if (zfs_prop_get(hdl, ZFS_PROP_MOUNTPOINT, mountpoint, sizeof (mountpoint), NULL, NULL, 0, B_FALSE) != 0) { /* no mountpoint */ return (NULL); } /* mountpoint must be a path */ if (strcmp(mountpoint, ZFS_MOUNTPOINT_NONE) == 0 || strcmp(mountpoint, ZFS_MOUNTPOINT_LEGACY) == 0) { /* * Search mmttab for mountpoint and get dataset. */ if (search_mnttab == B_TRUE && get_legacy_mountpoint(path, mountpoint, sizeof (mountpoint), NULL, 0) == 0) { return (strdup(mountpoint)); } return (NULL); } /* canmount must be set */ if (zfs_prop_get(hdl, ZFS_PROP_CANMOUNT, canmount, sizeof (canmount), NULL, NULL, 0, B_FALSE) != 0 || strcmp(canmount, "off") == 0) return (NULL); /* * have a mountable handle but want to skip those marked none * and legacy */ if (strcmp(mountpoint, path) == 0) { return (strdup((char *)zfs_get_name(hdl))); } return (NULL); }
/* * sa_get_zfs_info(libzfs, path, mountpoint, dataset) * * Find the ZFS dataset and mountpoint for a given path */ int sa_zfs_get_info(libzfs_handle_t *libzfs, char *path, char *mountpointp, char *datasetp) { get_all_cbdata_t cb = { 0 }; int i; char mountpoint[ZFS_MAXPROPLEN]; char dataset[ZFS_MAXPROPLEN]; char canmount[ZFS_MAXPROPLEN]; char *dp; int count; int ret = 0; cb.cb_types = ZFS_TYPE_FILESYSTEM; if (libzfs == NULL) return (0); (void) zfs_iter_root(libzfs, get_one_filesystem, &cb); count = cb.cb_used; qsort(cb.cb_handles, count, sizeof (void *), mountpoint_compare); for (i = 0; i < count; i++) { /* must have a mountpoint */ if (zfs_prop_get(cb.cb_handles[i], ZFS_PROP_MOUNTPOINT, mountpoint, sizeof (mountpoint), NULL, NULL, 0, B_FALSE) != 0) { /* no mountpoint */ continue; } /* mountpoint must be a path */ if (strcmp(mountpoint, ZFS_MOUNTPOINT_NONE) == 0 || strcmp(mountpoint, ZFS_MOUNTPOINT_LEGACY) == 0) { /* * Search mmttab for mountpoint */ if (get_legacy_mountpoint(path, dataset, ZFS_MAXPROPLEN, mountpoint, ZFS_MAXPROPLEN) == 0) { ret = 1; break; } continue; } /* canmount must be set */ canmount[0] = '\0'; if (zfs_prop_get(cb.cb_handles[i], ZFS_PROP_CANMOUNT, canmount, sizeof (canmount), NULL, NULL, 0, B_FALSE) != 0 || strcmp(canmount, "off") == 0) continue; /* * have a mountable handle but want to skip those marked none * and legacy */ if (strcmp(mountpoint, path) == 0) { dp = (char *)zfs_get_name(cb.cb_handles[i]); if (dp != NULL) { if (datasetp != NULL) (void) strcpy(datasetp, dp); if (mountpointp != NULL) (void) strcpy(mountpointp, mountpoint); ret = 1; } break; } } return (ret); }