Re: large device major/minor numbers not supported



Hi all,

here's my second try. Leonard, you were right. The code was too blown-up. I've shortened it a bit.

But I would like to keep the format_device_number() function, as we can surely need it in other places. What about adding it to utilunix.c?

I've also fixed the off-by-one error in ilog10.

Roland
Index: screen.c
===================================================================
RCS file: /cvsroot/mc/mc/src/screen.c,v
retrieving revision 1.199
diff -u -p -u -r1.199 screen.c
--- screen.c	16 Nov 2004 23:54:15 -0000	1.199
+++ screen.c	23 Jan 2005 18:46:49 -0000
@@ -45,6 +45,7 @@
 #include "execute.h"
 #include "widget.h"
 #include "menu.h"		/* menubar_visible */
+#include "utilunix.h"
 #define WANT_WIDGETS
 #include "main.h"		/* the_menubar */
 
@@ -190,6 +191,31 @@ string_file_name (file_entry *fe, int le
     return buffer;
 }
 
+static inline int ilog10(dev_t n)
+{
+    int digits = 0;
+    do {
+	digits++, n /= 10;
+    } while (n != 0);
+    return digits;
+}
+
+static void format_device_number (char *buf, size_t bufsize, dev_t dev)
+{
+    dev_t major_dev = major(dev);
+    dev_t minor_dev = minor(dev);
+    int major_digits = ilog10(major_dev);
+    int minor_digits = ilog10(minor_dev);
+
+    g_assert(bufsize >= 1);
+    if (major_digits + 1 + minor_digits + 1 <= bufsize) {
+        g_snprintf(buf, bufsize, "%lu,%lu", (unsigned long) major_dev,
+                   (unsigned long) minor_dev);
+    } else {
+        g_snprintf(buf, bufsize, _("[dev]"));
+    }
+}
+
 /* size */
 static const char *
 string_file_size (file_entry *fe, int len)
@@ -203,9 +229,7 @@ string_file_size (file_entry *fe, int le
 
 #ifdef HAVE_STRUCT_STAT_ST_RDEV
     if (S_ISBLK (fe->st.st_mode) || S_ISCHR (fe->st.st_mode))
-        g_snprintf (buffer, sizeof (buffer), "%3d,%3d",
-		    (int) ((fe->st.st_rdev >> 8) & 0xff),
-		    (int) (fe->st.st_rdev & 0xff));
+        format_device_number (buffer, len + 1, fe->st.st_rdev);
     else
 #endif
     {


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