variables/parameters, not off_t.
Adjust various parameters and variables accordingly. A few missed const's
and verbiage tweaks in passing.
No functional change.
-/* $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
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) &&
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;
}
-/* $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
* 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;
* 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);
-/* $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
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;
-/* $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>
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;
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;
}
-/* $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
}
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;
}
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;
}
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;
* 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);
-/* $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
#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;
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 */
-/* $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
}
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;
}
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;
-/* $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
};
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 *);
-/* $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
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;
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));
{
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. */
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
-/* $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
#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 */