From f4d7a804387374b12e63175fadcb637a8a4dca84 Mon Sep 17 00:00:00 2001 From: millert Date: Tue, 11 Feb 1997 06:59:25 +0000 Subject: [PATCH] Add fs_id support and random inode generation numbers for ffs. --- sys/kern/vfs_subr.c | 2 ++ sys/ufs/ffs/ffs_alloc.c | 13 +++++++++---- sys/ufs/ffs/ffs_vfsops.c | 16 +++++++++++----- sys/ufs/ffs/fs.h | 4 ++-- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 41ea7f092dc..1e6bd4b56a0 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -263,6 +263,8 @@ getnewfsid(mp, mtype) /* * Make a 'unique' number from a mount type name. + * Note that this is no longer used for ffs which + * now has an on-disk filesystem id. */ long makefstype(type) diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c index 666560caf32..cd81395a3e3 100644 --- a/sys/ufs/ffs/ffs_alloc.c +++ b/sys/ufs/ffs/ffs_alloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_alloc.c,v 1.4 1996/05/22 11:47:17 deraadt Exp $ */ +/* $OpenBSD: ffs_alloc.c,v 1.5 1997/02/11 06:59:27 millert Exp $ */ /* $NetBSD: ffs_alloc.c,v 1.11 1996/05/11 18:27:09 mycroft Exp $ */ /* @@ -47,6 +47,8 @@ #include +#include + #include #include #include @@ -563,10 +565,13 @@ ffs_valloc(v) ip->i_flags = 0; /* * Set up a new generation number for this inode. + * XXX - just increment for now, this is wrong! (millert) + * Need a way to preserve randomization. */ - 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 = arc4random(); + if (ip->i_gen == 0 || ip->i_gen == -1) + ip->i_gen = 1; /* shouldn't happen */ 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 ee4c214d7b4..a891ede9d9a 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_vfsops.c,v 1.6 1996/06/27 06:42:06 downsj Exp $ */ +/* $OpenBSD: ffs_vfsops.c,v 1.7 1997/02/11 06:59:28 millert Exp $ */ /* $NetBSD: ffs_vfsops.c,v 1.19 1996/02/09 22:22:26 christos Exp $ */ /* @@ -52,6 +52,8 @@ #include #include +#include + #include #include @@ -522,7 +524,11 @@ 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] = makefstype(MOUNT_FFS); + /* Use on-disk fsid if it exists, else fake it */ + 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] = makefstype(MOUNT_FFS); mp->mnt_maxsymlinklen = fs->fs_maxsymlinklen; mp->mnt_flag |= MNT_LOCAL; ump->um_mountp = mp; @@ -858,9 +864,9 @@ ffs_vget(mp, ino, vpp) * 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 = arc4random(); + if (ip->i_gen == 0 || ip->i_gen == -1) + ip->i_gen = 1; /* shouldn't happen */ 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 478db6a5be7..ce4f34bef21 100644 --- a/sys/ufs/ffs/fs.h +++ b/sys/ufs/ffs/fs.h @@ -198,8 +198,8 @@ 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 */ daddr_t fs_csaddr; /* blk addr of cyl grp summary area */ int32_t fs_cssize; /* size of cyl grp summary area */ -- 2.20.1