Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/disklabel Change printf formats to match the data type ...
details: https://anonhg.NetBSD.org/src/rev/615dc0faf265
branches: trunk
changeset: 760528:615dc0faf265
user: apb <apb%NetBSD.org@localhost>
date: Thu Jan 06 21:39:01 2011 +0000
description:
Change printf formats to match the data type of the values being
printed. There's now a lot of PRIu16 and PRIu32, some PRIu8, some
SCNu32, and a few cases where %u and %d were reversed. Multiplication
of 32-bit and 8-bit values is cast to uint64_t and printed with PRIu64.
Inspired by a report from Patrick Welche on current-users.
diffstat:
sbin/disklabel/interact.c | 54 ++++++++++++++++++++++----------------------
sbin/disklabel/main.c | 31 +++++++++++++++----------
sbin/disklabel/printlabel.c | 45 ++++++++++++++++++++-----------------
3 files changed, 69 insertions(+), 61 deletions(-)
diffs (truncated from 462 to 300 lines):
diff -r e8eae74d688b -r 615dc0faf265 sbin/disklabel/interact.c
--- a/sbin/disklabel/interact.c Thu Jan 06 19:49:37 2011 +0000
+++ b/sbin/disklabel/interact.c Thu Jan 06 21:39:01 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: interact.c,v 1.34 2010/05/28 07:40:53 dholland Exp $ */
+/* $NetBSD: interact.c,v 1.35 2011/01/06 21:39:01 apb Exp $ */
/*
* Copyright (c) 1997 Christos Zoulas. All rights reserved.
@@ -30,7 +30,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: interact.c,v 1.34 2010/05/28 07:40:53 dholland Exp $");
+__RCSID("$NetBSD: interact.c,v 1.35 2011/01/06 21:39:01 apb Exp $");
#endif /* lint */
#include <sys/param.h>
@@ -203,13 +203,13 @@
/* d_npartitions */
for (;;) {
- snprintf(def, sizeof(def), "%u", lp->d_npartitions);
+ snprintf(def, sizeof(def), "%" PRIu16, lp->d_npartitions);
i = getinput(":", "Number of partitions", def, line);
if (i == -1)
return;
else if (i == 0)
break;
- if (sscanf(line, "%u", &u) != 1) {
+ if (sscanf(line, "%" SCNu32, &u) != 1) {
printf("Invalid number of partitions `%s'\n", line);
continue;
}
@@ -219,13 +219,13 @@
/* d_secsize */
for (;;) {
- snprintf(def, sizeof(def), "%u", lp->d_secsize);
+ snprintf(def, sizeof(def), "%" PRIu32, lp->d_secsize);
i = getinput(":", "Sector size (bytes)", def, line);
if (i == -1)
return;
else if (i == 0)
break;
- if (sscanf(line, "%u", &u) != 1) {
+ if (sscanf(line, "%" SCNu32, &u) != 1) {
printf("Invalid sector size `%s'\n", line);
continue;
}
@@ -235,13 +235,13 @@
/* d_nsectors */
for (;;) {
- snprintf(def, sizeof(def), "%u", lp->d_nsectors);
+ snprintf(def, sizeof(def), "%" PRIu32, lp->d_nsectors);
i = getinput(":", "Number of sectors per track", def, line);
if (i == -1)
return;
else if (i == 0)
break;
- if (sscanf(line, "%u", &u) != 1) {
+ if (sscanf(line, "%" SCNu32, &u) != 1) {
printf("Invalid number of sectors `%s'\n", line);
continue;
}
@@ -251,13 +251,13 @@
/* d_ntracks */
for (;;) {
- snprintf(def, sizeof(def), "%u", lp->d_ntracks);
+ snprintf(def, sizeof(def), "%" PRIu32, lp->d_ntracks);
i = getinput(":", "Number of tracks per cylinder", def, line);
if (i == -1)
return;
else if (i == 0)
break;
- if (sscanf(line, "%u", &u) != 1) {
+ if (sscanf(line, "%" SCNu32, &u) != 1) {
printf("Invalid number of tracks `%s'\n", line);
continue;
}
@@ -267,13 +267,13 @@
/* d_secpercyl */
for (;;) {
- snprintf(def, sizeof(def), "%u", lp->d_secpercyl);
+ snprintf(def, sizeof(def), "%" PRIu32, lp->d_secpercyl);
i = getinput(":", "Number of sectors/cylinder", def, line);
if (i == -1)
return;
else if (i == 0)
break;
- if (sscanf(line, "%u", &u) != 1) {
+ if (sscanf(line, "%" SCNu32, &u) != 1) {
printf("Invalid number of sector/cylinder `%s'\n",
line);
continue;
@@ -284,13 +284,13 @@
/* d_ncylinders */
for (;;) {
- snprintf(def, sizeof(def), "%u", lp->d_ncylinders);
+ snprintf(def, sizeof(def), "%" PRIu32, lp->d_ncylinders);
i = getinput(":", "Total number of cylinders", def, line);
if (i == -1)
return;
else if (i == 0)
break;
- if (sscanf(line, "%u", &u) != 1) {
+ if (sscanf(line, "%" SCNu32, &u) != 1) {
printf("Invalid sector size `%s'\n", line);
continue;
}
@@ -300,13 +300,13 @@
/* d_secperunit */
for (;;) {
- snprintf(def, sizeof(def), "%u", lp->d_secperunit);
+ snprintf(def, sizeof(def), "%" PRIu32, lp->d_secperunit);
i = getinput(":", "Total number of sectors", def, line);
if (i == -1)
return;
else if (i == 0)
break;
- if (sscanf(line, "%u", &u) != 1) {
+ if (sscanf(line, "%" SCNu32, &u) != 1) {
printf("Invalid number of sectors `%s'\n", line);
continue;
}
@@ -318,13 +318,13 @@
/* d_interleave */
for (;;) {
- snprintf(def, sizeof(def), "%u", lp->d_interleave);
+ snprintf(def, sizeof(def), "%" PRIu16, lp->d_interleave);
i = getinput(":", "Hardware sectors interleave", def, line);
if (i == -1)
return;
else if (i == 0)
break;
- if (sscanf(line, "%u", &u) != 1) {
+ if (sscanf(line, "%" SCNu32, &u) != 1) {
printf("Invalid sector interleave `%s'\n", line);
continue;
}
@@ -334,13 +334,13 @@
/* d_trackskew */
for (;;) {
- snprintf(def, sizeof(def), "%u", lp->d_trackskew);
+ snprintf(def, sizeof(def), "%" PRIu16, lp->d_trackskew);
i = getinput(":", "Sector 0 skew, per track", def, line);
if (i == -1)
return;
else if (i == 0)
break;
- if (sscanf(line, "%u", &u) != 1) {
+ if (sscanf(line, "%" SCNu32, &u) != 1) {
printf("Invalid track sector skew `%s'\n", line);
continue;
}
@@ -350,13 +350,13 @@
/* d_cylskew */
for (;;) {
- snprintf(def, sizeof(def), "%u", lp->d_cylskew);
+ snprintf(def, sizeof(def), "%" PRIu16, lp->d_cylskew);
i = getinput(":", "Sector 0 skew, per cylinder", def, line);
if (i == -1)
return;
else if (i == 0)
break;
- if (sscanf(line, "%u", &u) != 1) {
+ if (sscanf(line, "%" SCNu32, &u) != 1) {
printf("Invalid cylinder sector `%s'\n", line);
continue;
}
@@ -366,13 +366,13 @@
/* d_headswitch */
for (;;) {
- snprintf(def, sizeof(def), "%u", lp->d_headswitch);
+ snprintf(def, sizeof(def), "%" PRIu32, lp->d_headswitch);
i = getinput(":", "Head switch time (usec)", def, line);
if (i == -1)
return;
else if (i == 0)
break;
- if (sscanf(line, "%u", &u) != 1) {
+ if (sscanf(line, "%" SCNu32, &u) != 1) {
printf("Invalid head switch time `%s'\n", line);
continue;
}
@@ -382,13 +382,13 @@
/* d_trkseek */
for (;;) {
- snprintf(def, sizeof(def), "%u", lp->d_trkseek);
+ snprintf(def, sizeof(def), "%" PRIu32, lp->d_trkseek);
i = getinput(":", "Track seek time (usec)", def, line);
if (i == -1)
return;
else if (i == 0)
break;
- if (sscanf(line, "%u", &u) != 1) {
+ if (sscanf(line, "%" SCNu32, &u) != 1) {
printf("Invalid track seek time `%s'\n", line);
continue;
}
@@ -704,7 +704,7 @@
defnum(struct disklabel *lp, char *buf, uint32_t size)
{
- (void) snprintf(buf, BUFSIZ, "%.40gc, %us, %.40gM",
+ (void) snprintf(buf, BUFSIZ, "%.40gc, %" PRIu32 "s, %.40gM",
size / (float) lp->d_secpercyl,
size, size * (lp->d_secsize / (float) (1024 * 1024)));
}
diff -r e8eae74d688b -r 615dc0faf265 sbin/disklabel/main.c
--- a/sbin/disklabel/main.c Thu Jan 06 19:49:37 2011 +0000
+++ b/sbin/disklabel/main.c Thu Jan 06 21:39:01 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.23 2011/01/06 19:34:28 christos Exp $ */
+/* $NetBSD: main.c,v 1.24 2011/01/06 21:39:01 apb Exp $ */
/*
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -76,7 +76,7 @@
static char sccsid[] = "@(#)disklabel.c 8.4 (Berkeley) 5/4/95";
/* from static char sccsid[] = "@(#)disklabel.c 1.2 (Symmetric) 11/28/85"; */
#else
-__RCSID("$NetBSD: main.c,v 1.23 2011/01/06 19:34:28 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.24 2011/01/06 21:39:01 apb Exp $");
#endif
#endif /* not lint */
@@ -624,7 +624,7 @@
if (pread(f, &mbr, sizeof mbr, this_ext * (off_t)DEV_BSIZE)
!= sizeof(mbr)) {
if (verbose)
- warn("Can't read master boot record %d",
+ warn("Can't read master boot record %u",
this_ext);
break;
}
@@ -632,7 +632,7 @@
/* Check if table is valid. */
if (mbr.mbr_magic != htole16(MBR_MAGIC)) {
if (verbose)
- warnx("Invalid signature in mbr record %d",
+ warnx("Invalid signature in mbr record %u",
this_ext);
break;
}
@@ -902,7 +902,8 @@
find_label(int f, u_int sector)
{
struct disklabel *disk_lp, hlp;
- int i, offset;
+ int i;
+ u_int offset;
const char *is_deleted;
bootarea_len = pread(f, bootarea, sizeof bootarea,
@@ -914,7 +915,7 @@
}
if (verbose > 2)
- warnx("read sector %u len %u looking for label",
+ warnx("read sector %u len %d looking for label",
sector, bootarea_len);
/* Check expected offset first */
@@ -1000,9 +1001,9 @@
if (wlen == bootarea_len)
return;
if (wlen == -1)
- err(1, "disklabel write (sector %u) size %u failed",
+ err(1, "disklabel write (sector %u) size %d failed",
sector, bootarea_len);
- errx(1, "disklabel write (sector %u) size %u truncated to %d",
+ errx(1, "disklabel write (sector %u) size %d truncated to %d",
sector, bootarea_len, wlen);
}
@@ -1164,8 +1165,9 @@
(void) fprintf(f, "t%c=%s:", c,
fstypenames[pp->p_fstype]);
else
- (void) fprintf(f, "t%c=unknown%" PRIu8
- ":", c, pp->p_fstype);
+ (void) fprintf(f,
+ "t%c=unknown%" PRIu8 ":",
+ c, pp->p_fstype);
}
switch (pp->p_fstype) {
@@ -1742,7 +1744,8 @@
} else if (lp->d_sbsize % lp->d_secsize)
Home |
Main Index |
Thread Index |
Old Index