diff options
author | jhb <jhb@FreeBSD.org> | 2004-03-16 17:07:06 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2004-03-16 17:07:06 +0000 |
commit | b7e56e9eea26be625659f4a99d9094c501a0a3bc (patch) | |
tree | 5aa997ef67b14b420649f8ea11a120707fde3633 | |
parent | 662b843050ffa69c81e8bd9be635806f6abd5739 (diff) | |
download | FreeBSD-src-b7e56e9eea26be625659f4a99d9094c501a0a3bc.zip FreeBSD-src-b7e56e9eea26be625659f4a99d9094c501a0a3bc.tar.gz |
Change libdisk and sysinstall to use d_addr_t rather than u_long for disk
addresses. For arch's with 64-bit longs, this is a nop, but for i386 this
allows sysinstall to properly handle disks and filesystems > 1 TB.
Changes from the original patch include:
- Use d_addr_t rather than inventing a blkcnt type based on int64_t.
- Use strtoimax() rather than strtoull() to parse d_addr_t's from config
files.
- Use intmax_t casts and %jd rather than %llu to printf d_addr_t values.
Tested on: i386
Tested by: kuriyama
Submitted by: julian
MFC after: 1 month
-rw-r--r-- | lib/libdisk/chunk.c | 26 | ||||
-rw-r--r-- | lib/libdisk/create_chunk.c | 10 | ||||
-rw-r--r-- | lib/libdisk/libdisk.3 | 30 | ||||
-rw-r--r-- | lib/libdisk/libdisk.h | 34 | ||||
-rw-r--r-- | lib/libdisk/open_disk.c | 6 | ||||
-rw-r--r-- | lib/libdisk/rules.c | 39 | ||||
-rw-r--r-- | usr.sbin/sade/disks.c | 37 | ||||
-rw-r--r-- | usr.sbin/sade/label.c | 69 | ||||
-rw-r--r-- | usr.sbin/sysinstall/disks.c | 37 | ||||
-rw-r--r-- | usr.sbin/sysinstall/label.c | 69 |
10 files changed, 190 insertions, 167 deletions
diff --git a/lib/libdisk/chunk.c b/lib/libdisk/chunk.c index 0fbb754..96d7338 100644 --- a/lib/libdisk/chunk.c +++ b/lib/libdisk/chunk.c @@ -10,11 +10,12 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include <sys/types.h> +#include <sys/stdint.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> -#include <sys/types.h> #include <err.h> #include "libdisk.h" @@ -44,7 +45,7 @@ Chunk_Inside(const struct chunk *c1, const struct chunk *c2) } static struct chunk * -Find_Mother_Chunk(struct chunk *chunks, u_long offset, u_long end, +Find_Mother_Chunk(struct chunk *chunks, daddr_t offset, daddr_t end, chunk_e type) { struct chunk *c1, *c2, ct; @@ -121,7 +122,7 @@ Clone_Chunk(const struct chunk *c1) } int -Insert_Chunk(struct chunk *c2, u_long offset, u_long size, const char *name, +Insert_Chunk(struct chunk *c2, daddr_t offset, daddr_t size, const char *name, chunk_e type, int subtype, u_long flags, const char *sname) { struct chunk *ct,*cs; @@ -204,11 +205,11 @@ Insert_Chunk(struct chunk *c2, u_long offset, u_long size, const char *name, } int -Add_Chunk(struct disk *d, long offset, u_long size, const char *name, +Add_Chunk(struct disk *d, daddr_t offset, daddr_t size, const char *name, chunk_e type, int subtype, u_long flags, const char *sname) { struct chunk *c1, *c2, ct; - u_long end = offset + size - 1; + daddr_t end = offset + size - 1; ct.offset = offset; ct.end = end; ct.size = size; @@ -379,7 +380,7 @@ ShowChunkFlags(struct chunk *c) } static void -Print_Chunk(struct chunk *c1,int offset) +Print_Chunk(struct chunk *c1, int offset) { int i; @@ -395,9 +396,10 @@ Print_Chunk(struct chunk *c1,int offset) #ifndef __ia64__ printf("%p ", c1); #endif - printf("%8ld %8lu %8lu %-8s %-16s %-8s 0x%02x %s", c1->offset, - c1->size, c1->end, c1->name, c1->sname, chunk_name(c1->type), - c1->subtype, ShowChunkFlags(c1)); + printf("%8jd %8jd %8jd %-8s %-16s %-8s 0x%02x %s", + (intmax_t)c1->offset, (intmax_t)c1->size, (intmax_t)c1->end, + c1->name, c1->sname, chunk_name(c1->type), c1->subtype, + ShowChunkFlags(c1)); putchar('\n'); Print_Chunk(c1->part, offset + 2); Print_Chunk(c1->next, offset); @@ -407,21 +409,21 @@ void Debug_Chunk(struct chunk *c1) { - Print_Chunk(c1,2); + Print_Chunk(c1, 2); } int Delete_Chunk(struct disk *d, struct chunk *c) { - return(Delete_Chunk2(d, c, 0)); + return (Delete_Chunk2(d, c, 0)); } int Delete_Chunk2(struct disk *d, struct chunk *c, int rflags) { struct chunk *c1, *c2, *c3; - u_long offset = c->offset; + daddr_t offset = c->offset; switch (c->type) { case whole: diff --git a/lib/libdisk/create_chunk.c b/lib/libdisk/create_chunk.c index d3625b9..c65b8f3 100644 --- a/lib/libdisk/create_chunk.c +++ b/lib/libdisk/create_chunk.c @@ -194,14 +194,14 @@ Fixup_Names(struct disk *d) } int -Create_Chunk(struct disk *d, u_long offset, u_long size, chunk_e type, +Create_Chunk(struct disk *d, daddr_t offset, daddr_t size, chunk_e type, int subtype, u_long flags, const char *sname) { int i; #ifndef __ia64__ if (!(flags & CHUNK_FORCE_ALL)) { - u_long l; + daddr_t l; #ifdef PC98 /* Never use the first cylinder */ if (!offset) { @@ -217,7 +217,7 @@ Create_Chunk(struct disk *d, u_long offset, u_long size, chunk_e type, #endif /* PC98 */ /* Always end on cylinder boundary */ - l = (offset+size) % (d->bios_sect * d->bios_hd); + l = (offset + size) % (d->bios_sect * d->bios_hd); size -= l; } #endif @@ -228,12 +228,12 @@ Create_Chunk(struct disk *d, u_long offset, u_long size, chunk_e type, } struct chunk * -Create_Chunk_DWIM(struct disk *d, struct chunk *parent, u_long size, +Create_Chunk_DWIM(struct disk *d, struct chunk *parent, daddr_t size, chunk_e type, int subtype, u_long flags) { int i; struct chunk *c1; - long offset; + daddr_t offset; if (!parent) parent = d->chunks; diff --git a/lib/libdisk/libdisk.3 b/lib/libdisk/libdisk.3 index 6d088b3..341bb4f 100644 --- a/lib/libdisk/libdisk.3 +++ b/lib/libdisk/libdisk.3 @@ -79,7 +79,7 @@ .Ft int .Fn Collapse_Chunk "struct disk *disk" "struct chunk *chunk" .Ft int -.Fn Create_Chunk "struct disk *disk" "u_long offset" "u_long size" "chunk_e type" "int subtype" "u_long flags" +.Fn Create_Chunk "struct disk *disk" "daddr_t offset" "daddr_t size" "chunk_e type" "int subtype" "u_long flags" .Ft void .Fn All_FreeBSD "struct disk *d" "int force_all" .Ft char * @@ -93,19 +93,19 @@ .Ft int .Fn Write_Disk "struct disk *d" .Ft int -.Fn Cyl_Aligned "struct disk *d" "u_long offset" -.Ft u_long -.Fn Next_Cyl_Aligned "struct disk *d" "u_long offset" -.Ft u_long -.Fn Prev_Cyl_Aligned "struct disk *d" "u_long offset" +.Fn Cyl_Aligned "struct disk *d" "daddr_t offset" +.Ft daddr_t +.Fn Next_Cyl_Aligned "struct disk *d" "daddr_t offset" +.Ft daddr_t +.Fn Prev_Cyl_Aligned "struct disk *d" "daddr_t offset" .Ft int -.Fn Track_Aligned "struct disk *d" "u_long offset" -.Ft u_long -.Fn Next_Track_Aligned "struct disk *d" "u_long offset" -.Ft u_long -.Fn Prev_Track_Aligned "struct disk *d" "u_long offset" +.Fn Track_Aligned "struct disk *d" "daddr_t offset" +.Ft daddr_t +.Fn Next_Track_Aligned "struct disk *d" "daddr_t offset" +.Ft daddr_t +.Fn Prev_Track_Aligned "struct disk *d" "daddr_t offset" .Ft struct chunk * -.Fn Create_Chunk_DWIM "struct disk *d" "struct chunk *parent" "u_long size" "chunk_e type" "int subtype" "u_long flags" +.Fn Create_Chunk_DWIM "struct disk *d" "struct chunk *parent" "daddr_t size" "chunk_e type" "int subtype" "u_long flags" .Ft int .Fn MakeDev "struct chunk *c" "const char *path" .Ft int @@ -150,9 +150,9 @@ struct chunk { struct chunk *next; struct chunk *part; struct disk *disk; - long offset; - u_long size; - u_long end; + daddr_t offset; + daddr_t size; + daddr_t end; char *name; char *oname; chunk_e type; diff --git a/lib/libdisk/libdisk.h b/lib/libdisk/libdisk.h index ac97d89..32ae5e7 100644 --- a/lib/libdisk/libdisk.h +++ b/lib/libdisk/libdisk.h @@ -89,9 +89,9 @@ struct chunk { struct chunk *next; struct chunk *part; struct disk *disk; - long offset; - u_long size; - u_long end; + daddr_t offset; + daddr_t size; + daddr_t end; char *sname; /* PC98 field */ char *name; char *oname; @@ -165,7 +165,7 @@ Sanitize_Bios_Geom(struct disk *); /* Set the bios geometry to something sane */ int -Insert_Chunk(struct chunk *, u_long, u_long, const char *, chunk_e, int, +Insert_Chunk(struct chunk *, daddr_t, daddr_t, const char *, chunk_e, int, u_long, const char *); int @@ -185,7 +185,7 @@ Collapse_Chunk(struct disk *, struct chunk *); /* Experimental, do not use. */ int -Create_Chunk(struct disk *, u_long, u_long, chunk_e, int, u_long, const char *); +Create_Chunk(struct disk *, daddr_t, daddr_t, chunk_e, int, u_long, const char *); /* Create a chunk with the specified paramters */ void @@ -231,28 +231,28 @@ int Write_Disk(const struct disk *); /* Write all the MBRs, disklabels, bootblocks and boot managers */ -u_long -Next_Cyl_Aligned(const struct disk *, u_long); +daddr_t +Next_Cyl_Aligned(const struct disk *, daddr_t); /* Round offset up to next cylinder according to the bios-geometry */ -u_long -Prev_Cyl_Aligned(const struct disk *, u_long); +daddr_t +Prev_Cyl_Aligned(const struct disk *, daddr_t); /* Round offset down to previous cylinder according to the bios-geometry */ int -Track_Aligned(const struct disk *, u_long); +Track_Aligned(const struct disk *, daddr_t); /* Check if offset is aligned on a track according to the bios geometry */ -u_long -Next_Track_Aligned(const struct disk *, u_long); +daddr_t +Next_Track_Aligned(const struct disk *, daddr_t); /* Round offset up to next track according to the bios-geometry */ -u_long -Prev_Track_Aligned(const struct disk *, u_long); +daddr_t +Prev_Track_Aligned(const struct disk *, daddr_t); /* Check if offset is aligned on a track according to the bios geometry */ struct chunk * -Create_Chunk_DWIM(struct disk *, struct chunk *, u_long, chunk_e, int, +Create_Chunk_DWIM(struct disk *, struct chunk *, daddr_t, chunk_e, int, u_long); /* * This one creates a partition inside the given parent of the given @@ -275,8 +275,8 @@ void Fill_Disklabel(struct disklabel *, const struct disk *, void Debug_Chunk(struct chunk *); void Free_Chunk(struct chunk *); struct chunk *Clone_Chunk(const struct chunk *); -int Add_Chunk(struct disk *, long, u_long, const char *, chunk_e, int, u_long, - const char *); +int Add_Chunk(struct disk *, daddr_t, daddr_t, const char *, chunk_e, int, + u_long, const char *); void *read_block(int, daddr_t, u_long); int write_block(int, daddr_t, const void *, u_long); struct disklabel *read_disklabel(int, daddr_t, u_long); diff --git a/lib/libdisk/open_disk.c b/lib/libdisk/open_disk.c index 99abba5..b0d4ac7 100644 --- a/lib/libdisk/open_disk.c +++ b/lib/libdisk/open_disk.c @@ -45,9 +45,9 @@ Int_Open_Disk(const char *name, char *conftxt) struct disk *d; int i; char *p, *q, *r, *a, *b, *n, *t, *sn; - off_t o, len, off; + daddr_t o, len, off; u_int l, s, ty, sc, hd, alt; - off_t lo[10]; + daddr_t lo[10]; for (p = conftxt; p != NULL && *p; p = strchr(p, '\n')) { if (*p == '\n') @@ -103,7 +103,7 @@ Int_Open_Disk(const char *name, char *conftxt) if (a == NULL) break; b = strsep(&p, " "); - o = strtoul(b, &r, 0); + o = strtoimax(b, &r, 0); if (*r) { printf("BARF %d <%d>\n", __LINE__, *r); exit (0); diff --git a/lib/libdisk/rules.c b/lib/libdisk/rules.c index b725b32..6c7f315 100644 --- a/lib/libdisk/rules.c +++ b/lib/libdisk/rules.c @@ -10,21 +10,22 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> #include <sys/types.h> +#include <sys/stdint.h> #include <sys/disklabel.h> #ifdef PC98 #include <sys/diskpc98.h> #else #include <sys/diskmbr.h> #endif +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> #include "libdisk.h" int -Track_Aligned(const struct disk *d, u_long offset) +Track_Aligned(const struct disk *d, daddr_t offset) { #ifndef __ia64__ if (!d->bios_sect) @@ -35,8 +36,8 @@ Track_Aligned(const struct disk *d, u_long offset) return 1; } -u_long -Prev_Track_Aligned(const struct disk *d, u_long offset) +daddr_t +Prev_Track_Aligned(const struct disk *d, daddr_t offset) { #ifndef __ia64__ if (!d->bios_sect) @@ -47,8 +48,8 @@ Prev_Track_Aligned(const struct disk *d, u_long offset) #endif } -u_long -Next_Track_Aligned(const struct disk *d, u_long offset) +daddr_t +Next_Track_Aligned(const struct disk *d, daddr_t offset) { #ifndef __ia64__ if (!d->bios_sect) @@ -60,7 +61,7 @@ Next_Track_Aligned(const struct disk *d, u_long offset) } static int -Cyl_Aligned(const struct disk *d, u_long offset) +Cyl_Aligned(const struct disk *d, daddr_t offset) { #ifndef __ia64__ if (!d->bios_sect || !d->bios_hd) @@ -71,8 +72,8 @@ Cyl_Aligned(const struct disk *d, u_long offset) return 1; } -u_long -Prev_Cyl_Aligned(const struct disk *d, u_long offset) +daddr_t +Prev_Cyl_Aligned(const struct disk *d, daddr_t offset) { #ifndef __ia64__ if (!d->bios_sect || !d->bios_hd) @@ -84,8 +85,8 @@ Prev_Cyl_Aligned(const struct disk *d, u_long offset) #endif } -u_long -Next_Cyl_Aligned(const struct disk *d, u_long offset) +daddr_t +Next_Cyl_Aligned(const struct disk *d, daddr_t offset) { #ifndef __ia64__ if (!d->bios_sect || !d->bios_hd) @@ -156,21 +157,21 @@ Rule_001(const struct disk *d, const struct chunk *c, char *msg) #endif sprintf(msg + strlen(msg), #ifdef PC98 - "chunk '%s' [%ld..%ld] does not start" + "chunk '%s' [%jd..%jd] does not start" " on a cylinder boundary\n", #else - "chunk '%s' [%ld..%ld] does not start" + "chunk '%s' [%jd..%jd] does not start" " on a track boundary\n", #endif - c1->name, c1->offset, c1->end); + c1->name, (intmax_t)c1->offset, (intmax_t)c1->end); if ((c->type == whole || c->end == c1->end) || Cyl_Aligned(d, c1->end + 1)) ; else sprintf(msg + strlen(msg), - "chunk '%s' [%ld..%ld] does not end" + "chunk '%s' [%jd..%jd] does not end" " on a cylinder boundary\n", - c1->name, c1->offset, c1->end); + c1->name, (intmax_t)c1->offset, (intmax_t)c1->end); } } diff --git a/usr.sbin/sade/disks.c b/usr.sbin/sade/disks.c index 4fba2c7..535fb05 100644 --- a/usr.sbin/sade/disks.c +++ b/usr.sbin/sade/disks.c @@ -37,6 +37,7 @@ #include "sysinstall.h" #include <ctype.h> #include <fcntl.h> +#include <inttypes.h> #include <sys/stat.h> #include <sys/disklabel.h> @@ -83,7 +84,7 @@ record_chunks(Disk *d) { struct chunk *c1 = NULL; int i = 0; - int last_free = 0; + daddr_t last_free = 0; if (!d->chunks) msgFatal("No chunk list found for %s!", d->name); @@ -100,20 +101,21 @@ record_chunks(Disk *d) current_chunk = i - 1; } -static int Total; +static daddr_t Total; static void print_chunks(Disk *d, int u) { int row; int i; - int sz; + daddr_t sz; char *szstr; szstr = (u == UNIT_GIG ? "GB" : (u == UNIT_MEG ? "MB" : (u == UNIT_KILO ? "KB" : "ST"))); - for (i = Total = 0; chunk_info[i]; i++) + Total = 0; + for (i = 0; chunk_info[i]; i++) Total += chunk_info[i]->size; #ifdef PC98 if (d->bios_cyl >= 65536 || d->bios_hd > 16 || d->bios_sect >= 256) { @@ -139,10 +141,10 @@ print_chunks(Disk *d, int u) attrset(A_REVERSE); addstr(d->name); attrset(A_NORMAL); attrset(A_REVERSE); mvaddstr(0, 55, "FDISK Partition Editor"); attrset(A_NORMAL); mvprintw(1, 0, - "DISK Geometry:\t%lu cyls/%lu heads/%lu sectors = %lu sectors (%luMB)", + "DISK Geometry:\t%lu cyls/%lu heads/%lu sectors = %jd sectors (%jdMB)", d->bios_cyl, d->bios_hd, d->bios_sect, - d->bios_cyl * d->bios_hd * d->bios_sect, - d->bios_cyl * d->bios_hd * d->bios_sect / (1024/512) / 1024); + (intmax_t)d->bios_cyl * d->bios_hd * d->bios_sect, + (intmax_t)d->bios_cyl * d->bios_hd * d->bios_sect / (1024/512) / 1024); mvprintw(3, 0, "%6s %10s(%s) %10s %8s %6s %10s %8s %8s", "Offset", "Size", szstr, "End", "Name", "PType", "Desc", "Subtype", "Flags"); @@ -164,9 +166,9 @@ print_chunks(Disk *d, int u) } if (i == current_chunk) attrset(ATTR_SELECTED); - mvprintw(row, 0, "%10ld %10lu %10lu %8s %6d %10s %8d\t%-6s", - chunk_info[i]->offset, sz, - chunk_info[i]->end, chunk_info[i]->name, + mvprintw(row, 0, "%10jd %10jd %10jd %8s %6d %10s %8d\t%-6s", + (intmax_t)chunk_info[i]->offset, (intmax_t)sz, + (intmax_t)chunk_info[i]->end, chunk_info[i]->name, chunk_info[i]->type, slice_type_name(chunk_info[i]->type, chunk_info[i]->subtype), chunk_info[i]->subtype, ShowChunkFlags(chunk_info[i])); @@ -423,7 +425,8 @@ diskPartition(Device *dev) msg = "Slice in use, delete it first or move to an unused one."; else { char *val, tmp[20], name[16], *cp; - int size, subtype; + daddr_t size; + int subtype; chunk_e partitiontype; #ifdef PC98 snprintf(name, sizeof (name), "%s", "FreeBSD"); @@ -434,10 +437,10 @@ diskPartition(Device *dev) #else name[0] = '\0'; #endif - snprintf(tmp, 20, "%lu", chunk_info[current_chunk]->size); + snprintf(tmp, 20, "%jd", (intmax_t)chunk_info[current_chunk]->size); val = msgGetInput(tmp, "Please specify the size for new FreeBSD slice in blocks\n" "or append a trailing `M' for megabytes (e.g. 20M)."); - if (val && (size = strtol(val, &cp, 0)) > 0) { + if (val && (size = strtoimax(val, &cp, 0)) > 0) { if (*cp && toupper(*cp) == 'M') size *= ONE_MEG; else if (*cp && toupper(*cp) == 'G') @@ -886,7 +889,8 @@ static void diskPartitionNonInteractive(Device *dev) { char *cp; - int i, sz, all_disk = 0; + int i, all_disk = 0; + daddr_t sz; #ifdef PC98 u_char *bootipl; size_t bootipl_size; @@ -939,7 +943,7 @@ diskPartitionNonInteractive(Device *dev) All_FreeBSD(d, all_disk = TRUE); } - else if ((sz = strtol(cp, &cp, 0))) { + else if ((sz = strtoimax(cp, &cp, 0))) { /* Look for sz bytes free */ if (*cp && toupper(*cp) == 'M') sz *= ONE_MEG; @@ -956,7 +960,8 @@ diskPartitionNonInteractive(Device *dev) } } if (!chunk_info[i]) { - msgConfirm("Unable to find %d free blocks on this disk!", sz); + msgConfirm("Unable to find %jd free blocks on this disk!", + (intmax_t)sz); return; } } diff --git a/usr.sbin/sade/label.c b/usr.sbin/sade/label.c index 5b4a51c..e75da48 100644 --- a/usr.sbin/sade/label.c +++ b/usr.sbin/sade/label.c @@ -36,6 +36,7 @@ #include "sysinstall.h" #include <ctype.h> +#include <inttypes.h> #include <sys/disklabel.h> #include <sys/param.h> #include <sys/sysctl.h> @@ -244,11 +245,11 @@ check_conflict(char *name) } /* How much space is in this FreeBSD slice? */ -static int +static daddr_t space_free(struct chunk *c) { struct chunk *c1; - int sz = c->size; + daddr_t sz = c->size; for (c1 = c->part; c1; c1 = c1->next) { if (c1->type != unused) @@ -551,8 +552,8 @@ getNewfsOptionalArguments(PartInfo *p) static void print_label_chunks(void) { - int i, j, spaces, srow, prow, pcol; - int sz; + int i, j, srow, prow, pcol; + daddr_t sz; char clrmsg[80]; int ChunkPartStartRow; WINDOW *ChunkWin; @@ -650,25 +651,27 @@ print_label_chunks(void) if (label_chunk_info[i].c->type == whole) { if (sz >= 100 * ONE_GIG) mvprintw(srow++, 0, - "Disk: %s\t\tFree: %d blocks (%dGB)", - label_chunk_info[i].c->disk->name, sz, (sz / ONE_GIG)); + "Disk: %s\t\tFree: %jd blocks (%jdGB)", + label_chunk_info[i].c->disk->name, (intmax_t)sz, + (intmax_t)(sz / ONE_GIG)); else mvprintw(srow++, 0, - "Disk: %s\t\tFree: %d blocks (%dMB)", - label_chunk_info[i].c->disk->name, sz, (sz / ONE_MEG)); + "Disk: %s\t\tFree: %jd blocks (%jdMB)", + label_chunk_info[i].c->disk->name, (intmax_t)sz, + (intmax_t)(sz / ONE_MEG)); } else { if (sz >= 100 * ONE_GIG) mvprintw(srow++, 0, - "Disk: %s\tPartition name: %s\tFree: %d blocks (%dGB)", + "Disk: %s\tPartition name: %s\tFree: %jd blocks (%jdGB)", label_chunk_info[i].c->disk->name, label_chunk_info[i].c->name, - sz, (sz / ONE_GIG)); + (intmax_t)sz, (intmax_t)(sz / ONE_GIG)); else mvprintw(srow++, 0, - "Disk: %s\tPartition name: %s\tFree: %d blocks (%dMB)", + "Disk: %s\tPartition name: %s\tFree: %jd blocks (%jdMB)", label_chunk_info[i].c->disk->name, label_chunk_info[i].c->name, - sz, (sz / ONE_MEG)); + (intmax_t)sz, (intmax_t)(sz / ONE_MEG)); } attrset(A_NORMAL); clrtoeol(); @@ -760,13 +763,13 @@ print_label_chunks(void) for (j = 0; j < MAX_MOUNT_NAME && mountpoint[j]; j++) onestr[PART_MOUNT_COL + j] = mountpoint[j]; if (label_chunk_info[i].c->size == 0) - snprintf(num, 10, "%5ldMB", 0); + snprintf(num, 10, "%5dMB", 0); else if (label_chunk_info[i].c->size < (100 * ONE_GIG)) - snprintf(num, 10, "%5ldMB", - label_chunk_info[i].c->size / ONE_MEG); + snprintf(num, 10, "%5jdMB", + (intmax_t)label_chunk_info[i].c->size / ONE_MEG); else - snprintf(num, 10, "%5ldGB", - label_chunk_info[i].c->size / ONE_GIG); + snprintf(num, 10, "%5jdGB", + (intmax_t)label_chunk_info[i].c->size / ONE_GIG); memcpy(onestr + PART_SIZE_COL, num, strlen(num)); memcpy(onestr + PART_NEWFS_COL, newfs, strlen(newfs)); onestr[PART_NEWFS_COL + strlen(newfs)] = '\0'; @@ -834,7 +837,8 @@ clear_wins(void) static int diskLabel(Device *dev) { - int sz, key = 0; + daddr_t sz; + int key = 0; Boolean labeling; char *msg = NULL; PartInfo *p, *oldp; @@ -991,12 +995,12 @@ diskLabel(Device *dev) } else { char *val; - int size; + daddr_t size; struct chunk *tmp; char osize[80]; u_long flags = 0; - sprintf(osize, "%d", sz); + sprintf(osize, "%jd", (intmax_t)sz); val = msgGetInput(osize, "Please specify the partition size in blocks or append a trailing G for\n" #ifdef __ia64__ @@ -1004,9 +1008,9 @@ diskLabel(Device *dev) #else "gigabytes, M for megabytes, or C for cylinders.\n" #endif - "%d blocks (%dMB) are free.", - sz, sz / ONE_MEG); - if (!val || (size = strtol(val, &cp, 0)) <= 0) { + "%jd blocks (%jdMB) are free.", + (intmax_t)sz, (intmax_t)sz / ONE_MEG); + if (!val || (size = strtoimax(val, &cp, 0)) <= 0) { clear_wins(); break; } @@ -1353,14 +1357,14 @@ diskLabel(Device *dev) return DITEM_SUCCESS; } -static __inline int -requested_part_size(char *varName, int nom, int def, int perc) +static __inline daddr_t +requested_part_size(char *varName, daddr_t nom, int def, int perc) { char *cp; - int sz; + daddr_t sz; if ((cp = variable_get(varName)) != NULL) - sz = atoi(cp); + sz = strtoimax(cp, NULL, 0); else sz = nom + (def - nom) * perc / 100; return(sz * ONE_MEG); @@ -1381,7 +1385,7 @@ requested_part_size(char *varName, int nom, int def, int perc) static char * try_auto_label(Device **devs, Device *dev, int perc, int *req) { - int sz; + daddr_t sz; struct chunk *root_chunk = NULL; struct chunk *swap_chunk = NULL; struct chunk *usr_chunk = NULL; @@ -1420,8 +1424,8 @@ try_auto_label(Device **devs, Device *dev, int perc, int *req) if (!swapdev) { sz = requested_part_size(VAR_SWAP_SIZE, 0, 0, perc); if (sz == 0) { - int nom; - int def; + daddr_t nom; + daddr_t def; mib[0] = CTL_HW; mib[1] = HW_PHYSMEM; @@ -1595,11 +1599,12 @@ diskLabelNonInteractive(Device *dev) int entries; for (entries = 1;; entries++) { - int sz, soft = 0; + intmax_t sz; + int soft = 0; snprintf(name, sizeof name, "%s-%d", c1->name, entries); if ((cp = variable_get(name)) == NULL) break; - if (sscanf(cp, "%s %d %s %d", typ, &sz, mpoint, &soft) < 3) { + if (sscanf(cp, "%s %jd %s %d", typ, &sz, mpoint, &soft) < 3) { msgConfirm("For slice entry %s, got an invalid detail entry of: %s", c1->name, cp); status = DITEM_FAILURE; break; diff --git a/usr.sbin/sysinstall/disks.c b/usr.sbin/sysinstall/disks.c index 4fba2c7..535fb05 100644 --- a/usr.sbin/sysinstall/disks.c +++ b/usr.sbin/sysinstall/disks.c @@ -37,6 +37,7 @@ #include "sysinstall.h" #include <ctype.h> #include <fcntl.h> +#include <inttypes.h> #include <sys/stat.h> #include <sys/disklabel.h> @@ -83,7 +84,7 @@ record_chunks(Disk *d) { struct chunk *c1 = NULL; int i = 0; - int last_free = 0; + daddr_t last_free = 0; if (!d->chunks) msgFatal("No chunk list found for %s!", d->name); @@ -100,20 +101,21 @@ record_chunks(Disk *d) current_chunk = i - 1; } -static int Total; +static daddr_t Total; static void print_chunks(Disk *d, int u) { int row; int i; - int sz; + daddr_t sz; char *szstr; szstr = (u == UNIT_GIG ? "GB" : (u == UNIT_MEG ? "MB" : (u == UNIT_KILO ? "KB" : "ST"))); - for (i = Total = 0; chunk_info[i]; i++) + Total = 0; + for (i = 0; chunk_info[i]; i++) Total += chunk_info[i]->size; #ifdef PC98 if (d->bios_cyl >= 65536 || d->bios_hd > 16 || d->bios_sect >= 256) { @@ -139,10 +141,10 @@ print_chunks(Disk *d, int u) attrset(A_REVERSE); addstr(d->name); attrset(A_NORMAL); attrset(A_REVERSE); mvaddstr(0, 55, "FDISK Partition Editor"); attrset(A_NORMAL); mvprintw(1, 0, - "DISK Geometry:\t%lu cyls/%lu heads/%lu sectors = %lu sectors (%luMB)", + "DISK Geometry:\t%lu cyls/%lu heads/%lu sectors = %jd sectors (%jdMB)", d->bios_cyl, d->bios_hd, d->bios_sect, - d->bios_cyl * d->bios_hd * d->bios_sect, - d->bios_cyl * d->bios_hd * d->bios_sect / (1024/512) / 1024); + (intmax_t)d->bios_cyl * d->bios_hd * d->bios_sect, + (intmax_t)d->bios_cyl * d->bios_hd * d->bios_sect / (1024/512) / 1024); mvprintw(3, 0, "%6s %10s(%s) %10s %8s %6s %10s %8s %8s", "Offset", "Size", szstr, "End", "Name", "PType", "Desc", "Subtype", "Flags"); @@ -164,9 +166,9 @@ print_chunks(Disk *d, int u) } if (i == current_chunk) attrset(ATTR_SELECTED); - mvprintw(row, 0, "%10ld %10lu %10lu %8s %6d %10s %8d\t%-6s", - chunk_info[i]->offset, sz, - chunk_info[i]->end, chunk_info[i]->name, + mvprintw(row, 0, "%10jd %10jd %10jd %8s %6d %10s %8d\t%-6s", + (intmax_t)chunk_info[i]->offset, (intmax_t)sz, + (intmax_t)chunk_info[i]->end, chunk_info[i]->name, chunk_info[i]->type, slice_type_name(chunk_info[i]->type, chunk_info[i]->subtype), chunk_info[i]->subtype, ShowChunkFlags(chunk_info[i])); @@ -423,7 +425,8 @@ diskPartition(Device *dev) msg = "Slice in use, delete it first or move to an unused one."; else { char *val, tmp[20], name[16], *cp; - int size, subtype; + daddr_t size; + int subtype; chunk_e partitiontype; #ifdef PC98 snprintf(name, sizeof (name), "%s", "FreeBSD"); @@ -434,10 +437,10 @@ diskPartition(Device *dev) #else name[0] = '\0'; #endif - snprintf(tmp, 20, "%lu", chunk_info[current_chunk]->size); + snprintf(tmp, 20, "%jd", (intmax_t)chunk_info[current_chunk]->size); val = msgGetInput(tmp, "Please specify the size for new FreeBSD slice in blocks\n" "or append a trailing `M' for megabytes (e.g. 20M)."); - if (val && (size = strtol(val, &cp, 0)) > 0) { + if (val && (size = strtoimax(val, &cp, 0)) > 0) { if (*cp && toupper(*cp) == 'M') size *= ONE_MEG; else if (*cp && toupper(*cp) == 'G') @@ -886,7 +889,8 @@ static void diskPartitionNonInteractive(Device *dev) { char *cp; - int i, sz, all_disk = 0; + int i, all_disk = 0; + daddr_t sz; #ifdef PC98 u_char *bootipl; size_t bootipl_size; @@ -939,7 +943,7 @@ diskPartitionNonInteractive(Device *dev) All_FreeBSD(d, all_disk = TRUE); } - else if ((sz = strtol(cp, &cp, 0))) { + else if ((sz = strtoimax(cp, &cp, 0))) { /* Look for sz bytes free */ if (*cp && toupper(*cp) == 'M') sz *= ONE_MEG; @@ -956,7 +960,8 @@ diskPartitionNonInteractive(Device *dev) } } if (!chunk_info[i]) { - msgConfirm("Unable to find %d free blocks on this disk!", sz); + msgConfirm("Unable to find %jd free blocks on this disk!", + (intmax_t)sz); return; } } diff --git a/usr.sbin/sysinstall/label.c b/usr.sbin/sysinstall/label.c index 5b4a51c..e75da48 100644 --- a/usr.sbin/sysinstall/label.c +++ b/usr.sbin/sysinstall/label.c @@ -36,6 +36,7 @@ #include "sysinstall.h" #include <ctype.h> +#include <inttypes.h> #include <sys/disklabel.h> #include <sys/param.h> #include <sys/sysctl.h> @@ -244,11 +245,11 @@ check_conflict(char *name) } /* How much space is in this FreeBSD slice? */ -static int +static daddr_t space_free(struct chunk *c) { struct chunk *c1; - int sz = c->size; + daddr_t sz = c->size; for (c1 = c->part; c1; c1 = c1->next) { if (c1->type != unused) @@ -551,8 +552,8 @@ getNewfsOptionalArguments(PartInfo *p) static void print_label_chunks(void) { - int i, j, spaces, srow, prow, pcol; - int sz; + int i, j, srow, prow, pcol; + daddr_t sz; char clrmsg[80]; int ChunkPartStartRow; WINDOW *ChunkWin; @@ -650,25 +651,27 @@ print_label_chunks(void) if (label_chunk_info[i].c->type == whole) { if (sz >= 100 * ONE_GIG) mvprintw(srow++, 0, - "Disk: %s\t\tFree: %d blocks (%dGB)", - label_chunk_info[i].c->disk->name, sz, (sz / ONE_GIG)); + "Disk: %s\t\tFree: %jd blocks (%jdGB)", + label_chunk_info[i].c->disk->name, (intmax_t)sz, + (intmax_t)(sz / ONE_GIG)); else mvprintw(srow++, 0, - "Disk: %s\t\tFree: %d blocks (%dMB)", - label_chunk_info[i].c->disk->name, sz, (sz / ONE_MEG)); + "Disk: %s\t\tFree: %jd blocks (%jdMB)", + label_chunk_info[i].c->disk->name, (intmax_t)sz, + (intmax_t)(sz / ONE_MEG)); } else { if (sz >= 100 * ONE_GIG) mvprintw(srow++, 0, - "Disk: %s\tPartition name: %s\tFree: %d blocks (%dGB)", + "Disk: %s\tPartition name: %s\tFree: %jd blocks (%jdGB)", label_chunk_info[i].c->disk->name, label_chunk_info[i].c->name, - sz, (sz / ONE_GIG)); + (intmax_t)sz, (intmax_t)(sz / ONE_GIG)); else mvprintw(srow++, 0, - "Disk: %s\tPartition name: %s\tFree: %d blocks (%dMB)", + "Disk: %s\tPartition name: %s\tFree: %jd blocks (%jdMB)", label_chunk_info[i].c->disk->name, label_chunk_info[i].c->name, - sz, (sz / ONE_MEG)); + (intmax_t)sz, (intmax_t)(sz / ONE_MEG)); } attrset(A_NORMAL); clrtoeol(); @@ -760,13 +763,13 @@ print_label_chunks(void) for (j = 0; j < MAX_MOUNT_NAME && mountpoint[j]; j++) onestr[PART_MOUNT_COL + j] = mountpoint[j]; if (label_chunk_info[i].c->size == 0) - snprintf(num, 10, "%5ldMB", 0); + snprintf(num, 10, "%5dMB", 0); else if (label_chunk_info[i].c->size < (100 * ONE_GIG)) - snprintf(num, 10, "%5ldMB", - label_chunk_info[i].c->size / ONE_MEG); + snprintf(num, 10, "%5jdMB", + (intmax_t)label_chunk_info[i].c->size / ONE_MEG); else - snprintf(num, 10, "%5ldGB", - label_chunk_info[i].c->size / ONE_GIG); + snprintf(num, 10, "%5jdGB", + (intmax_t)label_chunk_info[i].c->size / ONE_GIG); memcpy(onestr + PART_SIZE_COL, num, strlen(num)); memcpy(onestr + PART_NEWFS_COL, newfs, strlen(newfs)); onestr[PART_NEWFS_COL + strlen(newfs)] = '\0'; @@ -834,7 +837,8 @@ clear_wins(void) static int diskLabel(Device *dev) { - int sz, key = 0; + daddr_t sz; + int key = 0; Boolean labeling; char *msg = NULL; PartInfo *p, *oldp; @@ -991,12 +995,12 @@ diskLabel(Device *dev) } else { char *val; - int size; + daddr_t size; struct chunk *tmp; char osize[80]; u_long flags = 0; - sprintf(osize, "%d", sz); + sprintf(osize, "%jd", (intmax_t)sz); val = msgGetInput(osize, "Please specify the partition size in blocks or append a trailing G for\n" #ifdef __ia64__ @@ -1004,9 +1008,9 @@ diskLabel(Device *dev) #else "gigabytes, M for megabytes, or C for cylinders.\n" #endif - "%d blocks (%dMB) are free.", - sz, sz / ONE_MEG); - if (!val || (size = strtol(val, &cp, 0)) <= 0) { + "%jd blocks (%jdMB) are free.", + (intmax_t)sz, (intmax_t)sz / ONE_MEG); + if (!val || (size = strtoimax(val, &cp, 0)) <= 0) { clear_wins(); break; } @@ -1353,14 +1357,14 @@ diskLabel(Device *dev) return DITEM_SUCCESS; } -static __inline int -requested_part_size(char *varName, int nom, int def, int perc) +static __inline daddr_t +requested_part_size(char *varName, daddr_t nom, int def, int perc) { char *cp; - int sz; + daddr_t sz; if ((cp = variable_get(varName)) != NULL) - sz = atoi(cp); + sz = strtoimax(cp, NULL, 0); else sz = nom + (def - nom) * perc / 100; return(sz * ONE_MEG); @@ -1381,7 +1385,7 @@ requested_part_size(char *varName, int nom, int def, int perc) static char * try_auto_label(Device **devs, Device *dev, int perc, int *req) { - int sz; + daddr_t sz; struct chunk *root_chunk = NULL; struct chunk *swap_chunk = NULL; struct chunk *usr_chunk = NULL; @@ -1420,8 +1424,8 @@ try_auto_label(Device **devs, Device *dev, int perc, int *req) if (!swapdev) { sz = requested_part_size(VAR_SWAP_SIZE, 0, 0, perc); if (sz == 0) { - int nom; - int def; + daddr_t nom; + daddr_t def; mib[0] = CTL_HW; mib[1] = HW_PHYSMEM; @@ -1595,11 +1599,12 @@ diskLabelNonInteractive(Device *dev) int entries; for (entries = 1;; entries++) { - int sz, soft = 0; + intmax_t sz; + int soft = 0; snprintf(name, sizeof name, "%s-%d", c1->name, entries); if ((cp = variable_get(name)) == NULL) break; - if (sscanf(cp, "%s %d %s %d", typ, &sz, mpoint, &soft) < 3) { + if (sscanf(cp, "%s %jd %s %d", typ, &sz, mpoint, &soft) < 3) { msgConfirm("For slice entry %s, got an invalid detail entry of: %s", c1->name, cp); status = DITEM_FAILURE; break; |