Index: disklabel.c =================================================================== RCS file: /home/ncvs/src/sbin/disklabel/Attic/disklabel.c,v retrieving revision 1.28.2.15 diff -u -r1.28.2.15 disklabel.c --- disklabel.c 24 Jan 2003 16:18:16 -0000 1.28.2.15 +++ disklabel.c 23 Mar 2004 16:48:13 -0000 @@ -158,6 +158,9 @@ #define OPTIONS "BNRWb:enrs:w" #endif +int is_file; /* use a file, "-f" option */ + + int main(int argc, char *argv[]) { @@ -166,8 +169,12 @@ int ch, f = 0, flag, error = 0; char *name = 0; - while ((ch = getopt(argc, argv, OPTIONS)) != -1) + while ((ch = getopt(argc, argv, OPTIONS "f")) != -1) switch (ch) { + case 'f': + is_file++; + break; + #if NUMBOOT > 0 case 'B': ++installboot; @@ -450,6 +457,7 @@ * disable after writing. */ flag = 1; + if (!is_file) if (ioctl(f, DIOCWLABEL, &flag) < 0) warn("ioctl DIOCWLABEL"); if (write(f, boot, lp->d_bbsize) != lp->d_bbsize) { @@ -1575,6 +1583,31 @@ char namebuf[BBSIZE]; int f; + if (is_file) { + struct disklabel *lp = &lab; + off_t sz; + + if ((f = open(dkname, O_RDONLY)) == -1) { + warn("cannot open %s", namebuf); + return (NULL); + } + sz = lseek(f, (off_t)0, SEEK_END); + bzero(lp, sizeof(*lp)); + lp->d_magic = lp->d_magic2 = DISKMAGIC; + lp->d_secsize = DEV_BSIZE; + lp->d_bbsize = BBSIZE; + lp->d_sbsize = SBSIZE; + lp->d_npartitions = 8; /* XXX */ + lp->d_nsectors = sz/DEV_BSIZE; /* XXX */ + lp->d_ntracks = 1; + lp->d_ncylinders = 1; + lp->d_interleave = 1; + lp->d_rpm = 3600; + lp->d_secpercyl = lp->d_nsectors; + lp->d_secperunit = lp->d_nsectors; + lp->d_partitions[2].p_size = lp->d_nsectors; + goto done; + } if (dkname[0] == '/') { warnx("\"auto\" requires the usage of a canonical disk name"); return (NULL); @@ -1596,6 +1630,7 @@ return (NULL); } } + done: close(f); lab.d_boot0 = NULL; lab.d_boot1 = NULL;