Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
/*-
 * SPDX-License-Identifier: BSD-3-Clause
 *
 * Copyright (c) 2008, 2009 Yahoo!, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The names of the authors may not be used to endorse or promote
 *    products derived from this software without specific prior written
 *    permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#include <sys/types.h>
#include <sys/errno.h>
#include <err.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <time.h>
#include <unistd.h>
#include "mfiutil.h"

static int
mfi_event_get_info(int fd, struct mfi_evt_log_state *info, uint8_t *statusp)
{

	return (mfi_dcmd_command(fd, MFI_DCMD_CTRL_EVENT_GETINFO, info,
	    sizeof(struct mfi_evt_log_state), NULL, 0, statusp));
}

static int
mfi_get_events(int fd, struct mfi_evt_list *list, int num_events,
    union mfi_evt filter, uint32_t start_seq, uint8_t *statusp)
{
	uint32_t mbox[2];
	size_t size;

	mbox[0] = start_seq;
	mbox[1] = filter.word;
	size = sizeof(struct mfi_evt_list) + sizeof(struct mfi_evt_detail) *
	    (num_events - 1);
	return (mfi_dcmd_command(fd, MFI_DCMD_CTRL_EVENT_GET, list, size,
	    (uint8_t *)&mbox, sizeof(mbox), statusp));
}

static int
show_logstate(int ac, char **av __unused)
{
	struct mfi_evt_log_state info;
	int error, fd;

	if (ac != 1) {
		warnx("show logstate: extra arguments");
		return (EINVAL);
	}

	fd = mfi_open(mfi_unit, O_RDWR);
	if (fd < 0) {
		error = errno;
		warn("mfi_open");
		return (error);
	}

	if (mfi_event_get_info(fd, &info, NULL) < 0) {
		error = errno;
		warn("Failed to get event log info");
		close(fd);
		return (error);
	}

	printf("mfi%d Event Log Sequence Numbers:\n", mfi_unit);
	printf("  Newest Seq #: %u\n", info.newest_seq_num);
	printf("  Oldest Seq #: %u\n", info.oldest_seq_num);
	printf("   Clear Seq #: %u\n", info.clear_seq_num);
	printf("Shutdown Seq #: %u\n", info.shutdown_seq_num);
	printf("    Boot Seq #: %u\n", info.boot_seq_num);
	
	close(fd);

	return (0);
}
MFI_COMMAND(show, logstate, show_logstate);

static int
parse_seq(struct mfi_evt_log_state *info, char *arg, uint32_t *seq)
{
	char *cp;
	long val;

	if (strcasecmp(arg, "newest") == 0) {
		*seq = info->newest_seq_num;
		return (0);
	}
	if (strcasecmp(arg, "oldest") == 0) {
		*seq = info->oldest_seq_num;
		return (0);
	}
	if (strcasecmp(arg, "clear") == 0) {
		*seq = info->clear_seq_num;
		return (0);
	}
	if (strcasecmp(arg, "shutdown") == 0) {
		*seq = info->shutdown_seq_num;
		return (0);
	}
	if (strcasecmp(arg, "boot") == 0) {
		*seq = info->boot_seq_num;
		return (0);
	}
	val = strtol(arg, &cp, 0);
	if (*cp != '\0' || val < 0) {
		errno = EINVAL;
		return (-1);
	}
	*seq = val;
	return (0);
}

static int
parse_locale(char *arg, uint16_t *locale)
{
	char *cp;
	long val;

	if (strncasecmp(arg, "vol", 3) == 0 || strcasecmp(arg, "ld") == 0) {
		*locale = MFI_EVT_LOCALE_LD;
		return (0);
	}
	if (strncasecmp(arg, "drive", 5) == 0 || strcasecmp(arg, "pd") == 0) {
		*locale = MFI_EVT_LOCALE_PD;
		return (0);
	}
	if (strncasecmp(arg, "encl", 4) == 0) {
		*locale = MFI_EVT_LOCALE_ENCL;
		return (0);
	}
	if (strncasecmp(arg, "batt", 4) == 0 ||
	    strncasecmp(arg, "bbu", 3) == 0) {
		*locale = MFI_EVT_LOCALE_BBU;
		return (0);
	}
	if (strcasecmp(arg, "sas") == 0) {
		*locale = MFI_EVT_LOCALE_SAS;
		return (0);
	}
	if (strcasecmp(arg, "ctrl") == 0 || strncasecmp(arg, "cont", 4) == 0) {
		*locale = MFI_EVT_LOCALE_CTRL;
		return (0);
	}
	if (strcasecmp(arg, "config") == 0) {
		*locale = MFI_EVT_LOCALE_CONFIG;
		return (0);
	}
	if (strcasecmp(arg, "cluster") == 0) {
		*locale = MFI_EVT_LOCALE_CLUSTER;
		return (0);
	}
	if (strcasecmp(arg, "all") == 0) {
		*locale = MFI_EVT_LOCALE_ALL;
		return (0);
	}
	val = strtol(arg, &cp, 0);
	if (*cp != '\0' || val < 0 || val > 0xffff) {
		errno = EINVAL;
		return (-1);
	}
	*locale = val;
	return (0);
}

static int
parse_class(char *arg, int8_t *class)
{
	char *cp;
	long val;

	if (strcasecmp(arg, "debug") == 0) {
		*class = MFI_EVT_CLASS_DEBUG;
		return (0);
	}
	if (strncasecmp(arg, "prog", 4) == 0) {
		*class = MFI_EVT_CLASS_PROGRESS;
		return (0);
	}
	if (strncasecmp(arg, "info", 4) == 0) {
		*class = MFI_EVT_CLASS_INFO;
		return (0);
	}
	if (strncasecmp(arg, "warn", 4) == 0) {
		*class = MFI_EVT_CLASS_WARNING;
		return (0);
	}
	if (strncasecmp(arg, "crit", 4) == 0) {
		*class = MFI_EVT_CLASS_CRITICAL;
		return (0);
	}
	if (strcasecmp(arg, "fatal") == 0) {
		*class = MFI_EVT_CLASS_FATAL;
		return (0);
	}
	if (strcasecmp(arg, "dead") == 0) {
		*class = MFI_EVT_CLASS_DEAD;
		return (0);
	}
	val = strtol(arg, &cp, 0);
	if (*cp != '\0' || val < -128 || val > 127) {
		errno = EINVAL;
		return (-1);
	}
	*class = val;
	return (0);
}

/*
 * The timestamp is the number of seconds since 00:00 Jan 1, 2000.  If
 * the bits in 24-31 are all set, then it is the number of seconds since
 * boot.
 */
static const char *
format_timestamp(uint32_t timestamp)
{
	static char buffer[32];
	static time_t base;
	time_t t;
	struct tm tm;

	if ((timestamp & 0xff000000) == 0xff000000) {
		snprintf(buffer, sizeof(buffer), "boot + %us", timestamp &
		    0x00ffffff);
		return (buffer);
	}

	if (base == 0) {
		/* Compute 00:00 Jan 1, 2000 offset. */
		bzero(&tm, sizeof(tm));
		tm.tm_mday = 1;
		tm.tm_year = (2000 - 1900);
		base = mktime(&tm);
	}
	if (base == -1) {
		snprintf(buffer, sizeof(buffer), "%us", timestamp);
		return (buffer);
	}
	t = base + timestamp;
	strftime(buffer, sizeof(buffer), "%+", localtime(&t));
	return (buffer);
}

static const char *
format_locale(uint16_t locale)
{
	static char buffer[8];

	switch (locale) {
	case MFI_EVT_LOCALE_LD:
		return ("VOLUME");
	case MFI_EVT_LOCALE_PD:
		return ("DRIVE");
	case MFI_EVT_LOCALE_ENCL:
		return ("ENCL");
	case MFI_EVT_LOCALE_BBU:
		return ("BATTERY");
	case MFI_EVT_LOCALE_SAS:
		return ("SAS");
	case MFI_EVT_LOCALE_CTRL:
		return ("CTRL");
	case MFI_EVT_LOCALE_CONFIG:
		return ("CONFIG");
	case MFI_EVT_LOCALE_CLUSTER:
		return ("CLUSTER");
	case MFI_EVT_LOCALE_ALL:
		return ("ALL");
	default:
		snprintf(buffer, sizeof(buffer), "0x%04x", locale);
		return (buffer);
	}
}

static const char *
format_class(int8_t class)
{
	static char buffer[6];

	switch (class) {
	case MFI_EVT_CLASS_DEBUG:
		return ("debug");
	case MFI_EVT_CLASS_PROGRESS:
		return ("progress");
	case MFI_EVT_CLASS_INFO:
		return ("info");
	case MFI_EVT_CLASS_WARNING:
		return ("WARN");
	case MFI_EVT_CLASS_CRITICAL:
		return ("CRIT");
	case MFI_EVT_CLASS_FATAL:
		return ("FATAL");
	case MFI_EVT_CLASS_DEAD:
		return ("DEAD");
	default:
		snprintf(buffer, sizeof(buffer), "%d", class);
		return (buffer);
	}
}

/* Simulates %D from kernel printf(9). */
static void
simple_hex(void *ptr, size_t length, const char *separator)
{
	unsigned char *cp;
	u_int i;

	if (length == 0)
		return;
	cp = ptr;
	printf("%02x", cp[0]);
	for (i = 1; i < length; i++)
		printf("%s%02x", separator, cp[i]);
}

static const char *
pdrive_location(struct mfi_evt_pd *pd)
{
	static char buffer[16];

	if (pd->enclosure_index == 0)
		snprintf(buffer, sizeof(buffer), "%02d(s%d)", pd->device_id,
		    pd->slot_number);
	else
		snprintf(buffer, sizeof(buffer), "%02d(e%d/s%d)", pd->device_id,
		    pd->enclosure_index, pd->slot_number);
	return (buffer);
}

static const char *
volume_name(int fd, struct mfi_evt_ld *ld)
{

	return (mfi_volume_name(fd, ld->target_id));
}

/* Ripped from sys/dev/mfi/mfi.c. */
static void
mfi_decode_evt(int fd, struct mfi_evt_detail *detail, int verbose)
{

	printf("%5d (%s/%s/%s) - ", detail->seq, format_timestamp(detail->time),
	    format_locale(detail->evt_class.members.locale),
	    format_class(detail->evt_class.members.evt_class));
	switch (detail->arg_type) {
	case MR_EVT_ARGS_NONE:
		break;
	case MR_EVT_ARGS_CDB_SENSE:
		if (verbose) {
			printf("PD %s CDB ",
			    pdrive_location(&detail->args.cdb_sense.pd)
			    );
			simple_hex(detail->args.cdb_sense.cdb,
			    detail->args.cdb_sense.cdb_len, ":");
			printf(" Sense ");
			simple_hex(detail->args.cdb_sense.sense,
			    detail->args.cdb_sense.sense_len, ":");
			printf(":\n ");
		}
		break;
	case MR_EVT_ARGS_LD:
		printf("VOL %s event: ", volume_name(fd, &detail->args.ld));
		break;
	case MR_EVT_ARGS_LD_COUNT:
		printf("VOL %s", volume_name(fd, &detail->args.ld_count.ld));
		if (verbose) {
			printf(" count %lld: ",
			    (long long)detail->args.ld_count.count);
		}
		printf(": ");
		break;
	case MR_EVT_ARGS_LD_LBA:
		printf("VOL %s", volume_name(fd, &detail->args.ld_count.ld));
		if (verbose) {
			printf(" lba %lld",
			    (long long)detail->args.ld_lba.lba);
		}
		printf(": ");
		break;
	case MR_EVT_ARGS_LD_OWNER:
		printf("VOL %s", volume_name(fd, &detail->args.ld_count.ld));
		if (verbose) {
			printf(" owner changed: prior %d, new %d",
			    detail->args.ld_owner.pre_owner,
			    detail->args.ld_owner.new_owner);
		}
		printf(": ");
		break;
	case MR_EVT_ARGS_LD_LBA_PD_LBA:
		printf("VOL %s", volume_name(fd, &detail->args.ld_count.ld));
		if (verbose) {
			printf(" lba %lld, physical drive PD %s lba %lld",
			    (long long)detail->args.ld_lba_pd_lba.ld_lba,
			    pdrive_location(&detail->args.ld_lba_pd_lba.pd),
			    (long long)detail->args.ld_lba_pd_lba.pd_lba);
		}
		printf(": ");
		break;
	case MR_EVT_ARGS_LD_PROG:
		printf("VOL %s", volume_name(fd, &detail->args.ld_prog.ld));
		if (verbose) {
			printf(" progress %d%% in %ds",
			    detail->args.ld_prog.prog.progress/655,
			    detail->args.ld_prog.prog.elapsed_seconds);
		}
		printf(": ");
		break;
	case MR_EVT_ARGS_LD_STATE:
		printf("VOL %s", volume_name(fd, &detail->args.ld_prog.ld));
		if (verbose) {
			printf(" state prior %s new %s",
			    mfi_ldstate(detail->args.ld_state.prev_state),
			    mfi_ldstate(detail->args.ld_state.new_state));
		}
		printf(": ");
		break;
	case MR_EVT_ARGS_LD_STRIP:
		printf("VOL %s", volume_name(fd, &detail->args.ld_strip.ld));
		if (verbose) {
			printf(" strip %lld",
			    (long long)detail->args.ld_strip.strip);
		}
		printf(": ");
		break;
	case MR_EVT_ARGS_PD:
		if (verbose) {
			printf("PD %s event: ",
			    pdrive_location(&detail->args.pd));
		}
		break;
	case MR_EVT_ARGS_PD_ERR:
		if (verbose) {
			printf("PD %s err %d: ",
			    pdrive_location(&detail->args.pd_err.pd),
			    detail->args.pd_err.err);
		}
		break;
	case MR_EVT_ARGS_PD_LBA:
		if (verbose) {
			printf("PD %s lba %lld: ",
			    pdrive_location(&detail->args.pd_lba.pd),
			    (long long)detail->args.pd_lba.lba);
		}
		break;
	case MR_EVT_ARGS_PD_LBA_LD:
		if (verbose) {
			printf("PD %s lba %lld VOL %s: ",
			    pdrive_location(&detail->args.pd_lba_ld.pd),
			    (long long)detail->args.pd_lba.lba,
			    volume_name(fd, &detail->args.pd_lba_ld.ld));
		}
		break;
	case MR_EVT_ARGS_PD_PROG:
		if (verbose) {
			printf("PD %s progress %d%% seconds %ds: ",
			    pdrive_location(&detail->args.pd_prog.pd),
			    detail->args.pd_prog.prog.progress/655,
			    detail->args.pd_prog.prog.elapsed_seconds);
		}
		break;
	case MR_EVT_ARGS_PD_STATE:
		if (verbose) {
			printf("PD %s state prior %s new %s: ",
			    pdrive_location(&detail->args.pd_prog.pd),
			    mfi_pdstate(detail->args.pd_state.prev_state),
			    mfi_pdstate(detail->args.pd_state.new_state));
		}
		break;
	case MR_EVT_ARGS_PCI:
		if (verbose) {
			printf("PCI 0x%04x 0x%04x 0x%04x 0x%04x: ",
			    detail->args.pci.venderId,
			    detail->args.pci.deviceId,
			    detail->args.pci.subVenderId,
			    detail->args.pci.subDeviceId);
		}
		break;
	case MR_EVT_ARGS_RATE:
		if (verbose) {
			printf("Rebuild rate %d: ", detail->args.rate);
		}
		break;
	case MR_EVT_ARGS_TIME:
		if (verbose) {
			printf("Adapter time %s; %d seconds since power on: ",
			    format_timestamp(detail->args.time.rtc),
			    detail->args.time.elapsedSeconds);
		}
		break;
	case MR_EVT_ARGS_ECC:
		if (verbose) {
			printf("Adapter ECC %x,%x: %s: ",
			    detail->args.ecc.ecar,
			    detail->args.ecc.elog,
			    detail->args.ecc.str);
		}
		break;
	default:
		if (verbose) {
			printf("Type %d: ", detail->arg_type);
		}
		break;
	}
	printf("%s\n", detail->description);
}

static int
show_events(int ac, char **av)
{
	struct mfi_evt_log_state info;
	struct mfi_evt_list *list;
	union mfi_evt filter;
	bool first;
	long val;
	char *cp;
	ssize_t size;
	uint32_t seq, start, stop;
	uint16_t locale;
	uint8_t status;
	int ch, error, fd, num_events, verbose;
	u_int i;

	fd = mfi_open(mfi_unit, O_RDWR);
	if (fd < 0) {
		error = errno;
		warn("mfi_open");
		return (error);
	}

	if (mfi_event_get_info(fd, &info, NULL) < 0) {
		error = errno;
		warn("Failed to get event log info");
		close(fd);
		return (error);
	}

	/* Default settings. */
	num_events = 15;
	filter.members.reserved = 0;
	filter.members.locale = MFI_EVT_LOCALE_ALL;
	filter.members.evt_class = MFI_EVT_CLASS_WARNING;
	start = info.boot_seq_num;
	stop = info.newest_seq_num;
	verbose = 0;

	/* Parse any options. */
	optind = 1;
	while ((ch = getopt(ac, av, "c:l:n:v")) != -1) {
		switch (ch) {
		case 'c':
			if (parse_class(optarg, &filter.members.evt_class) < 0) {
				error = errno;
				warn("Error parsing event class");
				close(fd);
				return (error);
			}
			break;
		case 'l':
			if (parse_locale(optarg, &locale) < 0) {
				error = errno;
				warn("Error parsing event locale");
				close(fd);
				return (error);
			}
			filter.members.locale = locale;
			break;
		case 'n':
			val = strtol(optarg, &cp, 0);
			if (*cp != '\0' || val <= 0) {
				warnx("Invalid event count");
				close(fd);
				return (EINVAL);
			}
			num_events = val;
			break;
		case 'v':
			verbose = 1;
			break;
		case '?':
		default:
			close(fd);
			return (EINVAL);
		}
	}
	ac -= optind;
	av += optind;

	/* Determine buffer size and validate it. */
	size = sizeof(struct mfi_evt_list) + sizeof(struct mfi_evt_detail) *
	    (num_events - 1);
	if (size > getpagesize()) {
		warnx("Event count is too high");
		close(fd);
		return (EINVAL);
	}

	/* Handle optional start and stop sequence numbers. */
	if (ac > 2) {
		warnx("show events: extra arguments");
		close(fd);
		return (EINVAL);
	}
	if (ac > 0 && parse_seq(&info, av[0], &start) < 0) {
		error = errno;
		warn("Error parsing starting sequence number");
		close(fd);
		return (error);
	}
	if (ac > 1 && parse_seq(&info, av[1], &stop) < 0) {
		error = errno;
		warn("Error parsing ending sequence number");
		close(fd);
		return (error);
	}

	list = malloc(size);
	if (list == NULL) {
		warnx("malloc failed");
		close(fd);
		return (ENOMEM);
	}
	first = true;
	seq = start;
	for (;;) {
		if (mfi_get_events(fd, list, num_events, filter, seq,
		    &status) < 0) {
			error = errno;
			warn("Failed to fetch events");
			free(list);
			close(fd);
			return (error);
		}
		if (status == MFI_STAT_NOT_FOUND) {
			break;
		}
		if (status != MFI_STAT_OK) {
			warnx("Error fetching events: %s", mfi_status(status));
			free(list);
			close(fd);
			return (EIO);
		}

		for (i = 0; i < list->count; i++) {
			/*
			 * If this event is newer than 'stop_seq' then
			 * break out of the loop.  Note that the log
			 * is a circular buffer so we have to handle
			 * the case that our stop point is earlier in
			 * the buffer than our start point.
			 */
			if (list->event[i].seq > stop) {
				if (start <= stop)
					goto finish;
				else if (list->event[i].seq < start)
					goto finish;
			}
			mfi_decode_evt(fd, &list->event[i], verbose);
			first = false;
		}

		/*
		 * XXX: If the event's seq # is the end of the buffer
		 * then this probably won't do the right thing.  We
		 * need to know the size of the buffer somehow.
		 */
		seq = list->event[list->count - 1].seq + 1;
			
	}
finish:
	if (first)
		warnx("No matching events found");

	free(list);
	close(fd);

	return (0);
}
MFI_COMMAND(show, events, show_events);