FreeBSD/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c
/*
 * zpool list [-Hp] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
 *
 *	-H	Scripted mode.  Don't display headers, and separate properties
 *		by a single tab.
 *	-o	List of properties to display.  Defaults to
 *		"name,size,allocated,free,expandsize,fragmentation,capacity,"
 *		"dedupratio,health,altroot"
 * 	-p	Diplay values in parsable (exact) format.
 *	-T	Display a timestamp in date(1) or Unix format
 *
 * List all pools in the system, whether or not they're healthy.  Output space
 * statistics for each one, as well as health status summary.
 */


List all pools in the system, whether or not they're healthy.  Output space
statistics for each one, as well as health status summary.
List all pools in the system whether or not they ' re healthy . Output space statistics for each one as well as health status summary .
int
zpool_do_list(int argc, char **argv)
{
	int c;
	int ret;
	list_cbdata_t cb = { 0 };
	static char default_props[] =
	    "name,size,allocated,free,expandsize,fragmentation,capacity,"
	    "dedupratio,health,altroot";
	char *props = default_props;
	unsigned long interval = 0, count = 0;
	zpool_list_t *list;
	boolean_t first = B_TRUE;
	while ((c = getopt(argc, argv, ":Ho:pT:v")) != -1) {
		switch (c) {
		case 'H':
			cb.cb_scripted = B_TRUE;
			break;
		case 'o':
			props = optarg;
			break;
		case 'p':
			cb.cb_literal = B_TRUE;
			break;
		case 'T':
			get_timestamp_arg(*optarg);
			break;
		case 'v':
			cb.cb_verbose = B_TRUE;
			break;
		case ':':
			(void) fprintf(stderr, gettext("missing argument for "
			    "'%c' option\n"), optopt);
			usage(B_FALSE);
			break;
		case '?':
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
			    optopt);
			usage(B_FALSE);
		}
	}
	argc -= optind;
	argv += optind;
	get_interval_count(&argc, argv, &interval, &count);
	if (zprop_get_list(g_zfs, props, &cb.cb_proplist, ZFS_TYPE_POOL) != 0)
		usage(B_FALSE);
	for (;;) {
		if ((list = pool_list_get(argc, argv, &cb.cb_proplist,
		    &ret)) == NULL)
			return (1);
		if (pool_list_count(list) == 0)
			break;
		cb.cb_namewidth = 0;
		(void) pool_list_iter(list, B_FALSE, get_namewidth, &cb);
		if (timestamp_fmt != NODATE)
			print_timestamp(timestamp_fmt);
		if (!cb.cb_scripted && (first || cb.cb_verbose)) {
			print_header(&cb);
			first = B_FALSE;
		}
		ret = pool_list_iter(list, B_TRUE, list_callback, &cb);
		if (interval == 0)
			break;
		if (count != 0 && --count == 0)
			break;
		pool_list_free(list);
		(void) sleep(interval);
	}
	if (argc == 0 && !cb.cb_scripted && pool_list_count(list) == 0) {
		(void) printf(gettext("no pools available\n"));
		ret = 0;
	}
	pool_list_free(list);
	zprop_free_list(cb.cb_proplist);
	return (ret);
}
int zpool_do_list ( int argc , char * * argv ) { int c ; int ret ; list_cbdata_t cb = { 0 } ; static char default_props [ ] = " " " " ; char * props = default_props ; unsigned long interval = 0 , count = 0 ; zpool_list_t * list ; boolean_t first = B_TRUE ; while ( ( c = getopt ( argc , argv , " " ) ) != -1 ) { switch ( c ) { case ' ' : cb . cb_scripted = B_TRUE ; break ; case ' ' : props = optarg ; break ; case ' ' : cb . cb_literal = B_TRUE ; break ; case ' ' : get_timestamp_arg ( * optarg ) ; break ; case ' ' : cb . cb_verbose = B_TRUE ; break ; case ' ' : ( void ) fprintf ( stderr , gettext ( " " " \n " ) , optopt ) ; usage ( B_FALSE ) ; break ; case ' ' : ( void ) fprintf ( stderr , gettext ( " \n " ) , optopt ) ; usage ( B_FALSE ) ; } } argc -= optind ; argv += optind ; get_interval_count ( & argc , argv , & interval , & count ) ; if ( zprop_get_list ( g_zfs , props , & cb . cb_proplist , ZFS_TYPE_POOL ) != 0 ) usage ( B_FALSE ) ; for ( ; ; ) { if ( ( list = pool_list_get ( argc , argv , & cb . cb_proplist , & ret ) ) == NULL ) return ( 1 ) ; if ( pool_list_count ( list ) == 0 ) break ; cb . cb_namewidth = 0 ; ( void ) pool_list_iter ( list , B_FALSE , get_namewidth , & cb ) ; if ( timestamp_fmt != NODATE ) print_timestamp ( timestamp_fmt ) ; if ( ! cb . cb_scripted && ( first || cb . cb_verbose ) ) { print_header ( & cb ) ; first = B_FALSE ; } ret = pool_list_iter ( list , B_TRUE , list_callback , & cb ) ; if ( interval == 0 ) break ; if ( count != 0 && -- count == 0 ) break ; pool_list_free ( list ) ; ( void ) sleep ( interval ) ; } if ( argc == 0 && ! cb . cb_scripted && pool_list_count ( list ) == 0 ) { ( void ) printf ( gettext ( " \n " ) ) ; ret = 0 ; } pool_list_free ( list ) ; zprop_free_list ( cb . cb_proplist ) ; return ( ret ) ; }
zpool list [-Hp] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
      -H      Scripted mode.
zpool list [ - Hp ] [ - o prop [ prop ] * ] [ - T d|u ] [ pool ] ... [ interval [ count ]] - H Scripted mode .
/* check options */