util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/13] fdisk: remove unused 'require' member in enum action
@ 2011-12-15 19:02 Francesco Cosoleto
  2011-12-15 19:02 ` [PATCH 02/13] fdisk: remove possibly_osf_label variable that is only assigned Francesco Cosoleto
                   ` (12 more replies)
  0 siblings, 13 replies; 18+ messages in thread
From: Francesco Cosoleto @ 2011-12-15 19:02 UTC (permalink / raw)
  To: util-linux; +Cc: Francesco Cosoleto

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
---
 fdisk/fdisk.c |    2 --
 fdisk/fdisk.h |    2 +-
 2 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 00dd706..a6de6e2 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -1179,8 +1179,6 @@ got_dos_table:
 			create_doslabel();
 #endif
 			return 0;
-		case require:
-			return -1;
 		case try_only:
 		        return -1;
 		case create_empty_dos:
diff --git a/fdisk/fdisk.h b/fdisk/fdisk.h
index 81ff5a2..67642cd 100644
--- a/fdisk/fdisk.h
+++ b/fdisk/fdisk.h
@@ -54,7 +54,7 @@ enum failure {ioctl_error,
 	unable_to_open, unable_to_read, unable_to_seek,
 	unable_to_write};
 
-enum action {fdisk, require, try_only, create_empty_dos, create_empty_sun};
+enum action {fdisk, try_only, create_empty_dos, create_empty_sun};
 
 struct geom {
 	unsigned int heads;
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 02/13] fdisk: remove possibly_osf_label variable that is only assigned
  2011-12-15 19:02 [PATCH 01/13] fdisk: remove unused 'require' member in enum action Francesco Cosoleto
@ 2011-12-15 19:02 ` Francesco Cosoleto
  2011-12-15 19:02 ` [PATCH 03/13] fdisk: move code for renaming SGI bootfile to SGI module Francesco Cosoleto
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Francesco Cosoleto @ 2011-12-15 19:02 UTC (permalink / raw)
  To: util-linux; +Cc: Francesco Cosoleto

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
---
 fdisk/fdisk.c |    4 ----
 1 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index a6de6e2..a23f45e 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -292,8 +292,6 @@ int has_topology;
 
 enum labeltype disklabel = DOS_LABEL;	/* Current disklabel */
 
-int	possibly_osf_label = 0;
-
 jmp_buf listingbuf;
 
 static void __attribute__ ((__noreturn__)) usage(FILE *out)
@@ -862,7 +860,6 @@ create_doslabel(void) {
 	sun_nolabel();  /* otherwise always recognised as sun */
 	sgi_nolabel();  /* otherwise always recognised as sgi */
 	disklabel = DOS_LABEL;
-	possibly_osf_label = 0;
 	partitions = 4;
 
 	/* Zero out the MBR buffer */
@@ -1155,7 +1152,6 @@ get_boot(enum action what) {
 		return 0;
 
 	if (check_osf_label()) {
-		possibly_osf_label = 1;
 		if (!valid_part_table_flag(MBRbuffer)) {
 			disklabel = OSF_LABEL;
 			return 0;
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 03/13] fdisk: move code for renaming SGI bootfile to SGI module
  2011-12-15 19:02 [PATCH 01/13] fdisk: remove unused 'require' member in enum action Francesco Cosoleto
  2011-12-15 19:02 ` [PATCH 02/13] fdisk: remove possibly_osf_label variable that is only assigned Francesco Cosoleto
@ 2011-12-15 19:02 ` Francesco Cosoleto
  2011-12-15 19:02 ` [PATCH 04/13] fdisk: drop one parameter from try() function Francesco Cosoleto
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Francesco Cosoleto @ 2011-12-15 19:02 UTC (permalink / raw)
  To: util-linux; +Cc: Francesco Cosoleto

This moves the code for renaming SGI bootfile from command_prompt() to
sgi_set_bootfilename() function.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
---
 fdisk/fdisk.c         |   12 +++---------
 fdisk/fdisksgilabel.c |   21 +++++++++++----------
 fdisk/fdisksgilabel.h |    3 +--
 3 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index a23f45e..1a4c823 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -2906,15 +2906,9 @@ static void command_prompt(void)
 				unknown_command(c);
 			break;
 		case 'b':
-			if (disklabel == SGI_LABEL) {
-				printf(_("\nThe current boot file is: %s\n"),
-				       sgi_get_bootfile());
-				if (read_chars(_("Please enter the name of the "
-					       "new boot file: ")) == '\n')
-					printf(_("Boot file unchanged\n"));
-				else
-					sgi_set_bootfile(line_ptr);
-			} else if (disklabel == DOS_LABEL) {
+			if (disklabel == SGI_LABEL)
+				sgi_set_bootfile();
+			else if (disklabel == DOS_LABEL) {
 				disklabel = OSF_LABEL;
 				bsd_command_prompt();
 				disklabel = DOS_LABEL;
diff --git a/fdisk/fdisksgilabel.c b/fdisk/fdisksgilabel.c
index 002688a..b432b13 100644
--- a/fdisk/fdisksgilabel.c
+++ b/fdisk/fdisksgilabel.c
@@ -316,20 +316,21 @@ sgi_check_bootfile(const char* aFile) {
 	return 0;	/* filename did not change */
 }
 
-const char *
-sgi_get_bootfile(void) {
-	return (char *) sgilabel->boot_file;
-}
-
 void
-sgi_set_bootfile(const char* aFile) {
+sgi_set_bootfile(void)
+{
+	printf(_("\nThe current boot file is: %s\n"), sgilabel->boot_file);
+	if (read_chars(_("Please enter the name of the new boot file: ")) == '\n') {
+		printf(_("Boot file unchanged\n"));
+		return;
+	}
 
-	if (sgi_check_bootfile(aFile)) {
+	if (sgi_check_bootfile(line_ptr)) {
 		size_t i = 0;
 		while (i < 16) {
-			if ((aFile[i] != '\n')	/* in principle caught again by next line */
-			    &&  (strlen(aFile) > i))
-				sgilabel->boot_file[i] = aFile[i];
+			if ((line_ptr[i] != '\n')	/* in principle caught again by next line */
+			    &&  (strlen(line_ptr) > i))
+				sgilabel->boot_file[i] = line_ptr[i];
 			else
 				sgilabel->boot_file[i] = 0;
 			i++;
diff --git a/fdisk/fdisksgilabel.h b/fdisk/fdisksgilabel.h
index 1c47bb4..255fe9c 100644
--- a/fdisk/fdisksgilabel.h
+++ b/fdisk/fdisksgilabel.h
@@ -133,7 +133,6 @@ extern void	sgi_set_bootpartition( int i );
 extern void	sgi_set_swappartition( int i );
 extern int	sgi_get_bootpartition( void );
 extern int	sgi_get_swappartition( void );
-extern void	sgi_set_bootfile( const char* aFile );
-extern const char *sgi_get_bootfile( void );
+extern void	sgi_set_bootfile(void);
 
 #endif /* FDISK_SGI_LABEL_H */
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 04/13] fdisk: drop one parameter from try() function
  2011-12-15 19:02 [PATCH 01/13] fdisk: remove unused 'require' member in enum action Francesco Cosoleto
  2011-12-15 19:02 ` [PATCH 02/13] fdisk: remove possibly_osf_label variable that is only assigned Francesco Cosoleto
  2011-12-15 19:02 ` [PATCH 03/13] fdisk: move code for renaming SGI bootfile to SGI module Francesco Cosoleto
@ 2011-12-15 19:02 ` Francesco Cosoleto
  2011-12-16 13:18   ` Karel Zak
  2011-12-22  2:24   ` Guillem Jover
  2011-12-15 19:02 ` [PATCH 05/13] fdisk: rename try() and tryprocpt() functions Francesco Cosoleto
                   ` (9 subsequent siblings)
  12 siblings, 2 replies; 18+ messages in thread
From: Francesco Cosoleto @ 2011-12-15 19:02 UTC (permalink / raw)
  To: util-linux; +Cc: Francesco Cosoleto

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
---
 fdisk/fdisk.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 1a4c823..1ecab17 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -2800,15 +2800,13 @@ gpt_warning(char *dev)
 }
 
 static void
-try(char *device, int user_specified) {
+try(char *device)
+{
 	int gb;
 
 	disk_device = device;
 	if (setjmp(listingbuf))
 		return;
-	if (!user_specified)
-		if (is_ide_cdrom_or_tape(device))
-			return;
 	gpt_warning(device);
 	if ((fd = open(disk_device, type_open)) >= 0) {
 		gb = get_boot(try_only);
@@ -2859,7 +2857,7 @@ tryprocpt(void) {
 		if (is_whole_disk(devname)) {
 			char *cn = canonicalize_path(devname);
 			if (cn) {
-				try(cn, 0);
+				try(cn);
 				free(cn);
 			}
 		}
@@ -3079,7 +3077,8 @@ main(int argc, char **argv) {
 			dummy(&k);
 			listing = 1;
 			for (k = optind; k < argc; k++)
-				try(argv[k], 1);
+				if (!is_ide_cdrom_or_tape(argv[k]))
+					try(argv[k]);
 		} else {
 			/* we no longer have default device names */
 			/* but we can use /proc/partitions instead */
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 05/13] fdisk: rename try() and tryprocpt() functions
  2011-12-15 19:02 [PATCH 01/13] fdisk: remove unused 'require' member in enum action Francesco Cosoleto
                   ` (2 preceding siblings ...)
  2011-12-15 19:02 ` [PATCH 04/13] fdisk: drop one parameter from try() function Francesco Cosoleto
@ 2011-12-15 19:02 ` Francesco Cosoleto
  2011-12-15 19:02 ` [PATCH 06/13] fdisk: get rid of type_open global variable Francesco Cosoleto
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Francesco Cosoleto @ 2011-12-15 19:02 UTC (permalink / raw)
  To: util-linux; +Cc: Francesco Cosoleto

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
---
 fdisk/fdisk.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 1ecab17..a8a1800 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -2799,8 +2799,10 @@ gpt_warning(char *dev)
 			"The util fdisk doesn't support GPT. Use GNU Parted.\n\n"), dev);
 }
 
+/* Print disk geometry and partition table of a specified device (-l option) */
+
 static void
-try(char *device)
+print_partition_table_from_option(char *device)
 {
 	int gb;
 
@@ -2837,7 +2839,8 @@ try(char *device)
  * try all things in /proc/partitions that look like a full disk
  */
 static void
-tryprocpt(void) {
+print_all_partition_table_from_option(void)
+{
 	FILE *procpt;
 	char line[128], ptname[128], devname[256];
 	int ma, mi;
@@ -2857,7 +2860,7 @@ tryprocpt(void) {
 		if (is_whole_disk(devname)) {
 			char *cn = canonicalize_path(devname);
 			if (cn) {
-				try(cn);
+				print_partition_table_from_option(cn);
 				free(cn);
 			}
 		}
@@ -3078,12 +3081,9 @@ main(int argc, char **argv) {
 			listing = 1;
 			for (k = optind; k < argc; k++)
 				if (!is_ide_cdrom_or_tape(argv[k]))
-					try(argv[k]);
-		} else {
-			/* we no longer have default device names */
-			/* but we can use /proc/partitions instead */
-			tryprocpt();
-		}
+					print_partition_table_from_option(argv[k]);
+		} else
+			print_all_partition_table_from_option();
 		exit(0);
 	}
 
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 06/13] fdisk: get rid of type_open global variable
  2011-12-15 19:02 [PATCH 01/13] fdisk: remove unused 'require' member in enum action Francesco Cosoleto
                   ` (3 preceding siblings ...)
  2011-12-15 19:02 ` [PATCH 05/13] fdisk: rename try() and tryprocpt() functions Francesco Cosoleto
@ 2011-12-15 19:02 ` Francesco Cosoleto
  2011-12-15 19:02 ` [PATCH 07/13] fdisk: get rid of get_boot(create_empty_sun) call Francesco Cosoleto
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Francesco Cosoleto @ 2011-12-15 19:02 UTC (permalink / raw)
  To: util-linux; +Cc: Francesco Cosoleto

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
---
 fdisk/fdisk.c |   11 +++--------
 1 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index a8a1800..ab2e68d 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -230,9 +230,6 @@ get_random_id(void) {
 	return (unsigned int)(tv.tv_sec + (tv.tv_usec << 12) + getpid());
 }
 
-/* normally O_RDWR, -l option gives O_RDONLY */
-static int type_open = O_RDWR;
-
 /*
  * Raw disk label. For DOS-type partition tables the MBR,
  * with descriptions of the primary partitions.
@@ -1120,7 +1117,7 @@ get_boot(enum action what) {
 		goto got_dos_table;		/* skip reading disk */
 
 	if (what != try_only) {
-		if ((fd = open(disk_device, type_open)) < 0) {
+		if ((fd = open(disk_device, O_RDWR)) < 0) {
 			if ((fd = open(disk_device, O_RDONLY)) < 0)
 				fatal(unable_to_open);
 			else
@@ -2810,7 +2807,7 @@ print_partition_table_from_option(char *device)
 	if (setjmp(listingbuf))
 		return;
 	gpt_warning(device);
-	if ((fd = open(disk_device, type_open)) >= 0) {
+	if ((fd = open(disk_device, O_RDONLY)) >= 0) {
 		gb = get_boot(try_only);
 		if (gb > 0) { /* I/O error */
 		} else if (gb < 0) { /* no DOS signature */
@@ -3072,7 +3069,6 @@ main(int argc, char **argv) {
 
 	if (optl) {
 		nowarn = 1;
-		type_open = O_RDONLY;
 		if (argc > optind) {
 			int k;
 			/* avoid gcc warning:
@@ -3091,7 +3087,6 @@ main(int argc, char **argv) {
 		unsigned long long size;
 
 		nowarn = 1;
-		type_open = O_RDONLY;
 
 		opts = argc - optind;
 		if (opts <= 0)
@@ -3099,7 +3094,7 @@ main(int argc, char **argv) {
 
 		for (j = optind; j < argc; j++) {
 			disk_device = argv[j];
-			if ((fd = open(disk_device, type_open)) < 0)
+			if ((fd = open(disk_device, O_RDONLY)) < 0)
 				fatal(unable_to_open);
 			if (blkdev_get_sectors(fd, &size) == -1)
 				fatal(ioctl_error);
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 07/13] fdisk: get rid of get_boot(create_empty_sun) call
  2011-12-15 19:02 [PATCH 01/13] fdisk: remove unused 'require' member in enum action Francesco Cosoleto
                   ` (4 preceding siblings ...)
  2011-12-15 19:02 ` [PATCH 06/13] fdisk: get rid of type_open global variable Francesco Cosoleto
@ 2011-12-15 19:02 ` Francesco Cosoleto
  2011-12-15 19:02 ` [PATCH 08/13] fdisk: remove unused guess_device_type() function Francesco Cosoleto
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Francesco Cosoleto @ 2011-12-15 19:02 UTC (permalink / raw)
  To: util-linux; +Cc: Francesco Cosoleto

create_sunlabel() should create a new empty SUN disklabel without checking data
itself writes to memory and initialize internal related fdisk variables.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
---
 fdisk/fdisk.c         |    7 ++-----
 fdisk/fdisk.h         |    3 +--
 fdisk/fdisksunlabel.c |   17 +++++++++++------
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index ab2e68d..aacd73f 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -51,6 +51,7 @@
 
 #include "gpt.h"
 
+static int get_boot(enum action what);
 static void delete_partition(int i);
 
 #define hex_val(c)	({ \
@@ -1090,7 +1091,7 @@ void zeroize_mbr_buffer(void)
  *    0: found or created label
  *    1: I/O error
  */
-int
+static int
 get_boot(enum action what) {
 	int i;
 
@@ -1108,9 +1109,6 @@ get_boot(enum action what) {
 		pe->changed = (what == create_empty_dos);
 	}
 
-	if (what == create_empty_sun && check_sun_label())
-		return 0;
-
 	memset(MBRbuffer, 0, 512);
 
 	if (what == create_empty_dos)
@@ -1175,7 +1173,6 @@ got_dos_table:
 		case try_only:
 		        return -1;
 		case create_empty_dos:
-		case create_empty_sun:
 			break;
 		default:
 			fprintf(stderr, _("Internal error\n"));
diff --git a/fdisk/fdisk.h b/fdisk/fdisk.h
index 67642cd..6641880 100644
--- a/fdisk/fdisk.h
+++ b/fdisk/fdisk.h
@@ -54,7 +54,7 @@ enum failure {ioctl_error,
 	unable_to_open, unable_to_read, unable_to_seek,
 	unable_to_write};
 
-enum action {fdisk, try_only, create_empty_dos, create_empty_sun};
+enum action {fdisk, try_only, create_empty_dos};
 
 struct geom {
 	unsigned int heads;
@@ -69,7 +69,6 @@ extern unsigned int display_in_cyl_units, units_per_sector;
 extern void change_units(void);
 extern void fatal(enum failure why);
 extern void get_geometry(int fd, struct geom *);
-extern int get_boot(enum action what);
 extern int  get_partition(int warn, int max);
 extern void list_types(struct systypes *sys);
 extern int read_line (int *asked);
diff --git a/fdisk/fdisksunlabel.c b/fdisk/fdisksunlabel.c
index 80408dd..4fd8545 100644
--- a/fdisk/fdisksunlabel.c
+++ b/fdisk/fdisksunlabel.c
@@ -109,6 +109,12 @@ static void set_sun_partition(int i, uint32_t start, uint32_t stop, uint16_t sys
 	print_partition_size(i + 1, start, stop, sysid);
 }
 
+static void init(void)
+{
+	disklabel = SUN_LABEL;
+	partitions = SUN_NUM_PARTITIONS;
+}
+
 void sun_nolabel(void)
 {
 	sunlabel->magic = 0;
@@ -125,6 +131,8 @@ int check_sun_label(void)
 		other_endian = 0;
 		return 0;
 	}
+
+	init();
 	other_endian = (sunlabel->magic == SUN_LABEL_MAGIC_SWAPPED);
 
 	ush = ((unsigned short *) (sunlabel + 1)) - 1;
@@ -176,8 +184,6 @@ int check_sun_label(void)
 		}
 	}
 	update_units();
-	disklabel = SUN_LABEL;
-	partitions = SUN_NUM_PARTITIONS;
 	return 1;
 }
 
@@ -195,7 +201,10 @@ void create_sunlabel(void)
 #else
 	other_endian = 0;
 #endif
+
+	init();
 	zeroize_mbr_buffer();
+
 	sunlabel->magic = SSWAP16(SUN_LABEL_MAGIC);
 	sunlabel->sanity = SSWAP32(SUN_LABEL_SANE);
 	sunlabel->version = SSWAP32(SUN_LABEL_VERSION);
@@ -249,9 +258,6 @@ void create_sunlabel(void)
 	} else
 	        ndiv = cylinders * 2 / 3;
 
-	/* Make sure print_partition_size() uses correct sysid names */
-	disklabel = SUN_LABEL;
-
 	set_sun_partition(0, 0, ndiv * heads * sectors,
 			  SUN_TAG_LINUX_NATIVE);
 	set_sun_partition(1, ndiv * heads * sectors,
@@ -270,7 +276,6 @@ void create_sunlabel(void)
 	}
 
 	set_all_unchanged();
-	get_boot(create_empty_sun);
 	set_changed(0);
 }
 
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 08/13] fdisk: remove unused guess_device_type() function
  2011-12-15 19:02 [PATCH 01/13] fdisk: remove unused 'require' member in enum action Francesco Cosoleto
                   ` (5 preceding siblings ...)
  2011-12-15 19:02 ` [PATCH 07/13] fdisk: get rid of get_boot(create_empty_sun) call Francesco Cosoleto
@ 2011-12-15 19:02 ` Francesco Cosoleto
  2011-12-15 19:02 ` [PATCH 09/13] fdisk: don't use get_existing_partition() if disk label isn't dos Francesco Cosoleto
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Francesco Cosoleto @ 2011-12-15 19:02 UTC (permalink / raw)
  To: util-linux; +Cc: Francesco Cosoleto

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
---
 fdisk/fdisk.c         |    1 -
 fdisk/fdisksunlabel.c |   38 --------------------------------------
 fdisk/fdisksunlabel.h |    1 -
 3 files changed, 0 insertions(+), 40 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index aacd73f..8f5869d 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -1031,7 +1031,6 @@ get_geometry(int fd, struct geom *g) {
 	unsigned long long llcyls, nsects = 0;
 
 	get_topology(fd);
-	guess_device_type(fd);
 	heads = cylinders = sectors = 0;
 	kern_heads = kern_sectors = 0;
 	pt_heads = pt_sectors = 0;
diff --git a/fdisk/fdisksunlabel.c b/fdisk/fdisksunlabel.c
index 4fd8545..4a6db35 100644
--- a/fdisk/fdisksunlabel.c
+++ b/fdisk/fdisksunlabel.c
@@ -15,24 +15,17 @@
 #include <string.h>		/* strstr */
 #include <unistd.h>		/* write */
 #include <sys/ioctl.h>		/* ioctl */
-#include <sys/stat.h>		/* stat */
-#include <sys/sysmacros.h>	/* major */
 
 #include "nls.h"
 #include "blkdev.h"
 
 #include <endian.h>
-#ifdef HAVE_LINUX_MAJOR_H
-#include <linux/major.h>	/* FLOPPY_MAJOR */
-#endif
 
 #include "common.h"
 #include "fdisk.h"
 #include "fdisksunlabel.h"
 
 static int     other_endian = 0;
-static int     scsi_disk = 0;
-static int     floppy = 0;
 
 struct systypes sun_sys_types[] = {
 	{SUN_TAG_UNASSIGNED, N_("Unassigned")},
@@ -66,37 +59,6 @@ static inline uint32_t __swap32(uint32_t x) {
 #define SSWAP32(x) (other_endian ? __swap32(x) \
 				 : (uint32_t)(x))
 
-#ifndef FLOPPY_MAJOR
-#define FLOPPY_MAJOR 2
-#endif
-#ifndef IDE0_MAJOR
-#define IDE0_MAJOR 3
-#endif
-#ifndef IDE1_MAJOR
-#define IDE1_MAJOR 22
-#endif
-void guess_device_type(int fd)
-{
-	struct stat bootstat;
-
-	if (fstat (fd, &bootstat) < 0) {
-                scsi_disk = 0;
-                floppy = 0;
-	} else if (S_ISBLK(bootstat.st_mode)
-		   && (major(bootstat.st_rdev) == IDE0_MAJOR ||
-		       major(bootstat.st_rdev) == IDE1_MAJOR)) {
-                scsi_disk = 0;
-                floppy = 0;
-	} else if (S_ISBLK(bootstat.st_mode)
-		   && major(bootstat.st_rdev) == FLOPPY_MAJOR) {
-                scsi_disk = 0;
-                floppy = 1;
-	} else {
-                scsi_disk = 1;
-                floppy = 0;
-	}
-}
-
 static void set_sun_partition(int i, uint32_t start, uint32_t stop, uint16_t sysid)
 {
 	sunlabel->part_tags[i].tag = SSWAP16(sysid);
diff --git a/fdisk/fdisksunlabel.h b/fdisk/fdisksunlabel.h
index b7419cb..fa3f964 100644
--- a/fdisk/fdisksunlabel.h
+++ b/fdisk/fdisksunlabel.h
@@ -77,7 +77,6 @@ struct sun_disk_label {
 
 /* fdisksunlabel.c */
 extern struct systypes sun_sys_types[];
-extern void guess_device_type(int fd);
 extern int check_sun_label(void);
 extern void sun_nolabel(void);
 extern void create_sunlabel(void);
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 09/13] fdisk: don't use get_existing_partition() if disk label isn't dos
  2011-12-15 19:02 [PATCH 01/13] fdisk: remove unused 'require' member in enum action Francesco Cosoleto
                   ` (6 preceding siblings ...)
  2011-12-15 19:02 ` [PATCH 08/13] fdisk: remove unused guess_device_type() function Francesco Cosoleto
@ 2011-12-15 19:02 ` Francesco Cosoleto
  2011-12-15 19:02 ` [PATCH 10/13] fdisk: avoid an intermediate variable in command_prompt() Francesco Cosoleto
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Francesco Cosoleto @ 2011-12-15 19:02 UTC (permalink / raw)
  To: util-linux; +Cc: Francesco Cosoleto

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
---
 fdisk/fdisk.c |   27 +++++++++------------------
 1 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 8f5869d..53eed25 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -1472,11 +1472,16 @@ get_partition(int warn, int max) {
 	return get_partition_dflt(warn, max, 0);
 }
 
+/* User partition selection unless one partition only is available */
+
 static int
 get_existing_partition(int warn, int max) {
 	int pno = -1;
 	int i;
 
+	if (disklabel != DOS_LABEL)
+		goto not_implemented;
+
 	for (i = 0; i < max; i++) {
 		struct pte *pe = &ptes[i];
 		struct partition *p = pe->part_table;
@@ -1495,7 +1500,8 @@ get_existing_partition(int warn, int max) {
 	printf(_("No partition is defined yet!\n"));
 	return -1;
 
- not_unique:
+not_implemented:
+not_unique:
 	return get_partition(warn, max);
 }
 
@@ -1650,14 +1656,7 @@ change_sysid(void) {
 	int i, sys, origsys;
 	struct partition *p;
 
-	/* If sgi_label then don't use get_existing_partition,
-	   let the user select a partition, since get_existing_partition()
-	   only works for Linux like partition tables. */
-	if (disklabel != SGI_LABEL) {
-		i = get_existing_partition(0, partitions);
-	} else {
-		i = get_partition(0, partitions);
-	}
+	i = get_existing_partition(0, partitions);
 
 	if (i == -1)
 		return;
@@ -2922,15 +2921,7 @@ static void command_prompt(void)
 				unknown_command(c);
 			break;
 		case 'd':
-			/* If sgi_label then don't use get_existing_partition,
-			   let the user select a partition, since
-			   get_existing_partition() only works for Linux-like
-			   partition tables */
-			if (disklabel != SGI_LABEL) {
-				j = get_existing_partition(1, partitions);
-			} else {
-				j = get_partition(1, partitions);
-			}
+			j = get_existing_partition(1, partitions);
 			if (j >= 0)
 				delete_partition(j);
 			break;
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 10/13] fdisk: avoid an intermediate variable in command_prompt()
  2011-12-15 19:02 [PATCH 01/13] fdisk: remove unused 'require' member in enum action Francesco Cosoleto
                   ` (7 preceding siblings ...)
  2011-12-15 19:02 ` [PATCH 09/13] fdisk: don't use get_existing_partition() if disk label isn't dos Francesco Cosoleto
@ 2011-12-15 19:02 ` Francesco Cosoleto
  2011-12-15 19:02 ` [PATCH 11/13] fdisk: Fix bad invalid flag 0x00000 warning message Francesco Cosoleto
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Francesco Cosoleto @ 2011-12-15 19:02 UTC (permalink / raw)
  To: util-linux; +Cc: Francesco Cosoleto

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
---
 fdisk/fdisk.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 53eed25..acf0e67 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -1635,6 +1635,9 @@ static void dos_delete_partition(int i)
 static void
 delete_partition(int i)
 {
+	if (i < 0)
+		return;
+
 	if (warn_geometry())
 		return;		/* C/H/S not set */
 
@@ -2869,7 +2872,7 @@ unknown_command(int c) {
 
 static void command_prompt(void)
 {
-	int c, j;
+	int c;
 
 	if (disklabel == OSF_LABEL) {
 		putchar('\n');
@@ -2921,9 +2924,7 @@ static void command_prompt(void)
 				unknown_command(c);
 			break;
 		case 'd':
-			j = get_existing_partition(1, partitions);
-			if (j >= 0)
-				delete_partition(j);
+			delete_partition(get_existing_partition(1, partitions));
 			break;
 		case 'i':
 			if (disklabel == SGI_LABEL)
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 11/13] fdisk: Fix bad invalid flag 0x00000 warning message
  2011-12-15 19:02 [PATCH 01/13] fdisk: remove unused 'require' member in enum action Francesco Cosoleto
                   ` (8 preceding siblings ...)
  2011-12-15 19:02 ` [PATCH 10/13] fdisk: avoid an intermediate variable in command_prompt() Francesco Cosoleto
@ 2011-12-15 19:02 ` Francesco Cosoleto
  2011-12-15 19:02 ` [PATCH 12/13] fdisk: improve some messages Francesco Cosoleto
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Francesco Cosoleto @ 2011-12-15 19:02 UTC (permalink / raw)
  To: util-linux; +Cc: Francesco Cosoleto

This splits check_dos_label() and dos_init() off from get_boot() and gets
rid of the invalid flag 0x00000 warning message due to a check for MBR
signs in zeroized buffer:

	memset(MBRbuffer, 0, 512);

	if (what == create_empty_dos)
		goto got_dos_table;
[...]
got_dos_table:
	if (!valid_part_table_flag(MBRbuffer)) {
[...]
	if (!valid_part_table_flag(pe->sectorbuffer))
		fprintf(stderr, _("Warning: invalid flag 0x%04x of partition "
[...]

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
---
 fdisk/fdisk.c |  161 +++++++++++++++++++++++++++------------------------------
 fdisk/fdisk.h |    2 +-
 2 files changed, 78 insertions(+), 85 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index acf0e67..800ed02 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -288,7 +288,7 @@ unsigned long grain = DEFAULT_SECTOR_SIZE,
 	      alignment_offset;
 int has_topology;
 
-enum labeltype disklabel = DOS_LABEL;	/* Current disklabel */
+enum labeltype disklabel;	/* Current disklabel */
 
 jmp_buf listingbuf;
 
@@ -850,6 +850,30 @@ dos_set_mbr_id(void) {
 	dos_print_mbr_id();
 }
 
+static void dos_init(void)
+{
+	int i;
+
+	disklabel = DOS_LABEL;
+	partitions = 4;
+	ext_index = 0;
+	extended_offset = 0;
+
+	for (i = 0; i < 4; i++) {
+		struct pte *pe = &ptes[i];
+
+		pe->part_table = pt_offset(MBRbuffer, i);
+		pe->ext_pointer = NULL;
+		pe->offset = 0;
+		pe->sectorbuffer = MBRbuffer;
+		pe->changed = 0;
+	}
+
+	warn_geometry();
+	warn_limits();
+	warn_alignment();
+}
+
 static void
 create_doslabel(void) {
 	unsigned int id = get_random_id();
@@ -857,19 +881,17 @@ create_doslabel(void) {
 	fprintf(stderr, _("Building a new DOS disklabel with disk identifier 0x%08x.\n"), id);
 	sun_nolabel();  /* otherwise always recognised as sun */
 	sgi_nolabel();  /* otherwise always recognised as sgi */
-	disklabel = DOS_LABEL;
-	partitions = 4;
 
-	/* Zero out the MBR buffer */
-	extended_offset = 0;
+	dos_init();
+	zeroize_mbr_buffer();
+
 	set_all_unchanged();
 	set_changed(0);
-	get_boot(create_empty_dos);
 
 	/* Generate an MBR ID for this disk */
 	dos_write_mbr_id(MBRbuffer, id);
 
-	/* Mark it bootable (unfortunately required) */
+	/* Put MBR signature */
 	write_part_table_flag(MBRbuffer);
 }
 
@@ -1084,6 +1106,42 @@ void zeroize_mbr_buffer(void)
 		memset(MBRbuffer, 0, MAX_SECTOR_SIZE);
 }
 
+static int check_dos_label(void)
+{
+	int i;
+
+	if (!valid_part_table_flag(MBRbuffer))
+		return 0;
+
+	dos_init();
+
+	for (i = 0; i < 4; i++) {
+		struct pte *pe = &ptes[i];
+
+		if (IS_EXTENDED (pe->part_table->sys_ind)) {
+			if (partitions != 4)
+				fprintf(stderr, _("Ignoring extra extended "
+					"partition %d\n"), i + 1);
+			else
+				read_extended(i);
+		}
+	}
+
+	for (i = 3; i < partitions; i++) {
+		struct pte *pe = &ptes[i];
+
+		if (!valid_part_table_flag(pe->sectorbuffer)) {
+			fprintf(stderr,
+				_("Warning: invalid flag 0x%04x of partition "
+				"table %d will be corrected by w(rite)\n"),
+				part_table_flag(pe->sectorbuffer), i + 1);
+			pe->changed = 1;
+		}
+	}
+
+	return 1;
+}
+
 /*
  * Read MBR.  Returns:
  *   -1: no 0xaa55 flag present (possibly entire disk BSD)
@@ -1092,27 +1150,10 @@ void zeroize_mbr_buffer(void)
  */
 static int
 get_boot(enum action what) {
-	int i;
-
-	partitions = 4;
-	ext_index = 0;
-	extended_offset = 0;
-
-	for (i = 0; i < 4; i++) {
-		struct pte *pe = &ptes[i];
-
-		pe->part_table = pt_offset(MBRbuffer, i);
-		pe->ext_pointer = NULL;
-		pe->offset = 0;
-		pe->sectorbuffer = MBRbuffer;
-		pe->changed = (what == create_empty_dos);
-	}
 
+	disklabel = ANY_LABEL;
 	memset(MBRbuffer, 0, 512);
 
-	if (what == create_empty_dos)
-		goto got_dos_table;		/* skip reading disk */
-
 	if (what != try_only) {
 		if ((fd = open(disk_device, O_RDWR)) < 0) {
 			if ((fd = open(disk_device, O_RDONLY)) < 0)
@@ -1133,17 +1174,9 @@ get_boot(enum action what) {
 
 	update_units();
 
-	if (check_sun_label())
-		return 0;
-
-	if (check_sgi_label())
-		return 0;
-
-	if (check_aix_label())
-		return 0;
-
-	if (check_mac_label())
-		return 0;
+	if (!check_dos_label())
+		if (check_sun_label() || check_sgi_label() || check_aix_label() || check_mac_label())
+			return 0;
 
 	if (check_osf_label()) {
 		if (!valid_part_table_flag(MBRbuffer)) {
@@ -1152,61 +1185,21 @@ get_boot(enum action what) {
 		}
 		printf(_("This disk has both DOS and BSD magic.\n"
 			 "Give the 'b' command to go to BSD mode.\n"));
+		return 0;
 	}
 
-got_dos_table:
+	if (disklabel == ANY_LABEL) {
+		if (what == try_only)
+			return -1;
 
-	if (!valid_part_table_flag(MBRbuffer)) {
-		switch(what) {
-		case fdisk:
-			fprintf(stderr,
-				_("Device contains neither a valid DOS "
-				  "partition table, nor Sun, SGI or OSF "
-				  "disklabel\n"));
+		fprintf(stderr,
+			_("Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel\n"));
 #ifdef __sparc__
-			create_sunlabel();
+		create_sunlabel();
 #else
-			create_doslabel();
+		create_doslabel();
 #endif
-			return 0;
-		case try_only:
-		        return -1;
-		case create_empty_dos:
-			break;
-		default:
-			fprintf(stderr, _("Internal error\n"));
-			exit(1);
-		}
-	}
-
-	for (i = 0; i < 4; i++) {
-		struct pte *pe = &ptes[i];
-
-		if (IS_EXTENDED (pe->part_table->sys_ind)) {
-			if (partitions != 4)
-				fprintf(stderr, _("Ignoring extra extended "
-					"partition %d\n"), i + 1);
-			else
-				read_extended(i);
-		}
-	}
-
-	for (i = 3; i < partitions; i++) {
-		struct pte *pe = &ptes[i];
-
-		if (!valid_part_table_flag(pe->sectorbuffer)) {
-			fprintf(stderr,
-				_("Warning: invalid flag 0x%04x of partition "
-				"table %d will be corrected by w(rite)\n"),
-				part_table_flag(pe->sectorbuffer), i + 1);
-			pe->changed = 1;
-		}
 	}
-
-	warn_geometry();
-	warn_limits();
-	warn_alignment();
-
 	return 0;
 }
 
diff --git a/fdisk/fdisk.h b/fdisk/fdisk.h
index 6641880..84be09c 100644
--- a/fdisk/fdisk.h
+++ b/fdisk/fdisk.h
@@ -54,7 +54,7 @@ enum failure {ioctl_error,
 	unable_to_open, unable_to_read, unable_to_seek,
 	unable_to_write};
 
-enum action {fdisk, try_only, create_empty_dos};
+enum action {fdisk, try_only};
 
 struct geom {
 	unsigned int heads;
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 12/13] fdisk: improve some messages
  2011-12-15 19:02 [PATCH 01/13] fdisk: remove unused 'require' member in enum action Francesco Cosoleto
                   ` (9 preceding siblings ...)
  2011-12-15 19:02 ` [PATCH 11/13] fdisk: Fix bad invalid flag 0x00000 warning message Francesco Cosoleto
@ 2011-12-15 19:02 ` Francesco Cosoleto
  2011-12-15 19:02 ` [PATCH 13/13] tests: update fdisk tests Francesco Cosoleto
  2011-12-16 13:12 ` [PATCH 01/13] fdisk: remove unused 'require' member in enum action Karel Zak
  12 siblings, 0 replies; 18+ messages in thread
From: Francesco Cosoleto @ 2011-12-15 19:02 UTC (permalink / raw)
  To: util-linux; +Cc: Francesco Cosoleto

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
---
 fdisk/fdisk.c         |    2 +-
 fdisk/fdisksgilabel.c |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 800ed02..c41da7a 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -1193,7 +1193,7 @@ get_boot(enum action what) {
 			return -1;
 
 		fprintf(stderr,
-			_("Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel\n"));
+			_("Device does not contain a recognized partition table\n"));
 #ifdef __sparc__
 		create_sunlabel();
 #else
diff --git a/fdisk/fdisksgilabel.c b/fdisk/fdisksgilabel.c
index b432b13..dd3efd0 100644
--- a/fdisk/fdisksgilabel.c
+++ b/fdisk/fdisksgilabel.c
@@ -452,7 +452,7 @@ verify_sgi(int verbose)
 		lastblock = sgi_get_num_sectors(Index[0]);
 	} else {
 		if (verbose)
-			printf(_("One Partition (#11) should cover the entire disk.\n"));
+			printf(_("Partition 11 should cover the entire disk.\n"));
 		if (debug>2)
 			printf("sysid=%d\tpartition=%d\n",
 			       sgi_get_sysid(Index[0]), Index[0]+1);
@@ -570,7 +570,7 @@ sgi_set_partition(int i, unsigned int start, unsigned int length, int sys) {
 	sgilabel->partitions[i].start_sector = SSWAP32(start);
 	set_changed(i);
 	if (sgi_gaps() < 0)	/* rebuild freelist */
-		printf(_("Do You know, You got a partition overlap on the disk?\n"));
+		printf(_("Partition overlap on the disk.\n"));
 	if (length)
 		print_partition_size(i + 1, start, start + length, sys);
 }
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 13/13] tests: update fdisk tests
  2011-12-15 19:02 [PATCH 01/13] fdisk: remove unused 'require' member in enum action Francesco Cosoleto
                   ` (10 preceding siblings ...)
  2011-12-15 19:02 ` [PATCH 12/13] fdisk: improve some messages Francesco Cosoleto
@ 2011-12-15 19:02 ` Francesco Cosoleto
  2011-12-16 13:12 ` [PATCH 01/13] fdisk: remove unused 'require' member in enum action Karel Zak
  12 siblings, 0 replies; 18+ messages in thread
From: Francesco Cosoleto @ 2011-12-15 19:02 UTC (permalink / raw)
  To: util-linux; +Cc: Francesco Cosoleto

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
---
 tests/expected/fdisk/align-512-4K           |   12 ++++++------
 tests/expected/fdisk/align-512-4K-63        |   12 ++++++------
 tests/expected/fdisk/align-512-4K-md        |   24 ++++++++++++------------
 tests/expected/fdisk/align-512-512          |    6 +++---
 tests/expected/fdisk/align-512-512-topology |    6 +++---
 tests/expected/fdisk/oddinput               |    1 -
 6 files changed, 30 insertions(+), 31 deletions(-)

diff --git a/tests/expected/fdisk/align-512-4K b/tests/expected/fdisk/align-512-4K
index 615d609..a510c73 100644
--- a/tests/expected/fdisk/align-512-4K
+++ b/tests/expected/fdisk/align-512-4K
@@ -1,16 +1,16 @@
 Create partitions
-Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
 
-Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
+
+Changes will remain in memory only, until you decide to write them.
+Be careful before using the write command.
+
+Device does not contain a recognized partition table
+
 
 The device presents a logical sector size that is smaller than
 the physical sector size. Aligning to a physical sector (or optimal
 I/O) size boundary is recommended, or performance may be impacted.
 
-
-Changes will remain in memory only, until you decide to write them.
-Be careful before using the write command.
-
 Command (m for help): Partition type:
    p   primary (0 primary, 0 extended, 4 free)
    e   extended
diff --git a/tests/expected/fdisk/align-512-4K-63 b/tests/expected/fdisk/align-512-4K-63
index 63cef9c..e8192ce 100644
--- a/tests/expected/fdisk/align-512-4K-63
+++ b/tests/expected/fdisk/align-512-4K-63
@@ -1,16 +1,16 @@
 Create partitions
-Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
 
-Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
+
+Changes will remain in memory only, until you decide to write them.
+Be careful before using the write command.
+
+Device does not contain a recognized partition table
+
 
 The device presents a logical sector size that is smaller than
 the physical sector size. Aligning to a physical sector (or optimal
 I/O) size boundary is recommended, or performance may be impacted.
 
-
-Changes will remain in memory only, until you decide to write them.
-Be careful before using the write command.
-
 Command (m for help): Partition type:
    p   primary (0 primary, 0 extended, 4 free)
    e   extended
diff --git a/tests/expected/fdisk/align-512-4K-md b/tests/expected/fdisk/align-512-4K-md
index 3a0e7d5..b0081c6 100644
--- a/tests/expected/fdisk/align-512-4K-md
+++ b/tests/expected/fdisk/align-512-4K-md
@@ -1,16 +1,16 @@
 Create partitions
-Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
 
-Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
+
+Changes will remain in memory only, until you decide to write them.
+Be careful before using the write command.
+
+Device does not contain a recognized partition table
+
 
 The device presents a logical sector size that is smaller than
 the physical sector size. Aligning to a physical sector (or optimal
 I/O) size boundary is recommended, or performance may be impacted.
 
-
-Changes will remain in memory only, until you decide to write them.
-Be careful before using the write command.
-
 Command (m for help): Partition type:
    p   primary (0 primary, 0 extended, 4 free)
    e   extended
@@ -44,18 +44,18 @@ Alignment offsets:
 0
 0
 Create partitions (MD)
-Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
 
-Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
+
+Changes will remain in memory only, until you decide to write them.
+Be careful before using the write command.
+
+Device does not contain a recognized partition table
+
 
 The device presents a logical sector size that is smaller than
 the physical sector size. Aligning to a physical sector (or optimal
 I/O) size boundary is recommended, or performance may be impacted.
 
-
-Changes will remain in memory only, until you decide to write them.
-Be careful before using the write command.
-
 Command (m for help): Partition type:
    p   primary (0 primary, 0 extended, 4 free)
    e   extended
diff --git a/tests/expected/fdisk/align-512-512 b/tests/expected/fdisk/align-512-512
index 7f1cdb9..190ad0a 100644
--- a/tests/expected/fdisk/align-512-512
+++ b/tests/expected/fdisk/align-512-512
@@ -1,12 +1,12 @@
 Create partitions
-Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
-
-Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
 
 Changes will remain in memory only, until you decide to write them.
 Be careful before using the write command.
 
+Device does not contain a recognized partition table
+
+
 Command (m for help): Partition type:
    p   primary (0 primary, 0 extended, 4 free)
    e   extended
diff --git a/tests/expected/fdisk/align-512-512-topology b/tests/expected/fdisk/align-512-512-topology
index 3623f0b..2180081 100644
--- a/tests/expected/fdisk/align-512-512-topology
+++ b/tests/expected/fdisk/align-512-512-topology
@@ -1,12 +1,12 @@
 Create partitions
-Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
-
-Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
 
 Changes will remain in memory only, until you decide to write them.
 Be careful before using the write command.
 
+Device does not contain a recognized partition table
+
+
 Command (m for help): Partition type:
    p   primary (0 primary, 0 extended, 4 free)
    e   extended
diff --git a/tests/expected/fdisk/oddinput b/tests/expected/fdisk/oddinput
index 7fd14b5..8714f63 100644
--- a/tests/expected/fdisk/oddinput
+++ b/tests/expected/fdisk/oddinput
@@ -8,7 +8,6 @@ Disk testimage: 10 MB, 10485760 bytes
 Units = cylinders of 16065 * 512 = 8225280 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
-Disk identifier: 0x00000000
 
 Nonexistant file
 Too small file
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 01/13] fdisk: remove unused 'require' member in enum action
  2011-12-15 19:02 [PATCH 01/13] fdisk: remove unused 'require' member in enum action Francesco Cosoleto
                   ` (11 preceding siblings ...)
  2011-12-15 19:02 ` [PATCH 13/13] tests: update fdisk tests Francesco Cosoleto
@ 2011-12-16 13:12 ` Karel Zak
  12 siblings, 0 replies; 18+ messages in thread
From: Karel Zak @ 2011-12-16 13:12 UTC (permalink / raw)
  To: Francesco Cosoleto; +Cc: util-linux

On Thu, Dec 15, 2011 at 08:02:37PM +0100, Francesco Cosoleto wrote:
> --- a/fdisk/fdisk.c
> +++ b/fdisk/fdisk.c

 All (13) patches applied. Good work, you fixed exactly the things
 that I have hated (poor separation of DOS and non-DOS code).

 Thanks!

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 04/13] fdisk: drop one parameter from try() function
  2011-12-15 19:02 ` [PATCH 04/13] fdisk: drop one parameter from try() function Francesco Cosoleto
@ 2011-12-16 13:18   ` Karel Zak
  2011-12-22  2:24   ` Guillem Jover
  1 sibling, 0 replies; 18+ messages in thread
From: Karel Zak @ 2011-12-16 13:18 UTC (permalink / raw)
  To: Francesco Cosoleto; +Cc: util-linux

On Thu, Dec 15, 2011 at 08:02:40PM +0100, Francesco Cosoleto wrote:
> +				if (!is_ide_cdrom_or_tape(argv[k]))

 This function is pretty archaic, we use CDROM_GET_CAPABILITY ioctl to
 detect cdroms in libblkid/src/probe.c. 
 
 It would be nice to add 

    blkdev_is_cdrom(char *)
    blkdev_is_cdrom_fd(int fd) 

 to lkib/blkdev.c and use it for fdisk and libblkid. Volunteer? :-)

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 04/13] fdisk: drop one parameter from try() function
  2011-12-15 19:02 ` [PATCH 04/13] fdisk: drop one parameter from try() function Francesco Cosoleto
  2011-12-16 13:18   ` Karel Zak
@ 2011-12-22  2:24   ` Guillem Jover
  2011-12-22 15:26     ` Francesco Cosoleto
  1 sibling, 1 reply; 18+ messages in thread
From: Guillem Jover @ 2011-12-22  2:24 UTC (permalink / raw)
  To: util-linux

Hi!

On Thu, 2011-12-15 at 20:02:40 +0100, Francesco Cosoleto wrote:
> @@ -2800,15 +2800,13 @@ gpt_warning(char *dev)
>  }
>  
>  static void
> -try(char *device, int user_specified) {
> +try(char *device)
> +{
>  	int gb;
>  
>  	disk_device = device;
>  	if (setjmp(listingbuf))
>  		return;
> -	if (!user_specified)
> -		if (is_ide_cdrom_or_tape(device))
> -			return;
>  	gpt_warning(device);
>  	if ((fd = open(disk_device, type_open)) >= 0) {
>  		gb = get_boot(try_only);
> @@ -2859,7 +2857,7 @@ tryprocpt(void) {
>  		if (is_whole_disk(devname)) {
>  			char *cn = canonicalize_path(devname);
>  			if (cn) {
> -				try(cn, 0);
> +				try(cn);
>  				free(cn);
>  			}
>  		}
> @@ -3079,7 +3077,8 @@ main(int argc, char **argv) {
>  			dummy(&k);
>  			listing = 1;
>  			for (k = optind; k < argc; k++)
> -				try(argv[k], 1);
> +				if (!is_ide_cdrom_or_tape(argv[k]))
> +					try(argv[k]);
>  		} else {
>  			/* we no longer have default device names */
>  			/* but we can use /proc/partitions instead */

The logic on user_specified is inverted so it seems the checks on the
call sites would need to be swapped?

regards,
guillem

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 04/13] fdisk: drop one parameter from try() function
  2011-12-22  2:24   ` Guillem Jover
@ 2011-12-22 15:26     ` Francesco Cosoleto
  2012-01-04 13:36       ` Karel Zak
  0 siblings, 1 reply; 18+ messages in thread
From: Francesco Cosoleto @ 2011-12-22 15:26 UTC (permalink / raw)
  To: util-linux

[-- Attachment #1: Type: text/plain, Size: 255 bytes --]

2011/12/22 Guillem Jover <guillem@hadrons.org>:
> The logic on user_specified is inverted so it seems the checks on the
> call sites would need to be swapped?

Correct. Thank you for pointing out this.

Attached a patch to fix this regression.

Francesco

[-- Attachment #2: 0001-fdisk-fix-incorrect-position-of-is_ide_cdrom_or_tape.patch --]
[-- Type: text/x-patch, Size: 1180 bytes --]

From 2cf578cd4abfbe0609e1de97de754cfcc19a558c Mon Sep 17 00:00:00 2001
From: Francesco Cosoleto <cosoleto@gmail.com>
Date: Thu, 22 Dec 2011 15:53:25 +0100
Subject: [PATCH] fdisk: fix incorrect position of is_ide_cdrom_or_tape() call

Reported-by: Guillem Jover <guillem@hadrons.org>
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
---
 fdisk/fdisk.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index c41da7a..bde60a9 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -2848,7 +2848,8 @@ print_all_partition_table_from_option(void)
 		if (is_whole_disk(devname)) {
 			char *cn = canonicalize_path(devname);
 			if (cn) {
-				print_partition_table_from_option(cn);
+				if (!is_ide_cdrom_or_tape(cn))
+					print_partition_table_from_option(cn);
 				free(cn);
 			}
 		}
@@ -3057,8 +3058,7 @@ main(int argc, char **argv) {
 			dummy(&k);
 			listing = 1;
 			for (k = optind; k < argc; k++)
-				if (!is_ide_cdrom_or_tape(argv[k]))
-					print_partition_table_from_option(argv[k]);
+				print_partition_table_from_option(argv[k]);
 		} else
 			print_all_partition_table_from_option();
 		exit(0);
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 04/13] fdisk: drop one parameter from try() function
  2011-12-22 15:26     ` Francesco Cosoleto
@ 2012-01-04 13:36       ` Karel Zak
  0 siblings, 0 replies; 18+ messages in thread
From: Karel Zak @ 2012-01-04 13:36 UTC (permalink / raw)
  To: Francesco Cosoleto; +Cc: util-linux

On Thu, Dec 22, 2011 at 04:26:49PM +0100, Francesco Cosoleto wrote:
>  fdisk/fdisk.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)

 Applied, thanks. (Please, don't use attachment next time.)

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2012-01-04 13:36 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-15 19:02 [PATCH 01/13] fdisk: remove unused 'require' member in enum action Francesco Cosoleto
2011-12-15 19:02 ` [PATCH 02/13] fdisk: remove possibly_osf_label variable that is only assigned Francesco Cosoleto
2011-12-15 19:02 ` [PATCH 03/13] fdisk: move code for renaming SGI bootfile to SGI module Francesco Cosoleto
2011-12-15 19:02 ` [PATCH 04/13] fdisk: drop one parameter from try() function Francesco Cosoleto
2011-12-16 13:18   ` Karel Zak
2011-12-22  2:24   ` Guillem Jover
2011-12-22 15:26     ` Francesco Cosoleto
2012-01-04 13:36       ` Karel Zak
2011-12-15 19:02 ` [PATCH 05/13] fdisk: rename try() and tryprocpt() functions Francesco Cosoleto
2011-12-15 19:02 ` [PATCH 06/13] fdisk: get rid of type_open global variable Francesco Cosoleto
2011-12-15 19:02 ` [PATCH 07/13] fdisk: get rid of get_boot(create_empty_sun) call Francesco Cosoleto
2011-12-15 19:02 ` [PATCH 08/13] fdisk: remove unused guess_device_type() function Francesco Cosoleto
2011-12-15 19:02 ` [PATCH 09/13] fdisk: don't use get_existing_partition() if disk label isn't dos Francesco Cosoleto
2011-12-15 19:02 ` [PATCH 10/13] fdisk: avoid an intermediate variable in command_prompt() Francesco Cosoleto
2011-12-15 19:02 ` [PATCH 11/13] fdisk: Fix bad invalid flag 0x00000 warning message Francesco Cosoleto
2011-12-15 19:02 ` [PATCH 12/13] fdisk: improve some messages Francesco Cosoleto
2011-12-15 19:02 ` [PATCH 13/13] tests: update fdisk tests Francesco Cosoleto
2011-12-16 13:12 ` [PATCH 01/13] fdisk: remove unused 'require' member in enum action Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).