aboutsummaryrefslogtreecommitdiff
path: root/sbin/newfs
diff options
context:
space:
mode:
authorGuido van Rooij <guido@FreeBSD.org>1997-03-23 20:08:22 +0000
committerGuido van Rooij <guido@FreeBSD.org>1997-03-23 20:08:22 +0000
commit8f89943eda4491e3d0a67cc4084e0c9c49d5be52 (patch)
treeb9411eec7d5aa143a88d2b00622c513c58e81906 /sbin/newfs
parent8187fe48133bc2a01ee7fcbb9ad4589c545490f0 (diff)
downloadsrc-8f89943eda4491e3d0a67cc4084e0c9c49d5be52.tar.gz
src-8f89943eda4491e3d0a67cc4084e0c9c49d5be52.zip
Add generation number randomization. Newly created filesystems wil now
automatically have random generation numbers. The kenel way of handling those also changed. Further it is advised to run fsirand on all your nfs exported filesystems. the code is mostly copied from OpenBSD, with the randomization chanegd to use /dev/urandom Reviewed by: Garrett Obtained from: OpenBSD
Notes
Notes: svn path=/head/; revision=24149
Diffstat (limited to 'sbin/newfs')
-rw-r--r--sbin/newfs/Makefile2
-rw-r--r--sbin/newfs/mkfs.c43
2 files changed, 39 insertions, 6 deletions
diff --git a/sbin/newfs/Makefile b/sbin/newfs/Makefile
index ed9ad9d8d27c..d44fdbaa63fb 100644
--- a/sbin/newfs/Makefile
+++ b/sbin/newfs/Makefile
@@ -6,7 +6,7 @@ MAN8= newfs.8
MOUNT= ${.CURDIR}/../mount
CFLAGS+= -D_NEW_VFSCONF
-CFLAGS+=-DMFS -I${MOUNT}
+CFLAGS+=-DMFS -DFSIRAND -I${MOUNT}
.PATH: ${MOUNT} ${.CURDIR}/../disklabel
LINKS= ${BINDIR}/newfs ${BINDIR}/mount_mfs
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c
index ab4713da4b61..63ad1bf0bbc3 100644
--- a/sbin/newfs/mkfs.c
+++ b/sbin/newfs/mkfs.c
@@ -86,8 +86,6 @@ extern int realsectorsize; /* bytes/sector in hardware*/
extern int rpm; /* revolutions/minute of drive */
extern int interleave; /* hardware sector interleave */
extern int trackskew; /* sector 0 skew, per track */
-extern int headswitch; /* head switch time, usec */
-extern int trackseek; /* track-to-track seek, usec */
extern int fsize; /* fragment size */
extern int bsize; /* block size */
extern int cpg; /* cylinders/cylinder group */
@@ -121,6 +119,10 @@ union {
struct dinode zino[MAXBSIZE / sizeof(struct dinode)];
+#ifdef FSIRAND
+long fsi_random __P((void));
+#endif
+
int fsi, fso;
daddr_t alloc();
static int charsperline();
@@ -591,8 +593,6 @@ next:
sblock.fs_rotdelay = rotdelay;
sblock.fs_minfree = minfree;
sblock.fs_maxcontig = maxcontig;
- sblock.fs_headswitch = headswitch;
- sblock.fs_trkseek = trackseek;
sblock.fs_maxbpg = maxbpg;
sblock.fs_rps = rpm / 60;
sblock.fs_optim = opt;
@@ -604,6 +604,11 @@ next:
sblock.fs_fmod = 0;
sblock.fs_ronly = 0;
sblock.fs_clean = 1;
+#ifdef FSIRAND
+ sblock.fs_id[0] = (long)utime;
+ sblock.fs_id[1] = fsi_random();
+#endif
+
/*
* Dump out summary information about file system.
*/
@@ -751,9 +756,14 @@ initcg(cylno, utime)
setbit(cg_inosused(&acg), i);
acg.cg_cs.cs_nifree--;
}
- for (i = 0; i < sblock.fs_ipg / INOPF(&sblock); i += sblock.fs_frag)
+ for (i = 0; i < sblock.fs_ipg / INOPF(&sblock); i += sblock.fs_frag) {
+#ifdef FSIRAND
+ for (j = 0; j < sblock.fs_bsize / sizeof(struct dinode); j++)
+ zino[j].di_gen = fsi_random();
+#endif
wtfs(fsbtodb(&sblock, cgimin(&sblock, cylno) + i),
sblock.fs_bsize, (char *)zino);
+ }
if (cylno > 0) {
/*
* In cylno 0, beginning space is reserved
@@ -1057,6 +1067,9 @@ iput(ip, ino)
daddr_t d;
int c;
+#ifdef FSIRAND
+ ip->di_gen = fsi_random();
+#endif
c = ino_to_cg(&sblock, ino);
rdfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
(char *)&acg);
@@ -1336,3 +1349,23 @@ charsperline()
columns = 80; /* last resort */
return columns;
}
+
+#ifdef FSIRAND
+long
+fsi_random(void) {
+ static int fd = -1;
+ long ret;
+
+ if (fd == -1) {
+ if ((fd = open("/dev/urandom", O_RDONLY)) == -1) {
+ perror("open /dev/urandom");
+ exit(1);
+ }
+ }
+ if (read(fd, &ret, sizeof(ret)) != sizeof(ret)) {
+ perror("read /dev/urandom");
+ exit(1);
+ }
+ return(ret);
+}
+#endif