]>
Commit | Line | Data |
---|---|---|
64c4757e | 1 | /* |
9a9dab36 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. |
64c4757e | 3 | * |
4f589ad0 | 4 | * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de> |
64c4757e NB |
5 | * |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | * | |
21 | * Author: Neil Brown | |
22 | * Email: <neilb@cse.unsw.edu.au> | |
23 | * Paper: Neil Brown | |
24 | * School of Computer Science and Engineering | |
25 | * The University of New South Wales | |
26 | * Sydney, 2052 | |
27 | * Australia | |
28 | */ | |
29 | ||
9a9dab36 | 30 | #include "mdadm.h" |
64c4757e | 31 | #include "md_p.h" |
edd8d13c | 32 | #include <sys/socket.h> |
64c4757e | 33 | #include <sys/utsname.h> |
edd8d13c | 34 | #include <sys/un.h> |
98c6faba | 35 | #include <ctype.h> |
a322f70c | 36 | #include <dirent.h> |
a931db9e | 37 | #include <signal.h> |
0a816ef9 NB |
38 | |
39 | /* | |
40 | * following taken from linux/blkpg.h because they aren't | |
41 | * anywhere else and it isn't safe to #include linux/ * stuff. | |
42 | */ | |
43 | ||
44 | #define BLKPG _IO(0x12,105) | |
45 | ||
46 | /* The argument structure */ | |
47 | struct blkpg_ioctl_arg { | |
48 | int op; | |
49 | int flags; | |
50 | int datalen; | |
51 | void *data; | |
52 | }; | |
53 | ||
54 | /* The subfunctions (for the op field) */ | |
55 | #define BLKPG_ADD_PARTITION 1 | |
56 | #define BLKPG_DEL_PARTITION 2 | |
57 | ||
58 | /* Sizes of name fields. Unused at present. */ | |
59 | #define BLKPG_DEVNAMELTH 64 | |
60 | #define BLKPG_VOLNAMELTH 64 | |
61 | ||
62 | /* The data structure for ADD_PARTITION and DEL_PARTITION */ | |
63 | struct blkpg_partition { | |
64 | long long start; /* starting offset in bytes */ | |
65 | long long length; /* length in bytes */ | |
66 | int pno; /* partition number */ | |
67 | char devname[BLKPG_DEVNAMELTH]; /* partition name, like sda5 or c0d1p2, | |
68 | to be used in kernel messages */ | |
69 | char volname[BLKPG_VOLNAMELTH]; /* volume label */ | |
70 | }; | |
64c4757e NB |
71 | |
72 | /* | |
73 | * Parse a 128 bit uuid in 4 integers | |
74 | * format is 32 hexx nibbles with options :.<space> separator | |
75 | * If not exactly 32 hex digits are found, return 0 | |
76 | * else return 1 | |
77 | */ | |
78 | int parse_uuid(char *str, int uuid[4]) | |
79 | { | |
aba69144 NB |
80 | int hit = 0; /* number of Hex digIT */ |
81 | int i; | |
82 | char c; | |
83 | for (i=0; i<4; i++) uuid[i]=0; | |
84 | ||
85 | while ((c= *str++)) { | |
86 | int n; | |
87 | if (c>='0' && c<='9') | |
88 | n = c-'0'; | |
89 | else if (c>='a' && c <= 'f') | |
90 | n = 10 + c - 'a'; | |
91 | else if (c>='A' && c <= 'F') | |
92 | n = 10 + c - 'A'; | |
93 | else if (strchr(":. -", c)) | |
94 | continue; | |
95 | else return 0; | |
96 | ||
97 | if (hit<32) { | |
98 | uuid[hit/8] <<= 4; | |
99 | uuid[hit/8] += n; | |
100 | } | |
101 | hit++; | |
82b27616 | 102 | } |
aba69144 NB |
103 | if (hit == 32) |
104 | return 1; | |
105 | return 0; | |
64c4757e NB |
106 | } |
107 | ||
108 | ||
109 | /* | |
110 | * Get the md version number. | |
111 | * We use the RAID_VERSION ioctl if it is supported | |
112 | * If not, but we have a block device with major '9', we assume | |
113 | * 0.36.0 | |
114 | * | |
115 | * Return version number as 24 but number - assume version parts | |
116 | * always < 255 | |
117 | */ | |
118 | ||
119 | int md_get_version(int fd) | |
120 | { | |
121 | struct stat stb; | |
122 | mdu_version_t vers; | |
123 | ||
124 | if (fstat(fd, &stb)<0) | |
125 | return -1; | |
126 | if ((S_IFMT&stb.st_mode) != S_IFBLK) | |
127 | return -1; | |
128 | ||
129 | if (ioctl(fd, RAID_VERSION, &vers) == 0) | |
682c7051 | 130 | return (vers.major*10000) + (vers.minor*100) + vers.patchlevel; |
5787fa49 NB |
131 | if (errno == EACCES) |
132 | return -1; | |
0df46c2a | 133 | if (major(stb.st_rdev) == MD_MAJOR) |
682c7051 | 134 | return (3600); |
64c4757e NB |
135 | return -1; |
136 | } | |
137 | ||
64c4757e NB |
138 | int get_linux_version() |
139 | { | |
140 | struct utsname name; | |
98c6faba | 141 | char *cp; |
64c4757e NB |
142 | int a,b,c; |
143 | if (uname(&name) <0) | |
144 | return -1; | |
145 | ||
98c6faba NB |
146 | cp = name.release; |
147 | a = strtoul(cp, &cp, 10); | |
148 | if (*cp != '.') return -1; | |
149 | b = strtoul(cp+1, &cp, 10); | |
150 | if (*cp != '.') return -1; | |
151 | c = strtoul(cp+1, NULL, 10); | |
152 | ||
682c7051 | 153 | return (a*1000000)+(b*1000)+c; |
64c4757e NB |
154 | } |
155 | ||
0430ed48 NB |
156 | void remove_partitions(int fd) |
157 | { | |
158 | /* remove partitions from this block devices. | |
159 | * This is used for components added to an array | |
160 | */ | |
161 | #ifdef BLKPG_DEL_PARTITION | |
162 | struct blkpg_ioctl_arg a; | |
163 | struct blkpg_partition p; | |
164 | ||
165 | a.op = BLKPG_DEL_PARTITION; | |
166 | a.data = (void*)&p; | |
167 | a.datalen = sizeof(p); | |
168 | a.flags = 0; | |
169 | memset(a.data, 0, a.datalen); | |
170 | for (p.pno=0; p.pno < 16; p.pno++) | |
171 | ioctl(fd, BLKPG, &a); | |
172 | #endif | |
173 | } | |
174 | ||
583315d9 | 175 | int enough(int level, int raid_disks, int layout, int clean, |
265e0f17 | 176 | char *avail, int avail_disks) |
64c4757e | 177 | { |
265e0f17 | 178 | int copies, first; |
64c4757e | 179 | switch (level) { |
265e0f17 NB |
180 | case 10: |
181 | /* This is the tricky one - we need to check | |
182 | * which actual disks are present. | |
183 | */ | |
702b557b | 184 | copies = (layout&255)* ((layout>>8) & 255); |
265e0f17 NB |
185 | first=0; |
186 | do { | |
187 | /* there must be one of the 'copies' form 'first' */ | |
188 | int n = copies; | |
189 | int cnt=0; | |
190 | while (n--) { | |
191 | if (avail[first]) | |
192 | cnt++; | |
193 | first = (first+1) % raid_disks; | |
194 | } | |
195 | if (cnt == 0) | |
196 | return 0; | |
197 | ||
198 | } while (first != 0); | |
199 | return 1; | |
e5329c37 | 200 | |
e0d19036 NB |
201 | case -4: |
202 | return avail_disks>= 1; | |
64c4757e NB |
203 | case -1: |
204 | case 0: | |
205 | return avail_disks == raid_disks; | |
206 | case 1: | |
207 | return avail_disks >= 1; | |
208 | case 4: | |
209 | case 5: | |
583315d9 NB |
210 | if (clean) |
211 | return avail_disks >= raid_disks-1; | |
212 | else | |
213 | return avail_disks >= raid_disks; | |
98c6faba | 214 | case 6: |
583315d9 NB |
215 | if (clean) |
216 | return avail_disks >= raid_disks-2; | |
217 | else | |
218 | return avail_disks >= raid_disks; | |
64c4757e NB |
219 | default: |
220 | return 0; | |
221 | } | |
222 | } | |
223 | ||
f277ce36 | 224 | int same_uuid(int a[4], int b[4], int swapuuid) |
64c4757e | 225 | { |
f277ce36 NB |
226 | if (swapuuid) { |
227 | /* parse uuids are hostendian. | |
228 | * uuid's from some superblocks are big-ending | |
aba69144 | 229 | * if there is a difference, we need to swap.. |
f277ce36 NB |
230 | */ |
231 | unsigned char *ac = (unsigned char *)a; | |
232 | unsigned char *bc = (unsigned char *)b; | |
233 | int i; | |
234 | for (i=0; i<16; i+= 4) { | |
235 | if (ac[i+0] != bc[i+3] || | |
236 | ac[i+1] != bc[i+2] || | |
237 | ac[i+2] != bc[i+1] || | |
238 | ac[i+3] != bc[i+0]) | |
239 | return 0; | |
240 | } | |
241 | return 1; | |
242 | } else { | |
243 | if (a[0]==b[0] && | |
244 | a[1]==b[1] && | |
245 | a[2]==b[2] && | |
246 | a[3]==b[3]) | |
247 | return 1; | |
248 | return 0; | |
249 | } | |
64c4757e | 250 | } |
350f29f9 NB |
251 | void copy_uuid(void *a, int b[4], int swapuuid) |
252 | { | |
253 | if (swapuuid) { | |
254 | /* parse uuids are hostendian. | |
255 | * uuid's from some superblocks are big-ending | |
256 | * if there is a difference, we need to swap.. | |
257 | */ | |
258 | unsigned char *ac = (unsigned char *)a; | |
259 | unsigned char *bc = (unsigned char *)b; | |
260 | int i; | |
261 | for (i=0; i<16; i+= 4) { | |
262 | ac[i+0] = bc[i+3]; | |
263 | ac[i+1] = bc[i+2]; | |
264 | ac[i+2] = bc[i+1]; | |
265 | ac[i+3] = bc[i+0]; | |
266 | } | |
267 | } else | |
268 | memcpy(a, b, 16); | |
269 | } | |
64c4757e | 270 | |
435d4ebb | 271 | #ifndef MDASSEMBLE |
682c7051 NB |
272 | int check_ext2(int fd, char *name) |
273 | { | |
274 | /* | |
275 | * Check for an ext2fs file system. | |
276 | * Superblock is always 1K at 1K offset | |
277 | * | |
278 | * s_magic is le16 at 56 == 0xEF53 | |
279 | * report mtime - le32 at 44 | |
280 | * blocks - le32 at 4 | |
281 | * logblksize - le32 at 24 | |
282 | */ | |
283 | unsigned char sb[1024]; | |
284 | time_t mtime; | |
285 | int size, bsize; | |
286 | if (lseek(fd, 1024,0)!= 1024) | |
287 | return 0; | |
288 | if (read(fd, sb, 1024)!= 1024) | |
289 | return 0; | |
290 | if (sb[56] != 0x53 || sb[57] != 0xef) | |
291 | return 0; | |
292 | ||
293 | mtime = sb[44]|(sb[45]|(sb[46]|sb[47]<<8)<<8)<<8; | |
294 | bsize = sb[24]|(sb[25]|(sb[26]|sb[27]<<8)<<8)<<8; | |
295 | size = sb[4]|(sb[5]|(sb[6]|sb[7]<<8)<<8)<<8; | |
296 | fprintf(stderr, Name ": %s appears to contain an ext2fs file system\n", | |
297 | name); | |
298 | fprintf(stderr," size=%dK mtime=%s", | |
299 | size*(1<<bsize), ctime(&mtime)); | |
300 | return 1; | |
301 | } | |
302 | ||
303 | int check_reiser(int fd, char *name) | |
304 | { | |
305 | /* | |
306 | * superblock is at 64K | |
307 | * size is 1024; | |
308 | * Magic string "ReIsErFs" or "ReIsEr2Fs" at 52 | |
309 | * | |
310 | */ | |
311 | unsigned char sb[1024]; | |
881990a2 | 312 | unsigned long size; |
682c7051 NB |
313 | if (lseek(fd, 64*1024, 0) != 64*1024) |
314 | return 0; | |
315 | if (read(fd, sb, 1024) != 1024) | |
316 | return 0; | |
a46f4061 NB |
317 | if (strncmp((char*)sb+52, "ReIsErFs",8)!=0 && |
318 | strncmp((char*)sb+52, "ReIsEr2Fs",9)!=0) | |
682c7051 NB |
319 | return 0; |
320 | fprintf(stderr, Name ": %s appears to contain a reiserfs file system\n",name); | |
321 | size = sb[0]|(sb[1]|(sb[2]|sb[3]<<8)<<8)<<8; | |
881990a2 | 322 | fprintf(stderr, " size = %luK\n", size*4); |
aba69144 | 323 | |
682c7051 NB |
324 | return 1; |
325 | } | |
326 | ||
327 | int check_raid(int fd, char *name) | |
328 | { | |
4b1ac34b | 329 | struct mdinfo info; |
682c7051 | 330 | time_t crtime; |
d078d77c | 331 | char *level; |
82d9eba6 | 332 | struct supertype *st = guess_super(fd); |
f9ce90ba | 333 | |
82d9eba6 | 334 | if (!st) return 0; |
3da92f27 | 335 | st->ss->load_super(st, fd, name); |
82d9eba6 NB |
336 | /* Looks like a raid array .. */ |
337 | fprintf(stderr, Name ": %s appears to be part of a raid array:\n", | |
338 | name); | |
3da92f27 NB |
339 | st->ss->getinfo_super(st, &info); |
340 | st->ss->free_super(st); | |
82d9eba6 | 341 | crtime = info.array.ctime; |
d078d77c NB |
342 | level = map_num(pers, info.array.level); |
343 | if (!level) level = "-unknown-"; | |
344 | fprintf(stderr, " level=%s devices=%d ctime=%s", | |
345 | level, info.array.raid_disks, ctime(&crtime)); | |
82d9eba6 | 346 | return 1; |
682c7051 NB |
347 | } |
348 | ||
682c7051 NB |
349 | int ask(char *mesg) |
350 | { | |
351 | char *add = ""; | |
352 | int i; | |
353 | for (i=0; i<5; i++) { | |
354 | char buf[100]; | |
355 | fprintf(stderr, "%s%s", mesg, add); | |
356 | fflush(stderr); | |
357 | if (fgets(buf, 100, stdin)==NULL) | |
358 | return 0; | |
359 | if (buf[0]=='y' || buf[0]=='Y') | |
360 | return 1; | |
361 | if (buf[0]=='n' || buf[0]=='N') | |
362 | return 0; | |
363 | add = "(y/n) "; | |
364 | } | |
365 | fprintf(stderr, Name ": assuming 'no'\n"); | |
366 | return 0; | |
367 | } | |
435d4ebb | 368 | #endif /* MDASSEMBLE */ |
682c7051 NB |
369 | |
370 | char *map_num(mapping_t *map, int num) | |
371 | { | |
372 | while (map->name) { | |
373 | if (map->num == num) | |
374 | return map->name; | |
375 | map++; | |
376 | } | |
377 | return NULL; | |
378 | } | |
379 | ||
380 | int map_name(mapping_t *map, char *name) | |
381 | { | |
382 | while (map->name) { | |
383 | if (strcmp(map->name, name)==0) | |
384 | return map->num; | |
385 | map++; | |
386 | } | |
98c6faba | 387 | return UnSet; |
682c7051 | 388 | } |
82b27616 | 389 | |
e5329c37 | 390 | |
8d80900b | 391 | int is_standard(char *dev, int *nump) |
e5329c37 NB |
392 | { |
393 | /* tests if dev is a "standard" md dev name. | |
394 | * i.e if the last component is "/dNN" or "/mdNN", | |
aba69144 | 395 | * where NN is a string of digits |
598f0d58 NB |
396 | * Returns 1 if a partitionable standard, |
397 | * -1 if non-partitonable, | |
398 | * 0 if not a standard name. | |
e5329c37 | 399 | */ |
8d80900b NB |
400 | char *d = strrchr(dev, '/'); |
401 | int type=0; | |
402 | int num; | |
403 | if (!d) | |
e5329c37 | 404 | return 0; |
8d80900b NB |
405 | if (strncmp(d, "/d",2)==0) |
406 | d += 2, type=1; /* /dev/md/dN{pM} */ | |
407 | else if (strncmp(d, "/md_d", 5)==0) | |
408 | d += 5, type=1; /* /dev/md_dNpM */ | |
409 | else if (strncmp(d, "/md", 3)==0) | |
410 | d += 3, type=-1; /* /dev/mdN */ | |
411 | else if (d-dev > 3 && strncmp(d-2, "md/", 3)==0) | |
5a6d1148 | 412 | d += 1, type=-1; /* /dev/md/N */ |
e5329c37 NB |
413 | else |
414 | return 0; | |
8d80900b | 415 | if (!*d) |
e5329c37 | 416 | return 0; |
8d80900b NB |
417 | num = atoi(d); |
418 | while (isdigit(*d)) | |
419 | d++; | |
420 | if (*d) | |
e5329c37 | 421 | return 0; |
8d80900b NB |
422 | if (nump) *nump = num; |
423 | ||
424 | return type; | |
e5329c37 NB |
425 | } |
426 | ||
427 | ||
82b27616 NB |
428 | /* |
429 | * convert a major/minor pair for a block device into a name in /dev, if possible. | |
430 | * On the first call, walk /dev collecting name. | |
431 | * Put them in a simple linked listfor now. | |
432 | */ | |
433 | struct devmap { | |
434 | int major, minor; | |
435 | char *name; | |
436 | struct devmap *next; | |
437 | } *devlist = NULL; | |
438 | int devlist_ready = 0; | |
439 | ||
82b27616 NB |
440 | int add_dev(const char *name, const struct stat *stb, int flag, struct FTW *s) |
441 | { | |
bed256c2 NB |
442 | struct stat st; |
443 | if (S_ISLNK(stb->st_mode)) { | |
444 | stat(name, &st); | |
445 | stb = &st; | |
82b27616 | 446 | } |
bed256c2 NB |
447 | |
448 | if ((stb->st_mode&S_IFMT)== S_IFBLK) { | |
449 | char *n = strdup(name); | |
450 | struct devmap *dm = malloc(sizeof(*dm)); | |
451 | if (strncmp(n, "/dev/./", 7)==0) | |
452 | strcpy(n+4, name+6); | |
453 | if (dm) { | |
454 | dm->major = major(stb->st_rdev); | |
455 | dm->minor = minor(stb->st_rdev); | |
456 | dm->name = n; | |
457 | dm->next = devlist; | |
458 | devlist = dm; | |
459 | } | |
460 | } | |
461 | return 0; | |
82b27616 NB |
462 | } |
463 | ||
45e878bb NB |
464 | #ifndef HAVE_NFTW |
465 | #ifdef HAVE_FTW | |
466 | int add_dev_1(const char *name, const struct stat *stb, int flag) | |
467 | { | |
468 | return add_dev(name, stb, flag, NULL); | |
469 | } | |
470 | int nftw(const char *path, int (*han)(const char *name, const struct stat *stb, int flag, struct FTW *s), int nopenfd, int flags) | |
471 | { | |
472 | return ftw(path, add_dev_1, nopenfd); | |
473 | } | |
474 | #else | |
45e878bb NB |
475 | int nftw(const char *path, int (*han)(const char *name, const struct stat *stb, int flag, struct FTW *s), int nopenfd, int flags) |
476 | { | |
477 | return 0; | |
478 | } | |
479 | #endif /* HAVE_FTW */ | |
480 | #endif /* HAVE_NFTW */ | |
481 | ||
dd0781e5 NB |
482 | /* |
483 | * Find a block device with the right major/minor number. | |
b79713f8 NB |
484 | * If we find multiple names, choose the shortest. |
485 | * If we find a non-standard name, it is probably there | |
486 | * deliberately so prefer it over a standard name. | |
487 | * This applies only to names for MD devices. | |
dd0781e5 | 488 | */ |
16c6fa80 | 489 | char *map_dev(int major, int minor, int create) |
82b27616 | 490 | { |
dd0781e5 | 491 | struct devmap *p; |
b79713f8 | 492 | char *std = NULL, *nonstd=NULL; |
e7bb5d23 | 493 | int did_check = 0; |
eed35d66 | 494 | |
e81cdd9f | 495 | if (major == 0 && minor == 0) |
eed35d66 | 496 | return NULL; |
e81cdd9f | 497 | |
e7bb5d23 | 498 | retry: |
dd0781e5 | 499 | if (!devlist_ready) { |
0a416ec3 NB |
500 | char *dev = "/dev"; |
501 | struct stat stb; | |
eed35d66 NB |
502 | while(devlist) { |
503 | struct devmap *d = devlist; | |
504 | devlist = d->next; | |
505 | free(d->name); | |
506 | free(d); | |
507 | } | |
0a416ec3 NB |
508 | if (lstat(dev, &stb)==0 && |
509 | S_ISLNK(stb.st_mode)) | |
510 | dev = "/dev/."; | |
511 | nftw(dev, add_dev, 10, FTW_PHYS); | |
dd0781e5 | 512 | devlist_ready=1; |
e7bb5d23 | 513 | did_check = 1; |
dd0781e5 | 514 | } |
82b27616 | 515 | |
dd0781e5 NB |
516 | for (p=devlist; p; p=p->next) |
517 | if (p->major == major && | |
518 | p->minor == minor) { | |
b79713f8 NB |
519 | if (is_standard(p->name, NULL)) { |
520 | if (std == NULL || | |
521 | strlen(p->name) < strlen(std)) | |
522 | std = p->name; | |
523 | } else { | |
524 | if (nonstd == NULL || | |
525 | strlen(p->name) < strlen(nonstd)) | |
526 | nonstd = p->name; | |
527 | } | |
dd0781e5 | 528 | } |
e7bb5d23 NB |
529 | if (!std && !nonstd && !did_check) { |
530 | devlist_ready = 0; | |
531 | goto retry; | |
532 | } | |
16c6fa80 NB |
533 | if (create && !std && !nonstd) { |
534 | static char buf[30]; | |
382245c3 | 535 | snprintf(buf, sizeof(buf), "%d:%d", major, minor); |
16c6fa80 NB |
536 | nonstd = buf; |
537 | } | |
538 | ||
b79713f8 | 539 | return nonstd ? nonstd : std; |
82b27616 NB |
540 | } |
541 | ||
4b1ac34b | 542 | unsigned long calc_csum(void *super, int bytes) |
82b27616 | 543 | { |
56eb10c0 | 544 | unsigned long long newcsum = 0; |
82b27616 | 545 | int i; |
4b1ac34b NB |
546 | unsigned int csum; |
547 | unsigned int *superc = (unsigned int*) super; | |
82b27616 | 548 | |
4b1ac34b | 549 | for(i=0; i<bytes/4; i++) |
82b27616 NB |
550 | newcsum+= superc[i]; |
551 | csum = (newcsum& 0xffffffff) + (newcsum>>32); | |
570c0542 | 552 | #ifdef __alpha__ |
aba69144 | 553 | /* The in-kernel checksum calculation is always 16bit on |
570c0542 NB |
554 | * the alpha, though it is 32 bit on i386... |
555 | * I wonder what it is elsewhere... (it uses and API in | |
556 | * a way that it shouldn't). | |
557 | */ | |
558 | csum = (csum & 0xffff) + (csum >> 16); | |
559 | csum = (csum & 0xffff) + (csum >> 16); | |
560 | #endif | |
82b27616 NB |
561 | return csum; |
562 | } | |
cd29a5c8 | 563 | |
435d4ebb | 564 | #ifndef MDASSEMBLE |
56eb10c0 | 565 | char *human_size(long long bytes) |
cd29a5c8 NB |
566 | { |
567 | static char buf[30]; | |
d5d3721e NB |
568 | |
569 | /* We convert bytes to either centi-M{ega,ibi}bytes or | |
570 | * centi-G{igi,ibi}bytes, with appropriate rounding, | |
571 | * and then print 1/100th of those as a decimal. | |
572 | * We allow upto 2048Megabytes before converting to | |
573 | * gigabytes, as that shows more precision and isn't | |
574 | * too large a number. | |
575 | * Terrabytes are not yet handled. | |
576 | */ | |
cd29a5c8 | 577 | |
56eb10c0 | 578 | if (bytes < 5000*1024) |
cd29a5c8 | 579 | buf[0]=0; |
d5d3721e NB |
580 | else if (bytes < 2*1024LL*1024LL*1024LL) { |
581 | long cMiB = (bytes / ( (1LL<<20) / 200LL ) +1) /2; | |
582 | long cMB = (bytes / ( 1000000LL / 200LL ) +1) /2; | |
8f23b0b3 | 583 | snprintf(buf, sizeof(buf), " (%ld.%02ld MiB %ld.%02ld MB)", |
d5d3721e NB |
584 | cMiB/100 , cMiB % 100, |
585 | cMB/100, cMB % 100); | |
586 | } else { | |
587 | long cGiB = (bytes / ( (1LL<<30) / 200LL ) +1) /2; | |
588 | long cGB = (bytes / (1000000000LL/200LL ) +1) /2; | |
8f23b0b3 | 589 | snprintf(buf, sizeof(buf), " (%ld.%02ld GiB %ld.%02ld GB)", |
d5d3721e NB |
590 | cGiB/100 , cGiB % 100, |
591 | cGB/100, cGB % 100); | |
592 | } | |
cd29a5c8 NB |
593 | return buf; |
594 | } | |
e0d19036 NB |
595 | |
596 | char *human_size_brief(long long bytes) | |
597 | { | |
598 | static char buf[30]; | |
e0d19036 NB |
599 | |
600 | if (bytes < 5000*1024) | |
8f23b0b3 | 601 | snprintf(buf, sizeof(buf), "%ld.%02ldKiB", |
bd526cee | 602 | (long)(bytes>>10), (long)(((bytes&1023)*100+512)/1024) |
e0d19036 NB |
603 | ); |
604 | else if (bytes < 2*1024LL*1024LL*1024LL) | |
8f23b0b3 | 605 | snprintf(buf, sizeof(buf), "%ld.%02ldMiB", |
e0d19036 | 606 | (long)(bytes>>20), |
bd526cee | 607 | (long)((bytes&0xfffff)+0x100000/200)/(0x100000/100) |
e0d19036 NB |
608 | ); |
609 | else | |
8f23b0b3 | 610 | snprintf(buf, sizeof(buf), "%ld.%02ldGiB", |
e0d19036 | 611 | (long)(bytes>>30), |
bd526cee | 612 | (long)(((bytes>>10)&0xfffff)+0x100000/200)/(0x100000/100) |
e0d19036 NB |
613 | ); |
614 | return buf; | |
615 | } | |
435d4ebb | 616 | #endif |
e0d19036 | 617 | |
5f8097be NB |
618 | unsigned long long calc_array_size(int level, int raid_disks, int layout, |
619 | int chunksize, unsigned long long devsize) | |
620 | { | |
621 | int data_disks = 0; | |
622 | switch (level) { | |
623 | case 0: data_disks = raid_disks; break; | |
624 | case 1: data_disks = 1; break; | |
625 | case 4: | |
626 | case 5: data_disks = raid_disks - 1; break; | |
627 | case 6: data_disks = raid_disks - 2; break; | |
628 | case 10: data_disks = raid_disks / (layout & 255) / ((layout>>8)&255); | |
629 | break; | |
630 | } | |
631 | devsize &= ~(unsigned long long)((chunksize>>9)-1); | |
632 | return data_disks * devsize; | |
633 | } | |
634 | ||
435d4ebb | 635 | #if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) |
dd0781e5 | 636 | int get_mdp_major(void) |
98c6faba | 637 | { |
dd0781e5 NB |
638 | static int mdp_major = -1; |
639 | FILE *fl; | |
98c6faba NB |
640 | char *w; |
641 | int have_block = 0; | |
642 | int have_devices = 0; | |
643 | int last_num = -1; | |
dd0781e5 NB |
644 | |
645 | if (mdp_major != -1) | |
646 | return mdp_major; | |
647 | fl = fopen("/proc/devices", "r"); | |
98c6faba | 648 | if (!fl) |
dd0781e5 | 649 | return -1; |
98c6faba NB |
650 | while ((w = conf_word(fl, 1))) { |
651 | if (have_block && strcmp(w, "devices:")==0) | |
652 | have_devices = 1; | |
653 | have_block = (strcmp(w, "Block")==0); | |
654 | if (isdigit(w[0])) | |
655 | last_num = atoi(w); | |
656 | if (have_devices && strcmp(w, "mdp")==0) | |
657 | mdp_major = last_num; | |
658 | free(w); | |
659 | } | |
660 | fclose(fl); | |
dd0781e5 | 661 | return mdp_major; |
98c6faba NB |
662 | } |
663 | ||
664 | ||
e0d19036 | 665 | |
e0d19036 NB |
666 | char *get_md_name(int dev) |
667 | { | |
668 | /* find /dev/md%d or /dev/md/%d or make a device /dev/.tmp.md%d */ | |
98c6faba | 669 | /* if dev < 0, want /dev/md/d%d or find mdp in /proc/devices ... */ |
e0d19036 NB |
670 | static char devname[50]; |
671 | struct stat stb; | |
98c6faba | 672 | dev_t rdev; |
dd0781e5 | 673 | char *dn; |
98c6faba NB |
674 | |
675 | if (dev < 0) { | |
dd0781e5 NB |
676 | int mdp = get_mdp_major(); |
677 | if (mdp < 0) return NULL; | |
0df46c2a | 678 | rdev = makedev(mdp, (-1-dev)<<6); |
8f23b0b3 | 679 | snprintf(devname, sizeof(devname), "/dev/md/d%d", -1-dev); |
98c6faba NB |
680 | if (stat(devname, &stb) == 0 |
681 | && (S_IFMT&stb.st_mode) == S_IFBLK | |
682 | && (stb.st_rdev == rdev)) | |
683 | return devname; | |
684 | } else { | |
0df46c2a | 685 | rdev = makedev(MD_MAJOR, dev); |
8f23b0b3 | 686 | snprintf(devname, sizeof(devname), "/dev/md%d", dev); |
98c6faba NB |
687 | if (stat(devname, &stb) == 0 |
688 | && (S_IFMT&stb.st_mode) == S_IFBLK | |
689 | && (stb.st_rdev == rdev)) | |
690 | return devname; | |
691 | ||
8f23b0b3 | 692 | snprintf(devname, sizeof(devname), "/dev/md/%d", dev); |
98c6faba NB |
693 | if (stat(devname, &stb) == 0 |
694 | && (S_IFMT&stb.st_mode) == S_IFBLK | |
695 | && (stb.st_rdev == rdev)) | |
696 | return devname; | |
697 | } | |
16c6fa80 | 698 | dn = map_dev(major(rdev), minor(rdev), 0); |
dd0781e5 NB |
699 | if (dn) |
700 | return dn; | |
8f23b0b3 | 701 | snprintf(devname, sizeof(devname), "/dev/.tmp.md%d", dev); |
e0d19036 | 702 | if (mknod(devname, S_IFBLK | 0600, rdev) == -1) |
dd0781e5 NB |
703 | if (errno != EEXIST) |
704 | return NULL; | |
e0d19036 NB |
705 | |
706 | if (stat(devname, &stb) == 0 | |
707 | && (S_IFMT&stb.st_mode) == S_IFBLK | |
708 | && (stb.st_rdev == rdev)) | |
709 | return devname; | |
710 | unlink(devname); | |
711 | return NULL; | |
712 | } | |
713 | ||
714 | void put_md_name(char *name) | |
715 | { | |
716 | if (strncmp(name, "/dev/.tmp.md", 12)==0) | |
717 | unlink(name); | |
718 | } | |
ea24acd0 | 719 | |
ea24acd0 NB |
720 | int find_free_devnum(int use_partitions) |
721 | { | |
722 | int devnum; | |
723 | for (devnum = 127; devnum != 128; | |
724 | devnum = devnum ? devnum-1 : (1<<22)-1) { | |
725 | char *dn; | |
726 | int _devnum; | |
727 | ||
728 | _devnum = use_partitions ? (-1-devnum) : devnum; | |
729 | if (mddev_busy(_devnum)) | |
730 | continue; | |
731 | /* make sure it is new to /dev too, at least as a | |
732 | * non-standard */ | |
733 | dn = map_dev(dev2major(_devnum), dev2minor(_devnum), 0); | |
734 | if (dn && ! is_standard(dn, NULL)) | |
735 | continue; | |
736 | break; | |
737 | } | |
738 | if (devnum == 128) | |
739 | return NoMdDev; | |
740 | return use_partitions ? (-1-devnum) : devnum; | |
741 | } | |
435d4ebb | 742 | #endif /* !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) */ |
f9ce90ba | 743 | |
8b0dabea NB |
744 | int dev_open(char *dev, int flags) |
745 | { | |
746 | /* like 'open', but if 'dev' matches %d:%d, create a temp | |
747 | * block device and open that | |
748 | */ | |
749 | char *e; | |
750 | int fd = -1; | |
751 | char devname[32]; | |
e81cdd9f | 752 | int major; |
8b0dabea | 753 | int minor; |
e81cdd9f NB |
754 | |
755 | if (!dev) return -1; | |
756 | ||
757 | major = strtoul(dev, &e, 0); | |
8b0dabea NB |
758 | if (e > dev && *e == ':' && e[1] && |
759 | (minor = strtoul(e+1, &e, 0)) >= 0 && | |
760 | *e == 0) { | |
8c210183 NB |
761 | snprintf(devname, sizeof(devname), "/dev/.tmp.md.%d:%d:%d", |
762 | (int)getpid(), major, minor); | |
8b0dabea NB |
763 | if (mknod(devname, S_IFBLK|0600, makedev(major, minor))==0) { |
764 | fd = open(devname, flags); | |
765 | unlink(devname); | |
766 | } | |
767 | } else | |
768 | fd = open(dev, flags); | |
769 | return fd; | |
770 | } | |
f9ce90ba | 771 | |
a931db9e NB |
772 | int open_dev_excl(int devnum) |
773 | { | |
774 | char buf[20]; | |
775 | int i; | |
776 | ||
777 | sprintf(buf, "%d:%d", dev2major(devnum), dev2minor(devnum)); | |
778 | for (i=0 ; i<25 ; i++) { | |
779 | int fd = dev_open(buf, O_RDWR|O_EXCL); | |
780 | if (fd >= 0) | |
781 | return fd; | |
782 | if (errno != EBUSY) | |
783 | return fd; | |
784 | usleep(200000); | |
785 | } | |
786 | return -1; | |
787 | } | |
788 | ||
cdddbdbc | 789 | struct superswitch *superlist[] = { &super0, &super1, &super_ddf, &super_imsm, NULL }; |
f9ce90ba | 790 | |
ea24acd0 | 791 | #if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) |
f7dd881f | 792 | |
1686dc25 | 793 | struct supertype *super_by_fd(int fd) |
f9ce90ba | 794 | { |
1686dc25 NB |
795 | mdu_array_info_t array; |
796 | int vers; | |
797 | int minor; | |
798 | struct supertype *st = NULL; | |
7e0f6979 | 799 | struct mdinfo *sra; |
142cb9e1 | 800 | char *verstr; |
1686dc25 NB |
801 | char version[20]; |
802 | int i; | |
f7e7067b | 803 | char *subarray = NULL; |
1686dc25 NB |
804 | |
805 | sra = sysfs_read(fd, 0, GET_VERSION); | |
806 | ||
807 | if (sra) { | |
7e0f6979 NB |
808 | vers = sra->array.major_version; |
809 | minor = sra->array.minor_version; | |
142cb9e1 | 810 | verstr = sra->text_version; |
1686dc25 NB |
811 | } else { |
812 | if (ioctl(fd, GET_ARRAY_INFO, &array)) | |
813 | array.major_version = array.minor_version = 0; | |
814 | vers = array.major_version; | |
815 | minor = array.minor_version; | |
142cb9e1 | 816 | verstr = ""; |
6fbba4c9 | 817 | } |
82d9eba6 | 818 | |
1686dc25 NB |
819 | if (vers != -1) { |
820 | sprintf(version, "%d.%d", vers, minor); | |
821 | verstr = version; | |
6fbba4c9 | 822 | } |
f7e7067b NB |
823 | if (minor == -2 && verstr[0] == '/') { |
824 | char *dev = verstr+1; | |
825 | subarray = strchr(dev, '/'); | |
826 | int devnum; | |
827 | if (subarray) | |
828 | *subarray++ = '\0'; | |
829 | if (strncmp(dev, "md_d", 4) == 0) | |
830 | devnum = -1-atoi(dev+4); | |
831 | else | |
832 | devnum = atoi(dev+2); | |
833 | subarray = strdup(subarray); | |
834 | if (sra) | |
835 | sysfs_free(sra); | |
836 | sra = sysfs_read(-1, devnum, GET_VERSION); | |
837 | verstr = sra->text_version ? : "-no-metadata-"; | |
838 | } | |
839 | ||
840 | for (i = 0; st == NULL && superlist[i] ; i++) | |
841 | st = superlist[i]->match_metadata_desc(verstr); | |
1686dc25 NB |
842 | |
843 | if (sra) | |
844 | sysfs_free(sra); | |
f7e7067b | 845 | if (st) { |
3b0896f8 | 846 | st->sb = NULL; |
f7e7067b NB |
847 | if (subarray) { |
848 | strncpy(st->subarray, subarray, 32); | |
849 | st->subarray[31] = 0; | |
850 | free(subarray); | |
851 | } else | |
852 | st->subarray[0] = 0; | |
853 | } | |
82d9eba6 | 854 | return st; |
f9ce90ba | 855 | } |
ea24acd0 NB |
856 | #endif /* !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) */ |
857 | ||
f9ce90ba | 858 | |
159c3a1a | 859 | struct supertype *dup_super(struct supertype *orig) |
3da92f27 | 860 | { |
159c3a1a | 861 | struct supertype *st; |
1686dc25 | 862 | |
d2ca6449 NB |
863 | if (!orig) |
864 | return orig; | |
159c3a1a | 865 | st = malloc(sizeof(*st)); |
3da92f27 NB |
866 | if (!st) |
867 | return st; | |
ef609477 | 868 | memset(st, 0, sizeof(*st)); |
159c3a1a NB |
869 | st->ss = orig->ss; |
870 | st->max_devs = orig->max_devs; | |
871 | st->minor_version = orig->minor_version; | |
f7e7067b | 872 | strcpy(st->subarray, orig->subarray); |
159c3a1a NB |
873 | st->sb = NULL; |
874 | st->info = NULL; | |
875 | return st; | |
3da92f27 NB |
876 | } |
877 | ||
82d9eba6 | 878 | struct supertype *guess_super(int fd) |
f9ce90ba NB |
879 | { |
880 | /* try each load_super to find the best match, | |
881 | * and return the best superswitch | |
882 | */ | |
82d9eba6 NB |
883 | struct superswitch *ss; |
884 | struct supertype *st; | |
570c0542 NB |
885 | unsigned long besttime = 0; |
886 | int bestsuper = -1; | |
f9ce90ba NB |
887 | int i; |
888 | ||
82d9eba6 | 889 | st = malloc(sizeof(*st)); |
f9ce90ba NB |
890 | for (i=0 ; superlist[i]; i++) { |
891 | int rv; | |
892 | ss = superlist[i]; | |
ef609477 | 893 | memset(st, 0, sizeof(*st)); |
3da92f27 | 894 | rv = ss->load_super(st, fd, NULL); |
570c0542 NB |
895 | if (rv == 0) { |
896 | struct mdinfo info; | |
3da92f27 | 897 | st->ss->getinfo_super(st, &info); |
570c0542 NB |
898 | if (bestsuper == -1 || |
899 | besttime < info.array.ctime) { | |
900 | bestsuper = i; | |
901 | besttime = info.array.ctime; | |
570c0542 | 902 | } |
3da92f27 | 903 | ss->free_super(st); |
570c0542 NB |
904 | } |
905 | } | |
906 | if (bestsuper != -1) { | |
907 | int rv; | |
ef609477 | 908 | memset(st, 0, sizeof(*st)); |
3da92f27 | 909 | rv = superlist[bestsuper]->load_super(st, fd, NULL); |
f9ce90ba | 910 | if (rv == 0) { |
5e747af2 | 911 | superlist[bestsuper]->free_super(st); |
82d9eba6 | 912 | return st; |
f9ce90ba NB |
913 | } |
914 | } | |
570c0542 | 915 | free(st); |
f9ce90ba NB |
916 | return NULL; |
917 | } | |
fe6729fa | 918 | |
beae1dfe NB |
919 | /* Return size of device in bytes */ |
920 | int get_dev_size(int fd, char *dname, unsigned long long *sizep) | |
921 | { | |
922 | unsigned long long ldsize; | |
c2c9bb6f NB |
923 | struct stat st; |
924 | ||
925 | if (fstat(fd, &st) != -1 && S_ISREG(st.st_mode)) | |
926 | ldsize = (unsigned long long)st.st_size; | |
927 | else | |
beae1dfe NB |
928 | #ifdef BLKGETSIZE64 |
929 | if (ioctl(fd, BLKGETSIZE64, &ldsize) != 0) | |
930 | #endif | |
931 | { | |
932 | unsigned long dsize; | |
933 | if (ioctl(fd, BLKGETSIZE, &dsize) == 0) { | |
934 | ldsize = dsize; | |
935 | ldsize <<= 9; | |
936 | } else { | |
937 | if (dname) | |
938 | fprintf(stderr, Name ": Cannot get size of %s: %s\b", | |
939 | dname, strerror(errno)); | |
940 | return 0; | |
941 | } | |
942 | } | |
943 | *sizep = ldsize; | |
944 | return 1; | |
945 | } | |
8fac0577 | 946 | |
8382f19b NB |
947 | void get_one_disk(int mdfd, mdu_array_info_t *ainf, mdu_disk_info_t *disk) |
948 | { | |
949 | int d; | |
950 | ioctl(mdfd, GET_ARRAY_INFO, ainf); | |
951 | for (d = 0 ; d < ainf->raid_disks + ainf->nr_disks ; d++) | |
952 | if (ioctl(mdfd, GET_DISK_INFO, disk) == 0) | |
953 | return; | |
954 | } | |
63152c1b | 955 | |
a322f70c DW |
956 | int open_container(int fd) |
957 | { | |
958 | /* 'fd' is a block device. Find out if it is in use | |
959 | * by a container, and return an open fd on that container. | |
960 | */ | |
961 | char path[256]; | |
962 | char *e; | |
963 | DIR *dir; | |
964 | struct dirent *de; | |
965 | int dfd, n; | |
966 | char buf[200]; | |
967 | int major, minor; | |
968 | struct stat st; | |
969 | ||
970 | if (fstat(fd, &st) != 0) | |
971 | return -1; | |
972 | sprintf(path, "/sys/dev/block/%d:%d/holders", | |
973 | (int)major(st.st_rdev), (int)minor(st.st_rdev)); | |
974 | e = path + strlen(path); | |
975 | ||
976 | dir = opendir(path); | |
977 | if (!dir) | |
978 | return -1; | |
979 | while ((de = readdir(dir))) { | |
980 | if (de->d_ino == 0) | |
981 | continue; | |
982 | if (de->d_name[0] == '.') | |
983 | continue; | |
984 | sprintf(e, "/%s/dev", de->d_name); | |
985 | dfd = open(path, O_RDONLY); | |
986 | if (dfd < 0) | |
987 | continue; | |
988 | n = read(dfd, buf, sizeof(buf)); | |
989 | close(dfd); | |
990 | if (n <= 0 || n >= sizeof(buf)) | |
991 | continue; | |
992 | buf[n] = 0; | |
993 | if (sscanf(buf, "%d:%d", &major, &minor) != 2) | |
994 | continue; | |
995 | sprintf(buf, "%d:%d", major, minor); | |
996 | dfd = dev_open(buf, O_RDONLY); | |
997 | if (dfd >= 0) { | |
998 | closedir(dir); | |
999 | return dfd; | |
1000 | } | |
1001 | } | |
355726fa | 1002 | closedir(dir); |
a322f70c DW |
1003 | return -1; |
1004 | } | |
1005 | ||
2f6079dc NB |
1006 | char *devnum2devname(int num) |
1007 | { | |
1008 | char name[100]; | |
1009 | if (num > 0) | |
1010 | sprintf(name, "md%d", num); | |
1011 | else | |
1012 | sprintf(name, "md_d%d", -1-num); | |
1013 | return strdup(name); | |
1014 | } | |
1015 | ||
1016 | int fd2devnum(int fd) | |
1017 | { | |
1018 | struct stat stb; | |
1019 | if (fstat(fd, &stb) == 0 && | |
1020 | (S_IFMT&stb.st_mode)==S_IFBLK) { | |
1021 | if (major(stb.st_rdev) == MD_MAJOR) | |
1022 | return minor(stb.st_rdev); | |
1023 | else | |
1024 | return -1- (minor(stb.st_rdev)>>6); | |
1025 | } | |
1026 | return -1; | |
1027 | } | |
1028 | ||
a931db9e NB |
1029 | int mdmon_running(int devnum) |
1030 | { | |
1031 | char path[100]; | |
1032 | char pid[10]; | |
1033 | int fd; | |
1034 | int n; | |
1035 | sprintf(path, "/var/run/mdadm/%s.pid", devnum2devname(devnum)); | |
1036 | fd = open(path, O_RDONLY, 0); | |
1037 | ||
1038 | if (fd < 0) | |
1039 | return 0; | |
1040 | n = read(fd, pid, 9); | |
1041 | close(fd); | |
1042 | if (n <= 0) | |
1043 | return 0; | |
1044 | if (kill(atoi(pid), 0) == 0) | |
1045 | return 1; | |
1046 | return 0; | |
1047 | } | |
1048 | ||
1049 | int signal_mdmon(int devnum) | |
1050 | { | |
1051 | char path[100]; | |
1052 | char pid[10]; | |
1053 | int fd; | |
1054 | int n; | |
1055 | sprintf(path, "/var/run/mdadm/%s.pid", devnum2devname(devnum)); | |
1056 | fd = open(path, O_RDONLY, 0); | |
1057 | ||
1058 | if (fd < 0) | |
1059 | return 0; | |
1060 | n = read(fd, pid, 9); | |
1061 | close(fd); | |
1062 | if (n <= 0) | |
1063 | return 0; | |
1064 | if (kill(atoi(pid), SIGUSR1) == 0) | |
1065 | return 1; | |
1066 | return 0; | |
1067 | } | |
1068 | ||
1069 | ||
edd8d13c NB |
1070 | int flush_metadata_updates(struct supertype *st) |
1071 | { | |
1072 | int sfd; | |
1073 | if (!st->updates) { | |
1074 | st->update_tail = NULL; | |
1075 | return -1; | |
1076 | } | |
1077 | ||
1078 | sfd = connect_monitor(devnum2devname(st->container_dev)); | |
1079 | if (sfd < 0) | |
1080 | return -1; | |
1081 | ||
1082 | while (st->updates) { | |
1083 | struct metadata_update *mu = st->updates; | |
1084 | st->updates = mu->next; | |
1085 | ||
1086 | send_message(sfd, mu, 0); | |
1087 | wait_reply(sfd, 0); | |
1088 | free(mu->buf); | |
1089 | free(mu); | |
1090 | } | |
1091 | ack(sfd, 0); | |
1092 | wait_reply(sfd, 0); | |
1093 | close(sfd); | |
1094 | st->update_tail = NULL; | |
1095 | return 0; | |
1096 | } | |
1097 | ||
1098 | void append_metadata_update(struct supertype *st, void *buf, int len) | |
1099 | { | |
1100 | ||
1101 | struct metadata_update *mu = malloc(sizeof(*mu)); | |
1102 | ||
1103 | mu->buf = buf; | |
1104 | mu->len = len; | |
1105 | mu->space = NULL; | |
1106 | mu->next = NULL; | |
1107 | *st->update_tail = mu; | |
1108 | st->update_tail = &mu->next; | |
1109 | } | |
1110 | ||
a931db9e | 1111 | |
fe6729fa NB |
1112 | #ifdef __TINYC__ |
1113 | /* tinyc doesn't optimize this check in ioctl.h out ... */ | |
1114 | unsigned int __invalid_size_argument_for_IOC = 0; | |
1115 | #endif | |
1116 |