Path: blob/main/share/examples/ses/srcs/setobjstat.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*/3233#include <unistd.h>34#include <stddef.h>35#include <stdint.h>36#include <stdlib.h>37#include <stdio.h>38#include <fcntl.h>39#include <sys/ioctl.h>40#include <cam/scsi/scsi_all.h>41#include <cam/scsi/scsi_enc.h>4243int44main(int a, char **v)45{46int fd;47int i;48encioc_elm_status_t obj;49long cvt;50char *x;5152if (a != 7) {53usage:54fprintf(stderr,55"usage: %s device objectid stat0 stat1 stat2 stat3\n", *v);56return (1);57}58fd = open(v[1], O_RDWR);59if (fd < 0) {60perror(v[1]);61return (1);62}63x = v[2];64cvt = strtol(v[2], &x, 0);65if (x == v[2]) {66goto usage;67}68obj.elm_idx = cvt;69for (i = 0; i < 4; i++) {70x = v[3 + i];71cvt = strtol(v[3 + i], &x, 0);72if (x == v[3 + i]) {73goto usage;74}75obj.cstat[i] = cvt;76}77if (ioctl(fd, ENCIOC_SETELMSTAT, (caddr_t) &obj) < 0) {78perror("ENCIOC_SETELMSTAT");79}80(void) close(fd);81return (0);82}838485