summaryrefslogtreecommitdiffstats
path: root/libfdisk/src/sun.c
diff options
context:
space:
mode:
authorRuediger Meier2017-06-13 03:16:02 +0200
committerRuediger Meier2017-06-13 18:06:36 +0200
commit7f387c5c215e7208a7217d528878fb5d3b2a7b5b (patch)
tree7fe020dc1b94c17c935cec30764603dca2f8a06f /libfdisk/src/sun.c
parentlscpu: cleanup DMI detection return codes (diff)
downloadkernel-qcow2-util-linux-7f387c5c215e7208a7217d528878fb5d3b2a7b5b.tar.gz
kernel-qcow2-util-linux-7f387c5c215e7208a7217d528878fb5d3b2a7b5b.tar.xz
kernel-qcow2-util-linux-7f387c5c215e7208a7217d528878fb5d3b2a7b5b.zip
libfdisk: cleanup sun label checksum usuage
We are using now the formerly unused function sun_pt_checksum(). This cleanup was motivated by clang compiler warning, see below. Also nice that we are now always using uint16_t instead of short. Warning was: ../libfdisk/src/sun.c:177:35: warning: taking address of packed member 'csum' of class or structure 'sun_disklabel' may result in an unaligned pointer value [-Waddress-of-packed-member] while(ush < (unsigned short *)(&sunlabel->csum)) Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'libfdisk/src/sun.c')
-rw-r--r--libfdisk/src/sun.c33
1 files changed, 7 insertions, 26 deletions
diff --git a/libfdisk/src/sun.c b/libfdisk/src/sun.c
index a3a5b401e..0526227ce 100644
--- a/libfdisk/src/sun.c
+++ b/libfdisk/src/sun.c
@@ -110,8 +110,6 @@ static int sun_probe_label(struct fdisk_context *cxt)
{
struct fdisk_sun_label *sun;
struct sun_disklabel *sunlabel;
- unsigned short *ush;
- int csum;
int need_fixing = 0;
assert(cxt);
@@ -128,11 +126,7 @@ static int sun_probe_label(struct fdisk_context *cxt)
return 0; /* failed */
}
- ush = ((unsigned short *) (sunlabel + 1)) - 1;
- for (csum = 0; ush >= (unsigned short *)sunlabel;)
- csum ^= *ush--;
-
- if (csum) {
+ if (sun_pt_checksum(sunlabel)) {
fdisk_warnx(cxt, _("Detected sun disklabel with wrong checksum. "
"Probably you'll have to set all the values, "
"e.g. heads, sectors, cylinders and partitions "
@@ -171,12 +165,8 @@ static int sun_probe_label(struct fdisk_context *cxt)
sunlabel->vtoc.version = cpu_to_be32(SUN_VTOC_VERSION);
sunlabel->vtoc.sanity = cpu_to_be32(SUN_VTOC_SANITY);
sunlabel->vtoc.nparts = cpu_to_be16(SUN_MAXPARTITIONS);
-
- ush = (unsigned short *)sunlabel;
- csum = 0;
- while(ush < (unsigned short *)(&sunlabel->csum))
- csum ^= *ush++;
- sunlabel->csum = csum;
+ sunlabel->csum = 0;
+ sunlabel->csum = sun_pt_checksum(sunlabel);
fdisk_label_set_changed(cxt->label, 1);
}
@@ -286,13 +276,8 @@ static int sun_create_disklabel(struct fdisk_context *cxt)
SUN_TAG_WHOLEDISK);
}
- {
- unsigned short *ush = (unsigned short *)sunlabel;
- unsigned short csum = 0;
- while(ush < (unsigned short *)(&sunlabel->csum))
- csum ^= *ush++;
- sunlabel->csum = csum;
- }
+ sunlabel->csum = 0;
+ sunlabel->csum = sun_pt_checksum(sunlabel);
fdisk_label_set_changed(cxt->label, 1);
cxt->label->nparts_cur = count_used_partitions(cxt);
@@ -979,8 +964,6 @@ int fdisk_sun_set_pcylcount(struct fdisk_context *cxt)
static int sun_write_disklabel(struct fdisk_context *cxt)
{
struct sun_disklabel *sunlabel;
- unsigned short *ush;
- unsigned short csum = 0;
const size_t sz = sizeof(struct sun_disklabel);
assert(cxt);
@@ -999,11 +982,9 @@ static int sun_write_disklabel(struct fdisk_context *cxt)
sunlabel->ncyl = a - b;
}
- ush = (unsigned short *) sunlabel;
+ sunlabel->csum = 0;
+ sunlabel->csum = sun_pt_checksum(sunlabel);
- while(ush < (unsigned short *)(&sunlabel->csum))
- csum ^= *ush++;
- sunlabel->csum = csum;
if (lseek(cxt->dev_fd, 0, SEEK_SET) < 0)
return -errno;
if (write_all(cxt->dev_fd, sunlabel, sz) != 0)