[PATCH] cfdisk: use libblkid

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

 



Let cfdisk use the internal libblkid if available to get the filesystem
type and label.

Signed-off-by: Matthias König <mk@xxxxxxxxxxxx>
---
 fdisk/Makefile.am |   12 +++++++++++-
 fdisk/cfdisk.c    |   35 +++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletions(-)

diff --git a/fdisk/Makefile.am b/fdisk/Makefile.am
index 5496e24..9e46d76 100644
--- a/fdisk/Makefile.am
+++ b/fdisk/Makefile.am
@@ -55,13 +55,23 @@ if USE_SLANG
 sbin_PROGRAMS += cfdisk
 dist_man_MANS += cfdisk.8
 cfdisk_SOURCES = cfdisk.c $(fdisk_common)
-cfdisk_LDADD = -lslang
+cfdisk_CFLAGS = $(AM_CFLAGS)
+cfdisk_LDADD = -lslang 
+if BUILD_LIBBLKID
+cfdisk_CFLAGS += -I$(ul_libblkid_incdir)
+cfdisk_LDADD += $(ul_libblkid_la)
+endif # BUILD_LIBBLKID
 else
 if HAVE_NCURSES
 sbin_PROGRAMS += cfdisk
 dist_man_MANS += cfdisk.8
 cfdisk_SOURCES = cfdisk.c $(fdisk_common)
+cfdisk_CFLAGS = $(AM_CFLAGS)
 cfdisk_LDADD = @NCURSES_LIBS@
+if BUILD_LIBBLKID
+cfdisk_CFLAGS += -I$(ul_libblkid_incdir)
+cfdisk_LDADD += $(ul_libblkid_la) 
+endif # BUILD_LIBBLKID
 endif
 endif
 
diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c
index eec1689..a535e7e 100644
--- a/fdisk/cfdisk.c
+++ b/fdisk/cfdisk.c
@@ -79,6 +79,8 @@
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 
+#include <blkid.h>
+
 #include "nls.h"
 #include "blkdev.h"
 #include "xstrncpy.h"
@@ -584,6 +586,35 @@ dos_copy_to_info(char *to, int tosz, char *from, int fromsz) {
 }
 
 static void
+get_fsinfo(int i)
+{
+	blkid_probe pr;
+	blkid_loff_t offset;
+	const char *data;
+
+	offset = (p_info[i].first_sector + p_info[i].offset) * SECTOR_SIZE;
+	pr = blkid_new_probe();
+	if (!pr)
+		return;
+	blkid_probe_enable_superblocks(pr, 1);
+	blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_LABEL |
+					      BLKID_SUBLKS_TYPE);
+	blkid_probe_set_device(pr, fd, offset, 0);
+	if (blkid_do_safeprobe(pr)) {
+		blkid_free_probe(pr);
+		return;
+	}
+
+	if (!blkid_probe_lookup_value(pr, "TYPE", &data, 0))
+		strncpy(p_info[i].fstype, data, FSTYPESZ);
+	
+	if (!blkid_probe_lookup_value(pr, "LABEL", &data, 0))
+		strncpy(p_info[i].volume_label, data, LABELSZ);
+
+	blkid_free_probe(pr);
+}
+
+static void
 get_dos_label(int i) {
 	char sector[128];
 #define DOS_OSTYPE_OFFSET 3
@@ -1051,10 +1082,14 @@ add_part(int num, int id, int flags, long long first, long long last,
     p_info[i].fstype[0] = 0;
     p_info[i].ostype[0] = 0;
     if (want_label) {
+#ifdef HAVE_LIBBLKID_INTERNAL
+	 get_fsinfo(i);
+#else
 	 if (may_have_dos_label(id))
 	      get_dos_label(i);
 	 else if (id == LINUX)
 	      get_linux_label(i);
+#endif
     }
 
     check_part_info();

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux