FreeBSD/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c
/*
 * Attempt to find the local dataset associated with this guid.  In the case of
 * multiple matches, we attempt to find the "best" match by searching
 * progressively larger portions of the hierarchy.  This allows one to send a
 * tree of datasets individually and guarantee that we will find the source
 * guid within that hierarchy, even if there are multiple matches elsewhere.
 */
Attempt to find the local dataset associated with this guid.  In the case of
multiple matches, we attempt to find the "best" match by searching
progressively larger portions of the hierarchy.  This allows one to send a
tree of datasets individually and guarantee that we will find the source
guid within that hierarchy, even if there are multiple matches elsewhere.
Attempt to find the local dataset associated with this guid . In the case of multiple matches we attempt to find the " best " match by searching progressively larger portions of the hierarchy . This allows one to send a tree of datasets individually and guarantee that we will find the source guid within that hierarchy even if there are multiple matches elsewhere .
static int
guid_to_name(libzfs_handle_t *hdl, const char *parent, uint64_t guid,
    boolean_t bookmark_ok, char *name)
{
	char pname[ZFS_MAXNAMELEN];
	guid_to_name_data_t gtnd;
	gtnd.guid = guid;
	gtnd.bookmark_ok = bookmark_ok;
	gtnd.name = name;
	gtnd.skip = NULL;
	(void) strlcpy(pname, parent, sizeof (pname));
	char *cp = strrchr(pname, '@');
	if (cp == NULL)
		cp = strchr(pname, '\0');
	for (; cp != NULL; cp = strrchr(pname, '/')) {
		*cp = '\0';
		zfs_handle_t *zhp = make_dataset_handle(hdl, pname);
		if (zhp == NULL)
			continue;
		int err = guid_to_name_cb(zfs_handle_dup(zhp), &gtnd);
		if (err != EEXIST)
			err = zfs_iter_children(zhp, guid_to_name_cb, &gtnd);
		if (err != EEXIST && bookmark_ok)
			err = zfs_iter_bookmarks(zhp, guid_to_name_cb, &gtnd);
		zfs_close(zhp);
		if (err == EEXIST)
			return (0);
		gtnd.skip = strrchr(pname, '/') + 1;
	}
	return (ENOENT);
}
static int guid_to_name ( libzfs_handle_t * hdl , const char * parent , uint64_t guid , boolean_t bookmark_ok , char * name ) { char pname [ ZFS_MAXNAMELEN ] ; guid_to_name_data_t gtnd ; gtnd . guid = guid ; gtnd . bookmark_ok = bookmark_ok ; gtnd . name = name ; gtnd . skip = NULL ; ( void ) strlcpy ( pname , parent , sizeof ( pname ) ) ; char * cp = strrchr ( pname , ' ' ) ; if ( cp == NULL ) cp = strchr ( pname , ' \0 ' ) ; for ( ; cp != NULL ; cp = strrchr ( pname , ' ' ) ) { * cp = ' \0 ' ; zfs_handle_t * zhp = make_dataset_handle ( hdl , pname ) ; if ( zhp == NULL ) continue ; int err = guid_to_name_cb ( zfs_handle_dup ( zhp ) , & gtnd ) ; if ( err != EEXIST ) err = zfs_iter_children ( zhp , guid_to_name_cb , & gtnd ) ; if ( err != EEXIST && bookmark_ok ) err = zfs_iter_bookmarks ( zhp , guid_to_name_cb , & gtnd ) ; zfs_close ( zhp ) ; if ( err == EEXIST ) return ( 0 ) ; gtnd . skip = strrchr ( pname , ' ' ) + 1 ; } return ( ENOENT ) ; }
Attempt to find the local dataset associated with this guid.
Attempt to find the local dataset associated with this guid .
/*
	 * Search progressively larger portions of the hierarchy, starting
	 * with the filesystem specified by 'parent'.  This will
	 * select the "most local" version of the origin snapshot in the case
	 * that there are multiple matching snapshots in the system.
	 */ /* Chop off the last component and open the parent */ /*
		 * Remember the last portion of the dataset so we skip it next
		 * time through (as we've already searched that portion of the
		 * hierarchy).
		 */