summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2007-12-16 19:41:31 +0000
committerphk <phk@FreeBSD.org>2007-12-16 19:41:31 +0000
commit8869357e615c78e3fd49cef030938ecad98ad0fb (patch)
tree50cd9188ad39d14622684bb1674d4d82c2da2a3d /sbin
parentf0debf860a7293c754e26563a772bdac6d9aa62f (diff)
downloadFreeBSD-src-8869357e615c78e3fd49cef030938ecad98ad0fb.zip
FreeBSD-src-8869357e615c78e3fd49cef030938ecad98ad0fb.tar.gz
Rename the undocumented -E option to -X.
Implement -E option which will erase the filesystem sectors before making the new filesystem. Reserved space in front of the superblock (bootcode) is not erased. NB: Erasing can take as long time as writing every sector sequentially. This is relevant for all flash based disks which use wearlevelling.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/newfs/mkfs.c19
-rw-r--r--sbin/newfs/newfs.814
-rw-r--r--sbin/newfs/newfs.c11
-rw-r--r--sbin/newfs/newfs.h3
4 files changed, 32 insertions, 15 deletions
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c
index fe862b5..c4ddef3 100644
--- a/sbin/newfs/mkfs.c
+++ b/sbin/newfs/mkfs.c
@@ -448,6 +448,13 @@ mkfs(struct partition *pp, char *fsys)
printf("\twith soft updates\n");
# undef B2MBFACTOR
+ if (Eflag && !Nflag) {
+ printf("Erasing blocks [%jd...%jd[\n",
+ sblock.fs_sblockloc / disk.d_bsize,
+ sblock.fs_size * sblock.fs_fsize / disk.d_bsize);
+ berase(&disk, sblock.fs_sblockloc / disk.d_bsize,
+ sblock.fs_size * sblock.fs_fsize - sblock.fs_sblockloc);
+ }
/*
* Wipe out old UFS1 superblock(s) if necessary.
*/
@@ -466,12 +473,12 @@ mkfs(struct partition *pp, char *fsys)
}
if (!Nflag)
sbwrite(&disk, 0);
- if (Eflag == 1) {
- printf("** Exiting on Eflag 1\n");
+ if (Xflag == 1) {
+ printf("** Exiting on Xflag 1\n");
exit(0);
}
- if (Eflag == 2)
- printf("** Leaving BAD MAGIC on Eflag 2\n");
+ if (Xflag == 2)
+ printf("** Leaving BAD MAGIC on Xflag 2\n");
else
sblock.fs_magic = (Oflag != 1) ? FS_UFS2_MAGIC : FS_UFS1_MAGIC;
@@ -529,8 +536,8 @@ mkfs(struct partition *pp, char *fsys)
sblock.fs_old_cstotal.cs_nifree = sblock.fs_cstotal.cs_nifree;
sblock.fs_old_cstotal.cs_nffree = sblock.fs_cstotal.cs_nffree;
}
- if (Eflag == 3) {
- printf("** Exiting on Eflag 3\n");
+ if (Xflag == 3) {
+ printf("** Exiting on Xflag 3\n");
exit(0);
}
if (!Nflag)
diff --git a/sbin/newfs/newfs.8 b/sbin/newfs/newfs.8
index 875f915..b55cd34 100644
--- a/sbin/newfs/newfs.8
+++ b/sbin/newfs/newfs.8
@@ -36,7 +36,7 @@
.Nd construct a new UFS1/UFS2 file system
.Sh SYNOPSIS
.Nm
-.Op Fl JNUln
+.Op Fl EJNUln
.Op Fl L Ar volname
.Op Fl O Ar filesystem-type
.Op Fl S Ar sector-size
@@ -59,10 +59,6 @@
The
.Nm
utility is used to initialize and clear file systems before first use.
-Before running
-.Nm
-the disk must be labeled using
-.Xr bsdlabel 8 .
The
.Nm
utility builds a file system on the specified special file.
@@ -78,6 +74,14 @@ has numerous options to allow the defaults to be selectively overridden.
.Pp
The following options define the general layout policies:
.Bl -tag -width indent
+.It Fl E
+Erase the content of the disk before making the filesystem.
+The reserved area in front of the superblock (for bootcode) will not be erased.
+
+This is a relevant option for flash based storage devices that use
+wear levelling algorithms.
+
+NB: Erasing may take as long time as writing every sector on the disk.
.It Fl J
Enable journaling on the new file system via gjournal.
.It Fl L Ar volname
diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c
index f69411c..d5fb66d 100644
--- a/sbin/newfs/newfs.c
+++ b/sbin/newfs/newfs.c
@@ -111,12 +111,13 @@ __FBSDID("$FreeBSD$");
*/
#define NFPI 4
+int Eflag; /* Erase previous disk contents */
int Lflag; /* add a volume label */
int Nflag; /* run without writing file system */
int Oflag = 2; /* file system format (1 => UFS1, 2 => UFS2) */
int Rflag; /* regression test */
int Uflag; /* enable soft updates for file system */
-int Eflag = 0; /* exit in middle of newfs for testing */
+int Xflag = 0; /* exit in middle of newfs for testing */
int Jflag; /* enable gjournal for file system */
int lflag; /* enable multilabel for file system */
int nflag; /* do not create .snap directory */
@@ -160,10 +161,10 @@ main(int argc, char *argv[])
reserved = 0;
while ((ch = getopt(argc, argv,
- "EJL:NO:RS:T:Ua:b:c:d:e:f:g:h:i:lm:no:r:s:")) != -1)
+ "EJL:NO:RS:T:UXa:b:c:d:e:f:g:h:i:lm:no:r:s:")) != -1)
switch (ch) {
case 'E':
- Eflag++;
+ Eflag = 1;
break;
case 'J':
Jflag = 1;
@@ -202,6 +203,9 @@ main(int argc, char *argv[])
case 'U':
Uflag = 1;
break;
+ case 'X':
+ Xflag++;
+ break;
case 'a':
if ((maxcontig = atoi(optarg)) <= 0)
errx(1, "%s: bad maximum contiguous blocks",
@@ -440,6 +444,7 @@ usage()
getprogname(),
" [device-type]");
fprintf(stderr, "where fsoptions are:\n");
+ fprintf(stderr, "\t-E Erase previuos disk content\n");
fprintf(stderr, "\t-J Enable journaling via gjournal\n");
fprintf(stderr, "\t-L volume label to add to superblock\n");
fprintf(stderr,
diff --git a/sbin/newfs/newfs.h b/sbin/newfs/newfs.h
index 19e383a..5c428c4 100644
--- a/sbin/newfs/newfs.h
+++ b/sbin/newfs/newfs.h
@@ -43,12 +43,13 @@
/*
* variables set up by front end.
*/
+extern int Eflag; /* Erase previous disk contents */
extern int Lflag; /* add a volume label */
extern int Nflag; /* run mkfs without writing file system */
extern int Oflag; /* build UFS1 format file system */
extern int Rflag; /* regression test */
extern int Uflag; /* enable soft updates for file system */
-extern int Eflag; /* exit as if error, for testing */
+extern int Xflag; /* exit in middle of newfs for testing */
extern int Jflag; /* enable gjournal for file system */
extern int lflag; /* enable multilabel MAC for file system */
extern int nflag; /* do not create .snap directory */
OpenPOWER on IntegriCloud