summaryrefslogtreecommitdiffstats
path: root/sbin/newfs
diff options
context:
space:
mode:
authormckusick <mckusick@FreeBSD.org>2003-02-22 23:26:11 +0000
committermckusick <mckusick@FreeBSD.org>2003-02-22 23:26:11 +0000
commitd1a87a25b8ce7a87b0e2bb84ee0c60b4a61febe5 (patch)
tree066f3cf870606a899acbfe6ca97dd9b540344918 /sbin/newfs
parent9e23e010b0836a5077181c5e02436145cc3b007c (diff)
downloadFreeBSD-src-d1a87a25b8ce7a87b0e2bb84ee0c60b4a61febe5.zip
FreeBSD-src-d1a87a25b8ce7a87b0e2bb84ee0c60b4a61febe5.tar.gz
Fix the -R flag so that it provides sequential "random" numbers
so that the regression test will succeed. Sponsored by: DARPA & NAI Labs.
Diffstat (limited to 'sbin/newfs')
-rw-r--r--sbin/newfs/mkfs.c30
-rw-r--r--sbin/newfs/ref.test12
2 files changed, 27 insertions, 15 deletions
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c
index ddc8fcb..895d5a9 100644
--- a/sbin/newfs/mkfs.c
+++ b/sbin/newfs/mkfs.c
@@ -89,7 +89,6 @@ union dinode {
((sblock.fs_magic == FS_UFS1_MAGIC) ? \
(dp)->dp1.field : (dp)->dp2.field)
-static int randinit;
static caddr_t iobuf;
static long iobufsize;
static ufs2_daddr_t alloc(int size, int mode);
@@ -103,6 +102,7 @@ static void iput(union dinode *, ino_t);
static int makedir(struct direct *, int);
static void setblock(struct fs *, unsigned char *, int);
static void wtfs(ufs2_daddr_t, int, char *);
+static u_int32_t newfs_random(void);
void
mkfs(struct partition *pp, char *fsys)
@@ -120,12 +120,10 @@ mkfs(struct partition *pp, char *fsys)
*/
disk.d_bsize = sectorsize;
disk.d_ufs = Oflag;
- if (Rflag)
+ if (Rflag) {
utime = 1000000000;
- else
+ } else {
time(&utime);
- if (!Rflag && !randinit) {
- randinit = 1;
arc4random_stir();
}
sblock.fs_old_flags = FS_FLAGS_UPDATED;
@@ -387,7 +385,7 @@ mkfs(struct partition *pp, char *fsys)
sblock.fs_state = 0;
sblock.fs_clean = 1;
sblock.fs_id[0] = (long)utime;
- sblock.fs_id[1] = arc4random();
+ sblock.fs_id[1] = newfs_random();
sblock.fs_fsmnt[0] = '\0';
csfrags = howmany(sblock.fs_cssize, sblock.fs_fsize);
sblock.fs_dsize = sblock.fs_size - sblock.fs_sblkno -
@@ -649,10 +647,10 @@ initcg(int cylno, time_t utime)
dp2 = (struct ufs2_dinode *)(&iobuf[start]);
for (i = 0; i < acg.cg_initediblk; i++) {
if (sblock.fs_magic == FS_UFS1_MAGIC) {
- dp1->di_gen = arc4random();
+ dp1->di_gen = newfs_random();
dp1++;
} else {
- dp2->di_gen = arc4random();
+ dp2->di_gen = newfs_random();
dp2++;
}
}
@@ -666,7 +664,7 @@ initcg(int cylno, time_t utime)
i += sblock.fs_frag) {
dp1 = (struct ufs1_dinode *)(&iobuf[start]);
for (j = 0; j < INOPB(&sblock); j++) {
- dp1->di_gen = arc4random();
+ dp1->di_gen = newfs_random();
dp1++;
}
wtfs(fsbtodb(&sblock, cgimin(&sblock, cylno) + i),
@@ -962,3 +960,17 @@ ilog2(int val)
return (n);
errx(1, "ilog2: %d is not a power of 2\n", val);
}
+
+/*
+ * For the regression test, return predictable random values.
+ * Otherwise use a true random number generator.
+ */
+static u_int32_t
+newfs_random(void)
+{
+ static int nextnum = 1;
+
+ if (Rflag)
+ return (nextnum++);
+ return (arc4random());
+}
diff --git a/sbin/newfs/ref.test b/sbin/newfs/ref.test
index 66563af..1967e24 100644
--- a/sbin/newfs/ref.test
+++ b/sbin/newfs/ref.test
@@ -1,7 +1,7 @@
# $FreeBSD$
-b3e607f5666721bb97b90c57607d732c
-44d7dd10f124dd0b6cc77150cc28c515
-2244fff4e20df2f8d2e58892fec29da6
-103b03f6ef5d976bde65d03d0f457418
-1f5d2af756733946e7781af6bf2c25ca
-efcd85af54bf9eb4d404e21f663aadaa
+00c08266df6b0c79d2673515c182216a
+c00458f223a9119190591e8b8679bf97
+7d5b3c75244898dbb07a4cd20860c8a1
+a69179c925b67edc20c289c3321ae87a
+4d1c6cf3c563044a59c3d426bb890ece
+841ed8884da029d4590b56b2f033f404
OpenPOWER on IntegriCloud