]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - lib.c
Show all bitmaps while examining bitmap
[thirdparty/mdadm.git] / lib.c
diff --git a/lib.c b/lib.c
index 2c3d9368967224c52a7cb6182ce87400f33c9d04..6808f62d77ced0d6b044f48fa43a9b289f55b16b 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -23,6 +23,7 @@
  */
 
 #include       "mdadm.h"
+#include       "dlink.h"
 #include       <ctype.h>
 
 /* This fill contains various 'library' style function.  They
@@ -57,6 +58,32 @@ static int mdp_major = -1;
        return mdp_major;
 }
 
+char *devid2kname(int devid)
+{
+       char path[30];
+       char link[200];
+       static char devnm[32];
+       char *cp;
+       int n;
+
+       /* Look at the
+        * /sys/dev/block/%d:%d link which must look like
+        * and take the last component.
+        */
+       sprintf(path, "/sys/dev/block/%d:%d", major(devid),
+               minor(devid));
+       n = readlink(path, link, sizeof(link)-1);
+       if (n > 0) {
+               link[n] = 0;
+               cp = strrchr(link, '/');
+               if (cp) {
+                       strcpy(devnm, cp+1);
+                       return devnm;
+               }
+       }
+       return NULL;
+}
+
 char *devid2devnm(int devid)
 {
        char path[30];
@@ -112,8 +139,6 @@ char *fd2devnm(int fd)
        return NULL;
 }
 
-
-
 /*
  * convert a major/minor pair for a block device into a name in /dev, if possible.
  * On the first call, walk /dev collecting name.
@@ -233,8 +258,6 @@ char *map_dev_preferred(int major, int minor, int create,
        return preferred ? preferred : regular;
 }
 
-
-
 /* conf_word gets one word from the conf file.
  * if "allow_key", then accept words at the start of a line,
  * otherwise stop when such a word is found.
@@ -400,3 +423,53 @@ int use_udev(void)
        }
        return use;
 }
+
+unsigned long GCD(unsigned long a, unsigned long b)
+{
+       while (a != b) {
+               if (a < b)
+                       b -= a;
+               if (b < a)
+                       a -= b;
+       }
+       return a;
+}
+
+/*
+ * conf_line reads one logical line from the conffile or mdstat.
+ * It skips comments and continues until it finds a line that starts
+ * with a non blank/comment.  This character is pushed back for the next call
+ * A doubly linked list of words is returned.
+ * the first word will be a keyword.  Other words will have had quotes removed.
+ */
+
+char *conf_line(FILE *file)
+{
+       char *w;
+       char *list;
+
+       w = conf_word(file, 1);
+       if (w == NULL) return NULL;
+
+       list = dl_strdup(w);
+       free(w);
+       dl_init(list);
+
+       while ((w = conf_word(file,0))){
+               char *w2 = dl_strdup(w);
+               free(w);
+               dl_add(list, w2);
+       }
+/*    printf("got a line\n");*/
+       return list;
+}
+
+void free_line(char *line)
+{
+       char *w;
+       for (w=dl_next(line); w != line; w=dl_next(line)) {
+               dl_del(w);
+               dl_free(w);
+       }
+       dl_free(line);
+}