]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
fname_as_uuid: print uuids msb first
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index 7fe835a412411c9cc88e00cad86988af85a09ef1..4c0494236dfd6a97bf0d838d083346cf95c467ae 100644 (file)
--- a/util.c
+++ b/util.c
@@ -269,6 +269,27 @@ void copy_uuid(void *a, int b[4], int swapuuid)
                memcpy(a, b, 16);
 }
 
+char *fname_from_uuid(struct supertype *st, struct mdinfo *info, char *buf, char sep)
+{
+       int i, j;
+       int id;
+       char uuid[16];
+       char *c = buf;
+       strcpy(c, "UUID-");
+       c += strlen(c);
+       copy_uuid(uuid, info->uuid, st->ss->swapuuid);
+       for (i = 0; i < 4; i++) {
+               id = uuid[i];
+               if (i)
+                       *c++ = sep;
+               for (j = 3; j >= 0; j--) {
+                       sprintf(c,"%02x", (unsigned char) uuid[j+4*i]);
+                       c+= 2;
+               }
+       }
+       return buf;
+}
+
 #ifndef MDASSEMBLE
 int check_ext2(int fd, char *name)
 {
@@ -633,7 +654,6 @@ unsigned long long calc_array_size(int level, int raid_disks, int layout,
        return data_disks * devsize;
 }
 
-#if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
 int get_mdp_major(void)
 {
 static int mdp_major = -1;
@@ -662,8 +682,7 @@ static int mdp_major = -1;
        return mdp_major;
 }
 
-
-
+#if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
 char *get_md_name(int dev)
 {
        /* find /dev/md%d or /dev/md/%d or make a device /dev/.tmp.md%d */
@@ -1001,6 +1020,57 @@ int open_container(int fd)
        return -1;
 }
 
+int add_disk(int mdfd, struct supertype *st,
+            struct mdinfo *sra, struct mdinfo *info)
+{
+       /* Add a device to an array, in one of 2 ways. */
+       int rv;
+#ifndef MDASSEMBLE
+       if (st->ss->external) {
+               rv = sysfs_add_disk(sra, info);
+               if (! rv) {
+                       struct mdinfo *sd2;
+                       for (sd2 = sra->devs; sd2; sd2=sd2->next)
+                               if (sd2 == info)
+                                       break;
+                       if (sd2 == NULL) {
+                               sd2 = malloc(sizeof(*sd2));
+                               *sd2 = *info;
+                               sd2->next = sra->devs;
+                               sra->devs = sd2;
+                       }
+               }
+       } else
+#endif
+               rv = ioctl(mdfd, ADD_NEW_DISK, &info->disk);
+       return rv;
+}
+
+int set_array_info(int mdfd, struct supertype *st, struct mdinfo *info)
+{
+       /* Initialise kernel's knowledge of array.
+        * This varies between externally managed arrays
+        * and older kernels
+        */
+       int vers = md_get_version(mdfd);
+       int rv;
+
+#ifndef MDASSEMBLE
+       if (st->ss->external)
+               rv = sysfs_set_array(info, vers);
+       else
+#endif
+               if ((vers % 100) >= 1) { /* can use different versions */
+               mdu_array_info_t inf;
+               memset(&inf, 0, sizeof(inf));
+               inf.major_version = info->array.major_version;
+               inf.minor_version = info->array.minor_version;
+               rv = ioctl(mdfd, SET_ARRAY_INFO, &inf);
+       } else
+               rv = ioctl(mdfd, SET_ARRAY_INFO, NULL);
+       return rv;
+}
+
 char *devnum2devname(int num)
 {
        char name[100];
@@ -1145,7 +1215,7 @@ int env_no_mdmon(void)
        return 0;
 }
 
-
+#ifndef MDASSEMBLE
 int flush_metadata_updates(struct supertype *st)
 {
        int sfd;
@@ -1186,7 +1256,7 @@ void append_metadata_update(struct supertype *st, void *buf, int len)
        *st->update_tail = mu;
        st->update_tail = &mu->next;
 }
-
+#endif /* MDASSEMBLE */
 
 #ifdef __TINYC__
 /* tinyc doesn't optimize this check in ioctl.h out ... */