FreeBSD/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c
/*
 * Return +1 if guid1 is before guid2, 0 if they are the same, and -1 if
 * guid1 is after guid2.
 */
Return +1 if guid1 is before guid2, 0 if they are the same, and -1 if
guid1 is after guid2.
Return + 1 if guid1 is before guid2 0 if they are the same and - 1 if guid1 is after guid2 .
static int
created_before(libzfs_handle_t *hdl, avl_tree_t *avl,
    uint64_t guid1, uint64_t guid2)
{
	nvlist_t *nvfs;
	char *fsname, *snapname;
	char buf[ZFS_MAXNAMELEN];
	int rv;
	zfs_handle_t *guid1hdl, *guid2hdl;
	uint64_t create1, create2;
	if (guid2 == 0)
		return (0);
	if (guid1 == 0)
		return (1);
	nvfs = fsavl_find(avl, guid1, &snapname);
	VERIFY(0 == nvlist_lookup_string(nvfs, "name", &fsname));
	(void) snprintf(buf, sizeof (buf), "%s@%s", fsname, snapname);
	guid1hdl = zfs_open(hdl, buf, ZFS_TYPE_SNAPSHOT);
	if (guid1hdl == NULL)
		return (-1);
	nvfs = fsavl_find(avl, guid2, &snapname);
	VERIFY(0 == nvlist_lookup_string(nvfs, "name", &fsname));
	(void) snprintf(buf, sizeof (buf), "%s@%s", fsname, snapname);
	guid2hdl = zfs_open(hdl, buf, ZFS_TYPE_SNAPSHOT);
	if (guid2hdl == NULL) {
		zfs_close(guid1hdl);
		return (-1);
	}
	create1 = zfs_prop_get_int(guid1hdl, ZFS_PROP_CREATETXG);
	create2 = zfs_prop_get_int(guid2hdl, ZFS_PROP_CREATETXG);
	if (create1 < create2)
		rv = -1;
	else if (create1 > create2)
		rv = +1;
	else
		rv = 0;
	zfs_close(guid1hdl);
	zfs_close(guid2hdl);
	return (rv);
}
static int created_before ( libzfs_handle_t * hdl , avl_tree_t * avl , uint64_t guid1 , uint64_t guid2 ) { nvlist_t * nvfs ; char * fsname , * snapname ; char buf [ ZFS_MAXNAMELEN ] ; int rv ; zfs_handle_t * guid1hdl , * guid2hdl ; uint64_t create1 , create2 ; if ( guid2 == 0 ) return ( 0 ) ; if ( guid1 == 0 ) return ( 1 ) ; nvfs = fsavl_find ( avl , guid1 , & snapname ) ; VERIFY ( 0 == nvlist_lookup_string ( nvfs , " " , & fsname ) ) ; ( void ) snprintf ( buf , sizeof ( buf ) , " " , fsname , snapname ) ; guid1hdl = zfs_open ( hdl , buf , ZFS_TYPE_SNAPSHOT ) ; if ( guid1hdl == NULL ) return ( -1 ) ; nvfs = fsavl_find ( avl , guid2 , & snapname ) ; VERIFY ( 0 == nvlist_lookup_string ( nvfs , " " , & fsname ) ) ; ( void ) snprintf ( buf , sizeof ( buf ) , " " , fsname , snapname ) ; guid2hdl = zfs_open ( hdl , buf , ZFS_TYPE_SNAPSHOT ) ; if ( guid2hdl == NULL ) { zfs_close ( guid1hdl ) ; return ( -1 ) ; } create1 = zfs_prop_get_int ( guid1hdl , ZFS_PROP_CREATETXG ) ; create2 = zfs_prop_get_int ( guid2hdl , ZFS_PROP_CREATETXG ) ; if ( create1 < create2 ) rv = -1 ; else if ( create1 > create2 ) rv = +1 ; else rv = 0 ; zfs_close ( guid1hdl ) ; zfs_close ( guid2hdl ) ; return ( rv ) ; }
Return +1 if guid1 is before guid2, 0 if they are the same, and -1 if
 guid1 is after guid2.
Return + 1 if guid1 is before guid2 0 if they are the same and - 1 if guid1 is after guid2 .