| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: drvctl.c,v 1.6 2008/01/27 01:38:33 dyoung Exp $ */ | | 1 | /* $NetBSD: drvctl.c,v 1.6.10.1 2009/05/03 22:49:51 snj Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2004 | | 4 | * Copyright (c) 2004 |
5 | * Matthias Drochner. All rights reserved. | | 5 | * Matthias Drochner. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions, and the following disclaimer. | | 11 | * notice, this list of conditions, and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -39,27 +39,27 @@ | | | @@ -39,27 +39,27 @@ |
39 | | | 39 | |
40 | #define OPEN_MODE(mode) \ | | 40 | #define OPEN_MODE(mode) \ |
41 | (((mode) == 'd' || (mode) == 'r') ? O_RDWR \ | | 41 | (((mode) == 'd' || (mode) == 'r') ? O_RDWR \ |
42 | : O_RDONLY) | | 42 | : O_RDONLY) |
43 | | | 43 | |
44 | static void usage(void); | | 44 | static void usage(void); |
45 | | | 45 | |
46 | static void | | 46 | static void |
47 | usage(void) | | 47 | usage(void) |
48 | { | | 48 | { |
49 | | | 49 | |
50 | fprintf(stderr, "Usage: %s -r [-a attribute] busdevice [locator ...]\n" | | 50 | fprintf(stderr, "Usage: %s -r [-a attribute] busdevice [locator ...]\n" |
51 | " %s -d device\n" | | 51 | " %s -d device\n" |
52 | " %s -l device\n" | | 52 | " %s -l [device]\n" |
53 | " %s -p device\n" | | 53 | " %s -p device\n" |
54 | " %s -Q device\n" | | 54 | " %s -Q device\n" |
55 | " %s -R device\n" | | 55 | " %s -R device\n" |
56 | " %s -S device\n", | | 56 | " %s -S device\n", |
57 | getprogname(), getprogname(), getprogname(), getprogname(), | | 57 | getprogname(), getprogname(), getprogname(), getprogname(), |
58 | getprogname(), getprogname(), getprogname()); | | 58 | getprogname(), getprogname(), getprogname()); |
59 | exit(1); | | 59 | exit(1); |
60 | } | | 60 | } |
61 | | | 61 | |
62 | int | | 62 | int |
63 | main(int argc, char **argv) | | 63 | main(int argc, char **argv) |
64 | { | | 64 | { |
65 | int c, mode; | | 65 | int c, mode; |
| @@ -94,27 +94,27 @@ main(int argc, char **argv) | | | @@ -94,27 +94,27 @@ main(int argc, char **argv) |
94 | break; | | 94 | break; |
95 | case 'a': | | 95 | case 'a': |
96 | attr = optarg; | | 96 | attr = optarg; |
97 | break; | | 97 | break; |
98 | case '?': | | 98 | case '?': |
99 | default: | | 99 | default: |
100 | usage(); | | 100 | usage(); |
101 | } | | 101 | } |
102 | } | | 102 | } |
103 | | | 103 | |
104 | argc -= optind; | | 104 | argc -= optind; |
105 | argv += optind; | | 105 | argv += optind; |
106 | | | 106 | |
107 | if (argc < 1 || mode == 0) | | 107 | if ((argc < 1 && mode != 'l') || mode == 0) |
108 | usage(); | | 108 | usage(); |
109 | | | 109 | |
110 | fd = open(DRVCTLDEV, OPEN_MODE(mode), 0); | | 110 | fd = open(DRVCTLDEV, OPEN_MODE(mode), 0); |
111 | if (fd < 0) | | 111 | if (fd < 0) |
112 | err(2, "open %s", DRVCTLDEV); | | 112 | err(2, "open %s", DRVCTLDEV); |
113 | | | 113 | |
114 | switch (mode) { | | 114 | switch (mode) { |
115 | case 'Q': | | 115 | case 'Q': |
116 | paa.flags = DEVPM_F_SUBTREE; | | 116 | paa.flags = DEVPM_F_SUBTREE; |
117 | /*FALLTHROUGH*/ | | 117 | /*FALLTHROUGH*/ |
118 | case 'R': | | 118 | case 'R': |
119 | strlcpy(paa.devname, argv[0], sizeof(paa.devname)); | | 119 | strlcpy(paa.devname, argv[0], sizeof(paa.devname)); |
120 | | | 120 | |
| @@ -124,43 +124,48 @@ main(int argc, char **argv) | | | @@ -124,43 +124,48 @@ main(int argc, char **argv) |
124 | case 'S': | | 124 | case 'S': |
125 | strlcpy(paa.devname, argv[0], sizeof(paa.devname)); | | 125 | strlcpy(paa.devname, argv[0], sizeof(paa.devname)); |
126 | | | 126 | |
127 | if (ioctl(fd, DRVSUSPENDDEV, &paa) == -1) | | 127 | if (ioctl(fd, DRVSUSPENDDEV, &paa) == -1) |
128 | err(3, "DRVSUSPENDDEV"); | | 128 | err(3, "DRVSUSPENDDEV"); |
129 | break; | | 129 | break; |
130 | case 'd': | | 130 | case 'd': |
131 | strlcpy(daa.devname, argv[0], sizeof(daa.devname)); | | 131 | strlcpy(daa.devname, argv[0], sizeof(daa.devname)); |
132 | | | 132 | |
133 | if (ioctl(fd, DRVDETACHDEV, &daa) == -1) | | 133 | if (ioctl(fd, DRVDETACHDEV, &daa) == -1) |
134 | err(3, "DRVDETACHDEV"); | | 134 | err(3, "DRVDETACHDEV"); |
135 | break; | | 135 | break; |
136 | case 'l': | | 136 | case 'l': |
137 | strlcpy(laa.l_devname, argv[0], sizeof(laa.l_devname)); | | 137 | if (argc == 0) |
| | | 138 | *laa.l_devname = '\0'; |
| | | 139 | else |
| | | 140 | strlcpy(laa.l_devname, argv[0], sizeof(laa.l_devname)); |
138 | | | 141 | |
139 | if (ioctl(fd, DRVLISTDEV, &laa) == -1) | | 142 | if (ioctl(fd, DRVLISTDEV, &laa) == -1) |
140 | err(3, "DRVLISTDEV"); | | 143 | err(3, "DRVLISTDEV"); |
141 | | | 144 | |
142 | children = laa.l_children; | | 145 | children = laa.l_children; |
143 | | | 146 | |
144 | laa.l_childname = malloc(children * sizeof(laa.l_childname[0])); | | 147 | laa.l_childname = malloc(children * sizeof(laa.l_childname[0])); |
145 | if (laa.l_childname == NULL) | | 148 | if (laa.l_childname == NULL) |
146 | err(5, "DRVLISTDEV"); | | 149 | err(5, "DRVLISTDEV"); |
147 | if (ioctl(fd, DRVLISTDEV, &laa) == -1) | | 150 | if (ioctl(fd, DRVLISTDEV, &laa) == -1) |
148 | err(3, "DRVLISTDEV"); | | 151 | err(3, "DRVLISTDEV"); |
149 | if (laa.l_children > children) | | 152 | if (laa.l_children > children) |
150 | err(6, "DRVLISTDEV: number of children grew"); | | 153 | err(6, "DRVLISTDEV: number of children grew"); |
151 | | | 154 | |
152 | for (i = 0; i < laa.l_children; i++) | | 155 | for (i = 0; i < laa.l_children; i++) { |
153 | printf("%s %s\n", laa.l_devname, laa.l_childname[i]); | | 156 | printf("%s%s%s\n", laa.l_devname, (argc ? " " : ""), |
| | | 157 | laa.l_childname[i]); |
| | | 158 | } |
154 | break; | | 159 | break; |
155 | case 'r': | | 160 | case 'r': |
156 | memset(&raa, 0, sizeof(raa)); | | 161 | memset(&raa, 0, sizeof(raa)); |
157 | strlcpy(raa.busname, argv[0], sizeof(raa.busname)); | | 162 | strlcpy(raa.busname, argv[0], sizeof(raa.busname)); |
158 | if (attr) | | 163 | if (attr) |
159 | strlcpy(raa.ifattr, attr, sizeof(raa.ifattr)); | | 164 | strlcpy(raa.ifattr, attr, sizeof(raa.ifattr)); |
160 | if (argc > 1) { | | 165 | if (argc > 1) { |
161 | locs = malloc((argc - 1) * sizeof(int)); | | 166 | locs = malloc((argc - 1) * sizeof(int)); |
162 | if (!locs) | | 167 | if (!locs) |
163 | err(5, "malloc int[%d]", argc - 1); | | 168 | err(5, "malloc int[%d]", argc - 1); |
164 | for (i = 0; i < argc - 1; i++) | | 169 | for (i = 0; i < argc - 1; i++) |
165 | locs[i] = atoi(argv[i + 1]); | | 170 | locs[i] = atoi(argv[i + 1]); |
166 | raa.numlocators = argc - 1; | | 171 | raa.numlocators = argc - 1; |