]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: clean up sun geometry stuff
authorKarel Zak <kzak@redhat.com>
Wed, 22 May 2013 12:41:58 +0000 (14:41 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2013 14:46:56 +0000 (16:46 +0200)
 - move fdisk_sun_set_* functions to public API file
 - remove extra function to set ncyl -- this has to follow regular
   geo.cylinders
 - set alternative cylinders to zero (to be compatible with parted)
 - it seems that the previous code completely ignored relation between
   geo.cylinders, sunlabel->acyl and sunlabel->ncyl.

Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk.c
libfdisk/src/fdiskP.h
libfdisk/src/libfdisk.h
libfdisk/src/sun.c

index e884ee743b3a0fc69a19a81841ea3b0a64b1648f..09fa0746b31d68769cab6a5c1e68eb7168b9e2b1 100644 (file)
@@ -755,9 +755,6 @@ expert_command_prompt(struct fdisk_context *cxt)
                                user_cylinders = num;
                                fdisk_override_geometry(cxt, user_cylinders,
                                                user_heads, user_sectors);
-                               if (fdisk_is_disklabel(cxt, SUN))
-                                       fdisk_sun_set_ncyl(cxt,
-                                                       cxt->geom.cylinders);
                        }
                        break;
                case 'd':
index 6a184a0b7d10b05d63c0ca3a41029422af27312b..167670fcbb30b064289c32589fea7c95ed5db91d 100644 (file)
@@ -343,13 +343,4 @@ extern int fdisk_info_new_partition(
                        int num, sector_t start, sector_t stop,
                        struct fdisk_parttype *t);
 
-/* sun.h */
-extern void fdisk_sun_set_alt_cyl(struct fdisk_context *cxt);
-extern void fdisk_sun_set_ncyl(struct fdisk_context *cxt, int cyl);
-extern void fdisk_sun_set_xcyl(struct fdisk_context *cxt);
-extern void fdisk_sun_set_ilfact(struct fdisk_context *cxt);
-extern void fdisk_sun_set_rspeed(struct fdisk_context *cxt);
-extern void fdisk_sun_set_pcylcount(struct fdisk_context *cxt);
-
-
 #endif /* _LIBFDISK_PRIVATE_H */
index 049420d7ead8d6692943201a32ff4ebe8c46ac87..fc38ef77054be10c26c96bf3c2f7947fc499cebb 100644 (file)
@@ -142,6 +142,13 @@ extern int fdisk_reset_alignment(struct fdisk_context *cxt);
 extern int fdisk_dos_enable_compatible(struct fdisk_label *lb, int enable);
 extern int fdisk_dos_is_compatible(struct fdisk_label *lb);
 
+/* sun.h */
+extern int fdisk_sun_set_alt_cyl(struct fdisk_context *cxt);
+extern int fdisk_sun_set_xcyl(struct fdisk_context *cxt);
+extern int fdisk_sun_set_ilfact(struct fdisk_context *cxt);
+extern int fdisk_sun_set_rspeed(struct fdisk_context *cxt);
+extern int fdisk_sun_set_pcylcount(struct fdisk_context *cxt);
+
 /* gpt */
 extern int fdisk_gpt_partition_set_uuid(struct fdisk_context *cxt, size_t i);
 extern int fdisk_gpt_partition_set_name(struct fdisk_context *cxt, size_t i);
index e7a1c879ea6e5cd0de21819aeca530eb3c89f78c..cd14cccece891471f341d8b2013b8dbbb8b0f544 100644 (file)
@@ -248,9 +248,8 @@ static int sun_create_disklabel(struct fdisk_context *cxt)
 #endif
                ask_geom(cxt);
 
-       sunlabel->acyl   = cpu_to_be16(2);
+       sunlabel->acyl   = cpu_to_be16(0);
        sunlabel->pcyl   = cpu_to_be16(cxt->geom.cylinders);
-       sunlabel->ncyl   = cpu_to_be16(cxt->geom.cylinders - 2);
        sunlabel->rpm    = cpu_to_be16(5400);
        sunlabel->intrlv = cpu_to_be16(1);
        sunlabel->apc    = cpu_to_be16(0);
@@ -762,7 +761,7 @@ static int sun_list_disklabel(struct fdisk_context *cxt)
 }
 
 
-void fdisk_sun_set_alt_cyl(struct fdisk_context *cxt)
+int fdisk_sun_set_alt_cyl(struct fdisk_context *cxt)
 {
        struct sun_disklabel *sunlabel = self_disklabel(cxt);
        uintmax_t res;
@@ -771,17 +770,14 @@ void fdisk_sun_set_alt_cyl(struct fdisk_context *cxt)
                        65535,                                  /* high */
                        _("Number of alternate cylinders"),     /* query */
                        &res);                                  /* result */
-       if (!rc)
-               sunlabel->acyl = cpu_to_be16(res);
-}
+       if (rc)
+               return rc;
 
-void fdisk_sun_set_ncyl(struct fdisk_context *cxt, int cyl)
-{
-       struct sun_disklabel *sunlabel = self_disklabel(cxt);
-       sunlabel->ncyl = cpu_to_be16(cyl);
+       sunlabel->acyl = cpu_to_be16(res);
+       return 0;
 }
 
-void fdisk_sun_set_xcyl(struct fdisk_context *cxt)
+int fdisk_sun_set_xcyl(struct fdisk_context *cxt)
 {
        struct sun_disklabel *sunlabel = self_disklabel(cxt);
        uintmax_t res;
@@ -790,11 +786,13 @@ void fdisk_sun_set_xcyl(struct fdisk_context *cxt)
                        cxt->geom.sectors,                      /* high */
                        _("Extra sectors per cylinder"),        /* query */
                        &res);                                  /* result */
-       if (!rc)
-               sunlabel->apc = cpu_to_be16(res);
+       if (rc)
+               return rc;
+       sunlabel->apc = cpu_to_be16(res);
+       return 0;
 }
 
-void fdisk_sun_set_ilfact(struct fdisk_context *cxt)
+int fdisk_sun_set_ilfact(struct fdisk_context *cxt)
 {
        struct sun_disklabel *sunlabel = self_disklabel(cxt);
        uintmax_t res;
@@ -803,11 +801,13 @@ void fdisk_sun_set_ilfact(struct fdisk_context *cxt)
                        32,                                     /* high */
                        _("Interleave factor"), /* query */
                        &res);                                  /* result */
-       if (!rc)
-               sunlabel->intrlv = cpu_to_be16(res);
+       if (rc)
+               return rc;
+       sunlabel->intrlv = cpu_to_be16(res);
+       return 0;
 }
 
-void fdisk_sun_set_rspeed(struct fdisk_context *cxt)
+int fdisk_sun_set_rspeed(struct fdisk_context *cxt)
 {
        struct sun_disklabel *sunlabel = self_disklabel(cxt);
        uintmax_t res;
@@ -816,12 +816,13 @@ void fdisk_sun_set_rspeed(struct fdisk_context *cxt)
                        USHRT_MAX,                              /* high */
                        _("Rotation speed (rpm)"),              /* query */
                        &res);                                  /* result */
-       if (!rc)
-               sunlabel->rpm = cpu_to_be16(res);
-
+       if (rc)
+               return rc;
+       sunlabel->rpm = cpu_to_be16(res);
+       return 0;
 }
 
-void fdisk_sun_set_pcylcount(struct fdisk_context *cxt)
+int fdisk_sun_set_pcylcount(struct fdisk_context *cxt)
 {
        struct sun_disklabel *sunlabel = self_disklabel(cxt);
        uintmax_t res;
@@ -831,7 +832,9 @@ void fdisk_sun_set_pcylcount(struct fdisk_context *cxt)
                        _("Number of physical cylinders"),      /* query */
                        &res);                                  /* result */
        if (!rc)
-               sunlabel->pcyl = cpu_to_be16(res);
+               return rc;
+       sunlabel->pcyl = cpu_to_be16(res);
+       return 0;
 }
 
 static int sun_write_disklabel(struct fdisk_context *cxt)
@@ -846,6 +849,15 @@ static int sun_write_disklabel(struct fdisk_context *cxt)
        assert(fdisk_is_disklabel(cxt, SUN));
 
        sunlabel = self_disklabel(cxt);
+
+       /* Maybe geometry has been modified */
+       sunlabel->nhead = cpu_to_be16(cxt->geom.heads);
+       sunlabel->nsect = cpu_to_be16(cxt->geom.sectors);
+
+       if (cxt->geom.cylinders != be16_to_cpu(sunlabel->ncyl))
+               sunlabel->ncyl = cpu_to_be16( cxt->geom.cylinders
+                                     - be16_to_cpu(sunlabel->acyl) );
+
        ush = (unsigned short *) sunlabel;
 
        while(ush < (unsigned short *)(&sunlabel->csum))