Print this page
OS-1576 Sundry uninitialised variables
Reviewed by: Robert Mustacchi <rm@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/fs.d/hyprlofs/hlcfg/hlcfg.c
+++ new/usr/src/cmd/fs.d/hyprlofs/hlcfg/hlcfg.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2012, Joyent, Inc. All rights reserved.
24 24 */
25 25
26 26 /*
27 27 * This is a simple test program to exercise the hyprlofs ioctls. This is
28 28 * not designed as a full featured CLI and only does minimal error checking
29 29 * and reporting.
30 30 */
31 31 #include <stdio.h>
32 32 #include <unistd.h>
33 33 #include <stdlib.h>
34 34 #include <sys/types.h>
35 35 #include <sys/stat.h>
36 36 #include <fcntl.h>
37 37 #include <libgen.h>
38 38 #include <strings.h>
39 39 #include <sys/errno.h>
40 40 #include <sys/fs/hyprlofs.h>
41 41
42 42 extern int errno;
43 43
44 44 char *usage = "usage: <fs path> add [<file name> <alias>]+\n"
45 45 " <fs path> addl [<file name>]+\n"
46 46 " <fs path> rm [<alias>]+\n"
47 47 " <fs path> clear"
48 48 " <fs path> get";
49 49
50 50 typedef enum {
51 51 CMD_ADD,
52 52 CMD_RM,
53 53 CMD_CLR,
54 54 CMD_ADDL,
55 55 CMD_GET
56 56 } cmd_t;
57 57
58 58 static int
59 59 get_entries(int fd)
60 60 {
61 61 int err;
62 62 int i;
63 63 hyprlofs_curr_entries_t e;
64 64 hyprlofs_curr_entry_t *ep;
65 65
66 66 e.hce_cnt = 0;
67 67 e.hce_entries = NULL;
68 68
69 69 err = ioctl(fd, HYPRLOFS_GET_ENTRIES, &e);
70 70 if (err != 0 && errno != E2BIG) {
71 71 perror("ioctl");
72 72 return (1);
73 73 }
74 74
75 75 if (err == 0) {
76 76 (void) printf("success, but no entries\n");
77 77 return (0);
78 78 }
79 79
80 80 /*
81 81 * E2BIG is what we expect when there are existing mappings
82 82 * since the current cnt is still returned in that case.
83 83 */
84 84 (void) printf("cnt: %d\n", e.hce_cnt);
85 85
86 86 /* alloc array and call again, then print array */
87 87 if ((ep = (hyprlofs_curr_entry_t *)
88 88 malloc(sizeof (hyprlofs_curr_entry_t) * e.hce_cnt)) == NULL) {
89 89 (void) fprintf(stderr, "out of memory\n");
90 90 exit(1);
91 91 }
92 92
93 93 e.hce_entries = ep;
94 94 errno = 0;
95 95 if (ioctl(fd, HYPRLOFS_GET_ENTRIES, &e) != 0) {
96 96 /*
97 97 * Not handling an increase here. We would need to free and
98 98 * start over to do that, but ok for a test program.
99 99 */
100 100 perror("ioctl");
101 101 free(ep);
102 102 return (1);
103 103 }
104 104 for (i = 0; i < e.hce_cnt; i++)
105 105 (void) printf("%s %s\n", ep[i].hce_path, ep[i].hce_name);
106 106
107 107 free(ep);
108 108 return (0);
↓ open down ↓ |
108 lines elided |
↑ open up ↑ |
109 109 }
110 110
111 111 int
112 112 main(int argc, char **argv)
113 113 {
114 114 int i, ap;
115 115 cmd_t cmd;
116 116 int cnt = 0;
117 117 int fd;
118 118 int rv = 0;
119 - hyprlofs_entry_t *e;
119 + hyprlofs_entry_t *e = NULL;
120 120 hyprlofs_entries_t ents;
121 121
122 122 if (argc < 3) {
123 123 (void) fprintf(stderr, "%s\n", usage);
124 124 exit(1);
125 125 }
126 126
127 127 if ((fd = open(argv[1], O_RDONLY)) < 0) {
128 128 perror("can't open hyprlofs mount");
129 129 exit(1);
130 130 }
131 131
132 132 if (strcmp(argv[2], "add") == 0) {
133 133 cmd = CMD_ADD;
134 134 } else if (strcmp(argv[2], "rm") == 0) {
135 135 cmd = CMD_RM;
136 136 } else if (strcmp(argv[2], "clear") == 0) {
137 137 cmd = CMD_CLR;
138 138 } else if (strcmp(argv[2], "addl") == 0) {
139 139 cmd = CMD_ADDL;
140 140 } else if (strcmp(argv[2], "get") == 0) {
141 141 cmd = CMD_GET;
142 142 } else {
143 143 (void) fprintf(stderr, "%s\n", usage);
144 144 exit(1);
145 145 }
146 146
147 147 /* Count up the number of parameters. The arg format varies w/ cmd */
148 148 switch (cmd) {
149 149 case CMD_ADD:
150 150 for (i = 3; i < argc; i++) {
151 151 /* argv[i] is the file path */
152 152
153 153 /* The next arg is the alias */
154 154 if (++i >= argc) {
155 155 (void) fprintf(stderr, "missing alias for %s\n",
156 156 argv[i - 1]);
157 157 exit(1);
158 158 }
159 159
160 160 cnt++;
161 161 }
162 162 break;
163 163 case CMD_ADDL:
164 164 cnt = argc - 3;
165 165 break;
166 166 case CMD_RM:
167 167 cnt = argc - 3;
168 168 break;
169 169 case CMD_CLR: /*FALLTHRU*/
170 170 case CMD_GET:
171 171 if (argc > 3) {
172 172 (void) fprintf(stderr, "%s\n", usage);
173 173 exit(1);
174 174 }
175 175 break;
176 176 }
177 177
178 178 if (cnt > 0) {
179 179 if ((e = (hyprlofs_entry_t *)malloc(sizeof (hyprlofs_entry_t) *
180 180 cnt)) == NULL) {
181 181 (void) fprintf(stderr, "out of memory\n");
182 182 exit(1);
183 183 }
184 184 }
185 185
186 186 /*
187 187 * Format up the args.
188 188 * We only setup the path member for the add cmd.
189 189 * We won't run this loop for the clear cmd.
190 190 * The addl command is special since we use basename to get the alias.
191 191 */
192 192 for (i = 0, ap = 3; i < cnt; i++, ap++) {
193 193 if (cmd == CMD_ADDL) {
194 194 e[i].hle_path = argv[ap];
195 195 e[i].hle_plen = strlen(e[i].hle_path);
196 196
197 197 e[i].hle_name = basename(argv[ap]);
198 198 e[i].hle_nlen = strlen(e[i].hle_name);
199 199
200 200 continue;
201 201 }
202 202
203 203 if (cmd == CMD_ADD) {
204 204 e[i].hle_path = argv[ap++];
205 205 e[i].hle_plen = strlen(e[i].hle_path);
206 206 }
207 207
208 208 e[i].hle_name = argv[ap];
209 209 e[i].hle_nlen = strlen(e[i].hle_name);
210 210 }
211 211
212 212 ents.hle_entries = e;
213 213 ents.hle_len = cnt;
214 214
215 215 switch (cmd) {
216 216 case CMD_ADD: /*FALLTHRU*/
217 217 case CMD_ADDL:
218 218 if (ioctl(fd, HYPRLOFS_ADD_ENTRIES, &ents) < 0) {
219 219 perror("ioctl");
220 220 rv = 1;
221 221 }
222 222 break;
223 223 case CMD_RM:
224 224 if (ioctl(fd, HYPRLOFS_RM_ENTRIES, &ents) < 0) {
225 225 perror("ioctl");
226 226 rv = 1;
227 227 }
228 228 break;
229 229 case CMD_CLR:
230 230 if (ioctl(fd, HYPRLOFS_RM_ALL) < 0) {
231 231 perror("ioctl");
232 232 rv = 1;
233 233 }
234 234 break;
235 235 case CMD_GET:
236 236 rv = get_entries(fd);
237 237 break;
238 238 }
239 239
240 240 (void) close(fd);
241 241 if (cnt > 0)
242 242 free(e);
243 243 return (rv);
244 244 }
↓ open down ↓ |
115 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX