printf(" Raid Level : %s\n", c?c:"-unknown-");
if ((int)sb->level >= 0) {
int ddsks=0;
- printf(" Device Size : %d%s\n", sb->size, human_size((long long)sb->size<<10));
+ printf(" Used Dev Size : %d%s\n", sb->size,
+ human_size((long long)sb->size<<10));
switch(sb->level) {
case 1: ddsks=1;break;
case 4:
info->array.ctime = sb->ctime;
info->array.utime = sb->utime;
info->array.chunk_size = sb->chunk_size;
+ info->array.state = sb->state;
info->component_size = sb->size*2;
info->disk.state = sb->this_disk.state;
static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info,
- unsigned long long size, char *ignored_name, char *homehost)
+ unsigned long long size, char *ignored_name, char *homehost,
+ int *uuid)
{
mdp_super_t *sb = malloc(MD_SB_BYTES + sizeof(bitmap_super_t));
int spares;
- int rfd;
memset(sb, 0, MD_SB_BYTES + sizeof(bitmap_super_t));
if (info->major_version == -1) {
return 0;
}
- rfd = open("/dev/urandom", O_RDONLY);
sb->md_magic = MD_SB_MAGIC;
sb->major_version = 0;
sb->minor_version = 90;
sb->patch_version = 0;
sb->gvalid_words = 0; /* ignored */
- if (rfd < 0 || read(rfd, &sb->set_uuid0, 4) != 4)
- sb->set_uuid0 = random();
sb->ctime = time(0);
sb->level = info->level;
if (size != info->size)
sb->raid_disks = info->raid_disks;
sb->md_minor = info->md_minor;
sb->not_persistent = 0;
- if (rfd < 0 || read(rfd, &sb->set_uuid1, 12) != 12) {
- sb->set_uuid1 = random();
- sb->set_uuid2 = random();
- sb->set_uuid3 = random();
+ if (uuid) {
+ sb->set_uuid0 = uuid[0];
+ sb->set_uuid1 = uuid[1];
+ sb->set_uuid2 = uuid[2];
+ sb->set_uuid3 = uuid[3];
+ } else {
+ int rfd = open("/dev/urandom", O_RDONLY);
+ if (rfd < 0 || read(rfd, &sb->set_uuid0, 4) != 4)
+ sb->set_uuid0 = random();
+ if (rfd < 0 || read(rfd, &sb->set_uuid1, 12) != 12) {
+ sb->set_uuid1 = random();
+ sb->set_uuid2 = random();
+ sb->set_uuid3 = random();
+ }
+ if (rfd >= 0)
+ close(rfd);
}
- if (rfd >= 0)
- close(rfd);
if (homehost) {
char buf[20];
char *hash = sha1_buffer(homehost,
static int store_super0(struct supertype *st, int fd, void *sbv)
{
- unsigned long size;
unsigned long long dsize;
unsigned long long offset;
mdp_super_t *super = sbv;
-
-#ifdef BLKGETSIZE64
- if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
- {
- if (ioctl(fd, BLKGETSIZE, &size))
- return 1;
- else
- dsize = ((unsigned long long)size)<<9;
- }
+
+ if (!get_dev_size(fd, NULL, &dsize))
+ return 1;
if (dsize < MD_RESERVED_SECTORS*2*512)
return 2;
int uuid[4];
struct bitmap_super_s *bsb;
-#ifdef BLKGETSIZE64
- if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
- {
- if (ioctl(fd, BLKGETSIZE, &size)) {
- if (devname)
- fprintf(stderr, Name ": cannot find device size for %s: %s\n",
- devname, strerror(errno));
- return 1;
- } else
- dsize = size << 9;
- }
+ if (!get_dev_size(fd, devname, &dsize))
+ return 1;
- if (dsize < MD_RESERVED_SECTORS*2) {
+ if (dsize < MD_RESERVED_SECTORS*512 * 2) {
if (devname)
fprintf(stderr, Name ": %s is too small for md: size is %ld sectors.\n",
devname, size);
void locate_bitmap0(struct supertype *st, int fd, void *sbv)
{
unsigned long long dsize;
- unsigned long size;
unsigned long long offset;
-#ifdef BLKGETSIZE64
- if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
- {
- if (ioctl(fd, BLKGETSIZE, &size))
- return;
- else
- dsize = ((unsigned long long)size)<<9;
- }
- if (dsize < MD_RESERVED_SECTORS*2)
+ if (!get_dev_size(fd, NULL, &dsize))
+ return;
+
+ if (dsize < MD_RESERVED_SECTORS*512 * 2)
return;
offset = MD_NEW_SIZE_SECTORS(dsize>>9);
int write_bitmap0(struct supertype *st, int fd, void *sbv)
{
- unsigned long size;
unsigned long long dsize;
unsigned long long offset;
mdp_super_t *sb = sbv;
int towrite, n;
char buf[4096];
-#ifdef BLKGETSIZE64
- if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
- {
- if (ioctl(fd, BLKGETSIZE, &size))
- return 1;
- else
- dsize = ((unsigned long long)size)<<9;
- }
+ if (!get_dev_size(fd, NULL, &dsize))
+ return 1;
+
- if (dsize < MD_RESERVED_SECTORS*2)
+ if (dsize < MD_RESERVED_SECTORS*512 * 2)
return -1;
offset = MD_NEW_SIZE_SECTORS(dsize>>9);