diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index ecf2e1acc6cb..e6333ff38b5c 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -1,4 +1,4 @@ -/* $NetBSD: disklabel.c,v 1.68 1999/04/30 04:46:50 abs Exp $ */ +/* $NetBSD: disklabel.c,v 1.69 1999/05/03 09:45:01 christos Exp $ */ /* * Copyright (c) 1987, 1993 @@ -47,7 +47,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 1993\n\ static char sccsid[] = "@(#)disklabel.c 8.4 (Berkeley) 5/4/95"; /* from static char sccsid[] = "@(#)disklabel.c 1.2 (Symmetric) 11/28/85"; */ #else -__RCSID("$NetBSD: disklabel.c,v 1.68 1999/04/30 04:46:50 abs Exp $"); +__RCSID("$NetBSD: disklabel.c,v 1.69 1999/05/03 09:45:01 christos Exp $"); #endif #endif /* not lint */ @@ -158,6 +158,7 @@ static void makelabel __P((char *, char *, struct disklabel *)); static void l_perror __P((char *)); static struct disklabel *readlabel __P((int)); static struct disklabel *makebootarea __P((char *, struct disklabel *, int)); +static void showinfo __P((FILE *, struct disklabel *)); static int edit __P((struct disklabel *, int)); static int editit __P((void)); static char *skip __P((char *)); @@ -321,8 +322,10 @@ main(argc, argv) lp = readlabel(f); if (tflag) makedisktab(stdout, lp); - else - display(stdout, lp); + else { + showinfo(stdout, lp); + showpartitions(stdout, lp); + } error = checklabel(lp); break; @@ -1098,13 +1101,12 @@ makedisktab(f, lp) (void) fflush(f); } -void -display(f, lp) +static void +showinfo(f, lp) FILE *f; struct disklabel *lp; { int i, j; - struct partition *pp; (void) fprintf(f, "# %s:\n", specname); if ((unsigned) lp->d_type < DKMAXTYPES) @@ -1145,7 +1147,19 @@ display(f, lp) i = 0; for (j = 0; j <= i; j++) (void) fprintf(f, "%d ", lp->d_drivedata[j]); - (void) fprintf(f, "\n\n%d partitions:\n", lp->d_npartitions); + (void) fprintf(f, "\n\n"); + (void) fflush(f); +} + +void +showpartitions(f, lp) + FILE *f; + struct disklabel *lp; +{ + int i; + struct partition *pp; + + (void) fprintf(f, "%d partitions:\n", lp->d_npartitions); (void) fprintf(f, "# size offset fstype [fsize bsize cpg]\n"); pp = lp->d_partitions; @@ -1232,7 +1246,8 @@ edit(lp, f) return (1); } (void)fchmod(fd, 0600); - display(fp, lp); + showinfo(fp, lp); + showpartitions(fp, lp); (void) fclose(fp); for (;;) { if (!editit()) @@ -1331,7 +1346,7 @@ word(cp) /* * Read an ascii label in from fd f, - * in the same format as that put out by display(), + * in the same format as that put out by showinfo() and showpartitions(), * and fill in lp. */ static int diff --git a/sbin/disklabel/extern.h b/sbin/disklabel/extern.h index 8f54c594a21c..906606a4b941 100644 --- a/sbin/disklabel/extern.h +++ b/sbin/disklabel/extern.h @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.2 1997/06/30 22:51:33 christos Exp $ */ +/* $NetBSD: extern.h,v 1.3 1999/05/03 09:45:01 christos Exp $ */ /* * Copyright (c) 1997 Christos Zoulas. All rights reserved. @@ -31,6 +31,6 @@ int writelabel __P((int, char *, struct disklabel *)); int checklabel __P((struct disklabel *)); -void display __P((FILE *, struct disklabel *)); +void showpartitions __P((FILE *, struct disklabel *)); void interact __P((struct disklabel *, int)); extern char bootarea[]; diff --git a/sbin/disklabel/interact.c b/sbin/disklabel/interact.c index 576f72f5b9aa..718b7915b81f 100644 --- a/sbin/disklabel/interact.c +++ b/sbin/disklabel/interact.c @@ -1,4 +1,4 @@ -/* $NetBSD: interact.c,v 1.8 1998/11/12 16:19:48 christos Exp $ */ +/* $NetBSD: interact.c,v 1.9 1999/05/03 09:45:01 christos Exp $ */ /* * Copyright (c) 1997 Christos Zoulas. All rights reserved. @@ -31,7 +31,7 @@ #include #ifndef lint -__RCSID("$NetBSD: interact.c,v 1.8 1998/11/12 16:19:48 christos Exp $"); +__RCSID("$NetBSD: interact.c,v 1.9 1999/05/03 09:45:01 christos Exp $"); #endif /* lint */ #include @@ -46,6 +46,7 @@ __RCSID("$NetBSD: interact.c,v 1.8 1998/11/12 16:19:48 christos Exp $"); #include "extern.h" static void cmd_help __P((struct disklabel *, char *, int)); +static void cmd_chain __P((struct disklabel *, char *, int)); static void cmd_print __P((struct disklabel *, char *, int)); static void cmd_part __P((struct disklabel *, char *, int)); static void cmd_label __P((struct disklabel *, char *, int)); @@ -59,6 +60,7 @@ static void deffstypename __P((char *, int)); static int getfstypename __P((const char *)); static int rounding = 0; /* sector rounding */ +static int chaining = 0; /* make partitions contiguous */ static struct cmds { const char *name; @@ -66,6 +68,7 @@ static struct cmds { const char *help; } cmds[] = { { "?", cmd_help, "print this menu" }, + { "C", cmd_chain, "make partitions contiguous" }, { "N", cmd_name, "name the label" }, { "P", cmd_print, "print current partition table" }, { "Q", NULL, "quit" }, @@ -91,13 +94,41 @@ cmd_help(lp, s, fd) } +static void +cmd_chain(lp, s, fd) + struct disklabel *lp; + char *s; + int fd; +{ + int i; + char line[BUFSIZ]; + + i = getinput(":", "Automatically adjust partitions", + chaining ? "yes" : "no", line); + + if (i <= 0) + return; + + switch (line[0]) { + case 'y': + chaining = 1; + return; + case 'n': + chaining = 0; + return; + default: + printf("Invalid answer\n"); + return; + } +} + static void cmd_print(lp, s, fd) struct disklabel *lp; char *s; int fd; { - display(stdout, lp); + showpartitions(stdout, lp); } @@ -195,6 +226,18 @@ cmd_part(lp, s, fd) p->p_size = i; break; } + + if (chaining) { + int offs = p[0].p_offset + p[0].p_size; + p = lp->d_partitions; + part = getrawpartition(); + for (i = 1; i < lp->d_npartitions; i++) { + if (i != part && p[i].p_fstype) { + p[i].p_offset = offs; + offs = p[i].p_offset + p[i].p_size; + } + } + } }