char volname[BLKPG_VOLNAMELTH]; /* volume label */
};
-/* partition table structures so we can check metadata position
- * against the end of the last partition.
- * Only handle MBR ant GPT partition tables.
- */
-struct MBR_part_record {
- __u8 bootable;
- __u8 first_head;
- __u8 first_sector;
- __u8 first_cyl;
- __u8 part_type;
- __u8 last_head;
- __u8 last_sector;
- __u8 last_cyl;
- __u32 first_sect_lba;
- __u32 blocks_num;
-};
-
-struct MBR {
- __u8 pad[446];
- struct MBR_part_record parts[4];
- __u16 magic;
-} __attribute__((packed));
-
-struct GPT_part_entry {
- unsigned char type_guid[16];
- unsigned char partition_guid[16];
- __u64 starting_lba;
- __u64 ending_lba;
- unsigned char attr_bits[8];
- unsigned char name[72];
-} __attribute__((packed));
-
-struct GPT {
- __u64 magic;
- __u32 revision;
- __u32 header_size;
- __u32 crc;
- __u32 pad1;
- __u64 current_lba;
- __u64 backup_lba;
- __u64 first_lba;
- __u64 last_lba;
- __u8 guid[16];
- __u64 part_start;
- __u32 part_cnt;
- __u32 part_size;
- __u32 part_crc;
- __u8 pad2[420];
-} __attribute__((packed));
+#include "part.h"
/* Force a compilation error if condition is true */
#define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition))
aren't permitted). */
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
-
-/* MBR/GPT magic numbers */
-#define MBR_SIGNATURE_MAGIC __cpu_to_le16(0xAA55)
-#define GPT_SIGNATURE_MAGIC __cpu_to_le64(0x5452415020494645ULL)
-
-#define MBR_PARTITIONS 4
-#define MBR_GPT_PARTITION_TYPE 0xEE
-
/*
* Parse a 128 bit uuid in 4 integers
* format is 32 hexx nibbles with options :.<space> separator
int minor;
if (!dev) return -1;
+ flags |= O_DIRECT;
major = strtoul(dev, &e, 0);
if (e > dev && *e == ':' && e[1] &&
(minor = strtoul(e+1, &e, 0)) >= 0 &&
*e == 0) {
- snprintf(devname, sizeof(devname), "/dev/.tmp.md.%d:%d:%d",
- (int)getpid(), major, minor);
- if (mknod(devname, S_IFBLK|0600, makedev(major, minor))==0) {
- fd = open(devname, flags|O_DIRECT);
- unlink(devname);
+ char *path = map_dev(major, minor, 0);
+ if (path)
+ fd = open(path, flags);
+ if (fd < 0) {
+ snprintf(devname, sizeof(devname), "/dev/.tmp.md.%d:%d:%d",
+ (int)getpid(), major, minor);
+ if (mknod(devname, S_IFBLK|0600, makedev(major, minor))==0) {
+ fd = open(devname, flags);
+ unlink(devname);
+ }
+ }
+ if (fd < 0) {
+ snprintf(devname, sizeof(devname), "/tmp/.tmp.md.%d:%d:%d",
+ (int)getpid(), major, minor);
+ if (mknod(devname, S_IFBLK|0600, makedev(major, minor))==0) {
+ fd = open(devname, flags);
+ unlink(devname);
+ }
}
} else
- fd = open(dev, flags|O_DIRECT);
+ fd = open(dev, flags);
return fd;
}
dprintf("%s: timeout waiting for %s\n", __func__, dev);
}
-struct superswitch *superlist[] = { &super0, &super1, &super_ddf, &super_imsm, NULL };
+struct superswitch *superlist[] =
+{
+ &super0, &super1,
+ &super_ddf, &super_imsm,
+ &mbr, &gpt,
+ NULL };
#if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
return st;
}
-struct supertype *guess_super(int fd)
+struct supertype *guess_super_type(int fd, enum guess_types guess_type)
{
/* try each load_super to find the best match,
* and return the best superswitch
*/
struct superswitch *ss;
struct supertype *st;
- unsigned long besttime = 0;
+ time_t besttime = 0;
int bestsuper = -1;
int i;
for (i=0 ; superlist[i]; i++) {
int rv;
ss = superlist[i];
+ if (guess_type == guess_array && ss->add_to_super == NULL)
+ continue;
+ if (guess_type == guess_partitions && ss->add_to_super != NULL)
+ continue;
memset(st, 0, sizeof(*st));
rv = ss->load_super(st, fd, NULL);
if (rv == 0) {
struct GPT_part_entry *part;
unsigned long long curr_part_end;
unsigned all_partitions, entry_size;
- int part_nr;
+ unsigned part_nr;
*endofpart = 0;
struct MBR boot_sect;
struct MBR_part_record *part;
unsigned long long curr_part_end;
- int part_nr;
+ unsigned part_nr;
int retval = 0;
*endofpart = 0;
continue;
n = read(dfd, buf, sizeof(buf));
close(dfd);
- if (n <= 0 || n >= sizeof(buf))
+ if (n <= 0 || (unsigned)n >= sizeof(buf))
continue;
buf[n] = 0;
if (sscanf(buf, "%d:%d", &major, &minor) != 2)
if (is_container_member(ent, container)) {
char *inst = &ent->metadata_version[10+strlen(container)+1];
- if (strcmp(inst, subarray) == 0)
+ if (!subarray || strcmp(inst, subarray) == 0)
break;
}
}
return ent != NULL;
}
+int is_container_active(char *container)
+{
+ return is_subarray_active(NULL, container);
+}
+
/* open_subarray - opens a subarray in a container
* @dev: container device name
* @st: supertype with only ->subarray set
if ((S_IFMT & st->st_mode) == S_IFBLK) {
if (major(st->st_rdev) == MD_MAJOR)
return minor(st->st_rdev);
- else if (major(st->st_rdev) == get_mdp_major())
+ else if (major(st->st_rdev) == (unsigned)get_mdp_major())
return -1- (minor(st->st_rdev)>>MdpMinorShift);
/* must be an extended-minor partition. Look at the
return NoMdDev;
}
-char *pid_dir = VAR_RUN;
-
int mdmon_pid(int devnum)
{
char path[100];
char pid[10];
int fd;
int n;
- sprintf(path, "%s/%s.pid", pid_dir, devnum2devname(devnum));
+ char *devname = devnum2devname(devnum);
+
+ sprintf(path, "%s/%s.pid", MDMON_DIR, devname);
+ free(devname);
+
fd = open(path, O_RDONLY | O_NOATIME, 0);
if (fd < 0)