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 -I flag which, combined with -e, gives ...
details: https://anonhg.NetBSD.org/src/rev/9dc4439a40f7
branches: trunk
changeset: 486959:9dc4439a40f7
user: fvdl <fvdl%NetBSD.org@localhost>
date: Wed May 31 14:13:48 2000 +0000
description:
Add a -I flag which, combined with -e, gives the user the opportunity
to edit and create a new label on a virgin disk.
diffstat:
sbin/disklabel/disklabel.8 | 12 +++++++++++-
sbin/disklabel/disklabel.c | 41 ++++++++++++++++++++++++++++-------------
2 files changed, 39 insertions(+), 14 deletions(-)
diffs (162 lines):
diff -r a756a91fd837 -r 9dc4439a40f7 sbin/disklabel/disklabel.8
--- a/sbin/disklabel/disklabel.8 Wed May 31 12:27:30 2000 +0000
+++ b/sbin/disklabel/disklabel.8 Wed May 31 14:13:48 2000 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: disklabel.8,v 1.29 2000/03/09 12:50:36 hubertf Exp $
+.\" $NetBSD: disklabel.8,v 1.30 2000/05/31 14:13:48 fvdl Exp $
.\"
.\" Copyright (c) 1987, 1988, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -59,6 +59,11 @@
.Op Fl C
.Ar disk
.Nm ""
+.Fl I
+.Op Fl r
+.Op Fl C
+.Ar disk
+.Nm ""
.Fl i
.Op Fl r
.Ar disk
@@ -319,6 +324,11 @@
as on-disk.
Existing bootstrap code is unaffected.
.Pp
+.Dl disklabel -e -I sd0
+.Pp
+As previous, but don't fail if there was no label on the disk yet;
+provide some default values instead.
+.Pp
.Dl disklabel -R sd0 mylabel
.Pp
Restore the on-disk and in-core label for sd0 from information in
diff -r a756a91fd837 -r 9dc4439a40f7 sbin/disklabel/disklabel.c
--- a/sbin/disklabel/disklabel.c Wed May 31 12:27:30 2000 +0000
+++ b/sbin/disklabel/disklabel.c Wed May 31 14:13:48 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: disklabel.c,v 1.83 2000/05/27 19:01:13 jdolecek Exp $ */
+/* $NetBSD: disklabel.c,v 1.84 2000/05/31 14:13:48 fvdl 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.83 2000/05/27 19:01:13 jdolecek Exp $");
+__RCSID("$NetBSD: disklabel.c,v 1.84 2000/05/31 14:13:48 fvdl Exp $");
#endif
#endif /* not lint */
@@ -129,12 +129,13 @@
static int rflag;
static int tflag;
static int Cflag;
+static int Iflag;
#ifdef DEBUG
static int debug;
-#define OPTIONS "BCNRWb:def:irs:tw"
+#define OPTIONS "BCINRWb:def:irs:tw"
#else
-#define OPTIONS "BCNRWb:ef:irs:tw"
+#define OPTIONS "BCINRWb:ef:irs:tw"
#endif
#ifdef USE_MBR
@@ -195,6 +196,9 @@
case 'C':
++Cflag;
break;
+ case 'I':
+ ++Iflag;
+ break;
case 'N':
if (op != UNSPEC)
usage();
@@ -266,6 +270,9 @@
if (argc < 1)
usage();
+ if (Iflag && op != EDIT)
+ usage();
+
dkname = argv[0];
f = opendisk(dkname, op == READ ? O_RDONLY : O_RDWR, np, MAXPATHLEN, 0);
specname = np;
@@ -470,7 +477,7 @@
/* Let the kernel deal with SunOS disklabel compatibility */
if (0)
#else
- if (rflag)
+ if (rflag || Iflag)
#endif
{
#ifdef USE_MBR
@@ -586,7 +593,7 @@
case ESRCH:
warnx("%s: No disk label on disk;\n"
- "use \"disklabel -r\" to install initial label", s);
+ "use \"disklabel -I\" to install initial label", s);
break;
case EINVAL:
@@ -825,8 +832,8 @@
{
struct disklabel *lp;
- if (rflag) {
- char *msg;
+ if (rflag || Iflag) {
+ char *msg = NULL;
off_t sectoffset = 0;
#ifdef USE_MBR
@@ -840,7 +847,8 @@
if (lseek(f, sectoffset, SEEK_SET) < 0 ||
read(f, bootarea, BBSIZE) < BBSIZE)
err(4, "%s", specname);
- msg = "no disk label";
+ if (!Iflag)
+ msg = "no disklabel";
for (lp = (struct disklabel *)bootarea;
lp <= (struct disklabel *)(bootarea + BBSIZE - sizeof(*lp));
lp = (struct disklabel *)((char *)lp + sizeof(long))) {
@@ -852,8 +860,15 @@
msg = "disk label corrupted";
}
}
- /* lp = (struct disklabel *)(bootarea + LABELOFFSET); */
- errx(1, msg);
+ if (msg != NULL)
+ errx(1, msg);
+ /*
+ * There was no label on the disk. Get the fictious one
+ * as a basis for initialisation.
+ */
+ lp = makebootarea(bootarea, &lab, f);
+ if (ioctl(f, DIOCGDINFO, lp) < 0)
+ errx(1, "no disklabel");
} else {
lp = &lab;
if (ioctl(f, DIOCGDINFO, lp) < 0)
@@ -895,7 +910,7 @@
* We must read the current bootarea so we don't clobber the
* existing boot block, if any.
*/
- if (rflag) {
+ if (rflag || Iflag) {
off_t sectoffset = 0;
if (lseek(f, sectoffset, SEEK_SET) < 0 ||
@@ -911,7 +926,7 @@
* clobber the existing boot.
*/
if (!installboot) {
- if (rflag) {
+ if (rflag || Iflag) {
off_t sectoffset = 0;
#ifdef USE_MBR
Home |
Main Index |
Thread Index |
Old Index