]> git.neil.brown.name Git - mdadm.git/blob - super0.c
Release mdadm-4.0
[mdadm.git] / super0.c
1 /*
2  * mdadm - manage Linux "md" devices aka RAID arrays.
3  *
4  * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
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@suse.de>
23  */
24
25 #define HAVE_STDINT_H 1
26 #include "mdadm.h"
27 #include "sha1.h"
28 /*
29  * All handling for the 0.90.0 version superblock is in
30  * this file.
31  * This includes:
32  *   - finding, loading, and writing the superblock.
33  *   - initialising a new superblock
34  *   - printing the superblock for --examine
35  *   - printing part of the superblock for --detail
36  * .. other stuff
37  */
38
39 static unsigned long calc_sb0_csum(mdp_super_t *super)
40 {
41         unsigned long csum = super->sb_csum;
42         unsigned long newcsum;
43         super->sb_csum= 0 ;
44         newcsum = calc_csum(super, MD_SB_BYTES);
45         super->sb_csum = csum;
46         return newcsum;
47 }
48
49 static void super0_swap_endian(struct mdp_superblock_s *sb)
50 {
51         /* as super0 superblocks are host-endian, it is sometimes
52          * useful to be able to swap the endianness
53          * as (almost) everything is u32's we byte-swap every 4byte
54          * number.
55          * We then also have to swap the events_hi and events_lo
56          */
57         char *sbc = (char *)sb;
58         __u32 t32;
59         int i;
60
61         for (i=0; i < MD_SB_BYTES ; i+=4) {
62                 char t = sbc[i];
63                 sbc[i] = sbc[i+3];
64                 sbc[i+3] = t;
65                 t=sbc[i+1];
66                 sbc[i+1]=sbc[i+2];
67                 sbc[i+2]=t;
68         }
69         t32 = sb->events_hi;
70         sb->events_hi = sb->events_lo;
71         sb->events_lo = t32;
72
73         t32 = sb->cp_events_hi;
74         sb->cp_events_hi = sb->cp_events_lo;
75         sb->cp_events_lo = t32;
76
77 }
78
79 #ifndef MDASSEMBLE
80
81 static void examine_super0(struct supertype *st, char *homehost)
82 {
83         mdp_super_t *sb = st->sb;
84         time_t atime;
85         int d;
86         int delta_extra = 0;
87         char *c;
88
89         printf("          Magic : %08x\n", sb->md_magic);
90         printf("        Version : %d.%02d.%02d\n",
91                sb->major_version, sb->minor_version, sb->patch_version);
92         if (sb->minor_version >= 90) {
93                 printf("           UUID : %08x:%08x:%08x:%08x", sb->set_uuid0,
94                        sb->set_uuid1, sb->set_uuid2, sb->set_uuid3);
95                 if (homehost) {
96                         char buf[20];
97                         void *hash;
98
99                         hash = sha1_buffer(homehost, strlen(homehost), buf);
100                         if (memcmp(&sb->set_uuid2, hash, 8) == 0)
101                                 printf(" (local to host %s)", homehost);
102                 }
103                 printf("\n");
104         } else
105                 printf("           UUID : %08x\n", sb->set_uuid0);
106
107         if (sb->not_persistent)
108                 printf("           Eedk : not persistent\n");
109
110         atime = sb->ctime;
111         printf("  Creation Time : %.24s\n", ctime(&atime));
112         c = map_num(pers, sb->level);
113         printf("     Raid Level : %s\n", c?c:"-unknown-");
114         if ((int)sb->level > 0) {
115                 int ddsks = 0, ddsks_denom = 1;
116                 printf("  Used Dev Size : %d%s\n", sb->size,
117                        human_size((long long)sb->size<<10));
118                 switch(sb->level) {
119                 case 1:
120                         ddsks=1;
121                         break;
122                 case 4:
123                 case 5:
124                         ddsks = sb->raid_disks - 1;
125                         break;
126                 case 6:
127                         ddsks = sb->raid_disks - 2;
128                         break;
129                 case 10:
130                         ddsks = sb->raid_disks;
131                         ddsks_denom =
132                                 (sb->layout & 255) * ((sb->layout >> 8) & 255);
133                 }
134                 if (ddsks) {
135                         long long asize = sb->size;
136                         asize = (asize << 10) * ddsks / ddsks_denom;
137                         printf("     Array Size : %llu%s\n",
138                                asize >> 10,  human_size(asize));
139                 }
140         }
141         printf("   Raid Devices : %d\n", sb->raid_disks);
142         printf("  Total Devices : %d\n", sb->nr_disks);
143         printf("Preferred Minor : %d\n", sb->md_minor);
144         printf("\n");
145         if (sb->minor_version > 90 && (sb->reshape_position + 1) != 0) {
146                 printf("  Reshape pos'n : %llu%s\n",
147                        (unsigned long long)sb->reshape_position / 2,
148                        human_size((long long)sb->reshape_position << 9));
149                 if (sb->delta_disks) {
150                         printf("  Delta Devices : %d", sb->delta_disks);
151                         printf(" (%d->%d)\n", sb->raid_disks-sb->delta_disks,
152                                sb->raid_disks);
153                         if (((int)sb->delta_disks) < 0)
154                                 delta_extra = - sb->delta_disks;
155                 }
156                 if (sb->new_level != sb->level) {
157                         c = map_num(pers, sb->new_level);
158                         printf("      New Level : %s\n", c?c:"-unknown-");
159                 }
160                 if (sb->new_layout != sb->layout) {
161                         if (sb->level == 5) {
162                                 c = map_num(r5layout, sb->new_layout);
163                                 printf("     New Layout : %s\n",
164                                        c?c:"-unknown-");
165                         }
166                         if (sb->level == 6) {
167                                 c = map_num(r6layout, sb->new_layout);
168                                 printf("     New Layout : %s\n",
169                                        c?c:"-unknown-");
170                         }
171                         if (sb->level == 10) {
172                                 printf("     New Layout : near=%d, %s=%d\n",
173                                        sb->new_layout&255,
174                                        (sb->new_layout&0x10000)?"offset":"far",
175                                        (sb->new_layout>>8)&255);
176                         }
177                 }
178                 if (sb->new_chunk != sb->chunk_size)
179                         printf("  New Chunksize : %d\n", sb->new_chunk);
180                 printf("\n");
181         }
182         atime = sb->utime;
183         printf("    Update Time : %.24s\n", ctime(&atime));
184         printf("          State : %s\n",
185                (sb->state&(1 << MD_SB_CLEAN)) ? "clean":"active");
186         if (sb->state & (1 << MD_SB_BITMAP_PRESENT))
187                 printf("Internal Bitmap : present\n");
188         printf(" Active Devices : %d\n", sb->active_disks);
189         printf("Working Devices : %d\n", sb->working_disks);
190         printf(" Failed Devices : %d\n", sb->failed_disks);
191         printf("  Spare Devices : %d\n", sb->spare_disks);
192         if (calc_sb0_csum(sb) == sb->sb_csum)
193                 printf("       Checksum : %x - correct\n", sb->sb_csum);
194         else
195                 printf("       Checksum : %x - expected %lx\n",
196                        sb->sb_csum, calc_sb0_csum(sb));
197         printf("         Events : %llu\n",
198                ((unsigned long long)sb->events_hi << 32) + sb->events_lo);
199         printf("\n");
200         if (sb->level == 5) {
201                 c = map_num(r5layout, sb->layout);
202                 printf("         Layout : %s\n", c?c:"-unknown-");
203         }
204         if (sb->level == 6) {
205                 c = map_num(r6layout, sb->layout);
206                 printf("         Layout : %s\n", c?c:"-unknown-");
207         }
208         if (sb->level == 10) {
209                 printf("         Layout :");
210                 print_r10_layout(sb->layout);
211                 printf("\n");
212         }
213         switch(sb->level) {
214         case 0:
215         case 4:
216         case 5:
217         case 6:
218         case 10:
219                 printf("     Chunk Size : %dK\n", sb->chunk_size / 1024);
220                 break;
221         case -1:
222                 printf("       Rounding : %dK\n", sb->chunk_size / 1024);
223                 break;
224         default:
225                 break;
226         }
227         printf("\n");
228         printf("      Number   Major   Minor   RaidDevice State\n");
229         for (d = -1;
230              d < (signed int)(sb->raid_disks + delta_extra + sb->spare_disks);
231              d++) {
232                 mdp_disk_t *dp;
233                 char *dv;
234                 char nb[5];
235                 int wonly, failfast;
236                 if (d>=0) dp = &sb->disks[d];
237                 else dp = &sb->this_disk;
238                 snprintf(nb, sizeof(nb), "%4d", d);
239                 printf("%4s %5d   %5d    %5d    %5d     ", d < 0 ? "this" : nb,
240                        dp->number, dp->major, dp->minor, dp->raid_disk);
241                 wonly = dp->state & (1 << MD_DISK_WRITEMOSTLY);
242                 failfast = dp->state & (1<<MD_DISK_FAILFAST);
243                 dp->state &= ~(wonly | failfast);
244                 if (dp->state & (1 << MD_DISK_FAULTY))
245                         printf(" faulty");
246                 if (dp->state & (1 << MD_DISK_ACTIVE))
247                         printf(" active");
248                 if (dp->state & (1 << MD_DISK_SYNC))
249                         printf(" sync");
250                 if (dp->state & (1 << MD_DISK_REMOVED))
251                         printf(" removed");
252                 if (wonly)
253                         printf(" write-mostly");
254                 if (failfast)
255                         printf(" failfast");
256                 if (dp->state == 0)
257                         printf(" spare");
258                 if ((dv = map_dev(dp->major, dp->minor, 0)))
259                         printf("   %s", dv);
260                 printf("\n");
261                 if (d == -1)
262                         printf("\n");
263         }
264 }
265
266 static void brief_examine_super0(struct supertype *st, int verbose)
267 {
268         mdp_super_t *sb = st->sb;
269         char *c=map_num(pers, sb->level);
270         char devname[20];
271
272         sprintf(devname, "/dev/md%d", sb->md_minor);
273
274         if (verbose) {
275                 printf("ARRAY %s level=%s num-devices=%d",
276                        devname,
277                        c?c:"-unknown-", sb->raid_disks);
278         } else
279                 printf("ARRAY %s", devname);
280
281         if (sb->minor_version >= 90)
282                 printf(" UUID=%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
283                        sb->set_uuid2, sb->set_uuid3);
284         else
285                 printf(" UUID=%08x", sb->set_uuid0);
286         printf("\n");
287 }
288
289 static void export_examine_super0(struct supertype *st)
290 {
291         mdp_super_t *sb = st->sb;
292
293         printf("MD_LEVEL=%s\n", map_num(pers, sb->level));
294         printf("MD_DEVICES=%d\n", sb->raid_disks);
295         if (sb->minor_version >= 90)
296                 printf("MD_UUID=%08x:%08x:%08x:%08x\n",
297                        sb->set_uuid0, sb->set_uuid1,
298                        sb->set_uuid2, sb->set_uuid3);
299         else
300                 printf("MD_UUID=%08x\n", sb->set_uuid0);
301         printf("MD_UPDATE_TIME=%llu\n",
302                __le64_to_cpu(sb->ctime) & 0xFFFFFFFFFFULL);
303         printf("MD_EVENTS=%llu\n",
304                ((unsigned long long)sb->events_hi << 32)
305                + sb->events_lo);
306 }
307
308 static int copy_metadata0(struct supertype *st, int from, int to)
309 {
310         /* Read 64K from the appropriate offset of 'from'
311          * and if it looks a little like a 0.90 superblock,
312          * write it to the same offset of 'to'
313          */
314         void *buf;
315         unsigned long long dsize, offset;
316         const int bufsize = 64*1024;
317         mdp_super_t *super;
318
319         if (posix_memalign(&buf, 4096, bufsize) != 0)
320                 return 1;
321
322         if (!get_dev_size(from, NULL, &dsize))
323                 goto err;
324
325         if (dsize < MD_RESERVED_SECTORS*512)
326                 goto err;
327
328         offset = MD_NEW_SIZE_SECTORS(dsize>>9);
329
330         offset *= 512;
331
332         if (lseek64(from, offset, 0) < 0LL)
333                 goto err;
334         if (read(from, buf, bufsize) != bufsize)
335                 goto err;
336
337         if (lseek64(to, offset, 0) < 0LL)
338                 goto err;
339         super = buf;
340         if (super->md_magic != MD_SB_MAGIC ||
341             super->major_version != 0 ||
342             calc_sb0_csum(super) != super->sb_csum)
343                 goto err;
344         if (write(to, buf, bufsize) != bufsize)
345                 goto err;
346         free(buf);
347         return 0;
348 err:
349         free(buf);
350         return 1;
351 }
352
353 static void detail_super0(struct supertype *st, char *homehost)
354 {
355         mdp_super_t *sb = st->sb;
356         printf("           UUID : ");
357         if (sb->minor_version >= 90)
358                 printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
359                        sb->set_uuid2, sb->set_uuid3);
360         else
361                 printf("%08x", sb->set_uuid0);
362         if (homehost) {
363                 char buf[20];
364                 void *hash = sha1_buffer(homehost,
365                                          strlen(homehost),
366                                          buf);
367                 if (memcmp(&sb->set_uuid2, hash, 8)==0)
368                         printf(" (local to host %s)", homehost);
369         }
370         printf("\n         Events : %d.%d\n\n", sb->events_hi, sb->events_lo);
371 }
372
373 static void brief_detail_super0(struct supertype *st)
374 {
375         mdp_super_t *sb = st->sb;
376         printf(" UUID=");
377         if (sb->minor_version >= 90)
378                 printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
379                        sb->set_uuid2, sb->set_uuid3);
380         else
381                 printf("%08x", sb->set_uuid0);
382 }
383 #endif
384
385 static int match_home0(struct supertype *st, char *homehost)
386 {
387         mdp_super_t *sb = st->sb;
388         char buf[20];
389         char *hash;
390
391         if (!homehost)
392                 return 0;
393         hash = sha1_buffer(homehost,
394                            strlen(homehost),
395                            buf);
396
397         return (memcmp(&sb->set_uuid2, hash, 8)==0);
398 }
399
400 static void uuid_from_super0(struct supertype *st, int uuid[4])
401 {
402         mdp_super_t *super = st->sb;
403         uuid[0] = super->set_uuid0;
404         if (super->minor_version >= 90) {
405                 uuid[1] = super->set_uuid1;
406                 uuid[2] = super->set_uuid2;
407                 uuid[3] = super->set_uuid3;
408         } else {
409                 uuid[1] = 0;
410                 uuid[2] = 0;
411                 uuid[3] = 0;
412         }
413 }
414
415 static void getinfo_super0(struct supertype *st, struct mdinfo *info, char *map)
416 {
417         mdp_super_t *sb = st->sb;
418         int working = 0;
419         int i;
420         int map_disks = info->array.raid_disks;
421
422         memset(info, 0, sizeof(*info));
423         info->array.major_version = sb->major_version;
424         info->array.minor_version = sb->minor_version;
425         info->array.patch_version = sb->patch_version;
426         info->array.raid_disks = sb->raid_disks;
427         info->array.level = sb->level;
428         info->array.layout = sb->layout;
429         info->array.md_minor = sb->md_minor;
430         info->array.ctime = sb->ctime;
431         info->array.utime = sb->utime;
432         info->array.chunk_size = sb->chunk_size;
433         info->array.state = sb->state;
434         info->component_size = sb->size;
435         info->component_size *= 2;
436
437         if (sb->state & (1<<MD_SB_BITMAP_PRESENT))
438                 info->bitmap_offset = 8;
439
440         info->disk.state = sb->this_disk.state;
441         info->disk.major = sb->this_disk.major;
442         info->disk.minor = sb->this_disk.minor;
443         info->disk.raid_disk = sb->this_disk.raid_disk;
444         info->disk.number = sb->this_disk.number;
445
446         info->events = md_event(sb);
447         info->data_offset = 0;
448
449         sprintf(info->text_version, "0.%d", sb->minor_version);
450         info->safe_mode_delay = 200;
451
452         uuid_from_super0(st, info->uuid);
453
454         info->recovery_start = MaxSector;
455         if (sb->minor_version > 90 && (sb->reshape_position+1) != 0) {
456                 info->reshape_active = 1;
457                 info->reshape_progress = sb->reshape_position;
458                 info->new_level = sb->new_level;
459                 info->delta_disks = sb->delta_disks;
460                 info->new_layout = sb->new_layout;
461                 info->new_chunk = sb->new_chunk;
462                 if (info->delta_disks < 0)
463                         info->array.raid_disks -= info->delta_disks;
464         } else
465                 info->reshape_active = 0;
466
467         info->recovery_blocked = info->reshape_active;
468
469         sprintf(info->name, "%d", sb->md_minor);
470         /* work_disks is calculated rather than read directly */
471         for (i=0; i < MD_SB_DISKS; i++)
472                 if ((sb->disks[i].state & (1<<MD_DISK_SYNC)) &&
473                     (sb->disks[i].raid_disk < (unsigned)info->array.raid_disks) &&
474                     (sb->disks[i].state & (1<<MD_DISK_ACTIVE)) &&
475                     !(sb->disks[i].state & (1<<MD_DISK_FAULTY))) {
476                         working ++;
477                         if (map && i < map_disks)
478                                 map[i] = 1;
479                 } else if (map && i < map_disks)
480                         map[i] = 0;
481         info->array.working_disks = working;
482 }
483
484 static struct mdinfo *container_content0(struct supertype *st, char *subarray)
485 {
486         struct mdinfo *info;
487
488         if (subarray)
489                 return NULL;
490
491         info = xmalloc(sizeof(*info));
492         getinfo_super0(st, info, NULL);
493         return info;
494 }
495
496 static int update_super0(struct supertype *st, struct mdinfo *info,
497                          char *update,
498                          char *devname, int verbose,
499                          int uuid_set, char *homehost)
500 {
501         /* NOTE: for 'assemble' and 'force' we need to return non-zero
502          * if any change was made.  For others, the return value is
503          * ignored.
504          */
505         int rv = 0;
506         int uuid[4];
507         mdp_super_t *sb = st->sb;
508
509         if (strcmp(update, "homehost") == 0 &&
510             homehost) {
511                 /* note that 'homehost' is special as it is really
512                  * a "uuid" update.
513                  */
514                 uuid_set = 0;
515                 update = "uuid";
516                 info->uuid[0] = sb->set_uuid0;
517                 info->uuid[1] = sb->set_uuid1;
518         }
519
520         if (strcmp(update, "sparc2.2")==0 ) {
521                 /* 2.2 sparc put the events in the wrong place
522                  * So we copy the tail of the superblock
523                  * up 4 bytes before continuing
524                  */
525                 __u32 *sb32 = (__u32*)sb;
526                 memcpy(sb32+MD_SB_GENERIC_CONSTANT_WORDS+7,
527                        sb32+MD_SB_GENERIC_CONSTANT_WORDS+7+1,
528                        (MD_SB_WORDS - (MD_SB_GENERIC_CONSTANT_WORDS+7+1))*4);
529                 if (verbose >= 0)
530                         pr_err("adjusting superblock of %s for 2.2/sparc compatibility.\n",
531                                devname);
532         } else if (strcmp(update, "super-minor") ==0) {
533                 sb->md_minor = info->array.md_minor;
534                 if (verbose > 0)
535                         pr_err("updating superblock of %s with minor number %d\n",
536                                 devname, info->array.md_minor);
537         } else if (strcmp(update, "summaries") == 0) {
538                 unsigned int i;
539                 /* set nr_disks, active_disks, working_disks,
540                  * failed_disks, spare_disks based on disks[]
541                  * array in superblock.
542                  * Also make sure extra slots aren't 'failed'
543                  */
544                 sb->nr_disks = sb->active_disks =
545                         sb->working_disks = sb->failed_disks =
546                         sb->spare_disks = 0;
547                 for (i=0; i < MD_SB_DISKS ; i++)
548                         if (sb->disks[i].major ||
549                             sb->disks[i].minor) {
550                                 int state = sb->disks[i].state;
551                                 if (state & (1<<MD_DISK_REMOVED))
552                                         continue;
553                                 sb->nr_disks++;
554                                 if (state & (1<<MD_DISK_ACTIVE))
555                                         sb->active_disks++;
556                                 if (state & (1<<MD_DISK_FAULTY))
557                                         sb->failed_disks++;
558                                 else
559                                         sb->working_disks++;
560                                 if (state == 0)
561                                         sb->spare_disks++;
562                         } else if (i >= sb->raid_disks && sb->disks[i].number == 0)
563                                 sb->disks[i].state = 0;
564         } else if (strcmp(update, "force-one")==0) {
565                 /* Not enough devices for a working array, so
566                  * bring this one up-to-date.
567                  */
568                 __u32 ehi = sb->events_hi, elo = sb->events_lo;
569                 sb->events_hi = (info->events>>32) & 0xFFFFFFFF;
570                 sb->events_lo = (info->events) & 0xFFFFFFFF;
571                 if (sb->events_hi != ehi ||
572                     sb->events_lo != elo)
573                         rv = 1;
574         } else if (strcmp(update, "force-array")==0) {
575                 /* degraded array and 'force' requested, so
576                  * maybe need to mark it 'clean'
577                  */
578                 if ((sb->level == 5 || sb->level == 4 || sb->level == 6) &&
579                     (sb->state & (1 << MD_SB_CLEAN)) == 0) {
580                         /* need to force clean */
581                         sb->state |= (1 << MD_SB_CLEAN);
582                         rv = 1;
583                 }
584         } else if (strcmp(update, "assemble")==0) {
585                 int d = info->disk.number;
586                 int wonly = sb->disks[d].state & (1<<MD_DISK_WRITEMOSTLY);
587                 int failfast = sb->disks[d].state & (1<<MD_DISK_FAILFAST);
588                 int mask = (1<<MD_DISK_WRITEMOSTLY)|(1<<MD_DISK_FAILFAST);
589                 int add = 0;
590                 if (sb->minor_version >= 91)
591                         /* During reshape we don't insist on everything
592                          * being marked 'sync'
593                          */
594                         add = (1<<MD_DISK_SYNC);
595                 if (((sb->disks[d].state & ~mask) | add)
596                     != (unsigned)info->disk.state) {
597                         sb->disks[d].state = info->disk.state | wonly |failfast;
598                         rv = 1;
599                 }
600                 if (info->reshape_active &&
601                     sb->minor_version > 90 && (sb->reshape_position+1) != 0 &&
602                     info->delta_disks >= 0 &&
603                     info->reshape_progress < sb->reshape_position) {
604                         sb->reshape_position = info->reshape_progress;
605                         rv = 1;
606                 }
607                 if (info->reshape_active &&
608                     sb->minor_version > 90 && (sb->reshape_position+1) != 0 &&
609                     info->delta_disks < 0 &&
610                     info->reshape_progress > sb->reshape_position) {
611                         sb->reshape_position = info->reshape_progress;
612                         rv = 1;
613                 }
614         } else if (strcmp(update, "linear-grow-new") == 0) {
615                 memset(&sb->disks[info->disk.number], 0, sizeof(sb->disks[0]));
616                 sb->disks[info->disk.number].number = info->disk.number;
617                 sb->disks[info->disk.number].major = info->disk.major;
618                 sb->disks[info->disk.number].minor = info->disk.minor;
619                 sb->disks[info->disk.number].raid_disk = info->disk.raid_disk;
620                 sb->disks[info->disk.number].state = info->disk.state;
621                 sb->this_disk = sb->disks[info->disk.number];
622         } else if (strcmp(update, "linear-grow-update") == 0) {
623                 sb->raid_disks = info->array.raid_disks;
624                 sb->nr_disks = info->array.nr_disks;
625                 sb->active_disks = info->array.active_disks;
626                 sb->working_disks = info->array.working_disks;
627                 memset(&sb->disks[info->disk.number], 0, sizeof(sb->disks[0]));
628                 sb->disks[info->disk.number].number = info->disk.number;
629                 sb->disks[info->disk.number].major = info->disk.major;
630                 sb->disks[info->disk.number].minor = info->disk.minor;
631                 sb->disks[info->disk.number].raid_disk = info->disk.raid_disk;
632                 sb->disks[info->disk.number].state = info->disk.state;
633         } else if (strcmp(update, "resync") == 0) {
634                 /* make sure resync happens */
635                 sb->state &= ~(1<<MD_SB_CLEAN);
636                 sb->recovery_cp = 0;
637         } else if (strcmp(update, "uuid") == 0) {
638                 if (!uuid_set && homehost) {
639                         char buf[20];
640                         char *hash = sha1_buffer(homehost,
641                                                  strlen(homehost),
642                                                  buf);
643                         memcpy(info->uuid+2, hash, 8);
644                 }
645                 sb->set_uuid0 = info->uuid[0];
646                 sb->set_uuid1 = info->uuid[1];
647                 sb->set_uuid2 = info->uuid[2];
648                 sb->set_uuid3 = info->uuid[3];
649                 if (sb->state & (1<<MD_SB_BITMAP_PRESENT)) {
650                         struct bitmap_super_s *bm;
651                         bm = (struct bitmap_super_s*)(sb+1);
652                         uuid_from_super0(st, uuid);
653                         memcpy(bm->uuid, uuid, 16);
654                 }
655         } else if (strcmp(update, "metadata") == 0) {
656                 /* Create some v1.0 metadata to match ours but make the
657                  * ctime bigger.  Also update info->array.*_version.
658                  * We need to arrange that store_super writes out
659                  * the v1.0 metadata.
660                  * Not permitted for unclean array, or array with
661                  * bitmap.
662                  */
663                 if (info->bitmap_offset) {
664                         pr_err("Cannot update metadata when bitmap is present\n");
665                         rv = -2;
666                 } else if (info->array.state != 1) {
667                         pr_err("Cannot update metadata on unclean array\n");
668                         rv = -2;
669                 } else {
670                         info->array.major_version = 1;
671                         info->array.minor_version = 0;
672                         uuid_from_super0(st, info->uuid);
673                         st->other = super1_make_v0(st, info, st->sb);
674                 }
675         } else if (strcmp(update, "revert-reshape") == 0) {
676                 rv = -2;
677                 if (sb->minor_version <= 90)
678                         pr_err("No active reshape to revert on %s\n",
679                                devname);
680                 else if (sb->delta_disks == 0)
681                         pr_err("%s: Can only revert reshape which changes number of devices\n",
682                                devname);
683                 else {
684                         int tmp;
685                         int parity = sb->level == 6 ? 2 : 1;
686                         rv = 0;
687
688                         if (sb->level >= 4 && sb->level <= 6 &&
689                             sb->reshape_position % (
690                                     sb->new_chunk/512 *
691                                     (sb->raid_disks - sb->delta_disks - parity))) {
692                                 pr_err("Reshape position is not suitably aligned.\n");
693                                 pr_err("Try normal assembly and stop again\n");
694                                 return -2;
695                         }
696                         sb->raid_disks -= sb->delta_disks;
697                         sb->delta_disks = -sb->delta_disks;
698
699                         tmp = sb->new_layout;
700                         sb->new_layout = sb->layout;
701                         sb->layout = tmp;
702
703                         tmp = sb->new_chunk;
704                         sb->new_chunk = sb->chunk_size;
705                         sb->chunk_size = tmp;
706                 }
707         } else if (strcmp(update, "no-bitmap") == 0) {
708                 sb->state &= ~(1<<MD_SB_BITMAP_PRESENT);
709         } else if (strcmp(update, "_reshape_progress")==0)
710                 sb->reshape_position = info->reshape_progress;
711         else if (strcmp(update, "writemostly")==0)
712                 sb->state |= (1<<MD_DISK_WRITEMOSTLY);
713         else if (strcmp(update, "readwrite")==0)
714                 sb->state &= ~(1<<MD_DISK_WRITEMOSTLY);
715         else
716                 rv = -1;
717
718         sb->sb_csum = calc_sb0_csum(sb);
719         return rv;
720 }
721
722 /*
723  * For version-0 superblock, the homehost is 'stored' in the uuid.
724  * 8 bytes for a hash of the host leaving 8 bytes of random material.
725  * We use the first 8 bytes (64bits) of the sha1 of the host name
726  */
727 static int init_super0(struct supertype *st, mdu_array_info_t *info,
728                        unsigned long long size, char *ignored_name,
729                        char *homehost, int *uuid,
730                        unsigned long long data_offset)
731 {
732         mdp_super_t *sb;
733         int spares;
734
735         if (data_offset != INVALID_SECTORS) {
736                 pr_err("data-offset not support for 0.90\n");
737                 return 0;
738         }
739
740         if (posix_memalign((void**)&sb, 4096,
741                            MD_SB_BYTES + ROUND_UP(sizeof(bitmap_super_t), 4096)) != 0) {
742                 pr_err("could not allocate superblock\n");
743                 return 0;
744         }
745         memset(sb, 0, MD_SB_BYTES + sizeof(bitmap_super_t));
746
747         st->sb = sb;
748         if (info == NULL) {
749                 /* zeroing the superblock */
750                 return 0;
751         }
752
753         spares = info->working_disks - info->active_disks;
754         if (info->raid_disks + spares  > MD_SB_DISKS) {
755                 pr_err("too many devices requested: %d+%d > %d\n",
756                         info->raid_disks , spares, MD_SB_DISKS);
757                 return 0;
758         }
759
760         sb->md_magic = MD_SB_MAGIC;
761         sb->major_version = 0;
762         sb->minor_version = 90;
763         sb->patch_version = 0;
764         sb->gvalid_words = 0; /* ignored */
765         sb->ctime = time(0);
766         sb->level = info->level;
767         sb->size = size;
768         if (size != (unsigned long long)sb->size)
769                 return 0;
770         sb->nr_disks = info->nr_disks;
771         sb->raid_disks = info->raid_disks;
772         sb->md_minor = info->md_minor;
773         sb->not_persistent = 0;
774         if (uuid) {
775                 sb->set_uuid0 = uuid[0];
776                 sb->set_uuid1 = uuid[1];
777                 sb->set_uuid2 = uuid[2];
778                 sb->set_uuid3 = uuid[3];
779         } else {
780                 __u32 r[4];
781                 random_uuid((__u8 *)r);
782                 sb->set_uuid0 = r[0];
783                 sb->set_uuid1 = r[1];
784                 sb->set_uuid2 = r[2];
785                 sb->set_uuid3 = r[3];
786         }
787         if (homehost && !uuid) {
788                 char buf[20];
789                 char *hash = sha1_buffer(homehost,
790                                          strlen(homehost),
791                                          buf);
792                 memcpy(&sb->set_uuid2, hash, 8);
793         }
794
795         sb->utime = sb->ctime;
796         sb->state = info->state;
797         sb->active_disks = info->active_disks;
798         sb->working_disks = info->working_disks;
799         sb->failed_disks = info->failed_disks;
800         sb->spare_disks = info->spare_disks;
801         sb->events_hi = 0;
802         sb->events_lo = 1;
803
804         sb->layout = info->layout;
805         sb->chunk_size = info->chunk_size;
806
807         return 1;
808 }
809
810 struct devinfo {
811         int fd;
812         char *devname;
813         mdu_disk_info_t disk;
814         struct devinfo *next;
815 };
816
817 #ifndef MDASSEMBLE
818 /* Add a device to the superblock being created */
819 static int add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
820                          int fd, char *devname, unsigned long long data_offset)
821 {
822         mdp_super_t *sb = st->sb;
823         mdp_disk_t *dk = &sb->disks[dinfo->number];
824         struct devinfo *di, **dip;
825
826         dk->number = dinfo->number;
827         dk->major = dinfo->major;
828         dk->minor = dinfo->minor;
829         dk->raid_disk = dinfo->raid_disk;
830         dk->state = dinfo->state & ((1<<MD_DISK_ACTIVE) |
831                                     (1<<MD_DISK_SYNC));
832
833         sb->this_disk = sb->disks[dinfo->number];
834         sb->sb_csum = calc_sb0_csum(sb);
835
836         dip = (struct devinfo **)&st->info;
837         while (*dip)
838                 dip = &(*dip)->next;
839         di = xmalloc(sizeof(struct devinfo));
840         di->fd = fd;
841         di->devname = devname;
842         di->disk = *dinfo;
843         di->next = NULL;
844         *dip = di;
845
846         return 0;
847 }
848 #endif
849
850 static int store_super0(struct supertype *st, int fd)
851 {
852         unsigned long long dsize;
853         unsigned long long offset;
854         mdp_super_t *super = st->sb;
855
856         if (!get_dev_size(fd, NULL, &dsize))
857                 return 1;
858
859         if (dsize < MD_RESERVED_SECTORS*512)
860                 return 2;
861
862         if (st->other) {
863                 /* Writing out v1.0 metadata for --update=metadata */
864                 int ret = 0;
865
866                 offset = dsize/512 - 8*2;
867                 offset &= ~(4*2-1);
868                 offset *= 512;
869                 if (lseek64(fd, offset, 0)< 0LL)
870                         ret = 3;
871                 else if (write(fd, st->other, 1024) != 1024)
872                         ret = 4;
873                 else
874                         fsync(fd);
875                 free(st->other);
876                 st->other = NULL;
877                 return ret;
878         }
879
880         offset = MD_NEW_SIZE_SECTORS(dsize>>9);
881
882         offset *= 512;
883
884         if (lseek64(fd, offset, 0)< 0LL)
885                 return 3;
886
887         if (write(fd, super, sizeof(*super)) != sizeof(*super))
888                 return 4;
889
890         if (super->state & (1<<MD_SB_BITMAP_PRESENT)) {
891                 struct bitmap_super_s * bm = (struct bitmap_super_s*)(super+1);
892                 if (__le32_to_cpu(bm->magic) == BITMAP_MAGIC)
893                         if (write(fd, bm, ROUND_UP(sizeof(*bm),4096)) !=
894                             ROUND_UP(sizeof(*bm),4096))
895                             return 5;
896         }
897
898         fsync(fd);
899         return 0;
900 }
901
902 #ifndef MDASSEMBLE
903 static int write_init_super0(struct supertype *st)
904 {
905         mdp_super_t *sb = st->sb;
906         int rv = 0;
907         struct devinfo *di;
908
909         for (di = st->info ; di && ! rv ; di = di->next) {
910
911                 if (di->disk.state & (1 << MD_DISK_FAULTY))
912                         continue;
913                 if (di->fd == -1)
914                         continue;
915                 while (Kill(di->devname, NULL, 0, -1, 1) == 0)
916                         ;
917
918                 sb->disks[di->disk.number].state &= ~(1<<MD_DISK_FAULTY);
919
920                 sb->this_disk = sb->disks[di->disk.number];
921                 sb->sb_csum = calc_sb0_csum(sb);
922                 rv = store_super0(st, di->fd);
923
924                 if (rv == 0 && (sb->state & (1<<MD_SB_BITMAP_PRESENT)))
925                         rv = st->ss->write_bitmap(st, di->fd, NoUpdate);
926
927                 if (rv)
928                         pr_err("failed to write superblock to %s\n",
929                                di->devname);
930         }
931         return rv;
932 }
933 #endif
934
935 static int compare_super0(struct supertype *st, struct supertype *tst)
936 {
937         /*
938          * return:
939          *  0 same, or first was empty, and second was copied
940          *  1 second had wrong number
941          *  2 wrong uuid
942          *  3 wrong other info
943          */
944         mdp_super_t *first = st->sb;
945         mdp_super_t *second = tst->sb;
946         int uuid1[4], uuid2[4];
947
948         if (second->md_magic != MD_SB_MAGIC)
949                 return 1;
950         if (!first) {
951                 if (posix_memalign((void**)&first, 4096,
952                              MD_SB_BYTES +
953                              ROUND_UP(sizeof(struct bitmap_super_s), 4096)) != 0) {
954                         pr_err("could not allocate superblock\n");
955                         return 1;
956                 }
957                 memcpy(first, second, MD_SB_BYTES + sizeof(struct bitmap_super_s));
958                 st->sb = first;
959                 return 0;
960         }
961
962         uuid_from_super0(st, uuid1);
963         uuid_from_super0(tst, uuid2);
964         if (!same_uuid(uuid1, uuid2, 0))
965                 return 2;
966         if (first->major_version != second->major_version ||
967             first->minor_version != second->minor_version ||
968             first->patch_version != second->patch_version ||
969             first->gvalid_words  != second->gvalid_words  ||
970             first->ctime         != second->ctime         ||
971             first->level         != second->level         ||
972             first->size          != second->size          ||
973             first->raid_disks    != second->raid_disks    )
974                 return 3;
975
976         return 0;
977 }
978
979 static void free_super0(struct supertype *st);
980
981 static int load_super0(struct supertype *st, int fd, char *devname)
982 {
983         /* try to read in the superblock
984          * Return:
985          *  0 on success
986          *  1 on cannot get superblock
987          *  2 on superblock meaningless
988          */
989         unsigned long long dsize;
990         unsigned long long offset;
991         mdp_super_t *super;
992         int uuid[4];
993         struct bitmap_super_s *bsb;
994
995         free_super0(st);
996
997         if (!get_dev_size(fd, devname, &dsize))
998                 return 1;
999
1000         if (dsize < MD_RESERVED_SECTORS*512) {
1001                 if (devname)
1002                         pr_err("%s is too small for md: size is %llu sectors.\n",
1003                                devname, dsize);
1004                 return 1;
1005         }
1006         st->devsize = dsize;
1007
1008         offset = MD_NEW_SIZE_SECTORS(dsize>>9);
1009
1010         offset *= 512;
1011
1012         if (lseek64(fd, offset, 0)< 0LL) {
1013                 if (devname)
1014                         pr_err("Cannot seek to superblock on %s: %s\n",
1015                                 devname, strerror(errno));
1016                 return 1;
1017         }
1018
1019         if (posix_memalign((void**)&super, 4096,
1020                            MD_SB_BYTES +
1021                            ROUND_UP(sizeof(bitmap_super_t), 4096)) != 0) {
1022                 pr_err("could not allocate superblock\n");
1023                 return 1;
1024         }
1025
1026         if (read(fd, super, sizeof(*super)) != MD_SB_BYTES) {
1027                 if (devname)
1028                         pr_err("Cannot read superblock on %s\n",
1029                                 devname);
1030                 free(super);
1031                 return 1;
1032         }
1033
1034         if (st->ss && st->minor_version == 9)
1035                 super0_swap_endian(super);
1036
1037         if (super->md_magic != MD_SB_MAGIC) {
1038                 if (devname)
1039                         pr_err("No super block found on %s (Expected magic %08x, got %08x)\n",
1040                                 devname, MD_SB_MAGIC, super->md_magic);
1041                 free(super);
1042                 return 2;
1043         }
1044
1045         if (super->major_version != 0) {
1046                 if (devname)
1047                         pr_err("Cannot interpret superblock on %s - version is %d\n",
1048                                 devname, super->major_version);
1049                 free(super);
1050                 return 2;
1051         }
1052         st->sb = super;
1053
1054         if (st->ss == NULL) {
1055                 st->ss = &super0;
1056                 st->minor_version = super->minor_version;
1057                 st->max_devs = MD_SB_DISKS;
1058                 st->info = NULL;
1059         }
1060
1061         /* Now check on the bitmap superblock */
1062         if ((super->state & (1<<MD_SB_BITMAP_PRESENT)) == 0)
1063                 return 0;
1064         /* Read the bitmap superblock and make sure it looks
1065          * valid.  If it doesn't clear the bit.  An --assemble --force
1066          * should get that written out.
1067          */
1068         if (read(fd, super+1, ROUND_UP(sizeof(struct bitmap_super_s),4096))
1069             != ROUND_UP(sizeof(struct bitmap_super_s),4096))
1070                 goto no_bitmap;
1071
1072         uuid_from_super0(st, uuid);
1073         bsb = (struct bitmap_super_s *)(super+1);
1074         if (__le32_to_cpu(bsb->magic) != BITMAP_MAGIC ||
1075             memcmp(bsb->uuid, uuid, 16) != 0)
1076                 goto no_bitmap;
1077         return 0;
1078
1079  no_bitmap:
1080         super->state &= ~(1<<MD_SB_BITMAP_PRESENT);
1081
1082         return 0;
1083 }
1084
1085 static struct supertype *match_metadata_desc0(char *arg)
1086 {
1087         struct supertype *st = xcalloc(1, sizeof(*st));
1088
1089         st->container_devnm[0] = 0;
1090         st->ss = &super0;
1091         st->info = NULL;
1092         st->minor_version = 90;
1093         st->max_devs = MD_SB_DISKS;
1094         st->sb = NULL;
1095         /* we sometimes get 00.90 */
1096         while (arg[0] == '0' && arg[1] == '0')
1097                 arg++;
1098         if (strcmp(arg, "0") == 0 ||
1099 #ifdef DEFAULT_OLD_METADATA /* ifndef in super1.c */
1100             strcmp(arg, "default") == 0 ||
1101 #endif /* DEFAULT_OLD_METADATA */
1102             strcmp(arg, "0.90") == 0 ||
1103             strcmp(arg, "") == 0 /* no metadata  - i.e. non_persistent */
1104                 )
1105                 return st;
1106
1107         st->minor_version = 91; /* reshape in progress */
1108         if (strcmp(arg, "0.91") == 0) /* For dup_super support */
1109                 return st;
1110
1111         st->minor_version = 9; /* flag for 'byte-swapped' */
1112         if (strcmp(arg, "0.swap")==0 ||
1113             strcmp(arg, "0.9") == 0) /* For dup_super support */
1114                 return st;
1115
1116         free(st);
1117         return NULL;
1118 }
1119
1120 static __u64 avail_size0(struct supertype *st, __u64 devsize,
1121                          unsigned long long data_offset)
1122 {
1123         if (data_offset != 0 && data_offset != INVALID_SECTORS)
1124                 return 0ULL;
1125         if (devsize < MD_RESERVED_SECTORS)
1126                 return 0ULL;
1127         return MD_NEW_SIZE_SECTORS(devsize);
1128 }
1129
1130 static int add_internal_bitmap0(struct supertype *st, int *chunkp,
1131                                 int delay, int write_behind,
1132                                 unsigned long long size, int may_change,
1133                                 int major)
1134 {
1135         /*
1136          * The bitmap comes immediately after the superblock and must be 60K in size
1137          * at most.  The default size is between 30K and 60K
1138          *
1139          * size is in sectors,  chunk is in bytes !!!
1140          */
1141         unsigned long long bits;
1142         unsigned long long max_bits = (60*1024 - sizeof(bitmap_super_t))*8;
1143         unsigned long long min_chunk;
1144         int chunk = *chunkp;
1145         mdp_super_t *sb = st->sb;
1146         bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + MD_SB_BYTES);
1147         int uuid[4];
1148
1149         min_chunk = 4096; /* sub-page chunks don't work yet.. */
1150         bits = (size * 512) / min_chunk + 1;
1151         while (bits > max_bits) {
1152                 min_chunk *= 2;
1153                 bits = (bits+1)/2;
1154         }
1155         if (chunk == UnSet) {
1156                 /* A chunk size less than a few Megabytes gives poor
1157                  * performance without increasing resync noticeably
1158                  */
1159                 chunk = min_chunk;
1160                 if (chunk < 64*1024*1024)
1161                         chunk = 64*1024*1024;
1162         } else if ((unsigned long long)chunk < min_chunk)
1163                 return -EINVAL; /* chunk size too small */
1164
1165         sb->state |= (1<<MD_SB_BITMAP_PRESENT);
1166
1167         memset(bms, 0, sizeof(*bms));
1168         bms->magic = __cpu_to_le32(BITMAP_MAGIC);
1169         bms->version = __cpu_to_le32(major);
1170         uuid_from_super0(st, uuid);
1171         memcpy(bms->uuid, uuid, 16);
1172         bms->chunksize = __cpu_to_le32(chunk);
1173         bms->daemon_sleep = __cpu_to_le32(delay);
1174         bms->sync_size = __cpu_to_le64(size);
1175         bms->write_behind = __cpu_to_le32(write_behind);
1176         *chunkp = chunk;
1177         return 0;
1178 }
1179
1180 static int locate_bitmap0(struct supertype *st, int fd, int node_num)
1181 {
1182         unsigned long long dsize;
1183         unsigned long long offset;
1184
1185         if (!get_dev_size(fd, NULL, &dsize))
1186                 return -1;
1187
1188         if (dsize < MD_RESERVED_SECTORS*512)
1189                 return -1;
1190
1191         offset = MD_NEW_SIZE_SECTORS(dsize>>9);
1192
1193         offset *= 512;
1194
1195         offset += MD_SB_BYTES;
1196
1197         lseek64(fd, offset, 0);
1198         return 0;
1199 }
1200
1201 static int write_bitmap0(struct supertype *st, int fd, enum bitmap_update update)
1202 {
1203         unsigned long long dsize;
1204         unsigned long long offset;
1205         mdp_super_t *sb = st->sb;
1206
1207         int rv = 0;
1208
1209         int towrite, n;
1210         void *buf;
1211
1212         if (!get_dev_size(fd, NULL, &dsize))
1213                 return 1;
1214
1215         if (dsize < MD_RESERVED_SECTORS*512)
1216                 return -1;
1217
1218         offset = MD_NEW_SIZE_SECTORS(dsize>>9);
1219
1220         offset *= 512;
1221
1222         if (lseek64(fd, offset + 4096, 0)< 0LL)
1223                 return 3;
1224
1225         if (posix_memalign(&buf, 4096, 4096))
1226                 return -ENOMEM;
1227
1228         memset(buf, 0xff, 4096);
1229         memcpy(buf,  ((char*)sb)+MD_SB_BYTES, sizeof(bitmap_super_t));
1230         towrite = 60*1024;
1231         while (towrite > 0) {
1232                 n = towrite;
1233                 if (n > 4096)
1234                         n = 4096;
1235                 n = write(fd, buf, n);
1236                 if (n > 0)
1237                         towrite -= n;
1238                 else
1239                         break;
1240                 memset(buf, 0xff, 4096);
1241         }
1242         fsync(fd);
1243         if (towrite)
1244                 rv = -2;
1245
1246         free(buf);
1247         return rv;
1248 }
1249
1250 static void free_super0(struct supertype *st)
1251 {
1252         if (st->sb)
1253                 free(st->sb);
1254         while (st->info) {
1255                 struct devinfo *di = st->info;
1256                 st->info = di->next;
1257                 if (di->fd >= 0)
1258                         close(di->fd);
1259                 free(di);
1260         }
1261         st->sb = NULL;
1262 }
1263
1264 #ifndef MDASSEMBLE
1265 static int validate_geometry0(struct supertype *st, int level,
1266                               int layout, int raiddisks,
1267                               int *chunk, unsigned long long size,
1268                               unsigned long long data_offset,
1269                               char *subdev, unsigned long long *freesize,
1270                               int verbose)
1271 {
1272         unsigned long long ldsize;
1273         int fd;
1274         unsigned int tbmax = 4;
1275
1276         /* prior to linux 3.1, a but limits usable device size to 2TB.
1277          * It was introduced in 2.6.29, but we won't worry about that detail
1278          */
1279         if (get_linux_version() < 3001000)
1280                 tbmax = 2;
1281
1282         if (level == LEVEL_CONTAINER) {
1283                 if (verbose)
1284                         pr_err("0.90 metadata does not support containers\n");
1285                 return 0;
1286         }
1287         if (raiddisks > MD_SB_DISKS) {
1288                 if (verbose)
1289                         pr_err("0.90 metadata supports at most %d devices per array\n",
1290                                 MD_SB_DISKS);
1291                 return 0;
1292         }
1293         if (size >= tbmax * 2ULL*1024*1024*1024) {
1294                 if (verbose)
1295                         pr_err("0.90 metadata supports at most %d terabytes per device\n", tbmax);
1296                 return 0;
1297         }
1298         if (*chunk == UnSet)
1299                 *chunk = DEFAULT_CHUNK;
1300
1301         if (!subdev)
1302                 return 1;
1303
1304         fd = open(subdev, O_RDONLY|O_EXCL, 0);
1305         if (fd < 0) {
1306                 if (verbose)
1307                         pr_err("super0.90 cannot open %s: %s\n",
1308                                 subdev, strerror(errno));
1309                 return 0;
1310         }
1311
1312         if (!get_dev_size(fd, subdev, &ldsize)) {
1313                 close(fd);
1314                 return 0;
1315         }
1316         close(fd);
1317
1318         if (ldsize < MD_RESERVED_SECTORS * 512)
1319                 return 0;
1320         *freesize = MD_NEW_SIZE_SECTORS(ldsize >> 9);
1321         return 1;
1322 }
1323 #endif /* MDASSEMBLE */
1324
1325 struct superswitch super0 = {
1326 #ifndef MDASSEMBLE
1327         .examine_super = examine_super0,
1328         .brief_examine_super = brief_examine_super0,
1329         .export_examine_super = export_examine_super0,
1330         .detail_super = detail_super0,
1331         .brief_detail_super = brief_detail_super0,
1332         .write_init_super = write_init_super0,
1333         .validate_geometry = validate_geometry0,
1334         .add_to_super = add_to_super0,
1335         .copy_metadata = copy_metadata0,
1336 #endif
1337         .match_home = match_home0,
1338         .uuid_from_super = uuid_from_super0,
1339         .getinfo_super = getinfo_super0,
1340         .container_content = container_content0,
1341         .update_super = update_super0,
1342         .init_super = init_super0,
1343         .store_super = store_super0,
1344         .compare_super = compare_super0,
1345         .load_super = load_super0,
1346         .match_metadata_desc = match_metadata_desc0,
1347         .avail_size = avail_size0,
1348         .add_internal_bitmap = add_internal_bitmap0,
1349         .locate_bitmap = locate_bitmap0,
1350         .write_bitmap = write_bitmap0,
1351         .free_super = free_super0,
1352         .name = "0.90",
1353 };