summaryrefslogtreecommitdiffstats
path: root/sys/ufs
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 /sys/ufs
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 'sys/ufs')
-rw-r--r--sys/ufs/ffs/ffs_alloc.c9
-rw-r--r--sys/ufs/ffs/ffs_vfsops.c13
-rw-r--r--sys/ufs/ffs/fs.h5
3 files changed, 11 insertions, 16 deletions
diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c
index 3be3f2f..3483b56 100644
--- a/sys/ufs/ffs/ffs_alloc.c
+++ b/sys/ufs/ffs/ffs_alloc.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)ffs_alloc.c 8.18 (Berkeley) 5/26/95
- * $Id: ffs_alloc.c,v 1.31 1997/03/09 06:00:40 mpp Exp $
+ * $Id: ffs_alloc.c,v 1.32 1997/03/22 06:53:28 bde Exp $
*/
#include "opt_quota.h"
@@ -55,8 +55,6 @@
#include <ufs/ffs/fs.h>
#include <ufs/ffs/ffs_extern.h>
-extern u_long nextgennumber;
-
typedef ufs_daddr_t allocfcn_t __P((struct inode *ip, int cg, ufs_daddr_t bpref,
int size));
@@ -601,9 +599,8 @@ ffs_valloc(ap)
/*
* Set up a new generation number for this inode.
*/
- if (++nextgennumber < (u_long)time.tv_sec)
- nextgennumber = time.tv_sec;
- ip->i_gen = nextgennumber;
+ if (ip->i_gen == 0 || ++(ip->i_gen) == 0)
+ ip->i_gen = random() / 2 + 1;
return (0);
noinodes:
ffs_fserr(fs, ap->a_cred->cr_uid, "out of inodes");
diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c
index 6250975..31c5486 100644
--- a/sys/ufs/ffs/ffs_vfsops.c
+++ b/sys/ufs/ffs/ffs_vfsops.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)ffs_vfsops.c 8.31 (Berkeley) 5/20/95
- * $Id: ffs_vfsops.c,v 1.49 1997/03/22 06:53:30 bde Exp $
+ * $Id: ffs_vfsops.c,v 1.50 1997/03/23 03:37:34 bde Exp $
*/
#include "opt_quota.h"
@@ -92,8 +92,6 @@ struct vfsops ufs_vfsops = {
VFS_SET(ufs_vfsops, ufs, MOUNT_UFS, 0);
-extern u_long nextgennumber;
-
/*
* ffs_mount
*
@@ -585,7 +583,10 @@ ffs_mountfs(devvp, mp, p)
}
mp->mnt_data = (qaddr_t)ump;
mp->mnt_stat.f_fsid.val[0] = (long)dev;
- mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
+ if (fs->fs_id[0] != 0 && fs->fs_id[1] != 0)
+ mp->mnt_stat.f_fsid.val[1] = fs->fs_id[1];
+ else
+ mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
mp->mnt_maxsymlinklen = fs->fs_maxsymlinklen;
mp->mnt_flag |= MNT_LOCAL;
ump->um_mountp = mp;
@@ -1015,9 +1016,7 @@ restart:
* already have one. This should only happen on old filesystems.
*/
if (ip->i_gen == 0) {
- if (++nextgennumber < (u_long)time.tv_sec)
- nextgennumber = time.tv_sec;
- ip->i_gen = nextgennumber;
+ ip->i_gen = random() / 2 + 1;
if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
ip->i_flag |= IN_MODIFIED;
}
diff --git a/sys/ufs/ffs/fs.h b/sys/ufs/ffs/fs.h
index df9f95a..9c9debe 100644
--- a/sys/ufs/ffs/fs.h
+++ b/sys/ufs/ffs/fs.h
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)fs.h 8.13 (Berkeley) 3/21/95
- * $Id$
+ * $Id: fs.h,v 1.10 1997/02/22 09:47:11 peter Exp $
*/
#ifndef _UFS_FFS_FS_H_
@@ -200,8 +200,7 @@ struct fs {
int32_t fs_npsect; /* # sectors/track including spares */
int32_t fs_interleave; /* hardware sector interleave */
int32_t fs_trackskew; /* sector 0 skew, per track */
- int32_t fs_headswitch; /* head switch time, usec */
- int32_t fs_trkseek; /* track-to-track seek, usec */
+/* fs_id takes the space of the unused fs_headswitch and fs_trkseek fields */ int32_t fs_id[2]; /* unique filesystem id */
/* sizes determined by number of cylinder groups and their sizes */
ufs_daddr_t fs_csaddr; /* blk addr of cyl grp summary area */
int32_t fs_cssize; /* size of cyl grp summary area */
OpenPOWER on IntegriCloud