[klibc] bdevname() interface to print a dev_t instead of %x

Add a bdevname() function to print a dev_t (for block devices);
for now print (%u,%u) but we can add sysfs search later.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
diff --git a/usr/kinit/Kbuild b/usr/kinit/Kbuild
index f69cd87..bb54c83 100644
--- a/usr/kinit/Kbuild
+++ b/usr/kinit/Kbuild
@@ -3,8 +3,9 @@
 #
 
 static-y := kinit
-kinit-y  := kinit.o do_mounts.o getintfile.o initrd.o open.o readfile.o xpio.o
-kinit-y  += do_mounts_md.o do_mounts_mtd.o nfsroot.o resume.o ramdisk_load.o
+kinit-y  := kinit.o do_mounts.o ramdisk_load.o initrd.o
+kinit-y	 += devname.o getintfile.o open.o readfile.o xpio.o
+kinit-y  += do_mounts_md.o do_mounts_mtd.o nfsroot.o resume.o
 
 kinit-y  += ipconfig/
 kinit-y  += nfsmount/
diff --git a/usr/kinit/devname.c b/usr/kinit/devname.c
new file mode 100644
index 0000000..55d9974
--- /dev/null
+++ b/usr/kinit/devname.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/sysmacros.h>
+#include "kinit.h"
+
+/*
+ * devname.c
+ *
+ * Single interface to print a dev_t; we might end up adding sysfs
+ * lookup here at some point...
+ */
+const char *bdevname(dev_t dev)
+{
+	static char buf[16];
+	snprintf(buf, sizeof buf, "(%u,%u)", major(dev), minor(dev));
+	return buf;
+}
diff --git a/usr/kinit/do_mounts.c b/usr/kinit/do_mounts.c
index 97f37b2..acf57f4 100644
--- a/usr/kinit/do_mounts.c
+++ b/usr/kinit/do_mounts.c
@@ -261,12 +261,12 @@
 		 * Allow the user to distinguish between failed open
 		 * and bad superblock on root device.
 		 */
-		fprintf(stderr, "%s: Cannot open root device \"%04x\"\n",
-			progname, root_dev);
+		fprintf(stderr, "%s: Cannot open root device %s\n",
+			progname, bdevname(root_dev));
 		return -errno;
 	} else {
-		fprintf(stderr, "%s: Unable to mount root fs on \"%04x\"\n",
-			progname, root_dev);
+		fprintf(stderr, "%s: Unable to mount root fs on device %s\n",
+			progname, bdevname(root_dev));
 		return -ESRCH;
 	}
 
@@ -337,7 +337,7 @@
 		root_dev = Root_NFS;
 	}
 
-	DEBUG(("kinit: root_dev = %#x\n", root_dev));
+	DEBUG(("kinit: root_dev = %s\n", bdevname(root_dev)));
 
 	if ( initrd_load(argc, argv, root_dev) ) {
 		DEBUG(("initrd loaded\n"));
diff --git a/usr/kinit/kinit.h b/usr/kinit/kinit.h
index 2a023c6..2e484f3 100644
--- a/usr/kinit/kinit.h
+++ b/usr/kinit/kinit.h
@@ -15,6 +15,7 @@
 int ramdisk_load(int argc, char *argv[], dev_t root_dev);
 void md_run(int argc, char *argv[]);
 int do_resume(int argc, char *argv[]);
+const char *bdevname(dev_t dev);
 
 extern int mnt_procfs;
 extern int mnt_sysfs;