/* The argument structure */
struct blkpg_ioctl_arg {
- int op;
- int flags;
- int datalen;
- void *data;
+ int op;
+ int flags;
+ int datalen;
+ void *data;
};
/* The subfunctions (for the op field) */
int md_get_version(int fd)
{
- struct stat stb;
- mdu_version_t vers;
+ struct stat stb;
+ mdu_version_t vers;
- if (fstat(fd, &stb)<0)
- return -1;
- if ((S_IFMT&stb.st_mode) != S_IFBLK)
- return -1;
+ if (fstat(fd, &stb)<0)
+ return -1;
+ if ((S_IFMT&stb.st_mode) != S_IFBLK)
+ return -1;
- if (ioctl(fd, RAID_VERSION, &vers) == 0)
- return (vers.major*10000) + (vers.minor*100) + vers.patchlevel;
- if (errno == EACCES)
- return -1;
- if (major(stb.st_rdev) == MD_MAJOR)
- return (3600);
- return -1;
+ if (ioctl(fd, RAID_VERSION, &vers) == 0)
+ return (vers.major*10000) + (vers.minor*100) + vers.patchlevel;
+ if (errno == EACCES)
+ return -1;
+ if (major(stb.st_rdev) == MD_MAJOR)
+ return (3600);
+ return -1;
}
int get_linux_version()
* followed by 'K', 'M', or 'G'.
* Without a suffix, K is assumed.
* Number returned is in sectors (half-K)
- * 0 returned on error.
+ * INVALID_SECTORS returned on error.
*/
char *c;
long long s = strtoll(size, &c, 10);
c++;
s *= 1024 * 1024 * 2;
break;
+ case 's': /* sectors */
+ c++;
+ break;
}
} else
- s = 0;
+ s = INVALID_SECTORS;
if (*c)
- s = 0;
+ s = INVALID_SECTORS;
return s;
}
/* there must be one of the 'copies' form 'first' */
int n = copies;
int cnt = 0;
+ int this = first;
while (n--) {
- if (avail[first])
+ if (avail[this])
cnt++;
- first = (first+1) % raid_disks;
+ this = (this+1) % raid_disks;
}
if (cnt == 0)
return 0;
-
+ first = (first+(layout&255)) % raid_disks;
} while (first != 0);
return 1;
char *level;
struct supertype *st = guess_super(fd);
- if (!st) return 0;
- st->ignore_hw_compat = 1;
+ if (!st)
+ return 0;
st->ss->load_super(st, fd, name);
/* Looks like a raid array .. */
pr_err("%s appears to be part of a raid array:\n",
return buf;
}
-char *human_size_brief(long long bytes)
+char *human_size_brief(long long bytes, int prefix)
{
static char buf[30];
* gigabytes, as that shows more precision and isn't
* too large a number.
* Terabytes are not yet handled.
+ *
+ * If prefix == IEC, we mean prefixes like kibi,mebi,gibi etc.
+ * If prefix == JEDEC, we mean prefixes like kilo,mega,giga etc.
*/
if (bytes < 5000*1024)
buf[0] = 0;
- else if (bytes < 2*1024LL*1024LL*1024LL) {
- long cMiB = (bytes / ( (1LL<<20) / 200LL ) +1) /2;
- snprintf(buf, sizeof(buf), " (%ld.%02ldMiB)",
- cMiB/100 , cMiB % 100);
- } else {
- long cGiB = (bytes / ( (1LL<<30) / 200LL ) +1) /2;
- snprintf(buf, sizeof(buf), " (%ld.%02ldGiB)",
- cGiB/100 , cGiB % 100);
+ else if (prefix == IEC) {
+ if (bytes < 2*1024LL*1024LL*1024LL) {
+ long cMiB = (bytes / ( (1LL<<20) / 200LL ) +1) /2;
+ snprintf(buf, sizeof(buf), "%ld.%02ldMiB",
+ cMiB/100 , cMiB % 100);
+ } else {
+ long cGiB = (bytes / ( (1LL<<30) / 200LL ) +1) /2;
+ snprintf(buf, sizeof(buf), "%ld.%02ldGiB",
+ cGiB/100 , cGiB % 100);
+ }
}
+ else if (prefix == JEDEC) {
+ if (bytes < 2*1024LL*1024LL*1024LL) {
+ long cMB = (bytes / ( 1000000LL / 200LL ) +1) /2;
+ snprintf(buf, sizeof(buf), "%ld.%02ldMB",
+ cMB/100, cMB % 100);
+ } else {
+ long cGB = (bytes / (1000000000LL/200LL ) +1) /2;
+ snprintf(buf, sizeof(buf), "%ld.%02ldGB",
+ cGB/100 , cGB % 100);
+ }
+ }
+ else
+ buf[0] = 0;
return buf;
}
st->ss = orig->ss;
st->max_devs = orig->max_devs;
st->minor_version = orig->minor_version;
+ st->ignore_hw_compat = orig->ignore_hw_compat;
st->sb = NULL;
st->info = NULL;
return st;
rv = superlist[bestsuper]->load_super(st, fd, NULL);
if (rv == 0) {
superlist[bestsuper]->free_super(st);
- st->ignore_hw_compat = 0;
return st;
}
}
return 0;
}
-void get_one_disk(int mdfd, mdu_array_info_t *ainf, mdu_disk_info_t *disk)
-{
- int d;
-
- ioctl(mdfd, GET_ARRAY_INFO, ainf);
- for (d = 0 ; d < MAX_DISKS ; d++) {
- if (ioctl(mdfd, GET_DISK_INFO, disk) == 0 &&
- (disk->major || disk->minor))
- return;
- }
-}
-
int open_container(int fd)
{
/* 'fd' is a block device. Find out if it is in use
continue;
if (de->d_name[0] == '.')
continue;
+ /* Need to make sure it is a container and not a volume */
+ sprintf(e, "/%s/md/metadata_version", de->d_name);
+ dfd = open(path, O_RDONLY);
+ if (dfd < 0)
+ continue;
+ n = read(dfd, buf, sizeof(buf));
+ close(dfd);
+ if (n <= 0 || (unsigned)n >= sizeof(buf))
+ continue;
+ buf[n] = 0;
+ if (strncmp(buf, "external", 8) != 0 ||
+ n < 10 ||
+ buf[9] == '/')
+ continue;
sprintf(e, "/%s/dev", de->d_name);
dfd = open(path, O_RDONLY);
if (dfd < 0)
}
return disks;
}
+
+/* Checks if paths point to the same device
+ * Returns 0 if they do.
+ * Returns 1 if they don't.
+ * Returns -1 if something went wrong,
+ * e.g. paths are empty or the files
+ * they point to don't exist */
+int compare_paths (char* path1, char* path2)
+{
+ struct stat st1,st2;
+
+ if (path1 == NULL || path2 == NULL)
+ return -1;
+ if (stat(path1,&st1) != 0)
+ return -1;
+ if (stat(path2,&st2) != 0)
+ return -1;
+ if ((st1.st_ino == st2.st_ino) && (st1.st_dev == st2.st_dev))
+ return 0;
+ return 1;
+}