Path: blob/main/share/examples/ses/srcs/setencstat.c
39481 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;47long val;48encioc_enc_status_t stat;4950if (a != 3) {51fprintf(stderr, "usage: %s device enclosure_status\n", *v);52return (1);53}54fd = open(v[1], O_RDWR);55if (fd < 0) {56perror(v[1]);57return (1);58}5960val = strtol(v[2], NULL, 0);61stat = (encioc_enc_status_t)val;62if (ioctl(fd, ENCIOC_SETENCSTAT, (caddr_t) &stat) < 0) {63perror("ENCIOC_SETENCSTAT");64}65(void) close(fd);66return (0);67}686970