Subject: Re: CVS commit: src/sbin/newfs
To: matthew green <mrg@eterna.com.au>
From: Christian Limpach <cl@NetBSD.org>
List: source-changes
Date: 10/10/2003 07:14:49
On Fri, Oct 10, 2003 at 07:39:34PM +1000, matthew green wrote:
> > i think it would be best if newfs Just Worked with vinum devices.
>
> No question. Do you have any suggestion how? I suppose one way would
> be to ignore errors if you can't get the partition information
> indicated by the last letter. Another, tacky one would be to
> recognize the path name (/dev/vinum) and go by that. But that's even
> worse than the -V flag.
>
> i see there is a DIOCGPART ioctl that isn't used anywhere in our
> tree but does appear to be supported by all the drivers...perhaps
> that could be tried on the as-is name? (i had a quick look at
> the code in newfs, but it wasn't clear how all the partitioning
> stuff works.)
We should set a flag in struct disklabel which indicates if the label is a
default label or an actual label. Then newfs can use the flag to use the
RAW_PART (or 0) partition in the default label case or choose the partition
from the label/partition name like we've done so far.
I've used a modification like this for ~1/2 year now which (ab)uses a
special DTYPE (DTYPE_RAW) instead of a flag, but using a flag is better.
I'd use the high bit of d_type as the flag.
*getdefaultlabel sets the flag
*getdisklabel clears the flag after reading the disklabel if there is one
on the device
This also works for fsck.
christian
Index: newfs.c
===================================================================
RCS file: /cvs/netbsd/basesrc/sbin/newfs/newfs.c,v
retrieving revision 1.58
diff -u -r1.58 newfs.c
--- newfs.c 20 Feb 2002 04:04:39 -0000 1.58
+++ newfs.c 17 Feb 2003 19:06:20 -0000
@@ -82,6 +82,10 @@
#include "dkcksum.h"
#include "extern.h"
+#ifndef DTYPE_RAW
+#define DTYPE_RAW 9
+#endif
+
struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_ASYNC,
@@ -543,19 +547,23 @@
++mp;
}
}
- cp = strchr(argv[0], '\0') - 1;
- if (cp == 0 || ((*cp < 'a' || *cp > ('a' + maxpartitions - 1))
- && !isdigit(*cp)))
- errx(1, "can't figure out file system partition");
#ifdef COMPAT
if (disktype == NULL)
disktype = argv[1];
#endif
lp = getdisklabel(special, fsi);
- if (isdigit(*cp))
- pp = &lp->d_partitions[0];
- else
- pp = &lp->d_partitions[*cp - 'a'];
+ if (lp->d_type == DTYPE_RAW)
+ pp = &lp->d_partitions[RAW_PART];
+ else {
+ cp = strchr(argv[0], '\0') - 1;
+ if (cp == 0 || ((*cp < 'a' || *cp > ('a' + maxpartitions - 1))
+ && !isdigit(*cp)))
+ errx(1, "can't figure out file system partition");
+ if (isdigit(*cp))
+ pp = &lp->d_partitions[0];
+ else
+ pp = &lp->d_partitions[*cp - 'a'];
+ }
if (pp->p_size == 0)
errx(1, "`%c' partition is unavailable", *cp);
if (!Iflag && pp->p_fstype != FS_BSDFFS)
@@ -658,7 +666,7 @@
#endif
oldpartition = *pp;
mkfs(pp, special, fsi, fso, mfsmode, mfsuid, mfsgid);
- if (!Nflag && memcmp(pp, &oldpartition, sizeof(oldpartition)) && !Fflag)
+ if (!Nflag && memcmp(pp, &oldpartition, sizeof(oldpartition)) && !Fflag && lp->d_type != DTYPE_RAW)
rewritelabel(special, fso, lp);
if (!Nflag)
close(fso);