diff options
-rw-r--r-- | sbin/fdisk/cmd.c | 11 | ||||
-rw-r--r-- | sbin/fdisk/fdisk.c | 6 | ||||
-rw-r--r-- | sbin/fdisk/mbr.c | 15 | ||||
-rw-r--r-- | sbin/fdisk/mbr.h | 6 | ||||
-rw-r--r-- | sbin/fdisk/part.c | 19 | ||||
-rw-r--r-- | sbin/fdisk/part.h | 6 | ||||
-rw-r--r-- | sbin/fdisk/user.c | 20 | ||||
-rw-r--r-- | sbin/fdisk/user.h | 4 |
8 files changed, 56 insertions, 31 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index 3b3f67a0911..5d25aabfa95 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.13 1997/10/19 23:58:50 deraadt Exp $ */ +/* $OpenBSD: cmd.c,v 1.14 1997/10/21 22:49:32 provos Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -56,7 +56,7 @@ Xreinit(cmd, disk, mbr, tt, offset) /* Copy template MBR */ MBR_make(tt, buf); - MBR_parse(buf, mbr); + MBR_parse(buf, 0, 0, mbr); /* Fix up given mbr for this disk */ mbr->part[0].flag = 0; @@ -203,6 +203,7 @@ Xselect(cmd, disk, mbr, tt, offset) mbr_t *tt; int offset; { + static firstoff = 0; int off; int pn; @@ -219,6 +220,10 @@ Xselect(cmd, disk, mbr, tt, offset) printf("Partition %d is not an extended partition.\n", pn); return (CMD_CONT); } + + if (firstoff == 0) + firstoff = off; + if (!off) { printf("Loop to offset 0! Not selected.\n"); return (CMD_CONT); @@ -228,7 +233,7 @@ Xselect(cmd, disk, mbr, tt, offset) } /* Recursion is beautifull! */ - USER_modify(disk, tt, off); + USER_modify(disk, tt, off, firstoff); return (CMD_CONT); } diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index 518018188f9..dcb93487b55 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdisk.c,v 1.27 1997/10/19 23:30:47 deraadt Exp $ */ +/* $OpenBSD: fdisk.c,v 1.28 1997/10/21 22:49:33 provos Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -143,7 +143,7 @@ main(argc, argv) err(1, "open mbr file"); MBR_read(fd, 0, mbr_buf); close(fd); - MBR_parse(mbr_buf, &mbr); + MBR_parse(mbr_buf, 0, 0, &mbr); /* Print out current MBRs on disk */ @@ -159,7 +159,7 @@ main(argc, argv) USER_init(&disk, &mbr); if (m_flag) - USER_modify(&disk, &mbr, 0); + USER_modify(&disk, &mbr, 0, 0); return (0); } diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c index bbf31ff8c24..b19718bd182 100644 --- a/sbin/fdisk/mbr.c +++ b/sbin/fdisk/mbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.c,v 1.5 1997/10/19 23:30:47 deraadt Exp $ */ +/* $OpenBSD: mbr.c,v 1.6 1997/10/21 22:49:33 provos Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -47,19 +47,24 @@ void -MBR_parse(mbr_buf, mbr) +MBR_parse(mbr_buf, offset, reloff, mbr) char *mbr_buf; + off_t offset; + off_t reloff; mbr_t *mbr; { int i; memcpy(mbr->code, mbr_buf, MBR_CODE_SIZE); + mbr->offset = offset; + mbr->reloffset = reloff; mbr->nt_serial = getlong(&mbr_buf[MBR_NTSER_OFF]); mbr->spare = getshort(&mbr_buf[MBR_SPARE_OFF]); mbr->signature = getshort(&mbr_buf[MBR_SIG_OFF]); for (i = 0; i < NDOSPART; i++) - PRT_parse(&mbr_buf[MBR_PART_OFF + MBR_PART_SIZE * i], + PRT_parse(&mbr_buf[MBR_PART_OFF + MBR_PART_SIZE * i], + offset, reloff, &mbr->part[i]); } @@ -76,8 +81,8 @@ MBR_make(mbr, mbr_buf) putshort(&mbr_buf[MBR_SIG_OFF], mbr->signature); for (i = 0; i < NDOSPART; i++) - PRT_make(&mbr->part[i], &mbr_buf[MBR_PART_OFF + - MBR_PART_SIZE * i]); + PRT_make(&mbr->part[i], mbr->offset, mbr->reloffset, + &mbr_buf[MBR_PART_OFF + MBR_PART_SIZE * i]); } void diff --git a/sbin/fdisk/mbr.h b/sbin/fdisk/mbr.h index 0e138da9750..5a8efae6794 100644 --- a/sbin/fdisk/mbr.h +++ b/sbin/fdisk/mbr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.h,v 1.2 1997/09/29 23:33:36 mickey Exp $ */ +/* $OpenBSD: mbr.h,v 1.3 1997/10/21 22:49:34 provos Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -46,6 +46,8 @@ /* MBR type */ typedef struct _mbr_t { + off_t reloffset; + off_t offset; unsigned char code[MBR_CODE_SIZE]; unsigned long nt_serial; unsigned short spare; @@ -56,7 +58,7 @@ typedef struct _mbr_t { /* Prototypes */ void MBR_print_disk __P((char *)); void MBR_print __P((mbr_t *)); -void MBR_parse __P((char *, mbr_t *)); +void MBR_parse __P((char *, off_t, off_t, mbr_t *)); void MBR_make __P((mbr_t *, char *)); int MBR_read __P((int, off_t, char *)); int MBR_write __P((int, off_t, char *)); diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c index 5be6f642254..2aa687dea09 100644 --- a/sbin/fdisk/part.c +++ b/sbin/fdisk/part.c @@ -1,4 +1,4 @@ -/* $OpenBSD: part.c,v 1.6 1997/10/19 23:29:38 deraadt Exp $ */ +/* $OpenBSD: part.c,v 1.7 1997/10/21 22:49:34 provos Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -126,14 +126,18 @@ PRT_ascii_id(id) } void -PRT_parse(prt, partn) +PRT_parse(prt, offset, reloff, partn) void *prt; + off_t offset; + off_t reloff; prt_t *partn; { unsigned char *p = prt; + off_t off; partn->flag = *p++; partn->shead = *p++; + partn->ssect = (*p) & 0x3F; partn->scyl = ((*p << 2) & 0xFF00) | (*(p+1)); p += 2; @@ -144,16 +148,21 @@ PRT_parse(prt, partn) partn->ecyl = ((*p << 2) & 0xFF00) | (*(p+1)); p += 2; - partn->bs = getlong(p); + off = partn->id != DOSPTYP_EXTEND ? offset : reloff; + + partn->bs = getlong(p) + off; partn->ns = getlong(p+4); } void -PRT_make(partn, prt) +PRT_make(partn, offset, reloff, prt) prt_t *partn; + off_t offset; + off_t reloff; void *prt; { unsigned char *p = prt; + off_t off = partn->id != DOSPTYP_EXTEND ? offset : reloff; *p++ = partn->flag & 0xFF; *p++ = partn->shead & 0xFF; @@ -166,7 +175,7 @@ PRT_make(partn, prt) *p++ = (partn->esect & 0x3F) | ((partn->ecyl & 0x300) >> 2); *p++ = partn->ecyl & 0xFF; - putlong(p, partn->bs); + putlong(p, partn->bs - off); putlong(p+4, partn->ns); } diff --git a/sbin/fdisk/part.h b/sbin/fdisk/part.h index 3346834b45c..f42f6df2d51 100644 --- a/sbin/fdisk/part.h +++ b/sbin/fdisk/part.h @@ -1,4 +1,4 @@ -/* $OpenBSD: part.h,v 1.3 1997/10/16 01:47:12 deraadt Exp $ */ +/* $OpenBSD: part.h,v 1.4 1997/10/21 22:49:35 provos Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -46,8 +46,8 @@ typedef struct _prt_t { /* Prototypes */ void PRT_printall __P((void)); char *PRT_ascii_id __P((int)); -void PRT_parse __P((void *, prt_t *)); -void PRT_make __P((prt_t *, void *)); +void PRT_parse __P((void *, off_t, off_t, prt_t *)); +void PRT_make __P((prt_t *, off_t, off_t, void *)); void PRT_print __P((int, prt_t *)); /* This does CHS -> bs/ns */ diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c index 60eb7da2cbe..8ee8e8d373b 100644 --- a/sbin/fdisk/user.c +++ b/sbin/fdisk/user.c @@ -1,4 +1,4 @@ -/* $OpenBSD: user.c,v 1.10 1997/10/19 23:29:38 deraadt Exp $ */ +/* $OpenBSD: user.c,v 1.11 1997/10/21 22:49:35 provos Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -114,10 +114,11 @@ USER_init(disk, tt) int modified; int -USER_modify(disk, tt, offset) +USER_modify(disk, tt, offset, reloff) disk_t *disk; mbr_t *tt; - int offset; + off_t offset; + off_t reloff; { static int editlevel; char mbr_buf[DEV_BSIZE]; @@ -137,7 +138,7 @@ USER_modify(disk, tt, offset) DISK_close(fd); /* Parse the sucker */ - MBR_parse(mbr_buf, &mbr); + MBR_parse(mbr_buf, offset, reloff, &mbr); printf("Enter 'help' for information\n"); @@ -201,26 +202,29 @@ int USER_print_disk(disk) disk_t *disk; { - int fd, offset, i; + int fd, offset, firstoff, i; char mbr_buf[DEV_BSIZE]; mbr_t mbr; fd = DISK_open(disk->name, O_RDONLY); - offset = 0; + offset = firstoff = 0; DISK_printmetrics(disk); do { MBR_read(fd, (off_t)offset, mbr_buf); - MBR_parse(mbr_buf, &mbr); + MBR_parse(mbr_buf, offset, firstoff, &mbr); printf("Offset: %d\t", (int)offset); MBR_print(&mbr); /* Print out extended partitions too */ for (offset = i = 0; i < 4; i++) - if (mbr.part[i].id == DOSPTYP_EXTEND) + if (mbr.part[i].id == DOSPTYP_EXTEND) { offset = mbr.part[i].bs; + if (firstoff == 0) + firstoff = offset; + } } while (offset); return (DISK_close(fd)); diff --git a/sbin/fdisk/user.h b/sbin/fdisk/user.h index 79c085cd898..b97dde99c5f 100644 --- a/sbin/fdisk/user.h +++ b/sbin/fdisk/user.h @@ -1,4 +1,4 @@ -/* $OpenBSD: user.h,v 1.2 1997/09/29 23:33:41 mickey Exp $ */ +/* $OpenBSD: user.h,v 1.3 1997/10/21 22:49:36 provos Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -38,7 +38,7 @@ /* Prototypes */ int USER_init __P((disk_t *, mbr_t *)); -int USER_modify __P((disk_t *, mbr_t *, int)); +int USER_modify __P((disk_t *, mbr_t *, off_t, off_t)); int USER_print_disk __P((disk_t *)); #endif _USER_H |