157580Smjacob/* $FreeBSD$ */
257580Smjacob/*
357580Smjacob * Copyright (c) 2000 by Matthew Jacob
457580Smjacob * All rights reserved.
557580Smjacob *
657580Smjacob * Redistribution and use in source and binary forms, with or without
757580Smjacob * modification, are permitted provided that the following conditions
857580Smjacob * are met:
957580Smjacob * 1. Redistributions of source code must retain the above copyright
1057580Smjacob *    notice, this list of conditions, and the following disclaimer,
1157580Smjacob *    without modification, immediately at the beginning of the file.
1257580Smjacob * 2. The name of the author may not be used to endorse or promote products
1357580Smjacob *    derived from this software without specific prior written permission.
1457580Smjacob *
1557580Smjacob * Alternatively, this software may be distributed under the terms of the
1657580Smjacob * the GNU Public License ("GPL").
1757580Smjacob *
1857580Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1957580Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2057580Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2157580Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
2257580Smjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2357580Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2457580Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2557580Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2657580Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2757580Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2857580Smjacob * SUCH DAMAGE.
2957580Smjacob *
3057580Smjacob * Matthew Jacob
3157580Smjacob * Feral Software
3257580Smjacob * mjacob@feral.com
3357580Smjacob */
3457580Smjacob
3557580Smjacob#include <unistd.h>
36235911Smav#include <stddef.h>
37235911Smav#include <stdint.h>
3857580Smjacob#include <stdlib.h>
3957580Smjacob#include <stdio.h>
4057580Smjacob#include <fcntl.h>
4157580Smjacob#include <sys/ioctl.h>
42235911Smav#include <cam/scsi/scsi_all.h>
43235911Smav#include <cam/scsi/scsi_ses.h>
4457580Smjacob
45198934Sdelphij#include "eltsub.h"
4657580Smjacob
4757580Smjacobint
48198934Sdelphijmain(int a, char **v)
4957580Smjacob{
5057580Smjacob	ses_object *objp;
5157580Smjacob	int nobj, fd, i;
5257580Smjacob
5357580Smjacob	while (*++v) {
5457580Smjacob		fd = open(*v, O_RDONLY);
5557580Smjacob		if (fd < 0) {
5657580Smjacob			perror(*v);
5757580Smjacob			continue;
5857580Smjacob		}
5957580Smjacob		if (ioctl(fd, SESIOC_GETNOBJ, (caddr_t) &nobj) < 0) {
6057580Smjacob			perror("SESIOC_GETNOBJ");
6157580Smjacob			(void) close(fd);
6257580Smjacob			continue;
6357580Smjacob		}
6457580Smjacob		fprintf(stdout, "%s: %d objects\n", *v, nobj);
6557580Smjacob		if (nobj == 0) {
6657580Smjacob			(void) close(fd);
6757580Smjacob			continue;
6857580Smjacob		}
6957580Smjacob		objp = calloc(nobj, sizeof (ses_object));
7057580Smjacob		if (objp == NULL) {
7157580Smjacob			perror("calloc");
7257580Smjacob			(void) close(fd);
7357580Smjacob			continue;
7457580Smjacob		}
7557580Smjacob		if (ioctl(fd, SESIOC_GETOBJMAP, (caddr_t) objp) < 0) {
7657580Smjacob			perror("SESIOC_GETOBJMAP");
7757580Smjacob			(void) close(fd);
7857580Smjacob			continue;
7957580Smjacob		}
8057580Smjacob		for (i = 0; i < nobj; i++) {
8157580Smjacob			printf(" Object %d: ID 0x%x Type '%s'\n", i,
8257580Smjacob			    objp[i].obj_id, geteltnm((int)objp[i].object_type));
8357580Smjacob		}
8457580Smjacob		free(objp);
8557580Smjacob		(void) close(fd);
8657580Smjacob	}
8757580Smjacob	return (0);
8857580Smjacob}
89