xref: /freebsd/share/examples/ses/srcs/setobjstat.c (revision 2804a96a502283a0b41449bcfe2b049dbfc6dbae)
1daf1cffcSMatt Jacob /* $FreeBSD$ */
2daf1cffcSMatt Jacob /*
3daf1cffcSMatt Jacob  * Copyright (c) 2000 by Matthew Jacob
4daf1cffcSMatt Jacob  * All rights reserved.
5daf1cffcSMatt Jacob  *
6daf1cffcSMatt Jacob  * Redistribution and use in source and binary forms, with or without
7daf1cffcSMatt Jacob  * modification, are permitted provided that the following conditions
8daf1cffcSMatt Jacob  * are met:
9daf1cffcSMatt Jacob  * 1. Redistributions of source code must retain the above copyright
10daf1cffcSMatt Jacob  *    notice, this list of conditions, and the following disclaimer,
11daf1cffcSMatt Jacob  *    without modification, immediately at the beginning of the file.
12daf1cffcSMatt Jacob  * 2. The name of the author may not be used to endorse or promote products
13daf1cffcSMatt Jacob  *    derived from this software without specific prior written permission.
14daf1cffcSMatt Jacob  *
15daf1cffcSMatt Jacob  * Alternatively, this software may be distributed under the terms of the
16daf1cffcSMatt Jacob  * the GNU Public License ("GPL").
17daf1cffcSMatt Jacob  *
18daf1cffcSMatt Jacob  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19daf1cffcSMatt Jacob  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20daf1cffcSMatt Jacob  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21daf1cffcSMatt Jacob  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22daf1cffcSMatt Jacob  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23daf1cffcSMatt Jacob  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24daf1cffcSMatt Jacob  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25daf1cffcSMatt Jacob  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26daf1cffcSMatt Jacob  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27daf1cffcSMatt Jacob  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28daf1cffcSMatt Jacob  * SUCH DAMAGE.
29daf1cffcSMatt Jacob  *
30daf1cffcSMatt Jacob  * Matthew Jacob
31daf1cffcSMatt Jacob  * Feral Software
32daf1cffcSMatt Jacob  * mjacob@feral.com
33daf1cffcSMatt Jacob  */
34daf1cffcSMatt Jacob 
35daf1cffcSMatt Jacob #include <unistd.h>
36daf1cffcSMatt Jacob #include <stdlib.h>
37daf1cffcSMatt Jacob #include <stdio.h>
38daf1cffcSMatt Jacob #include <fcntl.h>
39daf1cffcSMatt Jacob #include <sys/ioctl.h>
40daf1cffcSMatt Jacob #include SESINC
41daf1cffcSMatt Jacob 
42daf1cffcSMatt Jacob int
432804a96aSXin LI main(int a, char **v)
44daf1cffcSMatt Jacob {
45daf1cffcSMatt Jacob 	int fd;
46daf1cffcSMatt Jacob 	int i;
47daf1cffcSMatt Jacob 	ses_objstat obj;
48daf1cffcSMatt Jacob 	long cvt;
49daf1cffcSMatt Jacob 	char *x;
50daf1cffcSMatt Jacob 
51daf1cffcSMatt Jacob 	if (a != 7) {
52daf1cffcSMatt Jacob usage:
53daf1cffcSMatt Jacob 		fprintf(stderr,
54daf1cffcSMatt Jacob 		    "usage: %s device objectid stat0 stat1 stat2 stat3\n", *v);
55daf1cffcSMatt Jacob 		return (1);
56daf1cffcSMatt Jacob 	}
57daf1cffcSMatt Jacob 	fd = open(v[1], O_RDWR);
58daf1cffcSMatt Jacob 	if (fd < 0) {
59daf1cffcSMatt Jacob 		perror(v[1]);
60daf1cffcSMatt Jacob 		return (1);
61daf1cffcSMatt Jacob 	}
62daf1cffcSMatt Jacob 	x = v[2];
63daf1cffcSMatt Jacob 	cvt = strtol(v[2], &x, 0);
64daf1cffcSMatt Jacob 	if (x == v[2]) {
65daf1cffcSMatt Jacob 		goto usage;
66daf1cffcSMatt Jacob 	}
67daf1cffcSMatt Jacob 	obj.obj_id = cvt;
68daf1cffcSMatt Jacob 	for (i = 0; i < 4; i++) {
69daf1cffcSMatt Jacob 		x = v[3 + i];
70daf1cffcSMatt Jacob 		cvt = strtol(v[3 + i],  &x, 0);
71daf1cffcSMatt Jacob 		if (x == v[3 + i]) {
72daf1cffcSMatt Jacob 			goto usage;
73daf1cffcSMatt Jacob 		}
74daf1cffcSMatt Jacob 		obj.cstat[i] = cvt;
75daf1cffcSMatt Jacob 	}
76daf1cffcSMatt Jacob 	if (ioctl(fd, SESIOC_SETOBJSTAT, (caddr_t) &obj) < 0) {
77daf1cffcSMatt Jacob 		perror("SESIOC_SETOBJSTAT");
78daf1cffcSMatt Jacob 	}
79daf1cffcSMatt Jacob 	(void) close(fd);
80daf1cffcSMatt Jacob 	return (0);
81daf1cffcSMatt Jacob }
82