From c337c37259502bbcb3efde45ca7db82f927ff512 Mon Sep 17 00:00:00 2001 From: guido Date: Sun, 23 Mar 1997 20:08:22 +0000 Subject: 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 --- sbin/newfs/mkfs.c | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'sbin/newfs/mkfs.c') 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 -- cgit v1.1