summaryrefslogtreecommitdiff
path: root/fdisk
diff options
context:
space:
mode:
Diffstat (limited to 'fdisk')
-rw-r--r--fdisk/Makefile.am23
-rw-r--r--fdisk/cfdisk.c232
-rw-r--r--fdisk/fdisk.c32
3 files changed, 66 insertions, 221 deletions
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 <sys/stat.h>
#include <sys/ioctl.h>
+#ifdef HAVE_LIBBLKID_INTERNAL
+#include <blkid.h>
+#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; i<tosz && i<fromsz && isascii(from[i]); i++)
- to[i] = from[i];
- to[i] = 0;
-}
-
-static void
-get_dos_label(int i) {
- char sector[128];
-#define DOS_OSTYPE_OFFSET 3
-#define DOS_LABEL_OFFSET 43
-#define DOS_FSTYPE_OFFSET 54
-#define DOS_OSTYPE_SZ 8
-#define DOS_LABEL_SZ 11
-#define DOS_FSTYPE_SZ 8
- long long offset;
+get_fsinfo(int i)
+{
+ blkid_probe pr;
+ blkid_loff_t offset, size;
+ const char *data;
offset = (p_info[i].first_sector + p_info[i].offset) * SECTOR_SIZE;
- if (lseek(fd, offset, SEEK_SET) == offset
- && read(fd, &sector, sizeof(sector)) == sizeof(sector)) {
- dos_copy_to_info(p_info[i].ostype, OSTYPESZ,
- sector+DOS_OSTYPE_OFFSET, DOS_OSTYPE_SZ);
- dos_copy_to_info(p_info[i].volume_label, LABELSZ,
- sector+DOS_LABEL_OFFSET, DOS_LABEL_SZ);
- dos_copy_to_info(p_info[i].fstype, FSTYPESZ,
- sector+DOS_FSTYPE_OFFSET, DOS_FSTYPE_SZ);
- }
-}
-
-#define REISERFS_SUPER_MAGIC_STRING "ReIsErFs"
-#define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs"
-struct reiserfs_super_block {
- char s_dummy0[52];
- char s_magic [10];
- char s_dummy1[38];
- u_char s_label[16];
-};
-#define REISERFSLABELSZ sizeof(reiserfsb.s_label)
-
-static int
-has_reiserfs_magic_string(const struct reiserfs_super_block *rs, int *is_3_6) {
- if (!strncmp(rs->s_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<EXT2LABELSZ && j<LABELSZ && isprint(label[j]); j++)
- p_info[i].volume_label[j] = label[j];
- p_info[i].volume_label[j] = 0;
- /* ext2 or ext3? */
- if (e2fsb.s_feature_compat[0]&EXT3_FEATURE_COMPAT_HAS_JOURNAL)
- strncpy(p_info[i].fstype, "ext3", FSTYPESZ);
- else
- strncpy(p_info[i].fstype, "ext2", FSTYPESZ);
+ size = (p_info[i].last_sector - p_info[i].first_sector + 1) * SECTOR_SIZE;
+ pr = blkid_new_probe();
+ if (!pr)
return;
- }
-
- offset = (p_info[i].first_sector + p_info[i].offset) * SECTOR_SIZE + 0;
- if (lseek(fd, offset, SEEK_SET) == offset
- && read(fd, &xfsb, sizeof(xfsb)) == sizeof(xfsb)
- && !strncmp((char *) xfsb.s_magic, XFS_SUPER_MAGIC, 4)) {
- label = (char *) xfsb.s_fname;
- for(j=0; j<XFSLABELSZ && j<LABELSZ && isprint(label[j]); j++)
- p_info[i].volume_label[j] = label[j];
- p_info[i].volume_label[j] = 0;
- strncpy(p_info[i].fstype, "xfs", FSTYPESZ);
- return;
- }
-
- /* jfs? */
- offset = (p_info[i].first_sector + p_info[i].offset) * SECTOR_SIZE
- + JFS_SUPER1_OFF;
- if (lseek(fd, offset, SEEK_SET) == offset
- && read(fd, &jfsb, sizeof(jfsb)) == sizeof(jfsb)
- && !strncmp(jfsb.s_magic, JFS_MAGIC, strlen(JFS_MAGIC))) {
- label = jfsb.s_label;
- for(j=0; j<JFSLABELSZ && j<LABELSZ && isprint(label[j]); j++)
- p_info[i].volume_label[j] = label[j];
- p_info[i].volume_label[j] = 0;
- strncpy(p_info[i].fstype, "jfs", FSTYPESZ);
- return;
- }
-
- /* reiserfs? */
- offset = (p_info[i].first_sector + p_info[i].offset) * SECTOR_SIZE
- + REISERFS_DISK_OFFSET_IN_BYTES;
- if (lseek(fd, offset, SEEK_SET) == offset
- && read(fd, &reiserfsb, sizeof(reiserfsb)) == sizeof(reiserfsb)
- && has_reiserfs_magic_string(&reiserfsb, &reiserfs_is_3_6)) {
- if (reiserfs_is_3_6) {
- /* label only on version 3.6 onward */
- label = (char *) reiserfsb.s_label;
- for(j=0; j<REISERFSLABELSZ && j<LABELSZ &&
- isprint(label[j]); j++)
- p_info[i].volume_label[j] = label[j];
- p_info[i].volume_label[j] = 0;
- }
- strncpy(p_info[i].fstype, "reiserfs", FSTYPESZ);
- return;
- }
+ blkid_probe_enable_superblocks(pr, 1);
+ blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_LABEL |
+ BLKID_SUBLKS_TYPE);
+ if (blkid_probe_set_device(pr, fd, offset, size))
+ goto done;
+ if (blkid_do_safeprobe(pr))
+ goto done;
+
+ 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);
+done:
+ blkid_free_probe(pr);
}
+#endif
static void
check_part_info(void) {
@@ -1050,13 +894,11 @@ add_part(int num, int id, int flags, long long first, long long last,
p_info[i].volume_label[0] = 0;
p_info[i].fstype[0] = 0;
p_info[i].ostype[0] = 0;
- if (want_label) {
- if (may_have_dos_label(id))
- get_dos_label(i);
- else if (id == LINUX)
- get_linux_label(i);
- }
+#ifdef HAVE_LIBBLKID_INTERNAL
+ if (want_label)
+ get_fsinfo(i);
+#endif
check_part_info();
return 0;
diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 5ef24f66..cc573646 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -222,7 +222,7 @@ unsigned int heads,
display_in_cyl_units = 1;
unsigned long long total_number_of_sectors; /* (!) 512-byte sectors */
-unsigned long minimum_io_size, alignment_offset;
+unsigned long io_size, alignment_offset;
#define dos_label (!sun_label && !sgi_label && !aix_label && !mac_label && !osf_label)
int sun_label = 0; /* looking at sun disklabel */
@@ -637,7 +637,7 @@ test_c(char **m, char *mesg) {
return val;
}
-#define alignment_required (minimum_io_size != sector_size)
+#define alignment_required (io_size != sector_size)
static int
lba_is_aligned(unsigned long long lba)
@@ -645,9 +645,9 @@ lba_is_aligned(unsigned long long lba)
unsigned long long bytes, phy_sectors;
bytes = lba * sector_size;
- phy_sectors = bytes / minimum_io_size;
+ phy_sectors = bytes / io_size;
- return (alignment_offset + (phy_sectors * minimum_io_size) == bytes);
+ return (alignment_offset + (phy_sectors * io_size) == bytes);
}
#define ALIGN_UP 1
@@ -662,7 +662,7 @@ align_lba(unsigned long long lba, int direction)
if (lba_is_aligned(lba))
return lba;
- sects_in_phy = minimum_io_size / sector_size;
+ sects_in_phy = io_size / sector_size;
if (lba < sects_in_phy)
/* align to the first physical sector */
@@ -685,7 +685,7 @@ align_lba(unsigned long long lba, int direction)
* at LBA < 0 (usually LBA -1). It means we have to move LBA
* according the offset to be on the physical boundary.
*/
- res -= (minimum_io_size - alignment_offset) / sector_size;
+ res -= (io_size - alignment_offset) / sector_size;
/* fprintf(stderr, "LBA %llu -align-> %llu (%s)\n", lba, res,
* lba_is_aligned(res) ? "OK" : "FALSE");
@@ -779,8 +779,8 @@ warn_alignment(void) {
fprintf(stderr, _("\n"
"The device presents a logical sector size that is smaller than\n"
-"the physical sector size. Aligning to a physical sector boundary\n"
-"is recommended, or performance may be impacted.\n\n"));
+"the optimal I/O size (often physical sector size). Aligning to a optimal\n"
+"I/O size boundary is recommended, or performance may be impacted.\n\n"));
/*
* Print warning when sector_offset is not aligned for DOS mode
@@ -968,7 +968,9 @@ get_topology(int fd) {
blkid_topology tp = blkid_probe_get_topology(pr);
if (tp) {
- minimum_io_size = blkid_topology_get_minimum_io_size(tp);
+ io_size = blkid_topology_get_optimal_io_size(tp);
+ if (!io_size)
+ io_size = blkid_topology_get_minimum_io_size(tp);
alignment_offset = blkid_topology_get_alignment_offset(tp);
}
}
@@ -980,8 +982,8 @@ get_topology(int fd) {
else if (blkdev_get_sector_size(fd, &arg) == 0)
sector_size = arg;
- if (!minimum_io_size)
- minimum_io_size = sector_size;
+ if (!io_size)
+ io_size = sector_size;
if (sector_size != DEFAULT_SECTOR_SIZE)
printf(_("Note: sector size is %d (not %d)\n"),
@@ -1054,7 +1056,7 @@ update_sector_offset(void)
/*
* Align the begin of the first partition to the physical block
*/
- unsigned long long x = minimum_io_size / sector_size;
+ unsigned long long x = io_size / sector_size;
sector_offset = align_lba(x, ALIGN_UP);
}
@@ -1810,7 +1812,7 @@ static void
check_alignment(struct partition *p, int partition)
{
if (!lba_is_aligned(get_start_sect(p)))
- printf(_("Partition %i does not start on physical block boundary.\n"),
+ printf(_("Partition %i does not start on optimal I/O size boundary.\n"),
partition + 1);
}
@@ -1837,8 +1839,8 @@ list_disk_geometry(void) {
str_units(PLURAL),
units_per_sector, sector_size, units_per_sector * sector_size);
- printf(_("Sector size (logical/physical): %u bytes / %lu bytes\n"),
- sector_size, minimum_io_size);
+ printf(_("Sector size (logical / optimal IO): %u bytes / %lu bytes\n"),
+ sector_size, io_size);
if (alignment_offset)
printf(_("Alignment offset: %lu bytes\n"), alignment_offset);
if (dos_label)