FreeBSD/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c
/*
 * Given a vdev configuration, determine the maximum width needed for the device
 * name column.
 */
Given a vdev configuration, determine the maximum width needed for the device
name column.
Given a vdev configuration determine the maximum width needed for the device name column .
static int
max_width(zpool_handle_t *zhp, nvlist_t *nv, int depth, int max)
{
	char *name = zpool_vdev_name(g_zfs, zhp, nv, B_TRUE);
	nvlist_t **child;
	uint_t c, children;
	int ret;
	if (strlen(name) + depth > max)
		max = strlen(name) + depth;
	free(name);
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
	    &child, &children) == 0) {
		for (c = 0; c < children; c++)
			if ((ret = max_width(zhp, child[c], depth + 2,
			    max)) > max)
				max = ret;
	}
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
	    &child, &children) == 0) {
		for (c = 0; c < children; c++)
			if ((ret = max_width(zhp, child[c], depth + 2,
			    max)) > max)
				max = ret;
	}
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
	    &child, &children) == 0) {
		for (c = 0; c < children; c++)
			if ((ret = max_width(zhp, child[c], depth + 2,
			    max)) > max)
				max = ret;
	}
	return (max);
}
static int max_width ( zpool_handle_t * zhp , nvlist_t * nv , int depth , int max ) { char * name = zpool_vdev_name ( g_zfs , zhp , nv , B_TRUE ) ; nvlist_t * * child ; uint_t c , children ; int ret ; if ( strlen ( name ) + depth > max ) max = strlen ( name ) + depth ; free ( name ) ; if ( nvlist_lookup_nvlist_array ( nv , ZPOOL_CONFIG_SPARES , & child , & children ) == 0 ) { for ( c = 0 ; c < children ; c ++ ) if ( ( ret = max_width ( zhp , child [ c ] , depth + 2 , max ) ) > max ) max = ret ; } if ( nvlist_lookup_nvlist_array ( nv , ZPOOL_CONFIG_L2CACHE , & child , & children ) == 0 ) { for ( c = 0 ; c < children ; c ++ ) if ( ( ret = max_width ( zhp , child [ c ] , depth + 2 , max ) ) > max ) max = ret ; } if ( nvlist_lookup_nvlist_array ( nv , ZPOOL_CONFIG_CHILDREN , & child , & children ) == 0 ) { for ( c = 0 ; c < children ; c ++ ) if ( ( ret = max_width ( zhp , child [ c ] , depth + 2 , max ) ) > max ) max = ret ; } return ( max ) ; }
Given a vdev configuration, determine the maximum width needed for the device
 name column.
Given a vdev configuration determine the maximum width needed for the device name column .