FreeBSD/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c
/*
 * zpool get [-Hp] [-o "all" | field[,...]] <"all" | property[,...]> <pool> ...
 *
 *	-H	Scripted mode.  Don't display headers, and separate properties
 *		by a single tab.
 *	-o	List of columns to display.  Defaults to
 *		"name,property,value,source".
 * 	-p	Diplay values in parsable (exact) format.
 *
 * Get properties of pools in the system. Output space statistics
 * for each one as well as other attributes.
 */


Get properties of pools in the system. Output space statistics
for each one as well as other attributes.
Get properties of pools in the system . Output space statistics for each one as well as other attributes .
int
zpool_do_get(int argc, char **argv)
{
	zprop_get_cbdata_t cb = { 0 };
	zprop_list_t fake_name = { 0 };
	int ret;
	int c, i;
	char *value;
	cb.cb_first = B_TRUE;
	cb.cb_sources = ZPROP_SRC_ALL;
	cb.cb_columns[0] = GET_COL_NAME;
	cb.cb_columns[1] = GET_COL_PROPERTY;
	cb.cb_columns[2] = GET_COL_VALUE;
	cb.cb_columns[3] = GET_COL_SOURCE;
	cb.cb_type = ZFS_TYPE_POOL;
	while ((c = getopt(argc, argv, ":Hpo:")) != -1) {
		switch (c) {
		case 'p':
			cb.cb_literal = B_TRUE;
			break;
		case 'H':
			cb.cb_scripted = B_TRUE;
			break;
		case 'o':
			bzero(&cb.cb_columns, sizeof (cb.cb_columns));
			i = 0;
			while (*optarg != '\0') {
				static char *col_subopts[] =
				{ "name", "property", "value", "source",
				"all", NULL };
				if (i == ZFS_GET_NCOLS) {
					(void) fprintf(stderr, gettext("too "
					"many fields given to -o "
					"option\n"));
					usage(B_FALSE);
				}
				switch (getsubopt(&optarg, col_subopts,
				    &value)) {
				case 0:
					cb.cb_columns[i++] = GET_COL_NAME;
					break;
				case 1:
					cb.cb_columns[i++] = GET_COL_PROPERTY;
					break;
				case 2:
					cb.cb_columns[i++] = GET_COL_VALUE;
					break;
				case 3:
					cb.cb_columns[i++] = GET_COL_SOURCE;
					break;
				case 4:
					if (i > 0) {
						(void) fprintf(stderr,
						    gettext("\"all\" conflicts "
						    "with specific fields "
						    "given to -o option\n"));
						usage(B_FALSE);
					}
					cb.cb_columns[0] = GET_COL_NAME;
					cb.cb_columns[1] = GET_COL_PROPERTY;
					cb.cb_columns[2] = GET_COL_VALUE;
					cb.cb_columns[3] = GET_COL_SOURCE;
					i = ZFS_GET_NCOLS;
					break;
				default:
					(void) fprintf(stderr,
					    gettext("invalid column name "
					    "'%s'\n"), suboptarg);
					usage(B_FALSE);
				}
			}
			break;
		case '?':
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
			    optopt);
			usage(B_FALSE);
		}
	}
	argc -= optind;
	argv += optind;
	if (argc < 1) {
		(void) fprintf(stderr, gettext("missing property "
		    "argument\n"));
		usage(B_FALSE);
	}
	if (zprop_get_list(g_zfs, argv[0], &cb.cb_proplist,
	    ZFS_TYPE_POOL) != 0)
		usage(B_FALSE);
	argc--;
	argv++;
	if (cb.cb_proplist != NULL) {
		fake_name.pl_prop = ZPOOL_PROP_NAME;
		fake_name.pl_width = strlen(gettext("NAME"));
		fake_name.pl_next = cb.cb_proplist;
		cb.cb_proplist = &fake_name;
	}
	ret = for_each_pool(argc, argv, B_TRUE, &cb.cb_proplist,
	    get_callback, &cb);
	if (cb.cb_proplist == &fake_name)
		zprop_free_list(fake_name.pl_next);
	else
		zprop_free_list(cb.cb_proplist);
	return (ret);
}
int zpool_do_get ( int argc , char * * argv ) { zprop_get_cbdata_t cb = { 0 } ; zprop_list_t fake_name = { 0 } ; int ret ; int c , i ; char * value ; cb . cb_first = B_TRUE ; cb . cb_sources = ZPROP_SRC_ALL ; cb . cb_columns [ 0 ] = GET_COL_NAME ; cb . cb_columns [ 1 ] = GET_COL_PROPERTY ; cb . cb_columns [ 2 ] = GET_COL_VALUE ; cb . cb_columns [ 3 ] = GET_COL_SOURCE ; cb . cb_type = ZFS_TYPE_POOL ; while ( ( c = getopt ( argc , argv , " " ) ) != -1 ) { switch ( c ) { case ' ' : cb . cb_literal = B_TRUE ; break ; case ' ' : cb . cb_scripted = B_TRUE ; break ; case ' ' : bzero ( & cb . cb_columns , sizeof ( cb . cb_columns ) ) ; i = 0 ; while ( * optarg != ' \0 ' ) { static char * col_subopts [ ] = { " " , " " , " " , " " , " " , NULL } ; if ( i == ZFS_GET_NCOLS ) { ( void ) fprintf ( stderr , gettext ( " " " " " \n " ) ) ; usage ( B_FALSE ) ; } switch ( getsubopt ( & optarg , col_subopts , & value ) ) { case 0 : cb . cb_columns [ i ++ ] = GET_COL_NAME ; break ; case 1 : cb . cb_columns [ i ++ ] = GET_COL_PROPERTY ; break ; case 2 : cb . cb_columns [ i ++ ] = GET_COL_VALUE ; break ; case 3 : cb . cb_columns [ i ++ ] = GET_COL_SOURCE ; break ; case 4 : if ( i > 0 ) { ( void ) fprintf ( stderr , gettext ( " \" \" " " " " \n " ) ) ; usage ( B_FALSE ) ; } cb . cb_columns [ 0 ] = GET_COL_NAME ; cb . cb_columns [ 1 ] = GET_COL_PROPERTY ; cb . cb_columns [ 2 ] = GET_COL_VALUE ; cb . cb_columns [ 3 ] = GET_COL_SOURCE ; i = ZFS_GET_NCOLS ; break ; default : ( void ) fprintf ( stderr , gettext ( " " " \n " ) , suboptarg ) ; usage ( B_FALSE ) ; } } break ; case ' ' : ( void ) fprintf ( stderr , gettext ( " \n " ) , optopt ) ; usage ( B_FALSE ) ; } } argc -= optind ; argv += optind ; if ( argc < 1 ) { ( void ) fprintf ( stderr , gettext ( " " " \n " ) ) ; usage ( B_FALSE ) ; } if ( zprop_get_list ( g_zfs , argv [ 0 ] , & cb . cb_proplist , ZFS_TYPE_POOL ) != 0 ) usage ( B_FALSE ) ; argc -- ; argv ++ ; if ( cb . cb_proplist != NULL ) { fake_name . pl_prop = ZPOOL_PROP_NAME ; fake_name . pl_width = strlen ( gettext ( " " ) ) ; fake_name . pl_next = cb . cb_proplist ; cb . cb_proplist = & fake_name ; } ret = for_each_pool ( argc , argv , B_TRUE , & cb . cb_proplist , get_callback , & cb ) ; if ( cb . cb_proplist == & fake_name ) zprop_free_list ( fake_name . pl_next ) ; else zprop_free_list ( cb . cb_proplist ) ; return ( ret ) ; }
zpool get [-Hp] [-o "all" | field[,...]] <"all" | property[,...]> <pool> ...
      -H      Scripted mode.
zpool get [ - Hp ] [ - o " all " | field [ ... ]] < " all " | property [ ... ] > <pool > ... - H Scripted mode .
/*
	 * Set up default columns and sources.
	 */ /* check options */