bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem in detecting RAID device!!


From: Andrew Clausen
Subject: Re: Problem in detecting RAID device!!
Date: Thu, 26 Dec 2002 21:20:42 +1100
User-agent: Mutt/1.4i

On Thu, Dec 26, 2002 at 02:15:06PM +0530, Veerapuram Varadhan wrote:
> > Perhaps the regexp /dev/.*[a-z]+[0-9]+[a-z]+[0-9]+ should match
> > devices?
>
> I do not think so, since the regular expression should include "/rd/"
> within it, where actually c0d0 exists. (if i am not wrong :) )

Why?

It could be in any directory, conceivably, so there's no need to
be specific.  The /dev/rd/c0d0 would be matched by that regexp,
for example.

Anyway, I made a patch... want to test it?

Apply with: cat the-patch | (cd parted-1.6.4; patch -p0)


diff -rup ./libparted/linux.c 
/home/parted/common/parted-stable/libparted/linux.c
--- ./libparted/linux.c 2002-11-13 07:42:36.000000000 +1100
+++ /home/parted/common/parted-stable/libparted/linux.c 2002-12-26 
21:17:33.000000000 +1100
@@ -1321,6 +1321,45 @@ linux_sync (PedDevice* dev)
        return 1;
 }
 
+static inline int
+_compare_digit_state (char ch, int need_digit)
+{
+       return !!isdigit (ch) == need_digit;
+}
+
+/* matches the regexp "[^0-9]+[0-9]+[^0-9]+[0-9]+$".
+ * Motivation: accept devices looking like /dev/rd/c0d0, but
+ * not looking like /dev/hda1 and /dev/rd/c0d0p1
+ */
+static int
+_match_rd_device (const char* name)
+{
+       const char* pos;
+       int state;
+
+       /* exclude directory names from test */
+       pos = strrchr(name, '/') ?: name;
+
+       /* states:
+        *      0       non-digits
+        *      1       digits
+        *      2       non-digits
+        *      3       digits
+        */
+       for (state = 0; state < 4; state++) {
+               int want_digits = (state % 2 == 1);
+               do {
+                       if (!*pos)
+                               return 0;
+                       if (!_compare_digit_state (*pos, want_digits))
+                               return 0;
+                       pos++;
+               } while (_compare_digit_state (*pos, want_digits));
+       }
+
+       return *pos == 0;
+}
+
 static int
 _probe_proc_partitions ()
 {
@@ -1343,7 +1382,8 @@ _probe_proc_partitions ()
                /* Heuristic for telling partitions and devices apart
                 * Probably needs to be improved
                 */
-               if (isdigit (part_name [strlen (part_name) - 1]))
+               if (!_match_rd_device (part_name)
+                   && isdigit (part_name [strlen (part_name) - 1]))
                        continue;
 
                strcpy (dev_name, "/dev/");



Cheers,
Andrew




reply via email to

[Prev in Thread] Current Thread [Next in Thread]