1*421949a3Ssevan /* $NetBSD: getobjmap.c,v 1.3 2018/01/23 21:06:26 sevan Exp $ */
2f249807bSmjacob /* $FreeBSD: $ */
3f249807bSmjacob /* $OpenBSD: $ */
4f249807bSmjacob /*
5f249807bSmjacob * Copyright (c) 2000 by Matthew Jacob
6f249807bSmjacob * All rights reserved.
7f249807bSmjacob *
8f249807bSmjacob * Redistribution and use in source and binary forms, with or without
9f249807bSmjacob * modification, are permitted provided that the following conditions
10f249807bSmjacob * are met:
11f249807bSmjacob * 1. Redistributions of source code must retain the above copyright
12f249807bSmjacob * notice, this list of conditions, and the following disclaimer,
13f249807bSmjacob * without modification, immediately at the beginning of the file.
14f249807bSmjacob * 2. The name of the author may not be used to endorse or promote products
15f249807bSmjacob * derived from this software without specific prior written permission.
16f249807bSmjacob *
17f249807bSmjacob * Alternatively, this software may be distributed under the terms of the
18f249807bSmjacob * the GNU Public License ("GPL").
19f249807bSmjacob *
20f249807bSmjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21f249807bSmjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22f249807bSmjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23f249807bSmjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24f249807bSmjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25f249807bSmjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26f249807bSmjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27f249807bSmjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28f249807bSmjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29f249807bSmjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30f249807bSmjacob * SUCH DAMAGE.
31f249807bSmjacob *
32f249807bSmjacob * Matthew Jacob
33f249807bSmjacob * Feral Software
34f249807bSmjacob * mjacob@feral.com
35f249807bSmjacob */
36f249807bSmjacob
37f249807bSmjacob #include <unistd.h>
38f249807bSmjacob #include <stdlib.h>
39f249807bSmjacob #include <stdio.h>
40f249807bSmjacob #include <fcntl.h>
41f249807bSmjacob #include <sys/ioctl.h>
42f249807bSmjacob #include SESINC
43f249807bSmjacob
44*421949a3Ssevan extern char *geteltnm(int);
45f249807bSmjacob
46f249807bSmjacob int
main(int a,char * v[])47*421949a3Ssevan main(int a, char *v[])
48f249807bSmjacob {
49f249807bSmjacob ses_object *objp;
50f249807bSmjacob int nobj, fd, i;
51f249807bSmjacob
52f249807bSmjacob while (*++v) {
53f249807bSmjacob fd = open(*v, O_RDONLY);
54f249807bSmjacob if (fd < 0) {
55f249807bSmjacob perror(*v);
56f249807bSmjacob continue;
57f249807bSmjacob }
58f249807bSmjacob if (ioctl(fd, SESIOC_GETNOBJ, (caddr_t) &nobj) < 0) {
59f249807bSmjacob perror("SESIOC_GETNOBJ");
60f249807bSmjacob (void) close(fd);
61f249807bSmjacob continue;
62f249807bSmjacob }
63f249807bSmjacob fprintf(stdout, "%s: %d objects\n", *v, nobj);
64f249807bSmjacob if (nobj == 0) {
65f249807bSmjacob (void) close(fd);
66f249807bSmjacob continue;
67f249807bSmjacob }
68f249807bSmjacob objp = calloc(nobj, sizeof (ses_object));
69f249807bSmjacob if (objp == NULL) {
70f249807bSmjacob perror("calloc");
71f249807bSmjacob (void) close(fd);
72f249807bSmjacob continue;
73f249807bSmjacob }
74f249807bSmjacob if (ioctl(fd, SESIOC_GETOBJMAP, (caddr_t) objp) < 0) {
75f249807bSmjacob perror("SESIOC_GETOBJMAP");
76f249807bSmjacob (void) close(fd);
77f249807bSmjacob continue;
78f249807bSmjacob }
79f249807bSmjacob for (i = 0; i < nobj; i++) {
80f249807bSmjacob printf(" Object %d: ID 0x%x Type '%s'\n", i,
81f249807bSmjacob objp[i].obj_id, geteltnm((int)objp[i].object_type));
82f249807bSmjacob }
83f249807bSmjacob free(objp);
84f249807bSmjacob (void) close(fd);
85f249807bSmjacob }
86f249807bSmjacob return (0);
87f249807bSmjacob }
88