From 4170ae9cbd3ad54c9c7427212eaae6fdb030b57a Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 22 May 2013 14:41:58 +0200 Subject: [PATCH] libfdisk: clean up sun geometry stuff - 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 --- fdisks/fdisk.c | 3 --- libfdisk/src/fdiskP.h | 9 ------- libfdisk/src/libfdisk.h | 7 ++++++ libfdisk/src/sun.c | 56 +++++++++++++++++++++++++---------------- 4 files changed, 41 insertions(+), 34 deletions(-) diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c index e884ee743b..09fa0746b3 100644 --- a/fdisks/fdisk.c +++ b/fdisks/fdisk.c @@ -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': diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h index 6a184a0b7d..167670fcbb 100644 --- a/libfdisk/src/fdiskP.h +++ b/libfdisk/src/fdiskP.h @@ -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 */ diff --git a/libfdisk/src/libfdisk.h b/libfdisk/src/libfdisk.h index 049420d7ea..fc38ef7705 100644 --- a/libfdisk/src/libfdisk.h +++ b/libfdisk/src/libfdisk.h @@ -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); diff --git a/libfdisk/src/sun.c b/libfdisk/src/sun.c index e7a1c879ea..cd14cccece 100644 --- a/libfdisk/src/sun.c +++ b/libfdisk/src/sun.c @@ -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)) -- 2.47.2