1248590Smm/* $FreeBSD: releng/10.3/share/examples/ses/srcs/setencstat.c 235911 2012-05-24 14:07:44Z mav $ */ 2248590Smm/* 3248590Smm * Copyright (c) 2000 by Matthew Jacob 4248590Smm * All rights reserved. 5248590Smm * 6248590Smm * Redistribution and use in source and binary forms, with or without 7248590Smm * modification, are permitted provided that the following conditions 8248590Smm * are met: 9248590Smm * 1. Redistributions of source code must retain the above copyright 10248590Smm * notice, this list of conditions, and the following disclaimer, 11248590Smm * without modification, immediately at the beginning of the file. 12248590Smm * 2. The name of the author may not be used to endorse or promote products 13248590Smm * derived from this software without specific prior written permission. 14248590Smm * 15248590Smm * Alternatively, this software may be distributed under the terms of the 16248590Smm * the GNU Public License ("GPL"). 17248590Smm * 18248590Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19248590Smm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20248590Smm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21248590Smm * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 22248590Smm * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23248590Smm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24248590Smm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25248590Smm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26248590Smm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27248590Smm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28248590Smm * SUCH DAMAGE. 29248590Smm * 30248590Smm * Matthew Jacob 31248590Smm * Feral Software 32248590Smm * mjacob@feral.com 33248590Smm */ 34248590Smm 35248590Smm#include <unistd.h> 36248590Smm#include <stddef.h> 37248590Smm#include <stdint.h> 38248590Smm#include <stdlib.h> 39248590Smm#include <stdio.h> 40248590Smm#include <fcntl.h> 41248590Smm#include <sys/ioctl.h> 42248590Smm#include <cam/scsi/scsi_all.h> 43248590Smm#include <cam/scsi/scsi_enc.h> 44248590Smm 45248590Smmint 46248590Smmmain(int a, char **v) 47248590Smm{ 48248590Smm int fd; 49248590Smm long val; 50248590Smm encioc_enc_status_t stat; 51248590Smm 52248590Smm if (a != 3) { 53248590Smm fprintf(stderr, "usage: %s device enclosure_status\n", *v); 54248590Smm return (1); 55248590Smm } 56248590Smm fd = open(v[1], O_RDWR); 57248590Smm if (fd < 0) { 58248590Smm perror(v[1]); 59248590Smm return (1); 60248590Smm } 61248590Smm 62248590Smm val = strtol(v[2], NULL, 0); 63248590Smm stat = (encioc_enc_status_t)val; 64248590Smm if (ioctl(fd, ENCIOC_SETENCSTAT, (caddr_t) &stat) < 0) { 65248590Smm perror("ENCIOC_SETENCSTAT"); 66248590Smm } 67248590Smm (void) close(fd); 68248590Smm return (0); 69248590Smm} 70248590Smm