getobjstat.c revision 256281
1139804Simp/* $FreeBSD: stable/10/share/examples/ses/srcs/getobjstat.c 235911 2012-05-24 14:07:44Z mav $ */
22729Sdfr/*
32729Sdfr * Copyright (c) 2000 by Matthew Jacob
42729Sdfr * All rights reserved.
52729Sdfr *
62729Sdfr * Redistribution and use in source and binary forms, with or without
72729Sdfr * modification, are permitted provided that the following conditions
82729Sdfr * are met:
92729Sdfr * 1. Redistributions of source code must retain the above copyright
102729Sdfr *    notice, this list of conditions, and the following disclaimer,
112729Sdfr *    without modification, immediately at the beginning of the file.
122729Sdfr * 2. The name of the author may not be used to endorse or promote products
132729Sdfr *    derived from this software without specific prior written permission.
142729Sdfr *
152729Sdfr * Alternatively, this software may be distributed under the terms of the
162729Sdfr * the GNU Public License ("GPL").
172729Sdfr *
182729Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19140614Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20140614Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21140614Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22140614Srwatson * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23140614Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24140614Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25140614Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26140614Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27140614Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28140614Srwatson * SUCH DAMAGE.
29140614Srwatson *
30140614Srwatson * Matthew Jacob
31140614Srwatson * Feral Software
32140614Srwatson * mjacob@feral.com
33140614Srwatson */
34140614Srwatson#include <unistd.h>
35140614Srwatson#include <stddef.h>
36140614Srwatson#include <stdint.h>
37140614Srwatson#include <stdlib.h>
38140614Srwatson#include <stdio.h>
39140614Srwatson#include <fcntl.h>
40140614Srwatson#include <sys/ioctl.h>
41140614Srwatson#include <cam/scsi/scsi_all.h>
42140614Srwatson#include <cam/scsi/scsi_ses.h>
43140614Srwatson
44140614Srwatsonint
45140614Srwatsonmain(int a, char **v)
46140614Srwatson{
47140614Srwatson	int fd;
48140614Srwatson	int i;
492729Sdfr	ses_objstat obj;
50116182Sobrien	long cvt;
51116182Sobrien	char *x;
52116182Sobrien
5359839Speter	if (a != 3) {
54140614Srwatsonusage:
5559839Speter		fprintf(stderr, "usage: %s device objectid\n", *v);
562729Sdfr		return (1);
572729Sdfr	}
5811626Sbde	fd = open(v[1], O_RDONLY);
592729Sdfr	if (fd < 0) {
602729Sdfr		perror(v[1]);
6182607Sdillon		return (1);
62140614Srwatson	}
6382607Sdillon	x = v[2];
64129882Sphk	cvt = strtol(v[2], &x, 0);
652729Sdfr	if (x == v[2]) {
6669449Salfred		goto usage;
6711626Sbde	}
6859839Speter	obj.obj_id = cvt;
6959839Speter	if (ioctl(fd, SESIOC_GETOBJSTAT, (caddr_t) &obj) < 0) {
7068024Srwatson		perror("SESIOC_GETOBJSTAT");
712729Sdfr		return (1);
7259839Speter	}
7359839Speter	fprintf(stdout, "Object 0x%x: 0x%x 0x%x 0x%x 0x%x\n", obj.obj_id,
7492723Salfred	    obj.cstat[0], obj.cstat[1], obj.cstat[2], obj.cstat[3]);
7592723Salfred	(void) close(fd);
7692723Salfred	return (0);
7710358Sjulian}
78100523Salfred