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