From 34b59b6bf2398cfcac5a70930e0272efbc8c1624 Mon Sep 17 00:00:00 2001 From: Wes Peters Date: Fri, 21 Jan 2005 22:20:25 +0000 Subject: [PATCH] Add an option to suppress the creation of the .snap directory in the new filesystem. This is intended for memory and vnode filesystems that will never be fsck'ed or dumped. Obtained from: St. Bernard Software RAPID MFC after: 2 weeks --- sbin/newfs/mkfs.c | 68 ++++++++++++++++++++++++++-------------------- sbin/newfs/newfs.8 | 17 +++++++++++- sbin/newfs/newfs.c | 6 +++- sbin/newfs/newfs.h | 1 + 4 files changed, 60 insertions(+), 32 deletions(-) diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index 66074c7850c9..b796aefa36fb 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -738,10 +738,12 @@ fsinit(time_t utime) { union dinode node; struct group *grp; + int entries; memset(&node, 0, sizeof node); if ((grp = getgrnam("operator")) == NULL) errx(35, "Cannot retrieve operator gid"); + entries = (nflag) ? ROOTLINKCNT - 1: ROOTLINKCNT; if (sblock.fs_magic == FS_UFS1_MAGIC) { /* * initialize the node @@ -753,27 +755,30 @@ fsinit(time_t utime) * create the root directory */ node.dp1.di_mode = IFDIR | UMASK; - node.dp1.di_nlink = ROOTLINKCNT; - node.dp1.di_size = makedir(root_dir, ROOTLINKCNT); + node.dp1.di_nlink = entries; + node.dp1.di_size = makedir(root_dir, entries); node.dp1.di_db[0] = alloc(sblock.fs_fsize, node.dp1.di_mode); node.dp1.di_blocks = btodb(fragroundup(&sblock, node.dp1.di_size)); wtfs(fsbtodb(&sblock, node.dp1.di_db[0]), sblock.fs_fsize, iobuf); iput(&node, ROOTINO); - /* - * create the .snap directory - */ - node.dp1.di_mode |= 020; - node.dp1.di_gid = grp->gr_gid; - node.dp1.di_nlink = SNAPLINKCNT; - node.dp1.di_size = makedir(snap_dir, SNAPLINKCNT); - node.dp1.di_db[0] = alloc(sblock.fs_fsize, node.dp1.di_mode); - node.dp1.di_blocks = - btodb(fragroundup(&sblock, node.dp1.di_size)); - wtfs(fsbtodb(&sblock, node.dp1.di_db[0]), sblock.fs_fsize, - iobuf); - iput(&node, ROOTINO + 1); + if (!nflag) { + /* + * create the .snap directory + */ + node.dp1.di_mode |= 020; + node.dp1.di_gid = grp->gr_gid; + node.dp1.di_nlink = SNAPLINKCNT; + node.dp1.di_size = makedir(snap_dir, SNAPLINKCNT); + node.dp1.di_db[0] = + alloc(sblock.fs_fsize, node.dp1.di_mode); + node.dp1.di_blocks = + btodb(fragroundup(&sblock, node.dp1.di_size)); + wtfs(fsbtodb(&sblock, node.dp1.di_db[0]), + sblock.fs_fsize, iobuf); + iput(&node, ROOTINO + 1); + } } else { /* * initialize the node @@ -786,27 +791,30 @@ fsinit(time_t utime) * create the root directory */ node.dp2.di_mode = IFDIR | UMASK; - node.dp2.di_nlink = ROOTLINKCNT; - node.dp2.di_size = makedir(root_dir, ROOTLINKCNT); + node.dp2.di_nlink = entries; + node.dp2.di_size = makedir(root_dir, entries); node.dp2.di_db[0] = alloc(sblock.fs_fsize, node.dp2.di_mode); node.dp2.di_blocks = btodb(fragroundup(&sblock, node.dp2.di_size)); wtfs(fsbtodb(&sblock, node.dp2.di_db[0]), sblock.fs_fsize, iobuf); iput(&node, ROOTINO); - /* - * create the .snap directory - */ - node.dp2.di_mode |= 020; - node.dp2.di_gid = grp->gr_gid; - node.dp2.di_nlink = SNAPLINKCNT; - node.dp2.di_size = makedir(snap_dir, SNAPLINKCNT); - node.dp2.di_db[0] = alloc(sblock.fs_fsize, node.dp2.di_mode); - node.dp2.di_blocks = - btodb(fragroundup(&sblock, node.dp2.di_size)); - wtfs(fsbtodb(&sblock, node.dp2.di_db[0]), sblock.fs_fsize, - iobuf); - iput(&node, ROOTINO + 1); + if (!nflag) { + /* + * create the .snap directory + */ + node.dp2.di_mode |= 020; + node.dp2.di_gid = grp->gr_gid; + node.dp2.di_nlink = SNAPLINKCNT; + node.dp2.di_size = makedir(snap_dir, SNAPLINKCNT); + node.dp2.di_db[0] = + alloc(sblock.fs_fsize, node.dp2.di_mode); + node.dp2.di_blocks = + btodb(fragroundup(&sblock, node.dp2.di_size)); + wtfs(fsbtodb(&sblock, node.dp2.di_db[0]), + sblock.fs_fsize, iobuf); + iput(&node, ROOTINO + 1); + } } } diff --git a/sbin/newfs/newfs.8 b/sbin/newfs/newfs.8 index 8cba772a44ab..48393e3ca235 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 NUl +.Op Fl NUln .Op Fl L Ar volname .Op Fl O Ar filesystem-type .Op Fl S Ar sector-size @@ -159,6 +159,20 @@ currently 8%. See .Xr tunefs 8 for more details on how to set this option. +.It Fl n +Do not create a .snap directory on the new filesystem. +The resulting filesystem will not support snapshot generation, so +.Xr dump 8 +in live mode and background +.Xr fsck 8 +will not function properly. +The traditional +.Xr fsck 8 +and offline +.Xr dump 8 +will work on the filesystem. +This option is intended primarily for memory or vnode filesystems that +do not require dump or fsck support. .It Fl o Ar optimization .Cm ( space or @@ -219,6 +233,7 @@ on file systems that contain many small files. .Xr fs 5 , .Xr bsdlabel 8 , .Xr camcontrol 8 , +.Xr dump 8 , .Xr dumpfs 8 , .Xr fsck 8 , .Xr mount 8 , diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c index f5a015442276..24cd094f194f 100644 --- a/sbin/newfs/newfs.c +++ b/sbin/newfs/newfs.c @@ -118,6 +118,7 @@ int Rflag; /* regression test */ int Uflag; /* enable soft updates for file system */ int Eflag = 0; /* exit in middle of newfs for testing */ int lflag; /* enable multilabel for file system */ +int nflag; /* do not create .snap directory */ quad_t fssize; /* file system size */ int sectorsize; /* bytes/sector */ int realsectorsize; /* bytes/sector in hardware */ @@ -155,7 +156,7 @@ main(int argc, char *argv[]) off_t mediasize; while ((ch = getopt(argc, argv, - "EL:NO:RS:T:Ua:b:c:d:e:f:g:h:i:lm:o:s:")) != -1) + "EL:NO:RS:T:Ua:b:c:d:e:f:g:h:i:lm:no:s:")) != -1) switch (ch) { case 'E': Eflag++; @@ -244,6 +245,9 @@ main(int argc, char *argv[]) if ((minfree = atoi(optarg)) < 0 || minfree > 99) errx(1, "%s: bad free space %%", optarg); break; + case 'n': + nflag = 1; + break; case 'o': if (strcmp(optarg, "space") == 0) opt = FS_OPTSPACE; diff --git a/sbin/newfs/newfs.h b/sbin/newfs/newfs.h index feb9bcd8fcd9..dae9fd877255 100644 --- a/sbin/newfs/newfs.h +++ b/sbin/newfs/newfs.h @@ -50,6 +50,7 @@ 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 lflag; /* enable multilabel MAC for file system */ +extern int nflag; /* do not create .snap directory */ extern quad_t fssize; /* file system size */ extern int sectorsize; /* bytes/sector */ extern int realsectorsize; /* bytes/sector in hardware*/