public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/5] fdisk: create DOS specific write table function
@ 2012-05-06 12:10 Davidlohr Bueso
  2012-05-06 18:11 ` Petr Uzel
  0 siblings, 1 reply; 4+ messages in thread
From: Davidlohr Bueso @ 2012-05-06 12:10 UTC (permalink / raw)
  To: Karel Zak, Petr Uzel; +Cc: util-linux

From: Davidlohr Bueso <dave@gnu.org>

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
 fdisk/fdisk.c         |   27 ++++-----------------------
 fdisk/fdiskdoslabel.c |   27 +++++++++++++++++++++++++++
 fdisk/fdiskdoslabel.h |    1 +
 3 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 8c2a162..3044879 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -1672,31 +1672,12 @@ static void
 write_table(void) {
 	int i;
 
-	if (disklabel == DOS_LABEL) {
-		/* MBR (primary partitions) */
-		if (!MBRbuffer_changed) {
-			for (i = 0; i < 4; i++)
-				if (ptes[i].changed)
-					MBRbuffer_changed = 1;
-		}
-		if (MBRbuffer_changed) {
-			write_part_table_flag(MBRbuffer);
-			write_sector(fd, 0, MBRbuffer);
-		}
-		/* EBR (logical partitions) */
-		for (i = 4; i < partitions; i++) {
-			struct pte *pe = &ptes[i];
-
-			if (pe->changed) {
-				write_part_table_flag(pe->sectorbuffer);
-				write_sector(fd, pe->offset, pe->sectorbuffer);
-			}
-		}
-	}
-	else if (disklabel == SGI_LABEL) {
+	if (disklabel == DOS_LABEL)
+		dos_write_table();
+	else if (disklabel == SGI_LABEL)
 		/* no test on change? the printf below might be mistaken */
 		sgi_write_table();
-	} else if (disklabel == SUN_LABEL) {
+	else if (disklabel == SUN_LABEL) {
 		int needw = 0;
 
 		for (i=0; i<8; i++)
diff --git a/fdisk/fdiskdoslabel.c b/fdisk/fdiskdoslabel.c
index 3f820db..a13a83a 100644
--- a/fdisk/fdiskdoslabel.c
+++ b/fdisk/fdiskdoslabel.c
@@ -657,3 +657,30 @@ void dos_new_partition(void)
 			printf(_("Invalid partition type `%c'\n"), c);
 	}
 }
+
+void dos_write_table(void)
+{
+	int i;
+
+	if (disklabel == DOS_LABEL) {
+		/* MBR (primary partitions) */
+		if (!MBRbuffer_changed) {
+			for (i = 0; i < 4; i++)
+				if (ptes[i].changed)
+					MBRbuffer_changed = 1;
+		}
+		if (MBRbuffer_changed) {
+			write_part_table_flag(MBRbuffer);
+			write_sector(fd, 0, MBRbuffer);
+		}
+		/* EBR (logical partitions) */
+		for (i = 4; i < partitions; i++) {
+			struct pte *pe = &ptes[i];
+
+			if (pe->changed) {
+				write_part_table_flag(pe->sectorbuffer);
+				write_sector(fd, pe->offset, pe->sectorbuffer);
+			}
+		}
+	}
+}
diff --git a/fdisk/fdiskdoslabel.h b/fdisk/fdiskdoslabel.h
index e45a026..8c116f7 100644
--- a/fdisk/fdiskdoslabel.h
+++ b/fdisk/fdiskdoslabel.h
@@ -52,5 +52,6 @@ extern int is_dos_partition(int t);
 extern void dos_init(void);
 extern void dos_add_partition(int n, int sys);
 extern void dos_new_partition(void);
+extern void dos_write_table(void);
 
 #endif
-- 
1.7.4.1

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

* Re: [PATCH 3/5] fdisk: create DOS specific write table function
  2012-05-06 12:10 [PATCH 3/5] fdisk: create DOS specific write table function Davidlohr Bueso
@ 2012-05-06 18:11 ` Petr Uzel
  2012-05-06 19:02   ` Davidlohr Bueso
  0 siblings, 1 reply; 4+ messages in thread
From: Petr Uzel @ 2012-05-06 18:11 UTC (permalink / raw)
  To: Davidlohr Bueso; +Cc: util-linux

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

On Sun, May 06, 2012 at 02:10:21PM +0200, Davidlohr Bueso wrote:
> From: Davidlohr Bueso <dave@gnu.org>
> 
> Signed-off-by: Davidlohr Bueso <dave@gnu.org>
> ---
>  fdisk/fdisk.c         |   27 ++++-----------------------
>  fdisk/fdiskdoslabel.c |   27 +++++++++++++++++++++++++++
>  fdisk/fdiskdoslabel.h |    1 +
>  3 files changed, 32 insertions(+), 23 deletions(-)
> 
> diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
> index 8c2a162..3044879 100644
> --- a/fdisk/fdisk.c
> +++ b/fdisk/fdisk.c
> @@ -1672,31 +1672,12 @@ static void
>  write_table(void) {
>  	int i;
>  
> -	if (disklabel == DOS_LABEL) {
> -		/* MBR (primary partitions) */
> -		if (!MBRbuffer_changed) {
> -			for (i = 0; i < 4; i++)
> -				if (ptes[i].changed)
> -					MBRbuffer_changed = 1;
> -		}
> -		if (MBRbuffer_changed) {
> -			write_part_table_flag(MBRbuffer);
> -			write_sector(fd, 0, MBRbuffer);
> -		}
> -		/* EBR (logical partitions) */
> -		for (i = 4; i < partitions; i++) {
> -			struct pte *pe = &ptes[i];
> -
> -			if (pe->changed) {
> -				write_part_table_flag(pe->sectorbuffer);
> -				write_sector(fd, pe->offset, pe->sectorbuffer);
> -			}
> -		}
> -	}
> -	else if (disklabel == SGI_LABEL) {
> +	if (disklabel == DOS_LABEL)
> +		dos_write_table();
> +	else if (disklabel == SGI_LABEL)
>  		/* no test on change? the printf below might be mistaken */
>  		sgi_write_table();
> -	} else if (disklabel == SUN_LABEL) {
> +	else if (disklabel == SUN_LABEL) {
>  		int needw = 0;
>  
>  		for (i=0; i<8; i++)
> diff --git a/fdisk/fdiskdoslabel.c b/fdisk/fdiskdoslabel.c
> index 3f820db..a13a83a 100644
> --- a/fdisk/fdiskdoslabel.c
> +++ b/fdisk/fdiskdoslabel.c
> @@ -657,3 +657,30 @@ void dos_new_partition(void)
>  			printf(_("Invalid partition type `%c'\n"), c);
>  	}
>  }
> +
> +void dos_write_table(void)
> +{
> +	int i;
> +
> +	if (disklabel == DOS_LABEL) {

This if is unnecessary - the caller should make sure that
disklabel == DOS_LABEL as write_table() does. What about

assert(disklabel == DOS_LABEL) instead?

> +		/* MBR (primary partitions) */
> +		if (!MBRbuffer_changed) {
> +			for (i = 0; i < 4; i++)
> +				if (ptes[i].changed)
> +					MBRbuffer_changed = 1;
> +		}
> +		if (MBRbuffer_changed) {
> +			write_part_table_flag(MBRbuffer);
> +			write_sector(fd, 0, MBRbuffer);
> +		}
> +		/* EBR (logical partitions) */
> +		for (i = 4; i < partitions; i++) {
> +			struct pte *pe = &ptes[i];
> +
> +			if (pe->changed) {
> +				write_part_table_flag(pe->sectorbuffer);
> +				write_sector(fd, pe->offset, pe->sectorbuffer);
> +			}
> +		}
> +	}
> +}
> diff --git a/fdisk/fdiskdoslabel.h b/fdisk/fdiskdoslabel.h
> index e45a026..8c116f7 100644
> --- a/fdisk/fdiskdoslabel.h
> +++ b/fdisk/fdiskdoslabel.h
> @@ -52,5 +52,6 @@ extern int is_dos_partition(int t);
>  extern void dos_init(void);
>  extern void dos_add_partition(int n, int sys);
>  extern void dos_new_partition(void);
> +extern void dos_write_table(void);
>  
>  #endif
> -- 
> 1.7.4.1

Petr

--
Petr Uzel
IRC: ptr_uzl @ freenode

[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: [PATCH 3/5] fdisk: create DOS specific write table function
  2012-05-06 18:11 ` Petr Uzel
@ 2012-05-06 19:02   ` Davidlohr Bueso
  2012-05-10  9:51     ` Karel Zak
  0 siblings, 1 reply; 4+ messages in thread
From: Davidlohr Bueso @ 2012-05-06 19:02 UTC (permalink / raw)
  To: Petr Uzel; +Cc: util-linux

On Sun, 2012-05-06 at 20:11 +0200, Petr Uzel wrote:
> On Sun, May 06, 2012 at 02:10:21PM +0200, Davidlohr Bueso wrote:
> > From: Davidlohr Bueso <dave@gnu.org>
> > 
> > Signed-off-by: Davidlohr Bueso <dave@gnu.org>
> > ---
> >  fdisk/fdisk.c         |   27 ++++-----------------------
> >  fdisk/fdiskdoslabel.c |   27 +++++++++++++++++++++++++++
> >  fdisk/fdiskdoslabel.h |    1 +
> >  3 files changed, 32 insertions(+), 23 deletions(-)
> > 
> > diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
> > index 8c2a162..3044879 100644
> > --- a/fdisk/fdisk.c
> > +++ b/fdisk/fdisk.c
> > @@ -1672,31 +1672,12 @@ static void
> >  write_table(void) {
> >  	int i;
> >  
> > -	if (disklabel == DOS_LABEL) {
> > -		/* MBR (primary partitions) */
> > -		if (!MBRbuffer_changed) {
> > -			for (i = 0; i < 4; i++)
> > -				if (ptes[i].changed)
> > -					MBRbuffer_changed = 1;
> > -		}
> > -		if (MBRbuffer_changed) {
> > -			write_part_table_flag(MBRbuffer);
> > -			write_sector(fd, 0, MBRbuffer);
> > -		}
> > -		/* EBR (logical partitions) */
> > -		for (i = 4; i < partitions; i++) {
> > -			struct pte *pe = &ptes[i];
> > -
> > -			if (pe->changed) {
> > -				write_part_table_flag(pe->sectorbuffer);
> > -				write_sector(fd, pe->offset, pe->sectorbuffer);
> > -			}
> > -		}
> > -	}
> > -	else if (disklabel == SGI_LABEL) {
> > +	if (disklabel == DOS_LABEL)
> > +		dos_write_table();
> > +	else if (disklabel == SGI_LABEL)
> >  		/* no test on change? the printf below might be mistaken */
> >  		sgi_write_table();
> > -	} else if (disklabel == SUN_LABEL) {
> > +	else if (disklabel == SUN_LABEL) {
> >  		int needw = 0;
> >  
> >  		for (i=0; i<8; i++)
> > diff --git a/fdisk/fdiskdoslabel.c b/fdisk/fdiskdoslabel.c
> > index 3f820db..a13a83a 100644
> > --- a/fdisk/fdiskdoslabel.c
> > +++ b/fdisk/fdiskdoslabel.c
> > @@ -657,3 +657,30 @@ void dos_new_partition(void)
> >  			printf(_("Invalid partition type `%c'\n"), c);
> >  	}
> >  }
> > +
> > +void dos_write_table(void)
> > +{
> > +	int i;
> > +
> > +	if (disklabel == DOS_LABEL) {
> 
> This if is unnecessary - the caller should make sure that
> disklabel == DOS_LABEL as write_table() does. What about
> 
> assert(disklabel == DOS_LABEL) instead?

Absolutely right. I don't think we even need an assert here since this
is only called from DOS context and fdisk.c does that check - plus no
other functions or labels do it anyway.

From: Davidlohr Bueso <dave@gnu.org>
Date: Sun, 6 May 2012 21:00:16 +0200
Subject: [PATCH] fdisk: create DOS specific write table function

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
 fdisk/fdisk.c         |   27 ++++-----------------------
 fdisk/fdiskdoslabel.c |   25 +++++++++++++++++++++++++
 fdisk/fdiskdoslabel.h |    1 +
 3 files changed, 30 insertions(+), 23 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 8c2a162..3044879 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -1672,31 +1672,12 @@ static void
 write_table(void) {
 	int i;
 
-	if (disklabel == DOS_LABEL) {
-		/* MBR (primary partitions) */
-		if (!MBRbuffer_changed) {
-			for (i = 0; i < 4; i++)
-				if (ptes[i].changed)
-					MBRbuffer_changed = 1;
-		}
-		if (MBRbuffer_changed) {
-			write_part_table_flag(MBRbuffer);
-			write_sector(fd, 0, MBRbuffer);
-		}
-		/* EBR (logical partitions) */
-		for (i = 4; i < partitions; i++) {
-			struct pte *pe = &ptes[i];
-
-			if (pe->changed) {
-				write_part_table_flag(pe->sectorbuffer);
-				write_sector(fd, pe->offset, pe->sectorbuffer);
-			}
-		}
-	}
-	else if (disklabel == SGI_LABEL) {
+	if (disklabel == DOS_LABEL)
+		dos_write_table();
+	else if (disklabel == SGI_LABEL)
 		/* no test on change? the printf below might be mistaken */
 		sgi_write_table();
-	} else if (disklabel == SUN_LABEL) {
+	else if (disklabel == SUN_LABEL) {
 		int needw = 0;
 
 		for (i=0; i<8; i++)
diff --git a/fdisk/fdiskdoslabel.c b/fdisk/fdiskdoslabel.c
index 3f820db..4e12d94 100644
--- a/fdisk/fdiskdoslabel.c
+++ b/fdisk/fdiskdoslabel.c
@@ -657,3 +657,28 @@ void dos_new_partition(void)
 			printf(_("Invalid partition type `%c'\n"), c);
 	}
 }
+
+void dos_write_table(void)
+{
+	int i;
+	
+	/* MBR (primary partitions) */
+	if (!MBRbuffer_changed) {
+		for (i = 0; i < 4; i++)
+			if (ptes[i].changed)
+				MBRbuffer_changed = 1;
+	}
+	if (MBRbuffer_changed) {
+		write_part_table_flag(MBRbuffer);
+		write_sector(fd, 0, MBRbuffer);
+	}
+	/* EBR (logical partitions) */
+	for (i = 4; i < partitions; i++) {
+		struct pte *pe = &ptes[i];
+
+		if (pe->changed) {
+			write_part_table_flag(pe->sectorbuffer);
+			write_sector(fd, pe->offset, pe->sectorbuffer);
+		}
+	}
+}
diff --git a/fdisk/fdiskdoslabel.h b/fdisk/fdiskdoslabel.h
index e45a026..8c116f7 100644
--- a/fdisk/fdiskdoslabel.h
+++ b/fdisk/fdiskdoslabel.h
@@ -52,5 +52,6 @@ extern int is_dos_partition(int t);
 extern void dos_init(void);
 extern void dos_add_partition(int n, int sys);
 extern void dos_new_partition(void);
+extern void dos_write_table(void);
 
 #endif
-- 
1.7.4.1




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

* Re: [PATCH 3/5] fdisk: create DOS specific write table function
  2012-05-06 19:02   ` Davidlohr Bueso
@ 2012-05-10  9:51     ` Karel Zak
  0 siblings, 0 replies; 4+ messages in thread
From: Karel Zak @ 2012-05-10  9:51 UTC (permalink / raw)
  To: Davidlohr Bueso; +Cc: Petr Uzel, util-linux

On Sun, May 06, 2012 at 09:02:45PM +0200, Davidlohr Bueso wrote:
>  fdisk/fdisk.c         |   27 ++++-----------------------
>  fdisk/fdiskdoslabel.c |   25 +++++++++++++++++++++++++
>  fdisk/fdiskdoslabel.h |    1 +
>  3 files changed, 30 insertions(+), 23 deletions(-)

 Applied, thanks.

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

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

end of thread, other threads:[~2012-05-10  9:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-06 12:10 [PATCH 3/5] fdisk: create DOS specific write table function Davidlohr Bueso
2012-05-06 18:11 ` Petr Uzel
2012-05-06 19:02   ` Davidlohr Bueso
2012-05-10  9:51     ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox