1*275c9da8Seschrock /* 2*275c9da8Seschrock * CDDL HEADER START 3*275c9da8Seschrock * 4*275c9da8Seschrock * The contents of this file are subject to the terms of the 5*275c9da8Seschrock * Common Development and Distribution License (the "License"). 6*275c9da8Seschrock * You may not use this file except in compliance with the License. 7*275c9da8Seschrock * 8*275c9da8Seschrock * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*275c9da8Seschrock * or http://www.opensolaris.org/os/licensing. 10*275c9da8Seschrock * See the License for the specific language governing permissions 11*275c9da8Seschrock * and limitations under the License. 12*275c9da8Seschrock * 13*275c9da8Seschrock * When distributing Covered Code, include this CDDL HEADER in each 14*275c9da8Seschrock * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*275c9da8Seschrock * If applicable, add the following below this CDDL HEADER, with the 16*275c9da8Seschrock * fields enclosed by brackets "[]" replaced with your own identifying 17*275c9da8Seschrock * information: Portions Copyright [yyyy] [name of copyright owner] 18*275c9da8Seschrock * 19*275c9da8Seschrock * CDDL HEADER END 20*275c9da8Seschrock */ 21*275c9da8Seschrock 22*275c9da8Seschrock /* 23*275c9da8Seschrock * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24*275c9da8Seschrock * Use is subject to license terms. 25*275c9da8Seschrock */ 26*275c9da8Seschrock 27*275c9da8Seschrock #pragma ident "%Z%%M% %I% %E% SMI" 28*275c9da8Seschrock 29*275c9da8Seschrock #include <libnvpair.h> 30*275c9da8Seschrock #include <stdio.h> 31*275c9da8Seschrock #include <unistd.h> 32*275c9da8Seschrock #include <scsi/libses.h> 33*275c9da8Seschrock 34*275c9da8Seschrock static void fatal(int, const char *, ...) __NORETURN; 35*275c9da8Seschrock 36*275c9da8Seschrock static void 37*275c9da8Seschrock fatal(int err, const char *fmt, ...) 38*275c9da8Seschrock { 39*275c9da8Seschrock va_list ap; 40*275c9da8Seschrock 41*275c9da8Seschrock va_start(ap, fmt); 42*275c9da8Seschrock (void) vfprintf(stderr, fmt, ap); 43*275c9da8Seschrock va_end(ap); 44*275c9da8Seschrock 45*275c9da8Seschrock (void) fprintf(stderr, "\n"); 46*275c9da8Seschrock (void) fflush(stderr); 47*275c9da8Seschrock 48*275c9da8Seschrock _exit(err); 49*275c9da8Seschrock } 50*275c9da8Seschrock 51*275c9da8Seschrock /*ARGSUSED*/ 52*275c9da8Seschrock static ses_walk_action_t 53*275c9da8Seschrock node(ses_node_t *np, void *arg) 54*275c9da8Seschrock { 55*275c9da8Seschrock ses_node_type_t type; 56*275c9da8Seschrock uint64_t val; 57*275c9da8Seschrock nvlist_t *props; 58*275c9da8Seschrock char *t; 59*275c9da8Seschrock 60*275c9da8Seschrock type = ses_node_type(np); 61*275c9da8Seschrock (void) printf("Node Type: %d\n", type); 62*275c9da8Seschrock if ((props = ses_node_props(np)) == NULL) { 63*275c9da8Seschrock (void) printf("No properties\n"); 64*275c9da8Seschrock return (SES_WALK_ACTION_CONTINUE); 65*275c9da8Seschrock } 66*275c9da8Seschrock if (type == SES_NODE_ELEMENT || type == SES_NODE_AGGREGATE) { 67*275c9da8Seschrock (void) nvlist_lookup_uint64(props, SES_PROP_ELEMENT_TYPE, &val); 68*275c9da8Seschrock if (nvlist_lookup_string(props, LIBSES_PROP_ELEMENT_TYPE_NAME, 69*275c9da8Seschrock &t) != 0) 70*275c9da8Seschrock t = NULL; 71*275c9da8Seschrock (void) printf("Element Type: %s\n", t ? t : "<unknown>"); 72*275c9da8Seschrock } 73*275c9da8Seschrock nvlist_print(stdout, props); 74*275c9da8Seschrock 75*275c9da8Seschrock return (SES_WALK_ACTION_CONTINUE); 76*275c9da8Seschrock } 77*275c9da8Seschrock 78*275c9da8Seschrock int 79*275c9da8Seschrock main(int argc, char *argv[]) 80*275c9da8Seschrock { 81*275c9da8Seschrock ses_target_t *tp; 82*275c9da8Seschrock ses_snap_t *sp; 83*275c9da8Seschrock 84*275c9da8Seschrock if (argc != 2) 85*275c9da8Seschrock fatal(1, "Usage: %s <device>", argv[0]); 86*275c9da8Seschrock 87*275c9da8Seschrock if ((tp = ses_open(LIBSES_VERSION, argv[1])) == NULL) 88*275c9da8Seschrock fatal(-1, "failed to open %s: %s", argv[1], ses_errmsg()); 89*275c9da8Seschrock 90*275c9da8Seschrock sp = ses_snap_hold(tp); 91*275c9da8Seschrock 92*275c9da8Seschrock (void) ses_walk(sp, node, NULL); 93*275c9da8Seschrock 94*275c9da8Seschrock ses_snap_rele(sp); 95*275c9da8Seschrock ses_close(tp); 96*275c9da8Seschrock 97*275c9da8Seschrock return (0); 98*275c9da8Seschrock } 99