summaryrefslogtreecommitdiffstats
path: root/sbin/newfs
diff options
context:
space:
mode:
authorguido <guido@FreeBSD.org>1997-03-23 20:08:22 +0000
committerguido <guido@FreeBSD.org>1997-03-23 20:08:22 +0000
commitc337c37259502bbcb3efde45ca7db82f927ff512 (patch)
treee2f5aeaa60774a851df745574651915a33ccf5a1 /sbin/newfs
parent8e15480d4907712b453456ae3366cfe75ea7b804 (diff)
downloadFreeBSD-src-c337c37259502bbcb3efde45ca7db82f927ff512.zip
FreeBSD-src-c337c37259502bbcb3efde45ca7db82f927ff512.tar.gz
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
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 ed9ad9d..d44fdba 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 ab4713d..63ad1bf 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
OpenPOWER on IntegriCloud