All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sfdisk: make some tests conditional to !Linux
@ 2011-08-18  7:30 Giulio
  2011-08-22  8:32 ` Karel Zak
  2011-08-23 10:21 ` Karel Zak
  0 siblings, 2 replies; 5+ messages in thread
From: Giulio @ 2011-08-18  7:30 UTC (permalink / raw)
  To: util-linux

This patch makes the following tests/actions conditional to "!Linux":

- Force cylinders as format instead of MB, even if user asked for MB.
This solves a bug where if you use "-L -uM", set 1 as starting MB and the
disk is larger than a certain size (about 1GB) the partition would start at
sector 1 instead of 1MB due to cyl rounding.

- Warn about partitions not starting/ending on cyl boundaries.

- Check if CHS is ok.

I used the "!Linux" notation since it was already used elsewhere in the
code.

Sorry, I don't use git, hope this is ok.

Signed-off-by: Giulio Orsero <giulioo@pobox.com>
---
--- a/fdisk/sfdisk.c	2011-08-17 17:17:43.000000000 +0200
+++ b/fdisk/sfdisk.c	2011-08-17 22:48:52.000000000 +0200
@@ -1315,7 +1315,7 @@ partitions_ok(struct disk_desc *z) {
      * The first partition starts after MBR.
      * Logical partitions start slightly after the containing extended partn.
      */
-    if (B.cylindersize) {
+    if (B.cylindersize && !Linux) {
 	for (p = partitions; p < partitions + partno; p++)
 	    if (p->size) {
 		if (p->start % B.cylindersize != 0
@@ -1325,14 +1325,12 @@ partitions_ok(struct disk_desc *z) {
 		    && (p->p.start_sect >= B.cylindersize)) {
 		    my_warn(_("Warning: partition %s does not start "
 			      "at a cylinder boundary\n"), PNO(p));
-		    if (!Linux)
-			return 0;
+		    return 0;
 		}
 		if ((p->start + p->size) % B.cylindersize) {
 		    my_warn(_("Warning: partition %s does not end "
 			      "at a cylinder boundary\n"), PNO(p));
-		    if (!Linux)
-			return 0;
+		    return 0;
 		}
 	    }
     }
@@ -1378,7 +1376,7 @@ partitions_ok(struct disk_desc *z) {
 	    b = p->p.begin_chs;
 	    aa = chs_to_longchs(a);
 	    bb = chs_to_longchs(b);
-	    if (!chs_ok(b, PNO(p), _("start")))
+	    if (!chs_ok(b, PNO(p), _("start")) && !Linux)
 		return 0;
 	    if (a.s && !is_equal_chs(a, b))
 		my_warn(_
@@ -1388,7 +1386,7 @@ partitions_ok(struct disk_desc *z) {
 	    b = p->p.end_chs;
 	    aa = chs_to_longchs(a);
 	    bb = chs_to_longchs(b);
-	    if (!chs_ok(b, PNO(p), _("end")))
+	    if (!chs_ok(b, PNO(p), _("end")) && !Linux)
 		return 0;
 	    if (a.s && !is_equal_chs(a, b))
 		my_warn(_
@@ -2087,7 +2085,7 @@ read_line(int pno, struct part_desc *ep,
 
     /* use specified format, but round to cylinders if F_MEGABYTE specified */
     format = 0;
-    if (B.cylindersize && specified_format == F_MEGABYTE)
+    if (B.cylindersize && specified_format == F_MEGABYTE && !Linux)
 	format = F_CYLINDER;
 
     orig = (one_only ? &(oldp.partitions[pno]) : 0);

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

* Re: [PATCH] sfdisk: make some tests conditional to !Linux
  2011-08-18  7:30 [PATCH] sfdisk: make some tests conditional to !Linux Giulio
@ 2011-08-22  8:32 ` Karel Zak
  2011-08-22 18:45   ` Giulio Orsero
  2011-08-22 18:46   ` Giulio Orsero
  2011-08-23 10:21 ` Karel Zak
  1 sibling, 2 replies; 5+ messages in thread
From: Karel Zak @ 2011-08-22  8:32 UTC (permalink / raw)
  To: giulioo; +Cc: util-linux

On Thu, Aug 18, 2011 at 09:30:30AM +0200, Giulio wrote:
> +	    if (!chs_ok(b, PNO(p), _("start")) && !Linux)
[...]
> +	    if (!chs_ok(b, PNO(p), _("end")) && !Linux)

would be better to use

    if (!Linux && chs_ok(b, PNO(p), ....)

so the chs_ok() will not called on Linux at all?

    Karel

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

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

* Re: [PATCH] sfdisk: make some tests conditional to !Linux
  2011-08-22  8:32 ` Karel Zak
@ 2011-08-22 18:45   ` Giulio Orsero
  2011-08-22 18:46   ` Giulio Orsero
  1 sibling, 0 replies; 5+ messages in thread
From: Giulio Orsero @ 2011-08-22 18:45 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

On Mon, 22 Aug 2011 10:32:06 +0200, Karel Zak <kzak@redhat.com> wrote:

>On Thu, Aug 18, 2011 at 09:30:30AM +0200, Giulio wrote:
>> +	    if (!chs_ok(b, PNO(p), _("start")) && !Linux)
>[...]
>> +	    if (!chs_ok(b, PNO(p), _("end")) && !Linux)
>would be better to use
>    if (!Linux && chs_ok(b, PNO(p), ....)
>so the chs_ok() will not called on Linux at all?

Maybe the compiler reordered it since it didn't print those messages =
anymore
anyway; for clarity I redordered the tests.

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

* Re: [PATCH] sfdisk: make some tests conditional to !Linux
  2011-08-22  8:32 ` Karel Zak
  2011-08-22 18:45   ` Giulio Orsero
@ 2011-08-22 18:46   ` Giulio Orsero
  1 sibling, 0 replies; 5+ messages in thread
From: Giulio Orsero @ 2011-08-22 18:46 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

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

This patch makes the following tests/actions conditional to "!Linux":

- Force cylinders as format instead of MB, even if user asked for MB.
This solves a bug where if you use "-L -uM", set 1 as starting MB and the
disk is larger than a certain size (about 1GB) the partition would start at
sector 1 instead of 1MB due to cyl rounding.

- Warn about partitions not starting/ending on cyl boundaries.

- Check if CHS is ok.

I used the "!Linux" notation since it was already used elsewhere in the
code.

Sorry, I don't use git, hope this is ok.

Signed-off-by: Giulio Orsero <giulioo@pobox.com>
-- 
giulioo@pobox.com

[-- Attachment #2: sfdisk.linux-compat2.diff --]
[-- Type: application/octet-stream, Size: 1943 bytes --]

--- a/fdisk/sfdisk.c	2011-08-17 17:17:43.000000000 +0200
+++ b/fdisk/sfdisk.c	2011-08-22 14:59:26.000000000 +0200
@@ -1315,7 +1315,7 @@ partitions_ok(struct disk_desc *z) {
      * The first partition starts after MBR.
      * Logical partitions start slightly after the containing extended partn.
      */
-    if (B.cylindersize) {
+    if (B.cylindersize && !Linux) {
 	for (p = partitions; p < partitions + partno; p++)
 	    if (p->size) {
 		if (p->start % B.cylindersize != 0
@@ -1325,14 +1325,12 @@ partitions_ok(struct disk_desc *z) {
 		    && (p->p.start_sect >= B.cylindersize)) {
 		    my_warn(_("Warning: partition %s does not start "
 			      "at a cylinder boundary\n"), PNO(p));
-		    if (!Linux)
-			return 0;
+		    return 0;
 		}
 		if ((p->start + p->size) % B.cylindersize) {
 		    my_warn(_("Warning: partition %s does not end "
 			      "at a cylinder boundary\n"), PNO(p));
-		    if (!Linux)
-			return 0;
+		    return 0;
 		}
 	    }
     }
@@ -1378,7 +1376,7 @@ partitions_ok(struct disk_desc *z) {
 	    b = p->p.begin_chs;
 	    aa = chs_to_longchs(a);
 	    bb = chs_to_longchs(b);
-	    if (!chs_ok(b, PNO(p), _("start")))
+	    if (!Linux && !chs_ok(b, PNO(p), _("start")))
 		return 0;
 	    if (a.s && !is_equal_chs(a, b))
 		my_warn(_
@@ -1388,7 +1386,7 @@ partitions_ok(struct disk_desc *z) {
 	    b = p->p.end_chs;
 	    aa = chs_to_longchs(a);
 	    bb = chs_to_longchs(b);
-	    if (!chs_ok(b, PNO(p), _("end")))
+	    if (!Linux && !chs_ok(b, PNO(p), _("end")))
 		return 0;
 	    if (a.s && !is_equal_chs(a, b))
 		my_warn(_
@@ -2087,7 +2085,7 @@ read_line(int pno, struct part_desc *ep,
 
     /* use specified format, but round to cylinders if F_MEGABYTE specified */
     format = 0;
-    if (B.cylindersize && specified_format == F_MEGABYTE)
+    if (B.cylindersize && specified_format == F_MEGABYTE && !Linux)
 	format = F_CYLINDER;
 
     orig = (one_only ? &(oldp.partitions[pno]) : 0);

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

* Re: [PATCH] sfdisk: make some tests conditional to !Linux
  2011-08-18  7:30 [PATCH] sfdisk: make some tests conditional to !Linux Giulio
  2011-08-22  8:32 ` Karel Zak
@ 2011-08-23 10:21 ` Karel Zak
  1 sibling, 0 replies; 5+ messages in thread
From: Karel Zak @ 2011-08-23 10:21 UTC (permalink / raw)
  To: giulioo; +Cc: util-linux

On Thu, Aug 18, 2011 at 09:30:30AM +0200, Giulio wrote:
> --- a/fdisk/sfdisk.c	2011-08-17 17:17:43.000000000 +0200
> +++ b/fdisk/sfdisk.c	2011-08-17 22:48:52.000000000 +0200

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

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

end of thread, other threads:[~2011-08-23 10:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-18  7:30 [PATCH] sfdisk: make some tests conditional to !Linux Giulio
2011-08-22  8:32 ` Karel Zak
2011-08-22 18:45   ` Giulio Orsero
2011-08-22 18:46   ` Giulio Orsero
2011-08-23 10:21 ` Karel Zak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.