2 * Copyright (c) 2008 Yahoo!, Inc.
4 * Written by: John Baldwin <jhb@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the author nor the names of any co-contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * $FreeBSD: src/usr.sbin/mptutil/mpt_evt.c,v 1.2 2010/11/09 19:28:06 jhb Exp $
33 #include <sys/param.h>
34 #include <sys/errno.h>
42 static CONFIG_PAGE_LOG_0
*
43 mpt_get_events(int fd
, U16
*IOCStatus
)
46 return (mpt_read_extended_config_page(fd
, MPI_CONFIG_EXTPAGETYPE_LOG
,
52 * 1234567890123456789012345678901234567890123456789012345678901234567890
53 * < ID> < time > <ty> <X XX XX XX XX XX XX XX XX XX XX XX XX XX |..............|
54 * ID Time Type Log Data
57 mpt_print_event(MPI_LOG_0_ENTRY
*entry
, int verbose __unused
)
61 printf("%5d %7ds %4x ", entry
->LogSequence
, entry
->TimeStamp
,
62 entry
->LogEntryQualifier
);
63 for (i
= 0; i
< 14; i
++)
64 printf("%02x ", entry
->LogData
[i
]);
66 for (i
= 0; i
< 14; i
++)
67 printf("%c", isprint(entry
->LogData
[i
]) ? entry
->LogData
[i
] :
71 for (i
= 0; i
< 14; i
++)
72 printf("%02x ", entry
->LogData
[i
+ 14]);
74 for (i
= 0; i
< 14; i
++)
75 printf("%c", isprint(entry
->LogData
[i
+ 14]) ?
76 entry
->LogData
[i
+ 14] : '.');
81 event_compare(const void *first
, const void *second
)
83 MPI_LOG_0_ENTRY
* const *one
;
84 MPI_LOG_0_ENTRY
* const *two
;
88 return ((*one
)->LogSequence
- ((*two
)->LogSequence
));
92 show_events(int ac
, char **av
)
94 CONFIG_PAGE_LOG_0
*log
;
95 MPI_LOG_0_ENTRY
**entries
;
96 int ch
, error
, fd
, i
, num_events
, verbose
;
98 fd
= mpt_open(mpt_unit
);
105 log
= mpt_get_events(fd
, NULL
);
108 warn("Failed to get event log info");
112 /* Default settings. */
115 /* Parse any options. */
117 while ((ch
= getopt(ac
, av
, "v")) != -1) {
130 /* Build a list of valid entries and sort them by sequence. */
131 entries
= malloc(sizeof(MPI_LOG_0_ENTRY
*) * log
->NumLogEntries
);
135 for (i
= 0; i
< log
->NumLogEntries
; i
++) {
136 if (log
->LogEntry
[i
].LogEntryQualifier
==
137 MPI_LOG_0_ENTRY_QUAL_ENTRY_UNUSED
)
139 entries
[num_events
] = &log
->LogEntry
[i
];
143 qsort(entries
, num_events
, sizeof(MPI_LOG_0_ENTRY
*), event_compare
);
146 printf("Event log is empty\n");
148 printf(" ID Time Type Log Data\n");
149 for (i
= 0; i
< num_events
; i
++)
150 mpt_print_event(entries
[i
], verbose
);
158 MPT_COMMAND(show
, events
, show_events
);