summaryrefslogtreecommitdiff
path: root/sbin/fdisk
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/fdisk')
-rw-r--r--sbin/fdisk/cmd.c20
-rw-r--r--sbin/fdisk/disk.c14
-rw-r--r--sbin/fdisk/disk.h6
-rw-r--r--sbin/fdisk/gpt.c14
-rw-r--r--sbin/fdisk/mbr.c16
-rw-r--r--sbin/fdisk/mbr.h14
-rw-r--r--sbin/fdisk/part.c11
-rw-r--r--sbin/fdisk/part.h9
-rw-r--r--sbin/fdisk/user.c28
-rw-r--r--sbin/fdisk/user.h6
10 files changed, 69 insertions, 69 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c
index 60984d530ef..09db543b32f 100644
--- a/sbin/fdisk/cmd.c
+++ b/sbin/fdisk/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.126 2021/07/12 22:18:54 krw Exp $ */
+/* $OpenBSD: cmd.c,v 1.127 2021/07/13 15:03:34 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -393,15 +393,15 @@ Xsetpid(char *args, struct mbr *mbr)
int
Xselect(char *args, struct mbr *mbr)
{
- static off_t firstoff = 0;
- off_t off;
+ static uint64_t lba_firstembr = 0;
+ uint64_t lba_self;
int pn;
pn = parsepn(args);
if (pn == -1)
return CMD_CONT;
- off = mbr->mbr_prt[pn].prt_bs;
+ lba_self = mbr->mbr_prt[pn].prt_bs;
/* Sanity checks */
if ((mbr->mbr_prt[pn].prt_id != DOSPTYP_EXTEND) &&
@@ -410,19 +410,19 @@ Xselect(char *args, struct mbr *mbr)
return CMD_CONT;
}
- if (firstoff == 0)
- firstoff = off;
+ if (lba_firstembr == 0)
+ lba_firstembr = lba_self;
- if (!off) {
- printf("Loop to offset 0! Not selected.\n");
+ if (lba_self == 0) {
+ printf("Loop to MBR (sector 0)! Not selected.\n");
return CMD_CONT;
} else {
printf("Selected extended partition %d\n", pn);
- printf("New MBR at offset %lld.\n", (long long)off);
+ printf("New EMBR at offset %llu.\n", lba_self);
}
/* Recursion is beautiful! */
- USER_edit(off, firstoff);
+ USER_edit(lba_self, lba_firstembr);
return CMD_CONT;
}
diff --git a/sbin/fdisk/disk.c b/sbin/fdisk/disk.c
index 00952c1b108..880aa0be2ba 100644
--- a/sbin/fdisk/disk.c
+++ b/sbin/fdisk/disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disk.c,v 1.62 2021/07/12 22:18:54 krw Exp $ */
+/* $OpenBSD: disk.c,v 1.63 2021/07/13 15:03:34 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -113,16 +113,16 @@ DISK_printgeometry(const char *units)
* The caller must free() the memory it gets.
*/
char *
-DISK_readsector(off_t where)
+DISK_readsector(const uint64_t sector)
{
char *secbuf;
ssize_t len;
- off_t off;
+ off_t off, where;
int secsize;
secsize = dl.d_secsize;
- where *= secsize;
+ where = sector * secsize;
off = lseek(disk.dk_fd, where, SEEK_SET);
if (off != where)
return NULL;
@@ -146,16 +146,16 @@ DISK_readsector(off_t where)
* errno if the write fails.
*/
int
-DISK_writesector(const char *secbuf, off_t where)
+DISK_writesector(const char *secbuf, const uint64_t sector)
{
int secsize;
ssize_t len;
- off_t off;
+ off_t off, where;
len = -1;
secsize = dl.d_secsize;
- where *= secsize;
+ where = secsize * sector;
off = lseek(disk.dk_fd, where, SEEK_SET);
if (off == where)
len = write(disk.dk_fd, secbuf, secsize);
diff --git a/sbin/fdisk/disk.h b/sbin/fdisk/disk.h
index 928be0942e8..465449e2ed7 100644
--- a/sbin/fdisk/disk.h
+++ b/sbin/fdisk/disk.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: disk.h,v 1.26 2021/07/12 22:18:54 krw Exp $ */
+/* $OpenBSD: disk.h,v 1.27 2021/07/13 15:03:34 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -33,8 +33,8 @@ struct disk {
void DISK_open(const int);
int DISK_printgeometry(const char *);
-char *DISK_readsector(off_t);
-int DISK_writesector(const char *, off_t);
+char *DISK_readsector(const uint64_t);
+int DISK_writesector(const char *, const uint64_t);
extern struct disk disk;
extern struct disklabel dl;
diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c
index 19a2a411eb2..9b0ebcd01e6 100644
--- a/sbin/fdisk/gpt.c
+++ b/sbin/fdisk/gpt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gpt.c,v 1.41 2021/07/13 11:18:25 krw Exp $ */
+/* $OpenBSD: gpt.c,v 1.42 2021/07/13 15:03:34 krw Exp $ */
/*
* Copyright (c) 2015 Markus Muller <mmu@grummel.net>
* Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org>
@@ -46,21 +46,21 @@ struct gpt_partition **sort_gpt(void);
int lba_start_cmp(const void *e1, const void *e2);
int lba_free(uint64_t *, uint64_t *);
int add_partition(const uint8_t *, const char *, uint64_t);
-int get_header(const off_t);
+int get_header(const uint64_t);
int get_partition_table(void);
int init_gh(void);
int init_gp(const int, const uint32_t);
uint32_t crc32(const u_char *, const uint32_t);
int
-get_header(const off_t where)
+get_header(const uint64_t sector)
{
char *secbuf;
uint64_t partlastlba, partslen, lba_end;
int partspersec;
uint32_t orig_gh_csum, new_gh_csum;
- secbuf = DISK_readsector(where);
+ secbuf = DISK_readsector(sector);
if (secbuf == 0)
return 1;
@@ -79,9 +79,9 @@ get_header(const off_t where)
return 1;
}
- if (letoh64(gh.gh_lba_self) != where) {
- DPRINTF("gpt self lba: expected %lld, got %llu\n",
- (long long)where, letoh64(gh.gh_lba_self));
+ if (letoh64(gh.gh_lba_self) != sector) {
+ DPRINTF("gpt self lba: expected %llu, got %llu\n",
+ sector, letoh64(gh.gh_lba_self));
return 1;
}
diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c
index 328d8536106..5714a26686f 100644
--- a/sbin/fdisk/mbr.c
+++ b/sbin/fdisk/mbr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbr.c,v 1.84 2021/07/12 22:18:54 krw Exp $ */
+/* $OpenBSD: mbr.c,v 1.85 2021/07/13 15:03:34 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -157,8 +157,8 @@ MBR_init(struct mbr *mbr)
}
void
-MBR_parse(const struct dos_mbr *dos_mbr, const off_t lba_self,
- const off_t lba_firstembr, struct mbr *mbr)
+MBR_parse(const struct dos_mbr *dos_mbr, const uint64_t lba_self,
+ const uint64_t lba_firstembr, struct mbr *mbr)
{
struct dos_partition dos_parts[NDOSPART];
int i;
@@ -210,11 +210,11 @@ MBR_print(const struct mbr *mbr, const char *units)
}
int
-MBR_read(const off_t where, struct dos_mbr *dos_mbr)
+MBR_read(const uint64_t sector, struct dos_mbr *dos_mbr)
{
char *secbuf;
- secbuf = DISK_readsector(where);
+ secbuf = DISK_readsector(sector);
if (secbuf == NULL)
return -1;
@@ -225,11 +225,11 @@ MBR_read(const off_t where, struct dos_mbr *dos_mbr)
}
int
-MBR_write(const off_t where, const struct dos_mbr *dos_mbr)
+MBR_write(const uint64_t sector, const struct dos_mbr *dos_mbr)
{
char *secbuf;
- secbuf = DISK_readsector(where);
+ secbuf = DISK_readsector(sector);
if (secbuf == NULL)
return -1;
@@ -238,7 +238,7 @@ MBR_write(const off_t where, const struct dos_mbr *dos_mbr)
* write the sector back to "disk".
*/
memcpy(secbuf, dos_mbr, sizeof(*dos_mbr));
- DISK_writesector(secbuf, where);
+ DISK_writesector(secbuf, sector);
/* Refresh in-kernel disklabel from the updated disk information. */
ioctl(disk.dk_fd, DIOCRLDINFO, 0);
diff --git a/sbin/fdisk/mbr.h b/sbin/fdisk/mbr.h
index 2387e4b011a..941ee3a5974 100644
--- a/sbin/fdisk/mbr.h
+++ b/sbin/fdisk/mbr.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbr.h,v 1.34 2021/07/12 22:18:54 krw Exp $ */
+/* $OpenBSD: mbr.h,v 1.35 2021/07/13 15:03:34 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -20,8 +20,8 @@
#define _MBR_H
struct mbr {
- off_t mbr_lba_firstembr;
- off_t mbr_lba_self;
+ uint64_t mbr_lba_firstembr;
+ uint64_t mbr_lba_self;
unsigned char mbr_code[DOSPARTOFF];
struct prt mbr_prt[NDOSPART];
uint16_t mbr_signature;
@@ -30,13 +30,13 @@ struct mbr {
extern struct mbr initial_mbr;
void MBR_print(const struct mbr *, const char *);
-void MBR_parse(const struct dos_mbr *, const off_t, const off_t,
- struct mbr *);
+void MBR_parse(const struct dos_mbr *, const uint64_t,
+ const uint64_t, struct mbr *);
void MBR_make(struct mbr *, struct dos_mbr *);
void MBR_init(struct mbr *);
void MBR_init_GPT(struct mbr *);
-int MBR_read(const off_t, struct dos_mbr *);
-int MBR_write(const off_t, const struct dos_mbr *);
+int MBR_read(const uint64_t, struct dos_mbr *);
+int MBR_write(const uint64_t, const struct dos_mbr *);
int MBR_protective_mbr(struct mbr *);
#endif /* _MBR_H */
diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c
index 40783e12c78..56502878d17 100644
--- a/sbin/fdisk/part.c
+++ b/sbin/fdisk/part.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: part.c,v 1.94 2021/07/12 22:18:54 krw Exp $ */
+/* $OpenBSD: part.c,v 1.95 2021/07/13 15:03:34 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -222,8 +222,8 @@ ascii_id(const int id)
}
void
-PRT_parse(const struct dos_partition *dp, const off_t lba_self,
- const off_t lba_firstembr, struct prt *prt)
+PRT_parse(const struct dos_partition *dp, const uint64_t lba_self,
+ const uint64_t lba_firstembr, struct prt *prt)
{
off_t off;
uint32_t t;
@@ -277,12 +277,11 @@ check_chs(const struct prt *prt)
}
void
-PRT_make(struct prt *prt, const off_t lba_self, const off_t lba_firstembr,
+PRT_make(struct prt *prt, const uint64_t lba_self, const uint64_t lba_firstembr,
struct dos_partition *dp)
{
- off_t off;
+ uint64_t off, t;
uint32_t ecsave, scsave;
- uint64_t t;
/* Save (and restore below) cylinder info we may fiddle with. */
scsave = prt->prt_scyl;
diff --git a/sbin/fdisk/part.h b/sbin/fdisk/part.h
index a04f5d719d5..08cfa9240c5 100644
--- a/sbin/fdisk/part.h
+++ b/sbin/fdisk/part.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: part.h,v 1.27 2021/07/12 22:18:54 krw Exp $ */
+/* $OpenBSD: part.h,v 1.28 2021/07/13 15:03:34 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -29,9 +29,10 @@ struct prt {
};
void PRT_printall(void);
-void PRT_parse(const struct dos_partition *, const off_t, const off_t,
- struct prt *);
-void PRT_make(struct prt *,const off_t, const off_t, struct dos_partition *);
+void PRT_parse(const struct dos_partition *, const uint64_t,
+ const uint64_t, struct prt *);
+void PRT_make(struct prt *,const uint64_t, const uint64_t,
+ struct dos_partition *);
void PRT_print(const int, const struct prt *, const char *);
char *PRT_uuid_to_typename(const struct uuid *);
int PRT_uuid_to_type(const struct uuid *);
diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c
index faff7afe92e..5b2202e2838 100644
--- a/sbin/fdisk/user.c
+++ b/sbin/fdisk/user.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: user.c,v 1.62 2021/07/12 22:18:54 krw Exp $ */
+/* $OpenBSD: user.c,v 1.63 2021/07/13 15:03:34 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -59,7 +59,7 @@ int modified;
void ask_cmd(char **, char **);
void
-USER_edit(const off_t offset, const off_t reloff)
+USER_edit(const uint64_t lba_self, const uint64_t lba_firstembr)
{
struct dos_mbr dos_mbr;
struct mbr mbr;
@@ -71,12 +71,12 @@ USER_edit(const off_t offset, const off_t reloff)
editlevel += 1;
/* Read MBR & partition */
- error = MBR_read(offset, &dos_mbr);
+ error = MBR_read(lba_self, &dos_mbr);
if (error == -1)
goto done;
/* Parse the sucker */
- MBR_parse(&dos_mbr, offset, reloff, &mbr);
+ MBR_parse(&dos_mbr, lba_self, lba_firstembr, &mbr);
if (editlevel == 1) {
memset(&gh, 0, sizeof(gh));
@@ -145,17 +145,17 @@ USER_print_disk(const int verbosity)
{
struct dos_mbr dos_mbr;
struct mbr mbr;
- off_t offset, firstoff;
+ uint64_t lba_self, lba_firstembr;
int i, efi, error;
- offset = firstoff = 0;
+ lba_self = lba_firstembr = 0;
do {
- error = MBR_read(offset, &dos_mbr);
+ error = MBR_read(lba_self, &dos_mbr);
if (error == -1)
break;
- MBR_parse(&dos_mbr, offset, firstoff, &mbr);
- if (offset == 0) {
+ MBR_parse(&dos_mbr, lba_self, lba_firstembr, &mbr);
+ if (lba_self == 0) {
efi = MBR_protective_mbr(&mbr);
if (efi == -1) {
/* No valid 0xEE partition means no GPT. */
@@ -191,14 +191,14 @@ USER_print_disk(const int verbosity)
MBR_print(&mbr, NULL);
/* Print out extended partitions too */
- for (offset = i = 0; i < 4; i++)
+ for (lba_self = i = 0; i < 4; i++)
if (mbr.mbr_prt[i].prt_id == DOSPTYP_EXTEND ||
mbr.mbr_prt[i].prt_id == DOSPTYP_EXTENDL) {
- offset = (off_t)mbr.mbr_prt[i].prt_bs;
- if (firstoff == 0)
- firstoff = offset;
+ lba_self = mbr.mbr_prt[i].prt_bs;
+ if (lba_firstembr == 0)
+ lba_firstembr = lba_self;
}
- } while (offset);
+ } while (lba_self);
}
void
diff --git a/sbin/fdisk/user.h b/sbin/fdisk/user.h
index 3ce20563297..522be670550 100644
--- a/sbin/fdisk/user.h
+++ b/sbin/fdisk/user.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: user.h,v 1.18 2021/07/11 13:23:18 krw Exp $ */
+/* $OpenBSD: user.h,v 1.19 2021/07/13 15:03:34 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -20,7 +20,7 @@
#define _USER_H
/* Prototypes */
-void USER_edit(off_t, off_t);
-void USER_print_disk(int);
+void USER_edit(const uint64_t, const uint64_t);
+void USER_print_disk(const int);
#endif /* _USER_H */