[PATCH 4/7] fdisk: print info and recommendations about alignment

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

 



 * inform user that phy.sector > log.sector
 * warn user when alignment_offset is not provided does, DOS-compatible
   mode is enabled and the default geo.sectors are not aligned
 * suggest to change display units to sectors (oh yes, fdisk
   default are cylinders...)

Signed-off-by: Karel Zak <kzak@xxxxxxxxxx>
---
 fdisk/fdisk.c                 |   40 ++++++++++++++++++++++++++++++++++++----
 tests/expected/fdisk/oddinput |    1 +
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 4daa014..f269164 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -752,8 +752,11 @@ warn_cylinders(void) {
 "2) booting and partitioning software from other OSs\n"
 "   (e.g., DOS FDISK, OS/2 FDISK)\n"),
 			cylinders);
+}
 
-	if (total_number_of_sectors > UINT_MAX) {
+static void
+warn_limits(void) {
+	if (total_number_of_sectors > UINT_MAX && !nowarn) {
 		int giga = (total_number_of_sectors << 9) / 1000000000;
 		int hectogiga = (giga + 50) / 100;
 
@@ -770,6 +773,33 @@ warn_cylinders(void) {
 }
 
 static void
+warn_alignment(void) {
+	if (nowarn || !alignment_required)
+		return;
+
+	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"));
+
+	/*
+	 * Print warning when sector_offset is not aligned for DOS mode
+	 */
+	if (alignment_offset == 0 && dos_compatible_flag &&
+	    !lba_is_aligned(sector_offset))
+
+		fprintf(stderr, _(
+"WARNING: The device does not provide compensation (alignment_offset)\n"
+"for DOS-compatible partitioning, but DOS-compatible mode is enabled.\n"
+"Use command 'c' to switch-off DOS mode.\n\n"));
+
+	if (display_in_cyl_units)
+		fprintf(stderr, _(
+"It's recommended to change display units to sectors (command 'u').\n\n"));
+
+}
+
+static void
 read_extended(int ext) {
 	int i;
 	struct pte *pex;
@@ -1193,9 +1223,6 @@ got_dos_table:
 		}
 	}
 
-	warn_cylinders();
-	warn_geometry();
-
 	for (i = 0; i < 4; i++) {
 		struct pte *pe = &ptes[i];
 
@@ -1220,6 +1247,11 @@ got_dos_table:
 		}
 	}
 
+	warn_cylinders();
+	warn_geometry();
+	warn_limits();
+	warn_alignment();
+
 	return 0;
 }
 
diff --git a/tests/expected/fdisk/oddinput b/tests/expected/fdisk/oddinput
index 59240fd..f1bfda5 100644
--- a/tests/expected/fdisk/oddinput
+++ b/tests/expected/fdisk/oddinput
@@ -6,6 +6,7 @@ Disk testimage doesn't contain a valid partition table
 Disk testimage: 0 MB, 0 bytes
 255 heads, 63 sectors/track, 0 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes
+Sector size (logical/physical): 512 bytes / 512 bytes
 Disk identifier: 0x00000000
 
 Nonexistant file
-- 
1.6.5.1

--
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