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.
This commit is contained in:
Poul-Henning Kamp 2007-12-16 19:41:31 +00:00
parent 015a11e695
commit 9a6378d803
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=174675
4 changed files with 32 additions and 15 deletions

View File

@ -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)

View File

@ -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

View File

@ -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,

View File

@ -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 */