Subject: bin/2452: enable disklabel to print disktab(5) entries
To: None <gnats-bugs@NetBSD.ORG>
From: Christos Zoulas <christos@deshaw.com>
List: netbsd-bugs
Date: 05/21/1996 20:00:04
>Number: 2452
>Category: bin
>Synopsis: enable disklabel to print disktab(5) entries
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people (Utility Bug People)
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Tue May 21 20:20:06 1996
>Last-Modified:
>Originator: Christos Zoulas
>Organization:
none.org
>Release: Tue May 21 19:58:35 EDT 1996
>Environment:
System: NetBSD ramoth.nyc.deshaw.com 1.1B NetBSD 1.1B (ZEOS_AIC) #24: Sat May 18 11:35:52 EDT 1996 christos@ramoth.nyc.deshaw.com:/tmp_mnt/src/NetBSD/cvsroot/src/sys/arch/i386/compile/ZEOS_AIC i386
>Description:
There is no easy way to get a disktab(5) formatted entry as the
output of disklabel.
>How-To-Repeat:
>Fix:
Add a -t option and code to format the entry appropriately.
christos
cvs server: Diffing .
Index: disklabel.8
===================================================================
RCS file: /a/cvsroot/src/sbin/disklabel/disklabel.8,v
retrieving revision 1.9
diff -c -r1.9 disklabel.8
*** disklabel.8 1995/03/18 14:54:38 1.9
--- disklabel.8 1996/05/21 23:51:21
***************
*** 44,50 ****
.Nd read and write disk pack label
.Sh SYNOPSIS
.Nm disklabel
! .Op Fl r
.Ar disk
.Nm disklabel
.Fl w
--- 44,50 ----
.Nd read and write disk pack label
.Sh SYNOPSIS
.Nm disklabel
! .Op Fl rt
.Ar disk
.Nm disklabel
.Fl w
***************
*** 130,135 ****
--- 130,140 ----
.Fl r
flag is given, the label from the raw disk will be displayed rather
than the in-core label.
+ If the
+ .Fl t
+ flag is given, then the label will be formatted as a
+ .Xr disktab 5
+ entry.
.Pp
The second form of the command, with the
.Fl w
Index: disklabel.c
===================================================================
RCS file: /a/cvsroot/src/sbin/disklabel/disklabel.c,v
retrieving revision 1.29
diff -c -r1.29 disklabel.c
*** disklabel.c 1995/06/26 23:17:26 1.29
--- disklabel.c 1996/05/21 23:51:27
***************
*** 119,130 ****
} op = UNSPEC;
int rflag;
#ifdef DEBUG
int debug;
! #define OPTIONS "BNRWb:ders:w"
#else
! #define OPTIONS "BNRWb:ers:w"
#endif
#ifdef i386
--- 119,131 ----
} op = UNSPEC;
int rflag;
+ int tflag;
#ifdef DEBUG
int debug;
! #define OPTIONS "BNRWb:ders:tw"
#else
! #define OPTIONS "BNRWb:ers:tw"
#endif
#ifdef i386
***************
*** 132,137 ****
--- 133,139 ----
struct dos_partition *readmbr __P((int));
#endif
+ void makedisktab __P((FILE *, struct disklabel *));
void makelabel __P((char *, char *, struct disklabel *));
int writelabel __P((int, char *, struct disklabel *));
void l_perror __P((char *));
***************
*** 195,200 ****
--- 197,205 ----
usage();
op = EDIT;
break;
+ case 't':
+ ++tflag;
+ break;
case 'r':
++rflag;
break;
***************
*** 273,279 ****
if (argc != 1)
usage();
lp = readlabel(f);
! display(stdout, lp);
error = checklabel(lp);
break;
--- 278,287 ----
if (argc != 1)
usage();
lp = readlabel(f);
! if (tflag)
! makedisktab(stdout, lp);
! else
! display(stdout, lp);
error = checklabel(lp);
break;
***************
*** 750,755 ****
--- 758,854 ----
if (*p)
errx(2, "Bootstrap doesn't leave room for disk label");
return (lp);
+ }
+
+ void
+ makedisktab(f, lp)
+ FILE *f;
+ struct disklabel *lp;
+ {
+ int i, j;
+ char *did = "\\\n\t:";
+ struct partition *pp;
+
+ fprintf(f, "%.*s|Automatically generated label:\\\n\t:dt=",
+ sizeof(lp->d_typename), lp->d_typename);
+ if ((unsigned) lp->d_type < DKMAXTYPES)
+ fprintf(f, "%s:", dktypenames[lp->d_type]);
+ else
+ fprintf(f, "unknown%d:", lp->d_type);
+
+ fprintf(f, "se#%d:", lp->d_secsize);
+ fprintf(f, "ns#%d:", lp->d_nsectors);
+ fprintf(f, "nt#%d:", lp->d_ntracks);
+ fprintf(f, "sc#%d:", lp->d_secpercyl);
+ fprintf(f, "nc#%d:", lp->d_ncylinders);
+
+ if (lp->d_rpm != 3600) {
+ fprintf(f, "%srm#%d:", did, lp->d_rpm);
+ did = "";
+ }
+ if (lp->d_interleave != 1) {
+ fprintf(f, "%sil#%d:", did, lp->d_interleave);
+ did = "";
+ }
+ if (lp->d_trackskew != 0) {
+ fprintf(f, "%ssk#%d:", did, lp->d_trackskew);
+ did = "";
+ }
+ if (lp->d_cylskew != 0) {
+ fprintf(f, "%scs#%d:", did, lp->d_cylskew);
+ did = "";
+ }
+ if (lp->d_headswitch != 0) {
+ fprintf(f, "%shs#%d:", did, lp->d_headswitch);
+ did = "";
+ }
+ if (lp->d_trkseek != 0) {
+ fprintf(f, "%sts#%d:", did, lp->d_trkseek);
+ did = "";
+ }
+ #ifdef notyet
+ fprintf(f, "drivedata: ");
+ for (i = NDDATA - 1; i >= 0; i--)
+ if (lp->d_drivedata[i])
+ break;
+ if (i < 0)
+ i = 0;
+ for (j = 0; j <= i; j++)
+ fprintf(f, "%d ", lp->d_drivedata[j]);
+ #endif
+ pp = lp->d_partitions;
+ for (i = 0; i < lp->d_npartitions; i++, pp++) {
+ if (pp->p_size) {
+ char c = 'a' + i;
+ fprintf(f, "\\\n\t:");
+ fprintf(f, "p%c#%d:", c, pp->p_size);
+ fprintf(f, "o%c#%d:", c, pp->p_offset);
+ if (pp->p_fstype != FS_UNUSED) {
+ if ((unsigned) pp->p_fstype < FSMAXTYPES)
+ fprintf(f, "t%c=%s:", c,
+ fstypenames[pp->p_fstype]);
+ else
+ fprintf(f, "t%c=unknown%d:",
+ c, pp->p_fstype);
+ }
+ switch (pp->p_fstype) {
+
+ case FS_UNUSED:
+ break;
+
+ case FS_BSDFFS:
+ fprintf(f, "b%c#%d:", c,
+ pp->p_fsize * pp->p_frag);
+ fprintf(f, "f%c#%d:", c, pp->p_fsize);
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+ fprintf(f, "\n");
+ fflush(f);
}
void
>Audit-Trail:
>Unformatted: