]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super1.c
Release 2.5.1
[thirdparty/mdadm.git] / super1.c
index b24bceae2ea291f6461638c7fe4487d5f349dac2..9dc66448d8c0fe1148f9b1e09612e345307c6238 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -104,7 +104,7 @@ struct mdp_superblock_1 {
 #define        MD_FEATURE_ALL                  (1|2|4)
 
 #ifndef offsetof
-#define offsetof(t,f) ((int)&(((t*)0)->f))
+#define offsetof(t,f) ((size_t)&(((t*)0)->f))
 #endif
 static unsigned int calc_sb_1_csum(struct mdp_superblock_1 * sb)
 {
@@ -308,10 +308,20 @@ static void brief_examine_super1(void *sbv)
 {
        struct mdp_superblock_1 *sb = sbv;
        int i;
+       char *nm;
+
+       nm = strchr(sb->set_name, ':');
+       if (nm)
+               nm++;
+       else if (sb->set_name[0])
+               nm = sb->set_name;
+       else
+               nm = "??";
 
        char *c=map_num(pers, __le32_to_cpu(sb->level));
 
-       printf("ARRAY /dev/?? level=%s metadata=1 num-devices=%d UUID=",
+       printf("ARRAY /dev/md/%s level=%s metadata=1 num-devices=%d UUID=",
+              nm,
               c?c:"-unknown-", sb->raid_disks);
        for (i=0; i<16; i++) {
                printf("%02x", sb->set_uuid[i]);
@@ -357,6 +367,16 @@ static void brief_detail_super1(void *sbv)
 
 #endif
 
+static int match_home1(void *sbv, char *homehost)
+{
+       struct mdp_superblock_1 *sb = sbv;
+       int l = homehost ? strlen(homehost) : 0;
+
+       return (l > 0 && l < 32 &&
+               sb->set_name[l] == ':' &&
+               strncmp(sb->set_name, homehost, l) == 0);
+}
+
 static void uuid_from_super1(int uuid[4], void * sbv)
 {
        struct mdp_superblock_1 *super = sbv;
@@ -692,10 +712,11 @@ static int store_super1(struct supertype *st, int fd, void *sbv)
 
        if (sb->feature_map & __cpu_to_le32(MD_FEATURE_BITMAP_OFFSET)) {
                struct bitmap_super_s *bm = (struct bitmap_super_s*)
-                       ((char*)sb)+1024;
+                       (((char*)sb)+1024);
                if (__le32_to_cpu(bm->magic) == BITMAP_MAGIC) {
                        locate_bitmap1(st, fd, sbv);
-                       write(fd, bm, sizeof(*bm));
+                       if (write(fd, bm, sizeof(*bm)) != sizeof(*bm))
+                           return 5;
                }
        }
        fsync(fd);
@@ -1191,6 +1212,7 @@ struct superswitch super1 = {
        .detail_super = detail_super1,
        .brief_detail_super = brief_detail_super1,
 #endif
+       .match_home = match_home1,
        .uuid_from_super = uuid_from_super1,
        .getinfo_super = getinfo_super1,
        .update_super = update_super1,