FreeBSD/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_util.c
/*
 * ================================================================
 * API shared by zfs and zpool property management
 * ================================================================
 */
API shared by zfs and zpool property management
API shared by zfs and zpool property management
static void
zprop_print_headers(zprop_get_cbdata_t *cbp, zfs_type_t type)
{
	zprop_list_t *pl = cbp->cb_proplist;
	int i;
	char *title;
	size_t len;
	cbp->cb_first = B_FALSE;
	if (cbp->cb_scripted)
		return;
	cbp->cb_colwidths[GET_COL_NAME] = strlen(dgettext(TEXT_DOMAIN, "NAME"));
	cbp->cb_colwidths[GET_COL_PROPERTY] = strlen(dgettext(TEXT_DOMAIN,
	    "PROPERTY"));
	cbp->cb_colwidths[GET_COL_VALUE] = strlen(dgettext(TEXT_DOMAIN,
	    "VALUE"));
	cbp->cb_colwidths[GET_COL_RECVD] = strlen(dgettext(TEXT_DOMAIN,
	    "RECEIVED"));
	cbp->cb_colwidths[GET_COL_SOURCE] = strlen(dgettext(TEXT_DOMAIN,
	    "SOURCE"));
	assert(cbp->cb_proplist->pl_prop ==
	    ((type == ZFS_TYPE_POOL) ?  ZPOOL_PROP_NAME : ZFS_PROP_NAME));
	for (pl = cbp->cb_proplist; pl != NULL; pl = pl->pl_next) {
		if (pl->pl_prop != ZPROP_INVAL) {
			const char *propname = (type == ZFS_TYPE_POOL) ?
			    zpool_prop_to_name(pl->pl_prop) :
			    zfs_prop_to_name(pl->pl_prop);
			len = strlen(propname);
			if (len > cbp->cb_colwidths[GET_COL_PROPERTY])
				cbp->cb_colwidths[GET_COL_PROPERTY] = len;
		} else {
			len = strlen(pl->pl_user_prop);
			if (len > cbp->cb_colwidths[GET_COL_PROPERTY])
				cbp->cb_colwidths[GET_COL_PROPERTY] = len;
		}
		if (pl != cbp->cb_proplist &&
		    pl->pl_width > cbp->cb_colwidths[GET_COL_VALUE])
			cbp->cb_colwidths[GET_COL_VALUE] = pl->pl_width;
		if (pl != cbp->cb_proplist &&
		    pl->pl_recvd_width > cbp->cb_colwidths[GET_COL_RECVD])
			cbp->cb_colwidths[GET_COL_RECVD] = pl->pl_recvd_width;
		if (pl->pl_prop == (type == ZFS_TYPE_POOL ? ZPOOL_PROP_NAME :
		    ZFS_PROP_NAME) &&
		    pl->pl_width > cbp->cb_colwidths[GET_COL_NAME]) {
			cbp->cb_colwidths[GET_COL_NAME] = pl->pl_width;
			cbp->cb_colwidths[GET_COL_SOURCE] = pl->pl_width +
			    strlen(dgettext(TEXT_DOMAIN, "inherited from"));
		}
	}
	for (i = 0; i < ZFS_GET_NCOLS; i++) {
		switch (cbp->cb_columns[i]) {
		case GET_COL_NAME:
			title = dgettext(TEXT_DOMAIN, "NAME");
			break;
		case GET_COL_PROPERTY:
			title = dgettext(TEXT_DOMAIN, "PROPERTY");
			break;
		case GET_COL_VALUE:
			title = dgettext(TEXT_DOMAIN, "VALUE");
			break;
		case GET_COL_RECVD:
			title = dgettext(TEXT_DOMAIN, "RECEIVED");
			break;
		case GET_COL_SOURCE:
			title = dgettext(TEXT_DOMAIN, "SOURCE");
			break;
		default:
			title = NULL;
		}
		if (title != NULL) {
			if (i == (ZFS_GET_NCOLS - 1) ||
			    cbp->cb_columns[i + 1] == GET_COL_NONE)
				(void) printf("%s", title);
			else
				(void) printf("%-*s  ",
				    cbp->cb_colwidths[cbp->cb_columns[i]],
				    title);
		}
	}
	(void) printf("\n");
}
static void zprop_print_headers ( zprop_get_cbdata_t * cbp , zfs_type_t type ) { zprop_list_t * pl = cbp -> cb_proplist ; int i ; char * title ; size_t len ; cbp -> cb_first = B_FALSE ; if ( cbp -> cb_scripted ) return ; cbp -> cb_colwidths [ GET_COL_NAME ] = strlen ( dgettext ( TEXT_DOMAIN , " " ) ) ; cbp -> cb_colwidths [ GET_COL_PROPERTY ] = strlen ( dgettext ( TEXT_DOMAIN , " " ) ) ; cbp -> cb_colwidths [ GET_COL_VALUE ] = strlen ( dgettext ( TEXT_DOMAIN , " " ) ) ; cbp -> cb_colwidths [ GET_COL_RECVD ] = strlen ( dgettext ( TEXT_DOMAIN , " " ) ) ; cbp -> cb_colwidths [ GET_COL_SOURCE ] = strlen ( dgettext ( TEXT_DOMAIN , " " ) ) ; assert ( cbp -> cb_proplist -> pl_prop == ( ( type == ZFS_TYPE_POOL ) ? ZPOOL_PROP_NAME : ZFS_PROP_NAME ) ) ; for ( pl = cbp -> cb_proplist ; pl != NULL ; pl = pl -> pl_next ) { if ( pl -> pl_prop != ZPROP_INVAL ) { const char * propname = ( type == ZFS_TYPE_POOL ) ? zpool_prop_to_name ( pl -> pl_prop ) : zfs_prop_to_name ( pl -> pl_prop ) ; len = strlen ( propname ) ; if ( len > cbp -> cb_colwidths [ GET_COL_PROPERTY ] ) cbp -> cb_colwidths [ GET_COL_PROPERTY ] = len ; } else { len = strlen ( pl -> pl_user_prop ) ; if ( len > cbp -> cb_colwidths [ GET_COL_PROPERTY ] ) cbp -> cb_colwidths [ GET_COL_PROPERTY ] = len ; } if ( pl != cbp -> cb_proplist && pl -> pl_width > cbp -> cb_colwidths [ GET_COL_VALUE ] ) cbp -> cb_colwidths [ GET_COL_VALUE ] = pl -> pl_width ; if ( pl != cbp -> cb_proplist && pl -> pl_recvd_width > cbp -> cb_colwidths [ GET_COL_RECVD ] ) cbp -> cb_colwidths [ GET_COL_RECVD ] = pl -> pl_recvd_width ; if ( pl -> pl_prop == ( type == ZFS_TYPE_POOL ? ZPOOL_PROP_NAME : ZFS_PROP_NAME ) && pl -> pl_width > cbp -> cb_colwidths [ GET_COL_NAME ] ) { cbp -> cb_colwidths [ GET_COL_NAME ] = pl -> pl_width ; cbp -> cb_colwidths [ GET_COL_SOURCE ] = pl -> pl_width + strlen ( dgettext ( TEXT_DOMAIN , " " ) ) ; } } for ( i = 0 ; i < ZFS_GET_NCOLS ; i ++ ) { switch ( cbp -> cb_columns [ i ] ) { case GET_COL_NAME : title = dgettext ( TEXT_DOMAIN , " " ) ; break ; case GET_COL_PROPERTY : title = dgettext ( TEXT_DOMAIN , " " ) ; break ; case GET_COL_VALUE : title = dgettext ( TEXT_DOMAIN , " " ) ; break ; case GET_COL_RECVD : title = dgettext ( TEXT_DOMAIN , " " ) ; break ; case GET_COL_SOURCE : title = dgettext ( TEXT_DOMAIN , " " ) ; break ; default : title = NULL ; } if ( title != NULL ) { if ( i == ( ZFS_GET_NCOLS - 1 ) || cbp -> cb_columns [ i + 1 ] == GET_COL_NONE ) ( void ) printf ( " " , title ) ; else ( void ) printf ( " " , cbp -> cb_colwidths [ cbp -> cb_columns [ i ] ] , title ) ; } } ( void ) printf ( " \n " ) ; }
API shared by zfs and zpool property management
API shared by zfs and zpool property management
/*
	 * Start with the length of the column headers.
	 */ /* first property is always NAME */ /*
	 * Go through and calculate the widths for each column.  For the
	 * 'source' column, we kludge it up by taking the worst-case scenario of
	 * inheriting from the longest name.  This is acceptable because in the
	 * majority of cases 'SOURCE' is the last column displayed, and we don't
	 * use the width anyway.  Note that the 'VALUE' column can be oversized,
	 * if the name of the property is much longer than any values we find.
	 */ /*
		 * 'PROPERTY' column
		 */ /*
		 * 'VALUE' column.  The first property is always the 'name'
		 * property that was tacked on either by /sbin/zfs's
		 * zfs_do_get() or when calling zprop_expand_list(), so we
		 * ignore its width.  If the user specified the name property
		 * to display, then it will be later in the list in any case.
		 */ /* 'RECEIVED' column. */ /*
		 * 'NAME' and 'SOURCE' columns
		 */ /*
	 * Now go through and print the headers.
	 */