int role;
info->array.major_version = 1;
- info->array.minor_version = __le32_to_cpu(sb->feature_map);
+ info->array.minor_version = st->minor_version;
info->array.patch_version = 0;
info->array.raid_disks = __le32_to_cpu(sb->raid_disks);
info->array.level = __le32_to_cpu(sb->level);
info->disk.raid_disk = role;
}
info->events = __le64_to_cpu(sb->events);
+ sprintf(info->text_version, "1.%d", st->minor_version);
memcpy(info->uuid, sb->set_uuid, 16);
__le64_to_cpu(sb->data_offset)) {
/* set data_size to device size less data_offset */
struct misc_dev_info *misc = (struct misc_dev_info*)
- (st->sb + 1024 + sizeof(struct bitmap_super_s));
+ (st->sb + 1024 + 512);
printf("Size was %llu\n", (unsigned long long)
__le64_to_cpu(sb->data_size));
sb->data_size = __cpu_to_le64(
static int init_super1(struct supertype *st, mdu_array_info_t *info,
unsigned long long size, char *name, char *homehost, int *uuid)
{
- struct mdp_superblock_1 *sb = malloc(1024 + sizeof(bitmap_super_t) +
- sizeof(struct misc_dev_info));
+ struct mdp_superblock_1 *sb;
int spares;
int rfd;
char defname[10];
+
+ posix_memalign((void**)&sb, 512, (1024 + 512 +
+ sizeof(struct misc_dev_info)));
memset(sb, 0, 1024);
st->sb = sb;
- if (info->major_version == -1) {
+ if (info == NULL) {
/* zeroing superblock */
return 0;
}
else
*rp = 0xfffe;
+ sb->dev_number = __cpu_to_le32(dk->number);
+ sb->sb_csum = calc_sb_1_csum(sb);
+
dip = (struct devinfo **)&st->info;
while (*dip)
dip = &(*dip)->next;
return 3;
sbsize = sizeof(*sb) + 2 * __le32_to_cpu(sb->max_dev);
+ sbsize = (sbsize+511)&(~511UL);
if (write(fd, sb, sbsize) != sbsize)
return 4;
(((char*)sb)+1024);
if (__le32_to_cpu(bm->magic) == BITMAP_MAGIC) {
locate_bitmap1(st, fd);
- if (write(fd, bm, sizeof(*bm)) != sizeof(*bm))
+ if (write(fd, bm, ROUND_UP(sizeof(*bm),512)) !=
+ ROUND_UP(sizeof(*bm),512))
return 5;
}
}
for (di = st->info; di && ! rv ; di = di->next) {
if (di->disk.state == 1)
continue;
+ if (di->fd < 0)
+ continue;
Kill(di->devname, 0, 1, 1);
Kill(di->devname, 0, 1, 1);
- if (di->fd < 0) {
- fprintf(stderr,
- Name": Failed to open %s to write superblock\n",
- di->devname);
- return -1;
- }
sb->dev_number = __cpu_to_le32(di->disk.number);
if (di->disk.state & (1<<MD_DISK_WRITEMOSTLY))
sb->devflags |= __cpu_to_le32(WriteMostly1);
return 1;
if (!first) {
- first = malloc(1024+sizeof(bitmap_super_t) +
+ posix_memalign((void**)&first, 512,
+ 1024 + 512 +
sizeof(struct misc_dev_info));
- memcpy(first, second, 1024+sizeof(bitmap_super_t) +
+ memcpy(first, second, 1024 + 512 +
sizeof(struct misc_dev_info));
st->sb = first;
return 0;
free_super1(st);
+ if (st->subarray[0])
+ return 1;
+
if (st->ss == NULL || st->minor_version == -1) {
int bestvers = -1;
struct supertype tst;
__u64 bestctime = 0;
/* guess... choose latest ctime */
+ memset(&tst, 0, sizeof(tst));
tst.ss = &super1;
- tst.sb = NULL;
for (tst.minor_version = 0; tst.minor_version <= 2 ; tst.minor_version++) {
switch(load_super1(&tst, fd, devname)) {
case 0: super = tst.sb;
return 1;
}
- super = malloc(1024 + sizeof(bitmap_super_t) +
+ posix_memalign((void**)&super, 512,
+ 1024 + 512 +
sizeof(struct misc_dev_info));
if (read(fd, super, 1024) != 1024) {
bsb = (struct bitmap_super_s *)(((char*)super)+1024);
- misc = (struct misc_dev_info*) (bsb+1);
+ misc = (struct misc_dev_info*) (((char*)super)+1024+512);
misc->device_size = dsize;
/* Now check on the bitmap superblock */
* should get that written out.
*/
locate_bitmap1(st, fd);
- if (read(fd, ((char*)super)+1024, sizeof(struct bitmap_super_s))
- != sizeof(struct bitmap_super_s))
+ if (read(fd, ((char*)super)+1024, 512)
+ != 512)
goto no_bitmap;
uuid_from_super1(st, uuid);
struct supertype *st = malloc(sizeof(*st));
if (!st) return st;
+ memset(st, 0, sizeof(*st));
st->ss = &super1;
st->max_devs = 384;
st->sb = NULL;
int rv = 0;
int towrite, n;
- char buf[4096];
+ char abuf[4096+512];
+ char *buf = (char*)(((long)(abuf+512))&~511UL);
locate_bitmap1(st, fd);
- if (write(fd, ((char*)sb)+1024, sizeof(bitmap_super_t)) !=
- sizeof(bitmap_super_t))
- return -2;
+ memset(buf, 0xff, 4096);
+ memcpy(buf, ((char*)sb)+1024, sizeof(bitmap_super_t));
+
towrite = __le64_to_cpu(bms->sync_size) / (__le32_to_cpu(bms->chunksize)>>9);
towrite = (towrite+7) >> 3; /* bits to bytes */
- memset(buf, 0xff, sizeof(buf));
+ towrite += sizeof(bitmap_super_t);
+ towrite = ROUND_UP(towrite, 512);
while (towrite > 0) {
n = towrite;
- if (n > sizeof(buf))
- n = sizeof(buf);
+ if (n > 4096)
+ n = 4096;
n = write(fd, buf, n);
if (n > 0)
towrite -= n;
else
break;
+ memset(buf, 0xff, 4096);
}
fsync(fd);
if (towrite)
static int validate_geometry1(struct supertype *st, int level,
int layout, int raiddisks,
int chunk, unsigned long long size,
- char *subdev, unsigned long long *freesize)
+ char *subdev, unsigned long long *freesize,
+ int verbose)
{
unsigned long long ldsize;
int fd;
fd = open(subdev, O_RDONLY|O_EXCL, 0);
if (fd < 0) {
- fprintf(stderr, Name ": Cannot open %s: %s\n",
- subdev, strerror(errno));
+ if (verbose)
+ fprintf(stderr, Name ": super1.x cannot open %s: %s\n",
+ subdev, strerror(errno));
return 0;
}
+
if (!get_dev_size(fd, subdev, &ldsize)) {
close(fd);
return 0;
.write_bitmap = write_bitmap1,
.free_super = free_super1,
.validate_geometry = validate_geometry1,
- .major = 1,
#if __BYTE_ORDER == BIG_ENDIAN
.swapuuid = 0,
#else