Path: blob/main/share/examples/ses/srcs/getobjstat.c
39530 views
/*1* Copyright (c) 2000 by Matthew Jacob2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions, and the following disclaimer,9* without modification, immediately at the beginning of the file.10* 2. The name of the author may not be used to endorse or promote products11* derived from this software without specific prior written permission.12*13* Alternatively, this software may be distributed under the terms of the14* the GNU Public License ("GPL").15*16* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR20* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*28* Matthew Jacob29* Feral Software30* [email protected]31*/32#include <unistd.h>33#include <stddef.h>34#include <stdint.h>35#include <stdlib.h>36#include <stdio.h>37#include <fcntl.h>38#include <sys/ioctl.h>39#include <cam/scsi/scsi_all.h>40#include <cam/scsi/scsi_ses.h>4142int43main(int a, char **v)44{45int fd;46int i;47ses_objstat obj;48long cvt;49char *x;5051if (a != 3) {52usage:53fprintf(stderr, "usage: %s device objectid\n", *v);54return (1);55}56fd = open(v[1], O_RDONLY);57if (fd < 0) {58perror(v[1]);59return (1);60}61x = v[2];62cvt = strtol(v[2], &x, 0);63if (x == v[2]) {64goto usage;65}66obj.obj_id = cvt;67if (ioctl(fd, SESIOC_GETOBJSTAT, (caddr_t) &obj) < 0) {68perror("SESIOC_GETOBJSTAT");69return (1);70}71fprintf(stdout, "Object 0x%x: 0x%x 0x%x 0x%x 0x%x\n", obj.obj_id,72obj.cstat[0], obj.cstat[1], obj.cstat[2], obj.cstat[3]);73(void) close(fd);74return (0);75}767778