1*421949a3Ssevan /* $NetBSD: getobjstat.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 #include <unistd.h>
37f249807bSmjacob #include <stdlib.h>
38f249807bSmjacob #include <stdio.h>
39f249807bSmjacob #include <fcntl.h>
40f249807bSmjacob #include <sys/ioctl.h>
41f249807bSmjacob #include SESINC
42f249807bSmjacob
43f249807bSmjacob int
main(int a,char * v[])44*421949a3Ssevan main(int a, char *v[])
45f249807bSmjacob {
46f249807bSmjacob int fd;
47f249807bSmjacob int i;
48f249807bSmjacob ses_objstat obj;
49f249807bSmjacob long cvt;
50f249807bSmjacob char *x;
51f249807bSmjacob
52f249807bSmjacob if (a != 3) {
53f249807bSmjacob usage:
54f249807bSmjacob fprintf(stderr, "usage: %s device objectid\n", *v);
55f249807bSmjacob return (1);
56f249807bSmjacob }
57f249807bSmjacob fd = open(v[1], O_RDONLY);
58f249807bSmjacob if (fd < 0) {
59f249807bSmjacob perror(v[1]);
60f249807bSmjacob return (1);
61f249807bSmjacob }
62f249807bSmjacob x = v[2];
63f249807bSmjacob cvt = strtol(v[2], &x, 0);
64f249807bSmjacob if (x == v[2]) {
65f249807bSmjacob goto usage;
66f249807bSmjacob }
67f249807bSmjacob obj.obj_id = cvt;
68f249807bSmjacob if (ioctl(fd, SESIOC_GETOBJSTAT, (caddr_t) &obj) < 0) {
69f249807bSmjacob perror("SESIOC_GETOBJSTAT");
70f249807bSmjacob return (1);
71f249807bSmjacob }
72f249807bSmjacob fprintf(stdout, "Object 0x%x: 0x%x 0x%x 0x%x 0x%x\n", obj.obj_id,
73f249807bSmjacob obj.cstat[0], obj.cstat[1], obj.cstat[2], obj.cstat[3]);
74f249807bSmjacob (void) close(fd);
75f249807bSmjacob return (0);
76f249807bSmjacob }
77