root/morphix/trunk/mini_fo/fist_ioctl.c

Revision 2, 1.9 kB (checked in by nextime, 2 years ago)

Initial import, branching from morphix svn

Line 
1 /*
2  * Copyright (c) 1997-2004 Erez Zadok <ezk@cs.stonybrook.edu>
3  * Copyright (c) 2001-2004 Stony Brook University
4  *
5  * For specific licensing information, see the COPYING file distributed with
6  * this package, or get one from ftp://ftp.filesystems.org/pub/fistgen/COPYING.
7  *
8  * This Copyright notice must be kept intact and distributed with all
9  * fistgen sources INCLUDING sources generated by fistgen.
10  */
11 /*
12  *  $Id: fist_ioctl.c 1364 2004-12-04 10:18:10Z alextreme $
13  */
14
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif /* HAVE_CONFIG_H */
18 #ifdef FISTGEN
19 # include "fist_mini_fo.h"
20 #endif /* FISTGEN */
21 #include "fist.h"
22 #include "mini_fo.h"
23
24 #include <sys/ioctl.h>
25 #include <fcntl.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <string.h>
29 #include <stdio.h>
30
31 static int opt_d = 0;
32 static int optcount;
33 static const char *progname;
34
35
36 void
37 usage(void)
38 {
39         fprintf(stderr, "Usage: %s -d file [val]\n\tto set/get debugging values\n", progname);
40         exit(1);
41 }
42
43
44 int
45 main(int argc, char *argv[])
46 {
47         int fd, ret, val = 0;
48
49         progname = argv[0];
50
51         /* check that minimum number of args were specified */
52         if (argc < 3)
53                 usage();
54
55
56         if (strcmp(argv[1], "-d") == 0) {
57                 if (argc > 4)
58                         usage();
59                 opt_d++;
60                 optcount++;
61         }
62
63
64         /* check that at least one option was used */
65         if (!optcount)
66                 usage();
67
68         /* open file on which ioctl will operate */
69         fd = open(argv[2], O_RDONLY);
70         if (fd < 0) {
71                 perror(argv[2]);
72                 exit(1);
73         }
74
75         /* if specified 3rd arg, want to set debug level */
76         if (opt_d) {
77                 if (argc == 4) {
78                         val = atoi(argv[3]);
79                         ret = ioctl(fd, FIST_IOCTL_SET_DEBUG_VALUE, &val);
80                         if (ret < 0) {
81                                 perror("ioctl set");
82                                 exit(1);
83                         }
84                 } else {
85                         ret = ioctl(fd, FIST_IOCTL_GET_DEBUG_VALUE, &val);
86                         if (ret < 0) {
87                                 perror("ioctl get");
88                                 exit(1);
89                         }
90                         printf("debug ioctl returned value %d\n", val);
91                 }
92                 goto out;
93         }
94
95
96
97 out:
98         close(fd);
99         exit(0);
100 }
101
102 /*
103  * Local variables:
104  * c-basic-offset: 4
105  * End:
106  */
Note: See TracBrowser for help on using the browser.