summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorchs <chs@NetBSD.org>2022-11-17 06:40:38 +0000
committerchs <chs@NetBSD.org>2022-11-17 06:40:38 +0000
commitfc045a9d183f85bd23de76a1f7fd30f941ccc178 (patch)
tree5404f15a8224e3aad20068954d19c826a62f850e /sys
parentf281a463874081e49743e76f8c259f85052d3627 (diff)
Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs). Add a new variant of UFS2 called "UFS2ea" that does support extended attributes. Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended attributes in the process).
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/hppa/stand/xxboot/readufs_ffs.c7
-rw-r--r--sys/arch/sparc/stand/bootblk/bootblk.fth5
-rw-r--r--sys/arch/sparc/stand/bootblk/genfth.cf3
-rw-r--r--sys/arch/x68k/stand/boot_ufs/readufs_ffs.c7
-rw-r--r--sys/lib/libsa/ffsv1.c7
-rw-r--r--sys/lib/libsa/ffsv2.c7
-rw-r--r--sys/lib/libsa/lfsv1.c4
-rw-r--r--sys/lib/libsa/lfsv2.c4
-rw-r--r--sys/lib/libsa/ufs.c46
-rw-r--r--sys/ufs/ffs/ffs_balloc.c6
-rw-r--r--sys/ufs/ffs/ffs_extattr.c8
-rw-r--r--sys/ufs/ffs/ffs_vfsops.c25
-rw-r--r--sys/ufs/ffs/fs.h4
-rw-r--r--sys/ufs/ufs/ufs_bmap.c6
-rw-r--r--sys/ufs/ufs/ufsmount.h3
15 files changed, 98 insertions, 44 deletions
diff --git a/sys/arch/hppa/stand/xxboot/readufs_ffs.c b/sys/arch/hppa/stand/xxboot/readufs_ffs.c
index 11d542d037a..392b8354a44 100644
--- a/sys/arch/hppa/stand/xxboot/readufs_ffs.c
+++ b/sys/arch/hppa/stand/xxboot/readufs_ffs.c
@@ -1,4 +1,4 @@
-/* $NetBSD: readufs_ffs.c,v 1.1 2014/02/24 07:23:43 skrll Exp $ */
+/* $NetBSD: readufs_ffs.c,v 1.2 2022/11/17 06:40:39 chs Exp $ */
/* from Id: readufs_ffs.c,v 1.8 2004/06/12 04:26:39 itohy Exp */
/*
@@ -66,7 +66,7 @@ try_ffs(void)
break;
#endif
#ifdef USE_UFS2
- if (magic == FS_UFS2_MAGIC) {
+ if (magic == FS_UFS2_MAGIC || magic == FS_UFS2EA_MAGIC) {
#ifdef USE_UFS1
fsi.ufstype = UFSTYPE_UFS2;
#endif
@@ -81,7 +81,8 @@ try_ffs(void)
*/
fsi_ffs.magic = magic;
#ifdef DEBUG_WITH_STDIO
- printf("FFS: detected UFS%d format\n", (magic == FS_UFS2_MAGIC) + 1);
+ printf("FFS: detected UFS%d format\n",
+ (magic == FS_UFS2_MAGIC || magic == FS_UFS2EA_MAGIC) + 1);
#endif
/* This partition looks like an FFS. */
diff --git a/sys/arch/sparc/stand/bootblk/bootblk.fth b/sys/arch/sparc/stand/bootblk/bootblk.fth
index 0107053a9c9..184b16859ec 100644
--- a/sys/arch/sparc/stand/bootblk/bootblk.fth
+++ b/sys/arch/sparc/stand/bootblk/bootblk.fth
@@ -1,4 +1,4 @@
-\ $NetBSD: bootblk.fth,v 1.16 2021/07/24 21:31:36 andvar Exp $
+\ $NetBSD: bootblk.fth,v 1.17 2022/11/17 06:40:39 chs Exp $
\
\ IEEE 1275 Open Firmware Boot Block
\
@@ -624,6 +624,7 @@ create cur-blockno -1 l, -1 l, \ Current disk block.
fs_magic l@ case
fs1_magic_value of init-ffs-v1 true endof
fs2_magic_value of init-ffs-v2 true endof
+ fs2ea_magic_value of init-ffs-v2 true endof
false swap \ Return false
endcase
;
@@ -890,7 +891,7 @@ create cur-blockno -1 l, -1 l, \ Current disk block.
: do-boot ( bootfile -- )
." NetBSD IEEE 1275 Multi-FS Bootblock" cr
- ." Version $NetBSD: bootblk.fth,v 1.16 2021/07/24 21:31:36 andvar Exp $" cr
+ ." Version $NetBSD: bootblk.fth,v 1.17 2022/11/17 06:40:39 chs Exp $" cr
boot-path load-file ( -- load-base )
dup 0<> if " init-program " evaluate then
;
diff --git a/sys/arch/sparc/stand/bootblk/genfth.cf b/sys/arch/sparc/stand/bootblk/genfth.cf
index 8c2cf1f8451..2bde08ee2e5 100644
--- a/sys/arch/sparc/stand/bootblk/genfth.cf
+++ b/sys/arch/sparc/stand/bootblk/genfth.cf
@@ -1,4 +1,4 @@
-# $NetBSD: genfth.cf,v 1.9 2013/06/10 10:26:22 hannken Exp $
+# $NetBSD: genfth.cf,v 1.10 2022/11/17 06:40:39 chs Exp $
#
# Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -158,6 +158,7 @@ member d_name
define fs1_magic_value FS_UFS1_MAGIC
define fs2_magic_value FS_UFS2_MAGIC
+define fs2ea_magic_value FS_UFS2EA_MAGIC
define fs_42postblfmt FS_42POSTBLFMT
define fs_44inodefmt FS_44INODEFMT
define ndaddr UFS_NDADDR
diff --git a/sys/arch/x68k/stand/boot_ufs/readufs_ffs.c b/sys/arch/x68k/stand/boot_ufs/readufs_ffs.c
index 61f8116f031..5ef632825a4 100644
--- a/sys/arch/x68k/stand/boot_ufs/readufs_ffs.c
+++ b/sys/arch/x68k/stand/boot_ufs/readufs_ffs.c
@@ -1,4 +1,4 @@
-/* $NetBSD: readufs_ffs.c,v 1.14 2013/06/23 02:06:05 dholland Exp $ */
+/* $NetBSD: readufs_ffs.c,v 1.15 2022/11/17 06:40:39 chs Exp $ */
/* from Id: readufs_ffs.c,v 1.6 2003/04/08 09:19:32 itohy Exp */
/*
@@ -69,7 +69,7 @@ try_ffs(void)
}
#endif
#ifdef USE_UFS2
- if (magic == FS_UFS2_MAGIC) {
+ if (magic == FS_UFS2_MAGIC || magic == FS_UFS2EA_MAGIC) {
#ifdef USE_UFS1
fsi.ufstype = UFSTYPE_UFS2;
#endif
@@ -84,7 +84,8 @@ try_ffs(void)
*/
fsi_ffs.magic = magic;
#ifdef DEBUG_WITH_STDIO
- printf("FFS: detected UFS%d format\n", (magic == FS_UFS2_MAGIC) + 1);
+ printf("FFS: detected UFS%d format\n",
+ (magic == FS_UFS2_MAGIC || magic == FS_UFS2EA_MAGIC) + 1);
#endif
/* This partition looks like an FFS. */
diff --git a/sys/lib/libsa/ffsv1.c b/sys/lib/libsa/ffsv1.c
index c3197c669d1..779bc2fdafa 100644
--- a/sys/lib/libsa/ffsv1.c
+++ b/sys/lib/libsa/ffsv1.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ffsv1.c,v 1.9 2022/04/24 06:52:59 mlelstv Exp $ */
+/* $NetBSD: ffsv1.c,v 1.10 2022/11/17 06:40:39 chs Exp $ */
#define LIBSA_FFSv1
@@ -17,9 +17,4 @@
#define ufs_indp_swap bswap32
#define indp_t int32_t
-#define FS_MAGIC FS_UFS1_MAGIC
-
-/* #define FSMOD "wapbl/ufs/ffs" */
-#define FSMOD NULL
-
#include "ufs.c"
diff --git a/sys/lib/libsa/ffsv2.c b/sys/lib/libsa/ffsv2.c
index 90b7cae30a1..390b3763046 100644
--- a/sys/lib/libsa/ffsv2.c
+++ b/sys/lib/libsa/ffsv2.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ffsv2.c,v 1.9 2022/04/24 06:52:59 mlelstv Exp $ */
+/* $NetBSD: ffsv2.c,v 1.10 2022/11/17 06:40:39 chs Exp $ */
#define LIBSA_FFSv2
@@ -17,9 +17,4 @@
#define ufs_indp_swap bswap64
#define indp_t int64_t
-#define FS_MAGIC FS_UFS2_MAGIC
-
-/* #define FSMOD "wapbl/ufs/ffs" */
-#define FSMOD NULL
-
#include "ufs.c"
diff --git a/sys/lib/libsa/lfsv1.c b/sys/lib/libsa/lfsv1.c
index 1c361c23bd8..825c457a2c2 100644
--- a/sys/lib/libsa/lfsv1.c
+++ b/sys/lib/libsa/lfsv1.c
@@ -1,4 +1,4 @@
-/* $NetBSD: lfsv1.c,v 1.15 2021/05/27 06:54:44 mrg Exp $ */
+/* $NetBSD: lfsv1.c,v 1.16 2022/11/17 06:40:39 chs Exp $ */
#define LIBSA_LFS
#define REQUIRED_LFS_VERSION 1
@@ -25,8 +25,6 @@
#define dblksize(a, b, c) lfs_dblksize((a), (b), (c))
#define FSBTODB(fs, daddr) (daddr) /* LFSv1 uses sectors for addresses */
-#define FS_MAGIC LFS_MAGIC
-
#define FSMOD "lfs"
#include "lib/libsa/ufs.c"
diff --git a/sys/lib/libsa/lfsv2.c b/sys/lib/libsa/lfsv2.c
index 0eb0583854b..089f763d875 100644
--- a/sys/lib/libsa/lfsv2.c
+++ b/sys/lib/libsa/lfsv2.c
@@ -1,4 +1,4 @@
-/* $NetBSD: lfsv2.c,v 1.15 2021/05/27 06:54:44 mrg Exp $ */
+/* $NetBSD: lfsv2.c,v 1.16 2022/11/17 06:40:40 chs Exp $ */
#define LIBSA_LFS
#define REQUIRED_LFS_VERSION 2
@@ -29,8 +29,6 @@
#define dblksize(a, b, c) lfs_dblksize((a), (b), (c))
#define FSBTODB(a, b) LFS_FSBTODB((a), (b))
-#define FS_MAGIC LFS_MAGIC
-
#define FSMOD "lfs"
#include "lib/libsa/ufs.c"
diff --git a/sys/lib/libsa/ufs.c b/sys/lib/libsa/ufs.c
index adf464e6d79..5641c5f018a 100644
--- a/sys/lib/libsa/ufs.c
+++ b/sys/lib/libsa/ufs.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs.c,v 1.86 2022/04/29 07:42:07 rin Exp $ */
+/* $NetBSD: ufs.c,v 1.87 2022/11/17 06:40:40 chs Exp $ */
/*-
* Copyright (c) 1993
@@ -156,9 +156,6 @@ typedef uint32_t ino32_t;
#ifndef FSBTODB
#define FSBTODB(fs, indp) FFS_FSBTODB(fs, indp)
#endif
-#ifndef FS_MAGIC
-#define FS_MAGIC FS_UFS1_MAGIC
-#endif
#ifndef UFS_NINDIR
#define UFS_NINDIR FFS_NINDIR
#endif
@@ -214,17 +211,54 @@ static int search_directory(const char *, int, struct open_file *, ino32_t *);
static void ffs_oldfscompat(FS *);
#endif
+#ifdef LIBSA_FFSv1
static __inline__ bool
ffs_is_magic(FS *fs)
{
- return fs->fs_magic == FS_MAGIC;
+ return fs->fs_magic == FS_UFS1_MAGIC;
+}
+
+static __inline__ bool
+ffs_is_magic_swapped(FS *fs)
+{
+ return fs->fs_magic == bswap32(FS_UFS1_MAGIC);
}
+#endif
+
+#ifdef LIBSA_FFSv2
+static __inline__ bool
+ffs_is_magic(FS *fs)
+{
+ return fs->fs_magic == FS_UFS2_MAGIC || fs->fs_magic == FS_UFS2EA_MAGIC;
+}
+
+static __inline__ bool
+ffs_is_magic_swapped(FS *fs)
+{
+ return fs->fs_magic == bswap32(FS_UFS2_MAGIC) ||
+ fs->fs_magic == bswap32(FS_UFS2EA_MAGIC);
+}
+#endif
+
+#ifdef LIBSA_LFS
+static __inline__ bool
+ffs_is_magic(FS *fs)
+{
+ return fs->fs_magic == LFS_MAGIC;
+}
+
+static __inline__ bool
+ffs_is_magic_swapped(FS *fs)
+{
+ return fs->fs_magic == bswap32(LFS_MAGIC);
+}
+#endif
static __inline__ void
ffs_fix_magic_swapped(struct file *fp, FS *fs)
{
#ifdef LIBSA_FFS_EI
- fp->f_swapped = fs->fs_magic == bswap32(FS_MAGIC);
+ fp->f_swapped = ffs_is_magic_swapped(fs);
if (fp->f_swapped)
{
ffs_sb_swap(fs, fs);
diff --git a/sys/ufs/ffs/ffs_balloc.c b/sys/ufs/ffs/ffs_balloc.c
index fb52b993f6f..954d7f1de4a 100644
--- a/sys/ufs/ffs/ffs_balloc.c
+++ b/sys/ufs/ffs/ffs_balloc.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ffs_balloc.c,v 1.65 2020/09/05 16:30:13 riastradh Exp $ */
+/* $NetBSD: ffs_balloc.c,v 1.66 2022/11/17 06:40:40 chs Exp $ */
/*
* Copyright (c) 2002 Networks Associates Technology, Inc.
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_balloc.c,v 1.65 2020/09/05 16:30:13 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_balloc.c,v 1.66 2022/11/17 06:40:40 chs Exp $");
#if defined(_KERNEL_OPT)
#include "opt_quota.h"
@@ -543,6 +543,8 @@ ffs_balloc_ufs2(struct vnode *vp, off_t off, int size, kauth_cred_t cred,
const int needswap = UFS_FSNEEDSWAP(fs);
UVMHIST_FUNC("ffs_balloc"); UVMHIST_CALLED(ubchist);
+ KASSERT((ump->um_flags & UFS_EA) != 0 || (flags & IO_EXT) == 0);
+
lbn = ffs_lblkno(fs, off);
size = ffs_blkoff(fs, off) + size;
if (size > fs->fs_bsize)
diff --git a/sys/ufs/ffs/ffs_extattr.c b/sys/ufs/ffs/ffs_extattr.c
index 41ba849c1d8..7c4728275ba 100644
--- a/sys/ufs/ffs/ffs_extattr.c
+++ b/sys/ufs/ffs/ffs_extattr.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ffs_extattr.c,v 1.8 2021/12/14 11:06:50 chs Exp $ */
+/* $NetBSD: ffs_extattr.c,v 1.9 2022/11/17 06:40:40 chs Exp $ */
/*-
* SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-3-Clause)
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.8 2021/12/14 11:06:50 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_extattr.c,v 1.9 2022/11/17 06:40:40 chs Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ffs.h"
@@ -464,6 +464,9 @@ ffs_open_ea(struct vnode *vp, kauth_cred_t cred)
int error;
ip = VTOI(vp);
+ if ((ip->i_ump->um_flags & UFS_EA) == 0) {
+ return EOPNOTSUPP;
+ }
ffs_lock_ea(vp);
if (ip->i_ea_area != NULL) {
@@ -497,6 +500,7 @@ ffs_close_ea(struct vnode *vp, int commit, kauth_cred_t cred)
struct ufs2_dinode *dp;
ip = VTOI(vp);
+ KASSERT((ip->i_ump->um_flags & UFS_EA) != 0);
if (commit)
KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c
index 181a38d826d..f39f29ad602 100644
--- a/sys/ufs/ffs/ffs_vfsops.c
+++ b/sys/ufs/ffs/ffs_vfsops.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ffs_vfsops.c,v 1.377 2022/11/10 10:53:29 hannken Exp $ */
+/* $NetBSD: ffs_vfsops.c,v 1.378 2022/11/17 06:40:40 chs Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.377 2022/11/10 10:53:29 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.378 2022/11/17 06:40:40 chs Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ffs.h"
@@ -845,6 +845,15 @@ ffs_reload(struct mount *mp, kauth_cred_t cred, struct lwp *l)
brelse(bp, 0);
+ /* Allow converting from UFS2 to UFS2EA but not vice versa. */
+ if (newfs->fs_magic == FS_UFS2EA_MAGIC) {
+ ump->um_flags |= UFS_EA;
+ newfs->fs_magic = FS_UFS2_MAGIC;
+ } else {
+ if ((ump->um_flags & UFS_EA) != 0)
+ return EINVAL;
+ }
+
if ((newfs->fs_magic != FS_UFS1_MAGIC) &&
(newfs->fs_magic != FS_UFS2_MAGIC)) {
kmem_free(newfs, fs_sbsize);
@@ -1217,6 +1226,13 @@ ffs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l)
* size to read the superblock. Once read, we swap the whole
* superblock structure.
*/
+ if (fs->fs_magic == FS_UFS2EA_MAGIC) {
+ ump->um_flags |= UFS_EA;
+ fs->fs_magic = FS_UFS2_MAGIC;
+ } else if (fs->fs_magic == FS_UFS2EA_MAGIC_SWAPPED) {
+ ump->um_flags |= UFS_EA;
+ fs->fs_magic = FS_UFS2_MAGIC_SWAPPED;
+ }
if (fs->fs_magic == FS_UFS1_MAGIC) {
fs_sbsize = fs->fs_sbsize;
fstype = UFS1;
@@ -2375,6 +2391,11 @@ ffs_sbupdate(struct ufsmount *mp, int waitfor)
memcpy(bp->b_data, fs, fs->fs_sbsize);
ffs_oldfscompat_write((struct fs *)bp->b_data, mp);
+ if (mp->um_flags & UFS_EA) {
+ struct fs *bfs = (struct fs *)bp->b_data;
+ KASSERT(bfs->fs_magic == FS_UFS2_MAGIC);
+ bfs->fs_magic = FS_UFS2EA_MAGIC;
+ }
#ifdef FFS_EI
if (mp->um_flags & UFS_NEEDSWAP)
ffs_sb_swap((struct fs *)bp->b_data, (struct fs *)bp->b_data);
diff --git a/sys/ufs/ffs/fs.h b/sys/ufs/ffs/fs.h
index ca92949e709..da0bf60cd1a 100644
--- a/sys/ufs/ffs/fs.h
+++ b/sys/ufs/ffs/fs.h
@@ -1,4 +1,4 @@
-/* $NetBSD: fs.h,v 1.69 2021/09/18 03:05:20 christos Exp $ */
+/* $NetBSD: fs.h,v 1.70 2022/11/17 06:40:40 chs Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
@@ -398,8 +398,10 @@ struct fs {
*/
#define FS_UFS1_MAGIC 0x011954 /* UFS1 fast file system magic number */
#define FS_UFS2_MAGIC 0x19540119 /* UFS2 fast file system magic number */
+#define FS_UFS2EA_MAGIC 0x19012038 /* UFS2 with extattrs */
#define FS_UFS1_MAGIC_SWAPPED 0x54190100
#define FS_UFS2_MAGIC_SWAPPED 0x19015419
+#define FS_UFS2EA_MAGIC_SWAPPED 0x38200119
#define FS_OKAY 0x7c269d38 /* superblock checksum */
#define FS_42INODEFMT -1 /* 4.2BSD inode format */
#define FS_44INODEFMT 2 /* 4.4BSD inode format */
diff --git a/sys/ufs/ufs/ufs_bmap.c b/sys/ufs/ufs/ufs_bmap.c
index 96e57032da3..7709dcf2b0c 100644
--- a/sys/ufs/ufs/ufs_bmap.c
+++ b/sys/ufs/ufs/ufs_bmap.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_bmap.c,v 1.53 2020/04/20 03:57:02 christos Exp $ */
+/* $NetBSD: ufs_bmap.c,v 1.54 2022/11/17 06:40:40 chs Exp $ */
/*
* Copyright (c) 1989, 1991, 1993
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_bmap.c,v 1.53 2020/04/20 03:57:02 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_bmap.c,v 1.54 2022/11/17 06:40:40 chs Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -191,7 +191,7 @@ ufs_bmaparray(struct vnode *vp, daddr_t bn, daddr_t *bnp, struct indir *ap,
}
return (0);
} else if (bn < 0 && bn >= -UFS_NXADDR) {
- KASSERT(ump->um_fstype == UFS2);
+ KASSERT(ump->um_fstype == UFS2 && (ump->um_flags & UFS_EA) != 0);
daddr = ufs_rw64(ip->i_ffs2_extb[-1 - bn], UFS_MPNEEDSWAP(ump));
*bnp = blkptrtodb(ump, daddr);
if (*bnp == 0)
diff --git a/sys/ufs/ufs/ufsmount.h b/sys/ufs/ufs/ufsmount.h
index 86b3968b90a..aa190ad7ef3 100644
--- a/sys/ufs/ufs/ufsmount.h
+++ b/sys/ufs/ufs/ufsmount.h
@@ -1,4 +1,4 @@
-/* $NetBSD: ufsmount.h,v 1.43 2015/03/27 17:27:56 riastradh Exp $ */
+/* $NetBSD: ufsmount.h,v 1.44 2022/11/17 06:40:40 chs Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@@ -163,6 +163,7 @@ struct ufs_ops {
#define UFS_ISAPPLEUFS 0x02 /* filesystem is Apple UFS */
#define UFS_QUOTA 0x04 /* filesystem has QUOTA (v1) */
#define UFS_QUOTA2 0x08 /* filesystem has QUOTA2 */
+#define UFS_EA 0x10 /* UFS2 with extattrs */
/*
* Filesystem types