From: Matthias König Date: Tue, 12 Jan 2010 12:58:38 +0000 (+0100) Subject: cfdisk: use libblkid X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f609e92e497a513ed759dc4166a372fb22d3f995;p=util-linux cfdisk: use libblkid Let cfdisk use the internal libblkid if available to get the filesystem type and label. [kzak@redhat.com: - remove old FS probing code from cfdisk - remove "Linux" prefix for filesystem names - enlarge fstype field in partition_info - restrict probing area by partition size] Signed-off-by: Matthias König Signed-off-by: Karel Zak --- diff --git a/fdisk/Makefile.am b/fdisk/Makefile.am index 5496e240..50f1dbe8 100644 --- a/fdisk/Makefile.am +++ b/fdisk/Makefile.am @@ -18,26 +18,25 @@ fdisk_SOURCES = fdisk.c fdiskbsdlabel.c fdisksgilabel.c \ fdisk.h fdisksunlabel.h fdisksgilabel.h fdiskaixlabel.h \ fdiskbsdlabel.h fdiskmaclabel.h $(fdisk_common) -cflags_fdisk = $(AM_CFLAGS) -ldadd_fdisk = +cflags_blkid = $(AM_CFLAGS) +ldadd_blkid = if BUILD_LIBBLKID # only in-tree libblkid has topology support -ldadd_fdisk += $(ul_libblkid_la) -cflags_fdisk += -I$(ul_libblkid_incdir) +ldadd_blkid += $(ul_libblkid_la) +cflags_blkid += -I$(ul_libblkid_incdir) endif if HAVE_STATIC_FDISK sbin_PROGRAMS += fdisk.static fdisk_static_SOURCES = $(fdisk_SOURCES) fdisk_static_LDFLAGS = -all-static -fdisk_static_CFLAGS = $(cflags_fdisk) -fdisk_static_LDADD = $(ldadd_fdisk) +fdisk_static_CFLAGS = $(cflags_blkid) +fdisk_static_LDADD = $(ldadd_blkid) endif -fdisk_CFLAGS = $(cflags_fdisk) -fdisk_LDADD = $(ldadd_fdisk) - +fdisk_CFLAGS = $(cflags_blkid) +fdisk_LDADD = $(ldadd_blkid) if !ARCH_SPARC @@ -55,13 +54,15 @@ if USE_SLANG sbin_PROGRAMS += cfdisk dist_man_MANS += cfdisk.8 cfdisk_SOURCES = cfdisk.c $(fdisk_common) -cfdisk_LDADD = -lslang +cfdisk_CFLAGS = $(cflags_blkid) +cfdisk_LDADD = -lslang $(ldadd_blkid) else if HAVE_NCURSES sbin_PROGRAMS += cfdisk dist_man_MANS += cfdisk.8 cfdisk_SOURCES = cfdisk.c $(fdisk_common) -cfdisk_LDADD = @NCURSES_LIBS@ +cfdisk_CFLAGS = $(cflags_blkid) +cfdisk_LDADD = @NCURSES_LIBS@ $(ldadd_blkid) endif endif diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c index eec16893..eaf766c8 100644 --- a/fdisk/cfdisk.c +++ b/fdisk/cfdisk.c @@ -79,6 +79,10 @@ #include #include +#ifdef HAVE_LIBBLKID_INTERNAL +#include +#endif + #include "nls.h" #include "blkdev.h" #include "xstrncpy.h" @@ -222,11 +226,6 @@ set_hsc_end(struct partition *p, long long sector) { #define is_extended(x) ((x) == DOS_EXTENDED || (x) == WIN98_EXTENDED || \ (x) == LINUX_EXTENDED) -#define is_dos_partition(x) ((x) == 1 || (x) == 4 || (x) == 6) -#define may_have_dos_label(x) (is_dos_partition(x) \ - || (x) == 7 || (x) == 0xb || (x) == 0xc || (x) == 0xe \ - || (x) == 0x11 || (x) == 0x14 || (x) == 0x16 || (x) == 0x17) - /* start_sect and nr_sects are stored little endian on all machines */ /* moreover, they are not aligned correctly */ static void @@ -289,7 +288,7 @@ typedef struct { char volume_label[LABELSZ+1]; #define OSTYPESZ 8 char ostype[OSTYPESZ+1]; -#define FSTYPESZ 8 +#define FSTYPESZ 12 char fstype[FSTYPESZ+1]; } partition_info; @@ -378,29 +377,9 @@ partition_type_text(int i) { return _("Unusable"); else if (p_info[i].id == FREE_SPACE) return _("Free Space"); - else if (p_info[i].id == LINUX) { - if (!strcmp(p_info[i].fstype, "ext2")) - return _("Linux ext2"); - else if (!strcmp(p_info[i].fstype, "ext3")) - return _("Linux ext3"); - else if (!strcmp(p_info[i].fstype, "xfs")) - return _("Linux XFS"); - else if (!strcmp(p_info[i].fstype, "jfs")) - return _("Linux JFS"); - else if (!strcmp(p_info[i].fstype, "reiserfs")) - return _("Linux ReiserFS"); - else - return _("Linux"); - } else if (p_info[i].id == OS2_OR_NTFS) { - if (!strncmp(p_info[i].fstype, "HPFS", 4)) - return _("OS/2 HPFS"); - else if (!strncmp(p_info[i].ostype, "OS2", 3)) - return _("OS/2 IFS"); - else if (!p_info[i].ostype) - return p_info[i].ostype; - else - return _("NTFS"); - } else + else if (*p_info[i].fstype) + return p_info[i].fstype; + else return _(partition_type_name(p_info[i].id)); } @@ -574,171 +553,36 @@ write_sector(unsigned char *buffer, long long sect_num) { fatal(_("Cannot write disk drive"), 2); } +#ifdef HAVE_LIBBLKID_INTERNAL static void -dos_copy_to_info(char *to, int tosz, char *from, int fromsz) { - int i; - - for(i=0; is_magic, REISERFS_SUPER_MAGIC_STRING, - strlen(REISERFS_SUPER_MAGIC_STRING))) { - *is_3_6 = 0; - return 1; - } - if (!strncmp(rs->s_magic, REISER2FS_SUPER_MAGIC_STRING, - strlen(REISER2FS_SUPER_MAGIC_STRING))) { - *is_3_6 = 1; - return 1; - } - return 0; -} - -static void -get_linux_label(int i) { - -#define EXT2LABELSZ 16 -#define EXT2_SUPER_MAGIC 0xEF53 -#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 - struct ext2_super_block { - char s_dummy0[56]; - unsigned char s_magic[2]; - char s_dummy1[34]; - unsigned char s_feature_compat[4]; - char s_dummy2[24]; - char s_volume_name[EXT2LABELSZ]; - char s_last_mounted[64]; - char s_dummy3[824]; - } e2fsb; - -#define REISERFS_DISK_OFFSET_IN_BYTES (64 * 1024) - struct reiserfs_super_block reiserfsb; - int reiserfs_is_3_6; - -#define JFS_SUPER1_OFF 0x8000 -#define JFS_MAGIC "JFS1" -#define JFSLABELSZ 16 - struct jfs_super_block { - char s_magic[4]; - u_char s_version[4]; - u_char s_dummy1[93]; - char s_fpack[11]; - u_char s_dummy2[24]; - u_char s_uuid[16]; - char s_label[JFSLABELSZ]; - } jfsb; - -#define XFS_SUPER_MAGIC "XFSB" -#define XFSLABELSZ 12 - struct xfs_super_block { - unsigned char s_magic[4]; - unsigned char s_dummy0[104]; - unsigned char s_fname[XFSLABELSZ]; - unsigned char s_dummy1[904]; - } xfsb; - - char *label; - long long offset; - int j; - - offset = (p_info[i].first_sector + p_info[i].offset) * SECTOR_SIZE - + 1024; - if (lseek(fd, offset, SEEK_SET) == offset - && read(fd, &e2fsb, sizeof(e2fsb)) == sizeof(e2fsb) - && e2fsb.s_magic[0] + (e2fsb.s_magic[1]<<8) == EXT2_SUPER_MAGIC) { - label = e2fsb.s_volume_name; - for(j=0; j