Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/gpt WARNS=6
details: https://anonhg.NetBSD.org/src/rev/c12640cffd0a
branches: trunk
changeset: 812161:c12640cffd0a
user: christos <christos%NetBSD.org@localhost>
date: Thu Dec 03 02:02:43 2015 +0000
description:
WARNS=6
diffstat:
sbin/gpt/Makefile | 3 +-
sbin/gpt/add.c | 9 ++-
sbin/gpt/biosboot.c | 8 +-
sbin/gpt/create.c | 5 +-
sbin/gpt/gpt.c | 106 +++++++++++++++++++++++++++++--------------------
sbin/gpt/gpt.h | 5 +-
sbin/gpt/gpt_uuid.c | 14 +++---
sbin/gpt/header.c | 45 ++------------------
sbin/gpt/main.c | 11 +---
sbin/gpt/migrate.c | 25 +++++++----
sbin/gpt/recover.c | 15 +++---
sbin/gpt/resize.c | 8 ++-
sbin/gpt/resizedisk.c | 24 +++++-----
sbin/gpt/restore.c | 53 +++++++++++++-----------
sbin/gpt/set.c | 4 +-
sbin/gpt/show.c | 26 +----------
sbin/gpt/unset.c | 4 +-
17 files changed, 172 insertions(+), 193 deletions(-)
diffs (truncated from 1033 to 300 lines):
diff -r 7a6e722f86ae -r c12640cffd0a sbin/gpt/Makefile
--- a/sbin/gpt/Makefile Thu Dec 03 01:16:21 2015 +0000
+++ b/sbin/gpt/Makefile Thu Dec 03 02:02:43 2015 +0000
@@ -1,8 +1,9 @@
-# $NetBSD: Makefile,v 1.17 2015/12/01 09:05:33 christos Exp $
+# $NetBSD: Makefile,v 1.18 2015/12/03 02:02:43 christos Exp $
# $FreeBSD: src/sbin/gpt/Makefile,v 1.7 2005/09/01 02:49:20 marcel Exp $
.include <bsd.own.mk>
+WARNS=6
PROG= gpt
SRCS= add.c biosboot.c create.c destroy.c gpt.c header.c label.c map.c \
main.c migrate.c recover.c remove.c resize.c resizedisk.c \
diff -r 7a6e722f86ae -r c12640cffd0a sbin/gpt/add.c
--- a/sbin/gpt/add.c Thu Dec 03 01:16:21 2015 +0000
+++ b/sbin/gpt/add.c Thu Dec 03 02:02:43 2015 +0000
@@ -33,7 +33,7 @@
__FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: add.c,v 1.38 2015/12/03 01:07:28 christos Exp $");
+__RCSID("$NetBSD: add.c,v 1.39 2015/12/03 02:02:43 christos Exp $");
#endif
#include <sys/types.h>
@@ -72,8 +72,9 @@
const uint8_t *xname)
{
gpt_uuid_copy(ent->ent_type, xtype);
- ent->ent_lba_start = htole64(map->map_start);
- ent->ent_lba_end = htole64(map->map_start + map->map_size - 1LL);
+ ent->ent_lba_start = htole64((uint64_t)map->map_start);
+ ent->ent_lba_end = htole64((uint64_t)(map->map_start +
+ map->map_size - 1LL));
if (xname == NULL)
return;
utf8_to_utf16(xname, ent->ent_name, __arraycount(ent->ent_name));
@@ -193,7 +194,7 @@
if (optind != argc)
return usage();
- if ((sectors = gpt_check_ais(gpt, alignment, ~0, size)) == -1)
+ if ((sectors = gpt_check_ais(gpt, alignment, ~0U, size)) == -1)
return -1;
return add(gpt, alignment, block, sectors, size, entry, name, type);
diff -r 7a6e722f86ae -r c12640cffd0a sbin/gpt/biosboot.c
--- a/sbin/gpt/biosboot.c Thu Dec 03 01:16:21 2015 +0000
+++ b/sbin/gpt/biosboot.c Thu Dec 03 02:02:43 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: biosboot.c,v 1.21 2015/12/03 01:07:28 christos Exp $ */
+/* $NetBSD: biosboot.c,v 1.22 2015/12/03 02:02:43 christos Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#ifdef __RCSID
-__RCSID("$NetBSD: biosboot.c,v 1.21 2015/12/03 01:07:28 christos Exp $");
+__RCSID("$NetBSD: biosboot.c,v 1.22 2015/12/03 02:02:43 christos Exp $");
#endif
#include <sys/stat.h>
@@ -126,7 +126,7 @@
goto fail;
}
- if (read(bfd, buf, st.st_size) != st.st_size) {
+ if (read(bfd, buf, (size_t)st.st_size) != (ssize_t)st.st_size) {
gpt_warn(gpt, "Error reading from `%s'", bp);
goto fail;
}
@@ -266,7 +266,7 @@
return usage();
break;
case 'i':
- if (gpt_entry_get(&entry) == -1)
+ if (gpt_uint_get(&entry) == -1)
return usage();
break;
case 'L':
diff -r 7a6e722f86ae -r c12640cffd0a sbin/gpt/create.c
--- a/sbin/gpt/create.c Thu Dec 03 01:16:21 2015 +0000
+++ b/sbin/gpt/create.c Thu Dec 03 02:02:43 2015 +0000
@@ -33,7 +33,7 @@
__FBSDID("$FreeBSD: src/sbin/gpt/create.c,v 1.11 2005/08/31 01:47:19 marcel Exp $");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: create.c,v 1.17 2015/12/03 01:07:28 christos Exp $");
+__RCSID("$NetBSD: create.c,v 1.18 2015/12/03 02:02:43 christos Exp $");
#endif
#include <sys/types.h>
@@ -138,7 +138,8 @@
primary_only = 1;
break;
case 'p':
- parts = atoi(optarg);
+ if (gpt_uint_get(&parts) == -1)
+ return -1;
break;
default:
return usage();
diff -r 7a6e722f86ae -r c12640cffd0a sbin/gpt/gpt.c
--- a/sbin/gpt/gpt.c Thu Dec 03 01:16:21 2015 +0000
+++ b/sbin/gpt/gpt.c Thu Dec 03 02:02:43 2015 +0000
@@ -35,7 +35,7 @@
__FBSDID("$FreeBSD: src/sbin/gpt/gpt.c,v 1.16 2006/07/07 02:44:23 marcel Exp $");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: gpt.c,v 1.58 2015/12/02 20:09:33 christos Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.59 2015/12/03 02:02:43 christos Exp $");
#endif
#include <sys/param.h>
@@ -144,25 +144,25 @@
if (utfchar < 0x80) {
if (s8idx + 1 >= s8len)
break;
- s8[s8idx++] = utfchar;
+ s8[s8idx++] = (uint8_t)utfchar;
} else if (utfchar < 0x800) {
if (s8idx + 2 >= s8len)
break;
- s8[s8idx++] = 0xc0 | (utfchar >> 6);
- s8[s8idx++] = 0x80 | (utfchar & 0x3f);
+ s8[s8idx++] = (uint8_t)(0xc0 | (utfchar >> 6));
+ s8[s8idx++] = (uint8_t)(0x80 | (utfchar & 0x3f));
} else if (utfchar < 0x10000) {
if (s8idx + 3 >= s8len)
break;
- s8[s8idx++] = 0xe0 | (utfchar >> 12);
- s8[s8idx++] = 0x80 | ((utfchar >> 6) & 0x3f);
- s8[s8idx++] = 0x80 | (utfchar & 0x3f);
+ s8[s8idx++] = (uint8_t)(0xe0 | (utfchar >> 12));
+ s8[s8idx++] = (uint8_t)(0x80 | ((utfchar >> 6) & 0x3f));
+ s8[s8idx++] = (uint8_t)(0x80 | (utfchar & 0x3f));
} else if (utfchar < 0x200000) {
if (s8idx + 4 >= s8len)
break;
- s8[s8idx++] = 0xf0 | (utfchar >> 18);
- s8[s8idx++] = 0x80 | ((utfchar >> 12) & 0x3f);
- s8[s8idx++] = 0x80 | ((utfchar >> 6) & 0x3f);
- s8[s8idx++] = 0x80 | (utfchar & 0x3f);
+ s8[s8idx++] = (uint8_t)(0xf0 | (utfchar >> 18));
+ s8[s8idx++] = (uint8_t)(0x80 | ((utfchar >> 12) & 0x3f));
+ s8[s8idx++] = (uint8_t)(0x80 | ((utfchar >> 6) & 0x3f));
+ s8[s8idx++] = (uint8_t)(0x80 | (utfchar & 0x3f));
}
}
s8[s8idx] = 0;
@@ -211,18 +211,18 @@
utfchar = (utfchar << 6) + (c & 0x3f);
utfbytes--;
} else if (utfbytes == 0)
- utfbytes = -1;
+ utfbytes = (u_int)~0;
}
if (utfbytes == 0) {
if (utfchar >= 0x10000 && s16idx + 2 >= s16len)
utfchar = 0xfffd;
if (utfchar >= 0x10000) {
- s16[s16idx++] =
- htole16(0xd800 | ((utfchar>>10)-0x40));
- s16[s16idx++] =
- htole16(0xdc00 | (utfchar & 0x3ff));
+ s16[s16idx++] = htole16((uint16_t)
+ (0xd800 | ((utfchar>>10) - 0x40)));
+ s16[s16idx++] = htole16((uint16_t)
+ (0xdc00 | (utfchar & 0x3ff)));
} else
- s16[s16idx++] = htole16(utfchar);
+ s16[s16idx++] = htole16((uint16_t)utfchar);
if (s16idx == s16len) {
s16[--s16idx] = 0;
return;
@@ -257,7 +257,7 @@
off_t ofs;
size_t count;
- count = map->map_size * gpt->secsz;
+ count = (size_t)(map->map_size * gpt->secsz);
ofs = map->map_start * gpt->secsz;
if (lseek(gpt->fd, ofs, SEEK_SET) != ofs ||
write(gpt->fd, map->map_data, count) != (ssize_t)count)
@@ -391,7 +391,7 @@
blocks = tblsz / gpt->secsz + ((tblsz % gpt->secsz) ? 1 : 0);
/* Use generic pointer to deal with hdr->hdr_entsz != sizeof(*ent). */
- p = gpt_read(gpt, le64toh(hdr->hdr_lba_table), blocks);
+ p = gpt_read(gpt, (off_t)le64toh((uint64_t)hdr->hdr_lba_table), blocks);
if (p == NULL) {
if (found) {
if (gpt->verbose)
@@ -419,8 +419,9 @@
if (m == NULL)
return (-1);
- m = map_add(gpt, le64toh(hdr->hdr_lba_table), blocks, (lba == 1)
- ? MAP_TYPE_PRI_GPT_TBL : MAP_TYPE_SEC_GPT_TBL, p);
+ m = map_add(gpt, (off_t)le64toh((uint64_t)hdr->hdr_lba_table),
+ (off_t)blocks,
+ lba == 1 ? MAP_TYPE_PRI_GPT_TBL : MAP_TYPE_SEC_GPT_TBL, p);
if (m == NULL)
return (-1);
@@ -432,8 +433,8 @@
if (gpt_uuid_is_nil(ent->ent_type))
continue;
- size = le64toh(ent->ent_lba_end) - le64toh(ent->ent_lba_start) +
- 1LL;
+ size = (off_t)(le64toh((uint64_t)ent->ent_lba_end) -
+ le64toh((uint64_t)ent->ent_lba_start) + 1LL);
if (gpt->verbose > 2) {
char buf[128];
gpt_uuid_snprintf(buf, sizeof(buf), "%s",
@@ -444,8 +445,8 @@
(uintmax_t)size);
}
// XXX: map add with not allocated memory.
- m = map_add(gpt, le64toh(ent->ent_lba_start), size,
- MAP_TYPE_GPT_PART, ent);
+ m = map_add(gpt, (off_t)le64toh((uint64_t)ent->ent_lba_start),
+ size, MAP_TYPE_GPT_PART, ent);
if (m == NULL)
return (-1);
m->map_index = i + 1;
@@ -711,8 +712,8 @@
part->part_size_lo = htole16(0xffff);
part->part_size_hi = htole16(0xffff);
} else {
- part->part_size_lo = htole16(last);
- part->part_size_hi = htole16(last >> 16);
+ part->part_size_lo = htole16((uint16_t)last);
+ part->part_size_hi = htole16((uint16_t)(last >> 16));
}
}
@@ -774,7 +775,7 @@
return gpt->mediasz / gpt->secsz - 1LL;
}
-int
+off_t
gpt_create(gpt_t gpt, off_t last, u_int parts, int primary_only)
{
off_t blocks;
@@ -800,7 +801,7 @@
/* Don't create more than parts entries. */
if ((uint64_t)(blocks - 1) * gpt->secsz >
parts * sizeof(struct gpt_ent)) {
- blocks = (parts * sizeof(struct gpt_ent)) / gpt->secsz;
+ blocks = (off_t)((parts * sizeof(struct gpt_ent)) / gpt->secsz);
if ((parts * sizeof(struct gpt_ent)) % gpt->secsz)
blocks++;
blocks++; /* Don't forget the header itself */
@@ -840,7 +841,7 @@
return -1;
}
- if ((p = calloc(blocks, gpt->secsz)) == NULL) {
+ if ((p = calloc((size_t)blocks, gpt->secsz)) == NULL) {
gpt_warnx(gpt, "Can't allocate the primary GPT table");
return -1;
}
@@ -860,15 +861,15 @@
*/
hdr->hdr_revision = htole32(GPT_HDR_REVISION);
hdr->hdr_size = htole32(GPT_HDR_SIZE);
- hdr->hdr_lba_self = htole64(gpt->gpt->map_start);
- hdr->hdr_lba_alt = htole64(last);
- hdr->hdr_lba_start = htole64(gpt->tbl->map_start + blocks);
- hdr->hdr_lba_end = htole64(last - blocks - 1LL);
+ hdr->hdr_lba_self = htole64((uint64_t)gpt->gpt->map_start);
+ hdr->hdr_lba_alt = htole64((uint64_t)last);
+ hdr->hdr_lba_start = htole64((uint64_t)(gpt->tbl->map_start + blocks));
+ hdr->hdr_lba_end = htole64((uint64_t)(last - blocks - 1LL));
if (gpt_uuid_generate(gpt, hdr->hdr_guid) == -1)
return -1;
- hdr->hdr_lba_table = htole64(gpt->tbl->map_start);
- hdr->hdr_entries = htole32((blocks * gpt->secsz) /
- sizeof(struct gpt_ent));
+ hdr->hdr_lba_table = htole64((uint64_t)(gpt->tbl->map_start));
+ hdr->hdr_entries = htole32((uint32_t)(((uint64_t)blocks * gpt->secsz) /
+ sizeof(struct gpt_ent)));
if (le32toh(hdr->hdr_entries) > parts)
hdr->hdr_entries = htole32(parts);
hdr->hdr_entsz = htole32(sizeof(struct gpt_ent));
@@ -905,9 +906,9 @@
memcpy(gpt->tpg->map_data, gpt->gpt->map_data, gpt->secsz);
hdr = gpt->tpg->map_data;
- hdr->hdr_lba_self = htole64(gpt->tpg->map_start);
- hdr->hdr_lba_alt = htole64(gpt->gpt->map_start);
- hdr->hdr_lba_table = htole64(gpt->lbt->map_start);
+ hdr->hdr_lba_self = htole64((uint64_t)gpt->tpg->map_start);
+ hdr->hdr_lba_alt = htole64((uint64_t)gpt->gpt->map_start);
Home |
Main Index |
Thread Index |
Old Index