133965Sjdp/* $FreeBSD: releng/10.3/share/examples/ses/srcs/setobjstat.c 235911 2012-05-24 14:07:44Z mav $ */
238889Sjdp/*
333965Sjdp * Copyright (c) 2000 by Matthew Jacob
433965Sjdp * All rights reserved.
533965Sjdp *
633965Sjdp * Redistribution and use in source and binary forms, with or without
733965Sjdp * modification, are permitted provided that the following conditions
833965Sjdp * are met:
933965Sjdp * 1. Redistributions of source code must retain the above copyright
1033965Sjdp *    notice, this list of conditions, and the following disclaimer,
1133965Sjdp *    without modification, immediately at the beginning of the file.
1233965Sjdp * 2. The name of the author may not be used to endorse or promote products
1333965Sjdp *    derived from this software without specific prior written permission.
1433965Sjdp *
1533965Sjdp * Alternatively, this software may be distributed under the terms of the
1633965Sjdp * the GNU Public License ("GPL").
1733965Sjdp *
1833965Sjdp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1933965Sjdp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2033965Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2133965Sjdp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
2233965Sjdp * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2333965Sjdp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2433965Sjdp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2533965Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2633965Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2733965Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2833965Sjdp * SUCH DAMAGE.
2933965Sjdp *
3033965Sjdp * Matthew Jacob
3133965Sjdp * Feral Software
3233965Sjdp * mjacob@feral.com
3333965Sjdp */
3433965Sjdp
3533965Sjdp#include <unistd.h>
3633965Sjdp#include <stddef.h>
3733965Sjdp#include <stdint.h>
3833965Sjdp#include <stdlib.h>
3933965Sjdp#include <stdio.h>
4033965Sjdp#include <fcntl.h>
4133965Sjdp#include <sys/ioctl.h>
4233965Sjdp#include <cam/scsi/scsi_all.h>
4333965Sjdp#include <cam/scsi/scsi_enc.h>
4433965Sjdp
4533965Sjdpint
4633965Sjdpmain(int a, char **v)
4733965Sjdp{
4833965Sjdp	int fd;
4933965Sjdp	int i;
5033965Sjdp	encioc_elm_status_t obj;
5133965Sjdp	long cvt;
5233965Sjdp	char *x;
5333965Sjdp
5433965Sjdp	if (a != 7) {
5533965Sjdpusage:
5633965Sjdp		fprintf(stderr,
5733965Sjdp		    "usage: %s device objectid stat0 stat1 stat2 stat3\n", *v);
5833965Sjdp		return (1);
5933965Sjdp	}
6033965Sjdp	fd = open(v[1], O_RDWR);
6133965Sjdp	if (fd < 0) {
6233965Sjdp		perror(v[1]);
6333965Sjdp		return (1);
6433965Sjdp	}
6533965Sjdp	x = v[2];
6633965Sjdp	cvt = strtol(v[2], &x, 0);
6733965Sjdp	if (x == v[2]) {
6833965Sjdp		goto usage;
6933965Sjdp	}
7033965Sjdp	obj.elm_idx = cvt;
7133965Sjdp	for (i = 0; i < 4; i++) {
7233965Sjdp		x = v[3 + i];
7333965Sjdp		cvt = strtol(v[3 + i],  &x, 0);
7433965Sjdp		if (x == v[3 + i]) {
7533965Sjdp			goto usage;
7633965Sjdp		}
7733965Sjdp		obj.cstat[i] = cvt;
7833965Sjdp	}
7933965Sjdp	if (ioctl(fd, ENCIOC_SETELMSTAT, (caddr_t) &obj) < 0) {
8033965Sjdp		perror("ENCIOC_SETELMSTAT");
8133965Sjdp	}
8233965Sjdp	(void) close(fd);
8333965Sjdp	return (0);
8433965Sjdp}
8533965Sjdp