Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/disklabel Add a 'chain' command in interactive mode tha...
details: https://anonhg.NetBSD.org/src/rev/554929007da4
branches: trunk
changeset: 472591:554929007da4
user: christos <christos%NetBSD.org@localhost>
date: Mon May 03 09:45:01 1999 +0000
description:
Add a 'chain' command in interactive mode that allows you to vary the
size of the partitions, while the starting point gets adjusted automagically.
This chaining works for partitions that are not 'unused'.
diffstat:
sbin/disklabel/disklabel.c | 35 +++++++++++++++++++++++---------
sbin/disklabel/extern.h | 4 +-
sbin/disklabel/interact.c | 49 +++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 73 insertions(+), 15 deletions(-)
diffs (215 lines):
diff -r 92f98d194aad -r 554929007da4 sbin/disklabel/disklabel.c
--- a/sbin/disklabel/disklabel.c Mon May 03 09:41:08 1999 +0000
+++ b/sbin/disklabel/disklabel.c Mon May 03 09:45:01 1999 +0000
@@ -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 @@
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 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 @@
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 @@
(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 @@
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 @@
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 @@
/*
* 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 -r 92f98d194aad -r 554929007da4 sbin/disklabel/extern.h
--- a/sbin/disklabel/extern.h Mon May 03 09:41:08 1999 +0000
+++ b/sbin/disklabel/extern.h Mon May 03 09:45:01 1999 +0000
@@ -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 -r 92f98d194aad -r 554929007da4 sbin/disklabel/interact.c
--- a/sbin/disklabel/interact.c Mon May 03 09:41:08 1999 +0000
+++ b/sbin/disklabel/interact.c Mon May 03 09:45:01 1999 +0000
@@ -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 <sys/cdefs.h>
#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 <stdio.h>
@@ -46,6 +46,7 @@
#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 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 @@
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" },
@@ -92,12 +95,40 @@
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 @@
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;
+ }
+ }
+ }
}
Home |
Main Index |
Thread Index |
Old Index