Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/ufs * Use the old and new time fields in the superblock ...
details: https://anonhg.NetBSD.org/src/rev/c1f0e3c0a789
branches: trunk
changeset: 545241:c1f0e3c0a789
user: fvdl <fvdl%NetBSD.org@localhost>
date: Sat Apr 05 13:37:36 2003 +0000
description:
* Use the old and new time fields in the superblock as well as a few others
to determine if this filesystem was mounted by an older kernel after
having been mounted by a newer one, to avoid some summary mismatches.
* Reinstate support for 4.2 cylinder groups (read-only, as it was before).
diffstat:
sys/ufs/ffs/ffs_vfsops.c | 106 ++++++++++++++++++++++++++++++++--------------
sys/ufs/ffs/fs.h | 31 +++++++++++--
sys/ufs/ufs/ufsmount.h | 5 +-
3 files changed, 103 insertions(+), 39 deletions(-)
diffs (truncated from 304 to 300 lines):
diff -r 6d3500ee63d3 -r c1f0e3c0a789 sys/ufs/ffs/ffs_vfsops.c
--- a/sys/ufs/ffs/ffs_vfsops.c Sat Apr 05 13:36:15 2003 +0000
+++ b/sys/ufs/ffs/ffs_vfsops.c Sat Apr 05 13:37:36 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ffs_vfsops.c,v 1.110 2003/04/02 10:39:38 fvdl Exp $ */
+/* $NetBSD: ffs_vfsops.c,v 1.111 2003/04/05 13:37:36 fvdl Exp $ */
/*
* Copyright (c) 1989, 1991, 1993, 1994
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.110 2003/04/02 10:39:38 fvdl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.111 2003/04/05 13:37:36 fvdl Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ffs.h"
@@ -461,13 +461,16 @@
daddr_t sblockloc;
int i, blks, size, error;
int32_t *lp;
+ struct ufsmount *ump;
if ((mountp->mnt_flag & MNT_RDONLY) == 0)
return (EINVAL);
+
+ ump = VFSTOUFS(mountp);
/*
* Step 1: invalidate all cached meta-data.
*/
- devvp = VFSTOUFS(mountp)->um_devvp;
+ devvp = ump->um_devvp;
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
error = vinvalbuf(devvp, 0, cred, p, 0, 0);
VOP_UNLOCK(devvp, 0);
@@ -476,7 +479,7 @@
/*
* Step 2: re-read superblock from disk.
*/
- fs = VFSTOUFS(mountp)->um_fs;
+ fs = ump->um_fs;
if (VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, NOCRED, p) != 0)
size = DEV_BSIZE;
else
@@ -489,8 +492,12 @@
}
newfs = malloc(fs->fs_sbsize, M_UFSMNT, M_WAITOK);
memcpy(newfs, bp->b_data, fs->fs_sbsize);
+#ifdef SUPPORT_42POSTBLFMT_WRITE
+ if (fs->fs_old_postblformat == FS_42POSTBLFMT)
+ memcpy(ump->um_opostsave, &newfs->fs_old_postbl_start, 256);
+#endif
#ifdef FFS_EI
- if (VFSTOUFS(mountp)->um_flags & UFS_NEEDSWAP) {
+ if (ump->um_flags & UFS_NEEDSWAP) {
ffs_sb_swap((struct fs*)bp->b_data, newfs);
fs->fs_flags |= FS_SWAPPED;
}
@@ -757,6 +764,23 @@
fs = malloc((u_long)sbsize, M_UFSMNT, M_WAITOK);
memcpy(fs, bp->b_data, sbsize);
+
+ ump = malloc(sizeof *ump, M_UFSMNT, M_WAITOK);
+ memset(ump, 0, sizeof *ump);
+ ump->um_fs = fs;
+
+ if (fs->fs_old_postblformat == FS_42POSTBLFMT) {
+#ifdef SUPPORT_FS_42POSTBLFMT_WRITE
+ ump->um_opostsave = malloc(256, M_UFSMNT, M_WAITOK);
+ memcpy(ump->um_opostsave, &fs->fs_old_postbl_start, 256);
+#else
+ if ((mp->mnt_flag & MNT_RDONLY) == 0) {
+ error = EROFS;
+ goto out2;
+ }
+#endif
+ }
+
#ifdef FFS_EI
if (needswap) {
ffs_sb_swap((struct fs*)bp->b_data, fs);
@@ -769,9 +793,6 @@
fs->fs_pendinginodes = 0;
}
- ump = malloc(sizeof *ump, M_UFSMNT, M_WAITOK);
- memset(ump, 0, sizeof *ump);
- ump->um_fs = fs;
ump->um_fstype = fstype;
if (fs->fs_sbsize < SBLOCKSIZE)
bp->b_flags |= B_INVAL;
@@ -945,6 +966,9 @@
{
off_t maxfilesize;
+ if (fs->fs_magic != FS_UFS1_MAGIC)
+ return;
+
/*
* If not yet done, update fs_flags location and value of fs_sblockloc.
*/
@@ -953,32 +977,41 @@
fs->fs_old_flags |= FS_FLAGS_UPDATED;
fs->fs_sblockloc = sblockloc;
}
+
+ /*
+ * If the new fields haven't been set yet, or if the filesystem
+ * was mounted and modified by an old kernel, use the old csum
+ * totals.
+ */
+ if (fs->fs_maxbsize != fs->fs_bsize || fs->fs_time < fs->fs_old_time) {
+ fs->fs_cstotal.cs_ndir = fs->fs_old_cstotal.cs_ndir;
+ fs->fs_cstotal.cs_nbfree = fs->fs_old_cstotal.cs_nbfree;
+ fs->fs_cstotal.cs_nifree = fs->fs_old_cstotal.cs_nifree;
+ fs->fs_cstotal.cs_nffree = fs->fs_old_cstotal.cs_nffree;
+ }
+
/*
* If not yet done, update UFS1 superblock with new wider fields.
*/
- if (fs->fs_magic == FS_UFS1_MAGIC && fs->fs_size != fs->fs_old_size) {
+ if (fs->fs_maxbsize != fs->fs_bsize) {
fs->fs_maxbsize = fs->fs_bsize;
fs->fs_time = fs->fs_old_time;
fs->fs_size = fs->fs_old_size;
fs->fs_dsize = fs->fs_old_dsize;
fs->fs_csaddr = fs->fs_old_csaddr;
- fs->fs_cstotal.cs_ndir = fs->fs_old_cstotal.cs_ndir;
- fs->fs_cstotal.cs_nbfree = fs->fs_old_cstotal.cs_nbfree;
- fs->fs_cstotal.cs_nifree = fs->fs_old_cstotal.cs_nifree;
- fs->fs_cstotal.cs_nffree = fs->fs_old_cstotal.cs_nffree;
}
- if (fs->fs_magic == FS_UFS1_MAGIC &&
- fs->fs_old_inodefmt < FS_44INODEFMT) {
+
+ if (fs->fs_old_inodefmt < FS_44INODEFMT) {
fs->fs_maxfilesize = (u_quad_t) 1LL << 39;
fs->fs_qbmask = ~fs->fs_bmask;
fs->fs_qfmask = ~fs->fs_fmask;
}
- if (fs->fs_magic == FS_UFS1_MAGIC) {
- ump->um_savedmaxfilesize = fs->fs_maxfilesize;
- maxfilesize = (u_int64_t)0x80000000 * fs->fs_bsize - 1;
- if (fs->fs_maxfilesize > maxfilesize)
- fs->fs_maxfilesize = maxfilesize;
- }
+
+ ump->um_savedmaxfilesize = fs->fs_maxfilesize;
+ maxfilesize = (u_int64_t)0x80000000 * fs->fs_bsize - 1;
+ if (fs->fs_maxfilesize > maxfilesize)
+ fs->fs_maxfilesize = maxfilesize;
+
/* Compatibility for old filesystems */
if (fs->fs_avgfilesize <= 0)
fs->fs_avgfilesize = AVFILESIZ;
@@ -1004,18 +1037,19 @@
struct fs *fs;
struct ufsmount *ump;
{
-
+ if (fs->fs_magic != FS_UFS1_MAGIC)
+ return;
/*
* Copy back UFS2 updated fields that UFS1 inspects.
*/
- if (fs->fs_magic == FS_UFS1_MAGIC) {
- fs->fs_old_time = fs->fs_time;
- fs->fs_old_cstotal.cs_ndir = fs->fs_cstotal.cs_ndir;
- fs->fs_old_cstotal.cs_nbfree = fs->fs_cstotal.cs_nbfree;
- fs->fs_old_cstotal.cs_nifree = fs->fs_cstotal.cs_nifree;
- fs->fs_old_cstotal.cs_nffree = fs->fs_cstotal.cs_nffree;
- fs->fs_maxfilesize = ump->um_savedmaxfilesize;
- }
+
+ fs->fs_old_time = fs->fs_time;
+ fs->fs_old_cstotal.cs_ndir = fs->fs_cstotal.cs_ndir;
+ fs->fs_old_cstotal.cs_nbfree = fs->fs_cstotal.cs_nbfree;
+ fs->fs_old_cstotal.cs_nifree = fs->fs_cstotal.cs_nifree;
+ fs->fs_old_cstotal.cs_nffree = fs->fs_cstotal.cs_nffree;
+ fs->fs_maxfilesize = ump->um_savedmaxfilesize;
+
#if 0
if (bigcgs) {
fs->fs_cgsize = fs->fs_save_cgsize;
@@ -1081,6 +1115,10 @@
vput(ump->um_devvp);
free(fs->fs_csp, M_UFSMNT);
free(fs, M_UFSMNT);
+#ifdef SUPPORT_FS_42POSTBLFMT_WRITE
+ if (ump->um_opostsave != NULL)
+ free(ump->um_opostsave, M_UFSMNT);
+#endif
free(ump, M_UFSMNT);
mp->mnt_data = NULL;
mp->mnt_flag &= ~MNT_LOCAL;
@@ -1545,9 +1583,13 @@
ffs_oldfscompat_write((struct fs *)bp->b_data, mp);
#ifdef FFS_EI
if (mp->um_flags & UFS_NEEDSWAP)
- ffs_sb_swap(fs, (struct fs*)bp->b_data);
+ ffs_sb_swap(fs, (struct fs *)bp->b_data);
#endif
-
+#ifdef SUPPORT_FS_42POSTBLFMT_WRITE
+ if (fs->fs_old_postblformat == FS_42POSTBLFMT)
+ memcpy(&((struct fs *)bp->b_data)->fs_old_postbl_start,
+ mp->um_opostsave, 256);
+#endif
fs->fs_flags |= saveflag;
if (waitfor == MNT_WAIT)
diff -r 6d3500ee63d3 -r c1f0e3c0a789 sys/ufs/ffs/fs.h
--- a/sys/ufs/ffs/fs.h Sat Apr 05 13:36:15 2003 +0000
+++ b/sys/ufs/ffs/fs.h Sat Apr 05 13:37:36 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fs.h,v 1.31 2003/04/05 11:12:42 he Exp $ */
+/* $NetBSD: fs.h,v 1.32 2003/04/05 13:37:36 fvdl Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
@@ -321,6 +321,7 @@
#define fs_old_postbloff fs_spare5[0]
#define fs_old_rotbloff fs_spare5[1]
+#define fs_old_postbl_start fs_maxbsize
#define FS_42POSTBLFMT -1 /* 4.2BSD rotational table format */
#define FS_DYNAMICPOSTBLFMT 1 /* dynamic rotational table format */
@@ -329,7 +330,7 @@
* File system identification
*/
#define FS_UFS1_MAGIC 0x011954 /* UFS1 fast file system magic number */
-#define FS_UFS2_MAGIC 0x19540119 /* UFS1 fast file system magic number */
+#define FS_UFS2_MAGIC 0x19540119 /* UFS2 fast file system magic number */
#define FS_UFS1_MAGIC_SWAPPED 0x54190100
#define FS_UFS2_MAGIC_SWAPPED 0x19015419
#define FS_OKAY 0x7c269d38 /* superblock checksum */
@@ -454,22 +455,40 @@
/*
- * Macros for access to cylinder group array structures
+ * Macros for access to cylinder group array structures.
*/
-#define cg_inosused(cgp, ns) \
+#define cg_inosused_new(cgp, ns) \
((u_int8_t *)((u_int8_t *)(cgp) + \
ufs_rw32((cgp)->cg_iusedoff, (ns))))
-#define cg_blksfree(cgp, ns) \
+#define cg_blksfree_new(cgp, ns) \
((u_int8_t *)((u_int8_t *)(cgp) + \
ufs_rw32((cgp)->cg_freeoff, (ns))))
-#define cg_chkmagic(cgp, ns) \
+#define cg_chkmagic_new(cgp, ns) \
(ufs_rw32((cgp)->cg_magic, (ns)) == CG_MAGIC)
+
+#define cg_inosused_old(cgp, ns) \
+ (((struct ocg *)(cgp))->cg_iused)
+#define cg_blksfree_old(cgp, ns) \
+ (((struct ocg *)(cgp))->cg_free)
+#define cg_chkmagic_old(cgp, ns) \
+ (ufs_rw32(((struct ocg *)(cgp))->cg_magic, (ns)) == CG_MAGIC)
+
+#define cg_inosused(cgp, ns) \
+ ((ufs_rw32((cgp)->cg_magic, (ns)) != CG_MAGIC) ? \
+ cg_inosused_old(cgp, ns) : cg_inosused_new(cgp, ns))
+#define cg_blksfree(cgp, ns) \
+ ((ufs_rw32((cgp)->cg_magic, (ns)) != CG_MAGIC) ? \
+ cg_blksfree_old(cgp, ns) : cg_blksfree_new(cgp, ns))
+#define cg_chkmagic(cgp, ns) \
+ (cg_chkmagic_new(cgp, ns) || cg_chkmagic_old(cgp, ns))
+
#define cg_clustersfree(cgp, ns) \
((u_int8_t *)((u_int8_t *)(cgp) + \
ufs_rw32((cgp)->cg_clusteroff, (ns))))
#define cg_clustersum(cgp, ns) \
((int32_t *)((u_int8_t *)(cgp) + \
ufs_rw32((cgp)->cg_clustersumoff, (ns))))
+
/*
* Turn file system block numbers into disk block addresses.
diff -r 6d3500ee63d3 -r c1f0e3c0a789 sys/ufs/ufs/ufsmount.h
--- a/sys/ufs/ufs/ufsmount.h Sat Apr 05 13:36:15 2003 +0000
+++ b/sys/ufs/ufs/ufsmount.h Sat Apr 05 13:37:36 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ufsmount.h,v 1.11 2003/04/02 10:39:46 fvdl Exp $ */
+/* $NetBSD: ufsmount.h,v 1.12 2003/04/05 13:37:36 fvdl Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@@ -99,6 +99,9 @@
char um_qflags[MAXQUOTAS]; /* quota specific flags */
struct netexport um_export; /* export information */
u_int64_t um_savedmaxfilesize; /* XXX - limit maxfilesize */
+#ifdef SUPPORT_42POSTBLFMT_WRITE /* untested */
+ void *um_opostsave; /* save 4.2 rotbl */
Home |
Main Index |
Thread Index |
Old Index