restripe: add support for new layouts including DDF
[thirdparty/mdadm.git] / util.c
CommitLineData
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>
9fe32043 34#include <sys/wait.h>
edd8d13c 35#include <sys/un.h>
98c6faba 36#include <ctype.h>
a322f70c 37#include <dirent.h>
a931db9e 38#include <signal.h>
0a816ef9
NB
39
40/*
41 * following taken from linux/blkpg.h because they aren't
42 * anywhere else and it isn't safe to #include linux/ * stuff.
43 */
44
45#define BLKPG _IO(0x12,105)
46
47/* The argument structure */
48struct blkpg_ioctl_arg {
49 int op;
50 int flags;
51 int datalen;
52 void *data;
53};
54
55/* The subfunctions (for the op field) */
56#define BLKPG_ADD_PARTITION 1
57#define BLKPG_DEL_PARTITION 2
58
59/* Sizes of name fields. Unused at present. */
60#define BLKPG_DEVNAMELTH 64
61#define BLKPG_VOLNAMELTH 64
62
63/* The data structure for ADD_PARTITION and DEL_PARTITION */
64struct blkpg_partition {
65 long long start; /* starting offset in bytes */
66 long long length; /* length in bytes */
67 int pno; /* partition number */
68 char devname[BLKPG_DEVNAMELTH]; /* partition name, like sda5 or c0d1p2,
69 to be used in kernel messages */
70 char volname[BLKPG_VOLNAMELTH]; /* volume label */
71};
64c4757e
NB
72
73/*
74 * Parse a 128 bit uuid in 4 integers
75 * format is 32 hexx nibbles with options :.<space> separator
76 * If not exactly 32 hex digits are found, return 0
77 * else return 1
78 */
79int parse_uuid(char *str, int uuid[4])
80{
aba69144
NB
81 int hit = 0; /* number of Hex digIT */
82 int i;
83 char c;
84 for (i=0; i<4; i++) uuid[i]=0;
85
86 while ((c= *str++)) {
87 int n;
88 if (c>='0' && c<='9')
89 n = c-'0';
90 else if (c>='a' && c <= 'f')
91 n = 10 + c - 'a';
92 else if (c>='A' && c <= 'F')
93 n = 10 + c - 'A';
94 else if (strchr(":. -", c))
95 continue;
96 else return 0;
97
98 if (hit<32) {
99 uuid[hit/8] <<= 4;
100 uuid[hit/8] += n;
101 }
102 hit++;
82b27616 103 }
aba69144
NB
104 if (hit == 32)
105 return 1;
106 return 0;
64c4757e
NB
107}
108
109
110/*
111 * Get the md version number.
112 * We use the RAID_VERSION ioctl if it is supported
113 * If not, but we have a block device with major '9', we assume
114 * 0.36.0
115 *
116 * Return version number as 24 but number - assume version parts
117 * always < 255
118 */
119
120int md_get_version(int fd)
121{
122 struct stat stb;
123 mdu_version_t vers;
124
125 if (fstat(fd, &stb)<0)
126 return -1;
127 if ((S_IFMT&stb.st_mode) != S_IFBLK)
128 return -1;
129
130 if (ioctl(fd, RAID_VERSION, &vers) == 0)
682c7051 131 return (vers.major*10000) + (vers.minor*100) + vers.patchlevel;
5787fa49
NB
132 if (errno == EACCES)
133 return -1;
0df46c2a 134 if (major(stb.st_rdev) == MD_MAJOR)
682c7051 135 return (3600);
64c4757e
NB
136 return -1;
137}
138
64c4757e
NB
139int get_linux_version()
140{
141 struct utsname name;
98c6faba 142 char *cp;
64c4757e
NB
143 int a,b,c;
144 if (uname(&name) <0)
145 return -1;
146
98c6faba
NB
147 cp = name.release;
148 a = strtoul(cp, &cp, 10);
149 if (*cp != '.') return -1;
150 b = strtoul(cp+1, &cp, 10);
151 if (*cp != '.') return -1;
152 c = strtoul(cp+1, NULL, 10);
153
682c7051 154 return (a*1000000)+(b*1000)+c;
64c4757e
NB
155}
156
0430ed48
NB
157void remove_partitions(int fd)
158{
159 /* remove partitions from this block devices.
160 * This is used for components added to an array
161 */
162#ifdef BLKPG_DEL_PARTITION
163 struct blkpg_ioctl_arg a;
164 struct blkpg_partition p;
165
166 a.op = BLKPG_DEL_PARTITION;
167 a.data = (void*)&p;
168 a.datalen = sizeof(p);
169 a.flags = 0;
170 memset(a.data, 0, a.datalen);
171 for (p.pno=0; p.pno < 16; p.pno++)
172 ioctl(fd, BLKPG, &a);
173#endif
174}
175
583315d9 176int enough(int level, int raid_disks, int layout, int clean,
265e0f17 177 char *avail, int avail_disks)
64c4757e 178{
265e0f17 179 int copies, first;
64c4757e 180 switch (level) {
265e0f17
NB
181 case 10:
182 /* This is the tricky one - we need to check
183 * which actual disks are present.
184 */
702b557b 185 copies = (layout&255)* ((layout>>8) & 255);
265e0f17
NB
186 first=0;
187 do {
188 /* there must be one of the 'copies' form 'first' */
189 int n = copies;
190 int cnt=0;
191 while (n--) {
192 if (avail[first])
193 cnt++;
194 first = (first+1) % raid_disks;
195 }
196 if (cnt == 0)
197 return 0;
198
199 } while (first != 0);
200 return 1;
e5329c37 201
e0d19036
NB
202 case -4:
203 return avail_disks>= 1;
64c4757e
NB
204 case -1:
205 case 0:
206 return avail_disks == raid_disks;
207 case 1:
208 return avail_disks >= 1;
209 case 4:
210 case 5:
583315d9
NB
211 if (clean)
212 return avail_disks >= raid_disks-1;
213 else
214 return avail_disks >= raid_disks;
98c6faba 215 case 6:
583315d9
NB
216 if (clean)
217 return avail_disks >= raid_disks-2;
218 else
219 return avail_disks >= raid_disks;
64c4757e
NB
220 default:
221 return 0;
222 }
223}
224
36ba7d48 225const int uuid_match_any[4] = { ~0, ~0, ~0, ~0 };
f277ce36 226int same_uuid(int a[4], int b[4], int swapuuid)
64c4757e 227{
36ba7d48
DW
228 if (memcmp(a, uuid_match_any, sizeof(int[4])) == 0 ||
229 memcmp(b, uuid_match_any, sizeof(int[4])) == 0)
230 return 1;
231
f277ce36
NB
232 if (swapuuid) {
233 /* parse uuids are hostendian.
234 * uuid's from some superblocks are big-ending
aba69144 235 * if there is a difference, we need to swap..
f277ce36
NB
236 */
237 unsigned char *ac = (unsigned char *)a;
238 unsigned char *bc = (unsigned char *)b;
239 int i;
240 for (i=0; i<16; i+= 4) {
241 if (ac[i+0] != bc[i+3] ||
242 ac[i+1] != bc[i+2] ||
243 ac[i+2] != bc[i+1] ||
244 ac[i+3] != bc[i+0])
245 return 0;
246 }
247 return 1;
248 } else {
249 if (a[0]==b[0] &&
250 a[1]==b[1] &&
251 a[2]==b[2] &&
252 a[3]==b[3])
253 return 1;
254 return 0;
255 }
64c4757e 256}
350f29f9
NB
257void copy_uuid(void *a, int b[4], int swapuuid)
258{
259 if (swapuuid) {
260 /* parse uuids are hostendian.
261 * uuid's from some superblocks are big-ending
262 * if there is a difference, we need to swap..
263 */
264 unsigned char *ac = (unsigned char *)a;
265 unsigned char *bc = (unsigned char *)b;
266 int i;
267 for (i=0; i<16; i+= 4) {
268 ac[i+0] = bc[i+3];
269 ac[i+1] = bc[i+2];
270 ac[i+2] = bc[i+1];
271 ac[i+3] = bc[i+0];
272 }
273 } else
274 memcpy(a, b, 16);
275}
64c4757e 276
ff54de6e 277char *fname_from_uuid(struct supertype *st, struct mdinfo *info, char *buf, char sep)
d7288ddc 278{
9968e376
DW
279 int i, j;
280 int id;
d7288ddc
N
281 char uuid[16];
282 char *c = buf;
283 strcpy(c, "UUID-");
284 c += strlen(c);
285 copy_uuid(uuid, info->uuid, st->ss->swapuuid);
9968e376
DW
286 for (i = 0; i < 4; i++) {
287 id = uuid[i];
288 if (i)
ff54de6e 289 *c++ = sep;
9968e376
DW
290 for (j = 3; j >= 0; j--) {
291 sprintf(c,"%02x", (unsigned char) uuid[j+4*i]);
292 c+= 2;
293 }
d7288ddc
N
294 }
295 return buf;
296}
297
435d4ebb 298#ifndef MDASSEMBLE
682c7051
NB
299int check_ext2(int fd, char *name)
300{
301 /*
302 * Check for an ext2fs file system.
303 * Superblock is always 1K at 1K offset
304 *
305 * s_magic is le16 at 56 == 0xEF53
306 * report mtime - le32 at 44
307 * blocks - le32 at 4
308 * logblksize - le32 at 24
309 */
310 unsigned char sb[1024];
311 time_t mtime;
312 int size, bsize;
313 if (lseek(fd, 1024,0)!= 1024)
314 return 0;
315 if (read(fd, sb, 1024)!= 1024)
316 return 0;
317 if (sb[56] != 0x53 || sb[57] != 0xef)
318 return 0;
319
320 mtime = sb[44]|(sb[45]|(sb[46]|sb[47]<<8)<<8)<<8;
321 bsize = sb[24]|(sb[25]|(sb[26]|sb[27]<<8)<<8)<<8;
322 size = sb[4]|(sb[5]|(sb[6]|sb[7]<<8)<<8)<<8;
323 fprintf(stderr, Name ": %s appears to contain an ext2fs file system\n",
324 name);
325 fprintf(stderr," size=%dK mtime=%s",
326 size*(1<<bsize), ctime(&mtime));
327 return 1;
328}
329
330int check_reiser(int fd, char *name)
331{
332 /*
333 * superblock is at 64K
334 * size is 1024;
335 * Magic string "ReIsErFs" or "ReIsEr2Fs" at 52
336 *
337 */
338 unsigned char sb[1024];
881990a2 339 unsigned long size;
682c7051
NB
340 if (lseek(fd, 64*1024, 0) != 64*1024)
341 return 0;
342 if (read(fd, sb, 1024) != 1024)
343 return 0;
a46f4061
NB
344 if (strncmp((char*)sb+52, "ReIsErFs",8)!=0 &&
345 strncmp((char*)sb+52, "ReIsEr2Fs",9)!=0)
682c7051
NB
346 return 0;
347 fprintf(stderr, Name ": %s appears to contain a reiserfs file system\n",name);
348 size = sb[0]|(sb[1]|(sb[2]|sb[3]<<8)<<8)<<8;
881990a2 349 fprintf(stderr, " size = %luK\n", size*4);
aba69144 350
682c7051
NB
351 return 1;
352}
353
354int check_raid(int fd, char *name)
355{
4b1ac34b 356 struct mdinfo info;
682c7051 357 time_t crtime;
d078d77c 358 char *level;
82d9eba6 359 struct supertype *st = guess_super(fd);
f9ce90ba 360
82d9eba6 361 if (!st) return 0;
3da92f27 362 st->ss->load_super(st, fd, name);
82d9eba6
NB
363 /* Looks like a raid array .. */
364 fprintf(stderr, Name ": %s appears to be part of a raid array:\n",
365 name);
3da92f27
NB
366 st->ss->getinfo_super(st, &info);
367 st->ss->free_super(st);
82d9eba6 368 crtime = info.array.ctime;
d078d77c
NB
369 level = map_num(pers, info.array.level);
370 if (!level) level = "-unknown-";
371 fprintf(stderr, " level=%s devices=%d ctime=%s",
372 level, info.array.raid_disks, ctime(&crtime));
82d9eba6 373 return 1;
682c7051
NB
374}
375
682c7051
NB
376int ask(char *mesg)
377{
378 char *add = "";
379 int i;
380 for (i=0; i<5; i++) {
381 char buf[100];
382 fprintf(stderr, "%s%s", mesg, add);
383 fflush(stderr);
384 if (fgets(buf, 100, stdin)==NULL)
385 return 0;
386 if (buf[0]=='y' || buf[0]=='Y')
387 return 1;
388 if (buf[0]=='n' || buf[0]=='N')
389 return 0;
390 add = "(y/n) ";
391 }
392 fprintf(stderr, Name ": assuming 'no'\n");
393 return 0;
394}
435d4ebb 395#endif /* MDASSEMBLE */
682c7051
NB
396
397char *map_num(mapping_t *map, int num)
398{
399 while (map->name) {
400 if (map->num == num)
401 return map->name;
402 map++;
403 }
404 return NULL;
405}
406
407int map_name(mapping_t *map, char *name)
408{
409 while (map->name) {
410 if (strcmp(map->name, name)==0)
411 return map->num;
412 map++;
413 }
98c6faba 414 return UnSet;
682c7051 415}
82b27616 416
e5329c37 417
8d80900b 418int is_standard(char *dev, int *nump)
e5329c37
NB
419{
420 /* tests if dev is a "standard" md dev name.
421 * i.e if the last component is "/dNN" or "/mdNN",
aba69144 422 * where NN is a string of digits
598f0d58
NB
423 * Returns 1 if a partitionable standard,
424 * -1 if non-partitonable,
425 * 0 if not a standard name.
e5329c37 426 */
8d80900b
NB
427 char *d = strrchr(dev, '/');
428 int type=0;
429 int num;
430 if (!d)
e5329c37 431 return 0;
8d80900b
NB
432 if (strncmp(d, "/d",2)==0)
433 d += 2, type=1; /* /dev/md/dN{pM} */
434 else if (strncmp(d, "/md_d", 5)==0)
2b4ca8f0 435 d += 5, type=1; /* /dev/md_dN{pM} */
8d80900b
NB
436 else if (strncmp(d, "/md", 3)==0)
437 d += 3, type=-1; /* /dev/mdN */
438 else if (d-dev > 3 && strncmp(d-2, "md/", 3)==0)
5a6d1148 439 d += 1, type=-1; /* /dev/md/N */
e5329c37
NB
440 else
441 return 0;
8d80900b 442 if (!*d)
e5329c37 443 return 0;
8d80900b
NB
444 num = atoi(d);
445 while (isdigit(*d))
446 d++;
447 if (*d)
e5329c37 448 return 0;
8d80900b
NB
449 if (nump) *nump = num;
450
451 return type;
e5329c37
NB
452}
453
454
82b27616
NB
455/*
456 * convert a major/minor pair for a block device into a name in /dev, if possible.
457 * On the first call, walk /dev collecting name.
458 * Put them in a simple linked listfor now.
459 */
460struct devmap {
461 int major, minor;
462 char *name;
463 struct devmap *next;
464} *devlist = NULL;
465int devlist_ready = 0;
466
82b27616
NB
467int add_dev(const char *name, const struct stat *stb, int flag, struct FTW *s)
468{
bed256c2 469 struct stat st;
bf68e9d9 470
bed256c2 471 if (S_ISLNK(stb->st_mode)) {
bf68e9d9
DW
472 if (stat(name, &st) != 0)
473 return 0;
bed256c2 474 stb = &st;
82b27616 475 }
bed256c2
NB
476
477 if ((stb->st_mode&S_IFMT)== S_IFBLK) {
478 char *n = strdup(name);
479 struct devmap *dm = malloc(sizeof(*dm));
480 if (strncmp(n, "/dev/./", 7)==0)
481 strcpy(n+4, name+6);
482 if (dm) {
483 dm->major = major(stb->st_rdev);
484 dm->minor = minor(stb->st_rdev);
485 dm->name = n;
486 dm->next = devlist;
487 devlist = dm;
488 }
489 }
490 return 0;
82b27616
NB
491}
492
45e878bb
NB
493#ifndef HAVE_NFTW
494#ifdef HAVE_FTW
495int add_dev_1(const char *name, const struct stat *stb, int flag)
496{
497 return add_dev(name, stb, flag, NULL);
498}
499int nftw(const char *path, int (*han)(const char *name, const struct stat *stb, int flag, struct FTW *s), int nopenfd, int flags)
500{
501 return ftw(path, add_dev_1, nopenfd);
502}
503#else
45e878bb
NB
504int nftw(const char *path, int (*han)(const char *name, const struct stat *stb, int flag, struct FTW *s), int nopenfd, int flags)
505{
506 return 0;
507}
508#endif /* HAVE_FTW */
509#endif /* HAVE_NFTW */
510
dd0781e5
NB
511/*
512 * Find a block device with the right major/minor number.
b79713f8 513 * If we find multiple names, choose the shortest.
70ef16db 514 * If we find a name in /dev/md/, we prefer that.
b79713f8 515 * This applies only to names for MD devices.
dd0781e5 516 */
16c6fa80 517char *map_dev(int major, int minor, int create)
82b27616 518{
dd0781e5 519 struct devmap *p;
70ef16db 520 char *regular = NULL, *preferred=NULL;
e7bb5d23 521 int did_check = 0;
eed35d66 522
e81cdd9f 523 if (major == 0 && minor == 0)
eed35d66 524 return NULL;
e81cdd9f 525
e7bb5d23 526 retry:
dd0781e5 527 if (!devlist_ready) {
0a416ec3
NB
528 char *dev = "/dev";
529 struct stat stb;
eed35d66
NB
530 while(devlist) {
531 struct devmap *d = devlist;
532 devlist = d->next;
533 free(d->name);
534 free(d);
535 }
0a416ec3
NB
536 if (lstat(dev, &stb)==0 &&
537 S_ISLNK(stb.st_mode))
538 dev = "/dev/.";
539 nftw(dev, add_dev, 10, FTW_PHYS);
dd0781e5 540 devlist_ready=1;
e7bb5d23 541 did_check = 1;
dd0781e5 542 }
82b27616 543
dd0781e5
NB
544 for (p=devlist; p; p=p->next)
545 if (p->major == major &&
546 p->minor == minor) {
70ef16db
N
547 if (strncmp(p->name, "/dev/md/",8) == 0) {
548 if (preferred == NULL ||
549 strlen(p->name) < strlen(preferred))
550 preferred = p->name;
b79713f8 551 } else {
70ef16db
N
552 if (regular == NULL ||
553 strlen(p->name) < strlen(regular))
554 regular = p->name;
b79713f8 555 }
dd0781e5 556 }
70ef16db 557 if (!regular && !preferred && !did_check) {
e7bb5d23
NB
558 devlist_ready = 0;
559 goto retry;
560 }
70ef16db 561 if (create && !regular && !preferred) {
16c6fa80 562 static char buf[30];
382245c3 563 snprintf(buf, sizeof(buf), "%d:%d", major, minor);
70ef16db 564 regular = buf;
16c6fa80
NB
565 }
566
70ef16db 567 return preferred ? preferred : regular;
82b27616
NB
568}
569
4b1ac34b 570unsigned long calc_csum(void *super, int bytes)
82b27616 571{
56eb10c0 572 unsigned long long newcsum = 0;
82b27616 573 int i;
4b1ac34b
NB
574 unsigned int csum;
575 unsigned int *superc = (unsigned int*) super;
82b27616 576
4b1ac34b 577 for(i=0; i<bytes/4; i++)
82b27616
NB
578 newcsum+= superc[i];
579 csum = (newcsum& 0xffffffff) + (newcsum>>32);
570c0542 580#ifdef __alpha__
aba69144 581/* The in-kernel checksum calculation is always 16bit on
570c0542
NB
582 * the alpha, though it is 32 bit on i386...
583 * I wonder what it is elsewhere... (it uses and API in
584 * a way that it shouldn't).
585 */
586 csum = (csum & 0xffff) + (csum >> 16);
587 csum = (csum & 0xffff) + (csum >> 16);
588#endif
82b27616
NB
589 return csum;
590}
cd29a5c8 591
435d4ebb 592#ifndef MDASSEMBLE
56eb10c0 593char *human_size(long long bytes)
cd29a5c8
NB
594{
595 static char buf[30];
d5d3721e
NB
596
597 /* We convert bytes to either centi-M{ega,ibi}bytes or
598 * centi-G{igi,ibi}bytes, with appropriate rounding,
599 * and then print 1/100th of those as a decimal.
600 * We allow upto 2048Megabytes before converting to
601 * gigabytes, as that shows more precision and isn't
602 * too large a number.
603 * Terrabytes are not yet handled.
604 */
cd29a5c8 605
56eb10c0 606 if (bytes < 5000*1024)
cd29a5c8 607 buf[0]=0;
d5d3721e
NB
608 else if (bytes < 2*1024LL*1024LL*1024LL) {
609 long cMiB = (bytes / ( (1LL<<20) / 200LL ) +1) /2;
610 long cMB = (bytes / ( 1000000LL / 200LL ) +1) /2;
8f23b0b3 611 snprintf(buf, sizeof(buf), " (%ld.%02ld MiB %ld.%02ld MB)",
d5d3721e
NB
612 cMiB/100 , cMiB % 100,
613 cMB/100, cMB % 100);
614 } else {
615 long cGiB = (bytes / ( (1LL<<30) / 200LL ) +1) /2;
616 long cGB = (bytes / (1000000000LL/200LL ) +1) /2;
8f23b0b3 617 snprintf(buf, sizeof(buf), " (%ld.%02ld GiB %ld.%02ld GB)",
d5d3721e
NB
618 cGiB/100 , cGiB % 100,
619 cGB/100, cGB % 100);
620 }
cd29a5c8
NB
621 return buf;
622}
e0d19036
NB
623
624char *human_size_brief(long long bytes)
625{
626 static char buf[30];
e0d19036
NB
627
628 if (bytes < 5000*1024)
8f23b0b3 629 snprintf(buf, sizeof(buf), "%ld.%02ldKiB",
bd526cee 630 (long)(bytes>>10), (long)(((bytes&1023)*100+512)/1024)
e0d19036
NB
631 );
632 else if (bytes < 2*1024LL*1024LL*1024LL)
8f23b0b3 633 snprintf(buf, sizeof(buf), "%ld.%02ldMiB",
e0d19036 634 (long)(bytes>>20),
bd526cee 635 (long)((bytes&0xfffff)+0x100000/200)/(0x100000/100)
e0d19036
NB
636 );
637 else
8f23b0b3 638 snprintf(buf, sizeof(buf), "%ld.%02ldGiB",
e0d19036 639 (long)(bytes>>30),
bd526cee 640 (long)(((bytes>>10)&0xfffff)+0x100000/200)/(0x100000/100)
e0d19036
NB
641 );
642 return buf;
643}
e4965ef8
N
644
645void print_r10_layout(int layout)
646{
647 int near = layout & 255;
648 int far = (layout >> 8) & 255;
649 int offset = (layout&0x10000);
650 char *sep = "";
651
652 if (near != 1) {
653 printf("%s near=%d", sep, near);
654 sep = ",";
655 }
656 if (far != 1)
657 printf("%s %s=%d", sep, offset?"offset":"far", far);
658 if (near*far == 1)
659 printf("NO REDUNDANCY");
660}
435d4ebb 661#endif
e0d19036 662
5f8097be
NB
663unsigned long long calc_array_size(int level, int raid_disks, int layout,
664 int chunksize, unsigned long long devsize)
665{
666 int data_disks = 0;
667 switch (level) {
668 case 0: data_disks = raid_disks; break;
669 case 1: data_disks = 1; break;
670 case 4:
671 case 5: data_disks = raid_disks - 1; break;
672 case 6: data_disks = raid_disks - 2; break;
673 case 10: data_disks = raid_disks / (layout & 255) / ((layout>>8)&255);
674 break;
675 }
676 devsize &= ~(unsigned long long)((chunksize>>9)-1);
677 return data_disks * devsize;
678}
679
dd0781e5 680int get_mdp_major(void)
98c6faba 681{
dd0781e5
NB
682static int mdp_major = -1;
683 FILE *fl;
98c6faba
NB
684 char *w;
685 int have_block = 0;
686 int have_devices = 0;
687 int last_num = -1;
dd0781e5
NB
688
689 if (mdp_major != -1)
690 return mdp_major;
691 fl = fopen("/proc/devices", "r");
98c6faba 692 if (!fl)
dd0781e5 693 return -1;
98c6faba
NB
694 while ((w = conf_word(fl, 1))) {
695 if (have_block && strcmp(w, "devices:")==0)
696 have_devices = 1;
697 have_block = (strcmp(w, "Block")==0);
698 if (isdigit(w[0]))
699 last_num = atoi(w);
700 if (have_devices && strcmp(w, "mdp")==0)
701 mdp_major = last_num;
702 free(w);
703 }
704 fclose(fl);
dd0781e5 705 return mdp_major;
98c6faba
NB
706}
707
0e600426 708#if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
e0d19036
NB
709char *get_md_name(int dev)
710{
711 /* find /dev/md%d or /dev/md/%d or make a device /dev/.tmp.md%d */
98c6faba 712 /* if dev < 0, want /dev/md/d%d or find mdp in /proc/devices ... */
e0d19036
NB
713 static char devname[50];
714 struct stat stb;
98c6faba 715 dev_t rdev;
dd0781e5 716 char *dn;
98c6faba
NB
717
718 if (dev < 0) {
dd0781e5
NB
719 int mdp = get_mdp_major();
720 if (mdp < 0) return NULL;
0df46c2a 721 rdev = makedev(mdp, (-1-dev)<<6);
8f23b0b3 722 snprintf(devname, sizeof(devname), "/dev/md/d%d", -1-dev);
98c6faba
NB
723 if (stat(devname, &stb) == 0
724 && (S_IFMT&stb.st_mode) == S_IFBLK
725 && (stb.st_rdev == rdev))
726 return devname;
727 } else {
0df46c2a 728 rdev = makedev(MD_MAJOR, dev);
8f23b0b3 729 snprintf(devname, sizeof(devname), "/dev/md%d", dev);
98c6faba
NB
730 if (stat(devname, &stb) == 0
731 && (S_IFMT&stb.st_mode) == S_IFBLK
732 && (stb.st_rdev == rdev))
733 return devname;
734
8f23b0b3 735 snprintf(devname, sizeof(devname), "/dev/md/%d", dev);
98c6faba
NB
736 if (stat(devname, &stb) == 0
737 && (S_IFMT&stb.st_mode) == S_IFBLK
738 && (stb.st_rdev == rdev))
739 return devname;
740 }
16c6fa80 741 dn = map_dev(major(rdev), minor(rdev), 0);
dd0781e5
NB
742 if (dn)
743 return dn;
8f23b0b3 744 snprintf(devname, sizeof(devname), "/dev/.tmp.md%d", dev);
e0d19036 745 if (mknod(devname, S_IFBLK | 0600, rdev) == -1)
dd0781e5
NB
746 if (errno != EEXIST)
747 return NULL;
e0d19036
NB
748
749 if (stat(devname, &stb) == 0
750 && (S_IFMT&stb.st_mode) == S_IFBLK
751 && (stb.st_rdev == rdev))
752 return devname;
753 unlink(devname);
754 return NULL;
755}
756
757void put_md_name(char *name)
758{
759 if (strncmp(name, "/dev/.tmp.md", 12)==0)
760 unlink(name);
761}
ea24acd0 762
ea24acd0
NB
763int find_free_devnum(int use_partitions)
764{
765 int devnum;
766 for (devnum = 127; devnum != 128;
a56fb7ec 767 devnum = devnum ? devnum-1 : (1<<20)-1) {
ea24acd0
NB
768 char *dn;
769 int _devnum;
770
771 _devnum = use_partitions ? (-1-devnum) : devnum;
772 if (mddev_busy(_devnum))
773 continue;
774 /* make sure it is new to /dev too, at least as a
775 * non-standard */
776 dn = map_dev(dev2major(_devnum), dev2minor(_devnum), 0);
777 if (dn && ! is_standard(dn, NULL))
778 continue;
779 break;
780 }
781 if (devnum == 128)
782 return NoMdDev;
783 return use_partitions ? (-1-devnum) : devnum;
784}
435d4ebb 785#endif /* !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) */
f9ce90ba 786
8b0dabea
NB
787int dev_open(char *dev, int flags)
788{
789 /* like 'open', but if 'dev' matches %d:%d, create a temp
790 * block device and open that
791 */
792 char *e;
793 int fd = -1;
794 char devname[32];
e81cdd9f 795 int major;
8b0dabea 796 int minor;
e81cdd9f
NB
797
798 if (!dev) return -1;
799
800 major = strtoul(dev, &e, 0);
8b0dabea
NB
801 if (e > dev && *e == ':' && e[1] &&
802 (minor = strtoul(e+1, &e, 0)) >= 0 &&
803 *e == 0) {
8c210183
NB
804 snprintf(devname, sizeof(devname), "/dev/.tmp.md.%d:%d:%d",
805 (int)getpid(), major, minor);
8b0dabea 806 if (mknod(devname, S_IFBLK|0600, makedev(major, minor))==0) {
6416d527 807 fd = open(devname, flags|O_DIRECT);
8b0dabea
NB
808 unlink(devname);
809 }
810 } else
6416d527 811 fd = open(dev, flags|O_DIRECT);
8b0dabea
NB
812 return fd;
813}
f9ce90ba 814
e8a70c89
N
815int open_dev(int devnum)
816{
817 char buf[20];
818
819 sprintf(buf, "%d:%d", dev2major(devnum), dev2minor(devnum));
820 return dev_open(buf, O_RDWR);
821}
822
a931db9e
NB
823int open_dev_excl(int devnum)
824{
825 char buf[20];
826 int i;
827
828 sprintf(buf, "%d:%d", dev2major(devnum), dev2minor(devnum));
829 for (i=0 ; i<25 ; i++) {
830 int fd = dev_open(buf, O_RDWR|O_EXCL);
831 if (fd >= 0)
832 return fd;
833 if (errno != EBUSY)
834 return fd;
835 usleep(200000);
836 }
837 return -1;
838}
839
9008ed1c
N
840int same_dev(char *one, char *two)
841{
842 struct stat st1, st2;
843 if (stat(one, &st1) != 0)
844 return 0;
845 if (stat(two, &st2) != 0)
846 return 0;
847 if ((st1.st_mode & S_IFMT) != S_IFBLK)
848 return 0;
849 if ((st2.st_mode & S_IFMT) != S_IFBLK)
850 return 0;
851 return st1.st_rdev == st2.st_rdev;
852}
853
a7c6e3fb 854void wait_for(char *dev, int fd)
a714580e
N
855{
856 int i;
a7c6e3fb
N
857 struct stat stb_want;
858
859 if (fstat(fd, &stb_want) != 0 ||
860 (stb_want.st_mode & S_IFMT) != S_IFBLK)
861 return;
a714580e
N
862
863 for (i=0 ; i<25 ; i++) {
864 struct stat stb;
a7c6e3fb
N
865 if (stat(dev, &stb) == 0 &&
866 (stb.st_mode & S_IFMT) == S_IFBLK &&
867 (stb.st_rdev == stb_want.st_rdev))
a714580e
N
868 return;
869 usleep(200000);
870 }
871}
872
cdddbdbc 873struct superswitch *superlist[] = { &super0, &super1, &super_ddf, &super_imsm, NULL };
f9ce90ba 874
ea24acd0 875#if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
f7dd881f 876
1686dc25 877struct supertype *super_by_fd(int fd)
f9ce90ba 878{
1686dc25
NB
879 mdu_array_info_t array;
880 int vers;
881 int minor;
882 struct supertype *st = NULL;
7e0f6979 883 struct mdinfo *sra;
142cb9e1 884 char *verstr;
1686dc25
NB
885 char version[20];
886 int i;
f7e7067b 887 char *subarray = NULL;
1686dc25
NB
888
889 sra = sysfs_read(fd, 0, GET_VERSION);
890
891 if (sra) {
7e0f6979
NB
892 vers = sra->array.major_version;
893 minor = sra->array.minor_version;
142cb9e1 894 verstr = sra->text_version;
1686dc25
NB
895 } else {
896 if (ioctl(fd, GET_ARRAY_INFO, &array))
897 array.major_version = array.minor_version = 0;
898 vers = array.major_version;
899 minor = array.minor_version;
142cb9e1 900 verstr = "";
6fbba4c9 901 }
82d9eba6 902
1686dc25
NB
903 if (vers != -1) {
904 sprintf(version, "%d.%d", vers, minor);
905 verstr = version;
6fbba4c9 906 }
3c558363 907 if (minor == -2 && is_subarray(verstr)) {
f7e7067b
NB
908 char *dev = verstr+1;
909 subarray = strchr(dev, '/');
910 int devnum;
911 if (subarray)
912 *subarray++ = '\0';
77472ff8 913 devnum = devname2devnum(dev);
f7e7067b
NB
914 subarray = strdup(subarray);
915 if (sra)
916 sysfs_free(sra);
917 sra = sysfs_read(-1, devnum, GET_VERSION);
603f24a0
N
918 if (sra && sra->text_version[0])
919 verstr = sra->text_version;
920 else
921 verstr = "-no-metadata-";
f7e7067b
NB
922 }
923
924 for (i = 0; st == NULL && superlist[i] ; i++)
925 st = superlist[i]->match_metadata_desc(verstr);
1686dc25
NB
926
927 if (sra)
928 sysfs_free(sra);
f7e7067b 929 if (st) {
3b0896f8 930 st->sb = NULL;
f7e7067b
NB
931 if (subarray) {
932 strncpy(st->subarray, subarray, 32);
933 st->subarray[31] = 0;
934 free(subarray);
935 } else
936 st->subarray[0] = 0;
937 }
82d9eba6 938 return st;
f9ce90ba 939}
ea24acd0
NB
940#endif /* !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) */
941
f9ce90ba 942
159c3a1a 943struct supertype *dup_super(struct supertype *orig)
3da92f27 944{
159c3a1a 945 struct supertype *st;
1686dc25 946
d2ca6449
NB
947 if (!orig)
948 return orig;
159c3a1a 949 st = malloc(sizeof(*st));
3da92f27
NB
950 if (!st)
951 return st;
ef609477 952 memset(st, 0, sizeof(*st));
159c3a1a
NB
953 st->ss = orig->ss;
954 st->max_devs = orig->max_devs;
955 st->minor_version = orig->minor_version;
f7e7067b 956 strcpy(st->subarray, orig->subarray);
159c3a1a
NB
957 st->sb = NULL;
958 st->info = NULL;
959 return st;
3da92f27
NB
960}
961
82d9eba6 962struct supertype *guess_super(int fd)
f9ce90ba
NB
963{
964 /* try each load_super to find the best match,
965 * and return the best superswitch
966 */
82d9eba6
NB
967 struct superswitch *ss;
968 struct supertype *st;
570c0542
NB
969 unsigned long besttime = 0;
970 int bestsuper = -1;
f9ce90ba
NB
971 int i;
972
82d9eba6 973 st = malloc(sizeof(*st));
f9ce90ba
NB
974 for (i=0 ; superlist[i]; i++) {
975 int rv;
976 ss = superlist[i];
ef609477 977 memset(st, 0, sizeof(*st));
3da92f27 978 rv = ss->load_super(st, fd, NULL);
570c0542
NB
979 if (rv == 0) {
980 struct mdinfo info;
3da92f27 981 st->ss->getinfo_super(st, &info);
570c0542
NB
982 if (bestsuper == -1 ||
983 besttime < info.array.ctime) {
984 bestsuper = i;
985 besttime = info.array.ctime;
570c0542 986 }
3da92f27 987 ss->free_super(st);
570c0542
NB
988 }
989 }
990 if (bestsuper != -1) {
991 int rv;
ef609477 992 memset(st, 0, sizeof(*st));
3da92f27 993 rv = superlist[bestsuper]->load_super(st, fd, NULL);
f9ce90ba 994 if (rv == 0) {
5e747af2 995 superlist[bestsuper]->free_super(st);
82d9eba6 996 return st;
f9ce90ba
NB
997 }
998 }
570c0542 999 free(st);
f9ce90ba
NB
1000 return NULL;
1001}
fe6729fa 1002
beae1dfe
NB
1003/* Return size of device in bytes */
1004int get_dev_size(int fd, char *dname, unsigned long long *sizep)
1005{
1006 unsigned long long ldsize;
c2c9bb6f
NB
1007 struct stat st;
1008
1009 if (fstat(fd, &st) != -1 && S_ISREG(st.st_mode))
1010 ldsize = (unsigned long long)st.st_size;
1011 else
beae1dfe
NB
1012#ifdef BLKGETSIZE64
1013 if (ioctl(fd, BLKGETSIZE64, &ldsize) != 0)
1014#endif
1015 {
1016 unsigned long dsize;
1017 if (ioctl(fd, BLKGETSIZE, &dsize) == 0) {
1018 ldsize = dsize;
1019 ldsize <<= 9;
1020 } else {
1021 if (dname)
1022 fprintf(stderr, Name ": Cannot get size of %s: %s\b",
1023 dname, strerror(errno));
1024 return 0;
1025 }
1026 }
1027 *sizep = ldsize;
1028 return 1;
1029}
8fac0577 1030
8382f19b
NB
1031void get_one_disk(int mdfd, mdu_array_info_t *ainf, mdu_disk_info_t *disk)
1032{
1033 int d;
1034 ioctl(mdfd, GET_ARRAY_INFO, ainf);
1035 for (d = 0 ; d < ainf->raid_disks + ainf->nr_disks ; d++)
1036 if (ioctl(mdfd, GET_DISK_INFO, disk) == 0)
1037 return;
1038}
63152c1b 1039
a322f70c
DW
1040int open_container(int fd)
1041{
1042 /* 'fd' is a block device. Find out if it is in use
1043 * by a container, and return an open fd on that container.
1044 */
1045 char path[256];
1046 char *e;
1047 DIR *dir;
1048 struct dirent *de;
1049 int dfd, n;
1050 char buf[200];
1051 int major, minor;
1052 struct stat st;
1053
1054 if (fstat(fd, &st) != 0)
1055 return -1;
1056 sprintf(path, "/sys/dev/block/%d:%d/holders",
1057 (int)major(st.st_rdev), (int)minor(st.st_rdev));
1058 e = path + strlen(path);
1059
1060 dir = opendir(path);
1061 if (!dir)
1062 return -1;
1063 while ((de = readdir(dir))) {
1064 if (de->d_ino == 0)
1065 continue;
1066 if (de->d_name[0] == '.')
1067 continue;
1068 sprintf(e, "/%s/dev", de->d_name);
1069 dfd = open(path, O_RDONLY);
1070 if (dfd < 0)
1071 continue;
1072 n = read(dfd, buf, sizeof(buf));
1073 close(dfd);
1074 if (n <= 0 || n >= sizeof(buf))
1075 continue;
1076 buf[n] = 0;
1077 if (sscanf(buf, "%d:%d", &major, &minor) != 2)
1078 continue;
1079 sprintf(buf, "%d:%d", major, minor);
1080 dfd = dev_open(buf, O_RDONLY);
1081 if (dfd >= 0) {
1082 closedir(dir);
1083 return dfd;
1084 }
1085 }
355726fa 1086 closedir(dir);
a322f70c
DW
1087 return -1;
1088}
1089
7801ac20
N
1090int add_disk(int mdfd, struct supertype *st,
1091 struct mdinfo *sra, struct mdinfo *info)
1092{
1093 /* Add a device to an array, in one of 2 ways. */
1094 int rv;
1095#ifndef MDASSEMBLE
1096 if (st->ss->external) {
462906cd
N
1097 rv = sysfs_add_disk(sra, info,
1098 info->disk.state & (1<<MD_DISK_SYNC));
7801ac20
N
1099 if (! rv) {
1100 struct mdinfo *sd2;
f35f2525
N
1101 for (sd2 = sra->devs; sd2; sd2=sd2->next)
1102 if (sd2 == info)
1103 break;
1104 if (sd2 == NULL) {
1105 sd2 = malloc(sizeof(*sd2));
1106 *sd2 = *info;
1107 sd2->next = sra->devs;
1108 sra->devs = sd2;
1109 }
7801ac20
N
1110 }
1111 } else
1112#endif
1113 rv = ioctl(mdfd, ADD_NEW_DISK, &info->disk);
1114 return rv;
1115}
1116
f35f2525
N
1117int set_array_info(int mdfd, struct supertype *st, struct mdinfo *info)
1118{
1119 /* Initialise kernel's knowledge of array.
1120 * This varies between externally managed arrays
1121 * and older kernels
1122 */
1123 int vers = md_get_version(mdfd);
1124 int rv;
1125
1126#ifndef MDASSEMBLE
1127 if (st->ss->external)
1128 rv = sysfs_set_array(info, vers);
1129 else
1130#endif
1131 if ((vers % 100) >= 1) { /* can use different versions */
1132 mdu_array_info_t inf;
1133 memset(&inf, 0, sizeof(inf));
1134 inf.major_version = info->array.major_version;
1135 inf.minor_version = info->array.minor_version;
1136 rv = ioctl(mdfd, SET_ARRAY_INFO, &inf);
1137 } else
1138 rv = ioctl(mdfd, SET_ARRAY_INFO, NULL);
1139 return rv;
1140}
1141
2f6079dc
NB
1142char *devnum2devname(int num)
1143{
1144 char name[100];
1145 if (num > 0)
1146 sprintf(name, "md%d", num);
1147 else
1148 sprintf(name, "md_d%d", -1-num);
1149 return strdup(name);
1150}
1151
77472ff8
NB
1152int devname2devnum(char *name)
1153{
1154 char *ep;
1155 int num;
1156 if (strncmp(name, "md_d", 4)==0)
1157 num = -1-strtoul(name+4, &ep, 10);
1158 else
1159 num = strtoul(name+2, &ep, 10);
1160 return num;
1161}
1162
c94709e8 1163int stat2devnum(struct stat *st)
2f6079dc 1164{
d7ab966b
N
1165 char path[30];
1166 char link[200];
1167 char *cp;
1168 int n;
1169
c94709e8
DW
1170 if ((S_IFMT & st->st_mode) == S_IFBLK) {
1171 if (major(st->st_rdev) == MD_MAJOR)
1172 return minor(st->st_rdev);
d7ab966b
N
1173 else if (major(st->st_rdev) == get_mdp_major())
1174 return -1- (minor(st->st_rdev)>>MdpMinorShift);
1175
1176 /* must be an extended-minor partition. Look at the
1177 * /sys/dev/block/%d:%d link which must look like
1178 * ../../block/mdXXX/mdXXXpYY
1179 */
1180 sprintf(path, "/sys/dev/block/%d:%d", major(st->st_rdev),
1181 minor(st->st_rdev));
1182 n = readlink(path, link, sizeof(link)-1);
1183 if (n <= 0)
1184 return NoMdDev;
1185 link[n] = 0;
1186 cp = strrchr(link, '/');
1187 if (cp) *cp = 0;
1188 cp = strchr(link, '/');
1189 if (cp && strncmp(cp, "/md", 3) == 0)
1190 return devname2devnum(cp+1);
2f6079dc 1191 }
d7ab966b 1192 return NoMdDev;
c94709e8
DW
1193
1194}
1195
1196int fd2devnum(int fd)
1197{
1198 struct stat stb;
1199 if (fstat(fd, &stb) == 0)
1200 return stat2devnum(&stb);
d7ab966b 1201 return NoMdDev;
2f6079dc
NB
1202}
1203
a931db9e
NB
1204int mdmon_running(int devnum)
1205{
1206 char path[100];
1207 char pid[10];
1208 int fd;
1209 int n;
1210 sprintf(path, "/var/run/mdadm/%s.pid", devnum2devname(devnum));
1211 fd = open(path, O_RDONLY, 0);
1212
1213 if (fd < 0)
1214 return 0;
1215 n = read(fd, pid, 9);
1216 close(fd);
1217 if (n <= 0)
1218 return 0;
1219 if (kill(atoi(pid), 0) == 0)
1220 return 1;
1221 return 0;
1222}
1223
1224int signal_mdmon(int devnum)
1225{
1226 char path[100];
1227 char pid[10];
1228 int fd;
1229 int n;
1230 sprintf(path, "/var/run/mdadm/%s.pid", devnum2devname(devnum));
1231 fd = open(path, O_RDONLY, 0);
1232
1233 if (fd < 0)
1234 return 0;
1235 n = read(fd, pid, 9);
1236 close(fd);
1237 if (n <= 0)
1238 return 0;
1239 if (kill(atoi(pid), SIGUSR1) == 0)
1240 return 1;
1241 return 0;
1242}
1243
8850ee3e
N
1244int start_mdmon(int devnum)
1245{
1246 int i;
44d2e365 1247 int len;
9fe32043
N
1248 pid_t pid;
1249 int status;
44d2e365
N
1250 char pathbuf[1024];
1251 char *paths[4] = {
1252 pathbuf,
1253 "/sbin/mdmon",
1254 "mdmon",
1255 NULL
1256 };
8850ee3e 1257
40ebbb9c 1258 if (check_env("MDADM_NO_MDMON"))
8850ee3e
N
1259 return 0;
1260
44d2e365
N
1261 len = readlink("/proc/self/exe", pathbuf, sizeof(pathbuf));
1262 if (len > 0) {
1263 char *sl;
1264 pathbuf[len] = 0;
1265 sl = strrchr(pathbuf, '/');
1266 if (sl)
1267 sl++;
1268 else
1269 sl = pathbuf;
1270 strcpy(sl, "mdmon");
1271 } else
1272 pathbuf[0] = '\0';
1273
8850ee3e
N
1274 switch(fork()) {
1275 case 0:
1276 /* FIXME yuk. CLOSE_EXEC?? */
1277 for (i=3; i < 100; i++)
1278 close(i);
44d2e365
N
1279 for (i=0; paths[i]; i++)
1280 if (paths[i][0])
1281 execl(paths[i], "mdmon",
e8a70c89
N
1282 devnum2devname(devnum),
1283 NULL);
8850ee3e
N
1284 exit(1);
1285 case -1: fprintf(stderr, Name ": cannot run mdmon. "
1286 "Array remains readonly\n");
1287 return -1;
9fe32043
N
1288 default: /* parent - good */
1289 pid = wait(&status);
1290 if (pid < 0 || status != 0)
1291 return -1;
8850ee3e
N
1292 }
1293 return 0;
1294}
1295
40ebbb9c 1296int check_env(char *name)
5dcfcb71 1297{
40ebbb9c 1298 char *val = getenv(name);
5dcfcb71
DW
1299
1300 if (val && atoi(val) == 1)
1301 return 1;
1302
1303 return 0;
1304}
1305
0e600426 1306#ifndef MDASSEMBLE
edd8d13c
NB
1307int flush_metadata_updates(struct supertype *st)
1308{
1309 int sfd;
1310 if (!st->updates) {
1311 st->update_tail = NULL;
1312 return -1;
1313 }
1314
1315 sfd = connect_monitor(devnum2devname(st->container_dev));
1316 if (sfd < 0)
1317 return -1;
1318
1319 while (st->updates) {
1320 struct metadata_update *mu = st->updates;
1321 st->updates = mu->next;
1322
1323 send_message(sfd, mu, 0);
1324 wait_reply(sfd, 0);
1325 free(mu->buf);
1326 free(mu);
1327 }
1328 ack(sfd, 0);
1329 wait_reply(sfd, 0);
1330 close(sfd);
1331 st->update_tail = NULL;
1332 return 0;
1333}
1334
1335void append_metadata_update(struct supertype *st, void *buf, int len)
1336{
1337
1338 struct metadata_update *mu = malloc(sizeof(*mu));
1339
1340 mu->buf = buf;
1341 mu->len = len;
1342 mu->space = NULL;
1343 mu->next = NULL;
1344 *st->update_tail = mu;
1345 st->update_tail = &mu->next;
1346}
0e600426 1347#endif /* MDASSEMBLE */
a931db9e 1348
fe6729fa
NB
1349#ifdef __TINYC__
1350/* tinyc doesn't optimize this check in ioctl.h out ... */
1351unsigned int __invalid_size_argument_for_IOC = 0;
1352#endif
1353