[PATCH 05/10] ufs: honour on-disk immutable and append-only flags

From: Ali Ahmet Memis

Date: Sat Aug 01 2026 - 18:57:21 EST


ui_flags holds the BSD chflags of the inode. ufs1_read_inode() and
ufs2_read_inode() copy it into ufsi->i_flags and nothing else ever looks
at it. In particular it never reaches inode->i_flags, so IS_IMMUTABLE()
and IS_APPEND() are always false for a UFS inode. The check in
ufs_truncate(),

if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
return -EPERM;

can never fire, and neither can the generic ones in the VFS.

A file that FreeBSD marked with chflags schg or uchg is therefore freely
writable and removable once the filesystem is mounted on Linux, and an
sappnd file can be rewritten rather than only appended to.

Map the immutable and append-only bits onto S_IMMUTABLE and S_APPEND
when the inode is read. Only 44BSD and UFS2 are handled: the other
flavours put something else at that offset and their ui_flags is not a
chflags word.

NOUNLINK has no equivalent in inode->i_flags. Mapping it to S_IMMUTABLE
would be wrong, since it is meant to allow modification, so files marked
that way stay removable for now.

Note that Linux offers no way to clear these flags again; UFS has no
FS_IOC_SETFLAGS support. Filesystems carrying them have to be edited
from an operating system that implements chflags.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Ali Ahmet Memis <ali@xxxxxxxxxxxxxx>
---
fs/ufs/inode.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/fs/ufs/inode.c b/fs/ufs/inode.c
index 7079285bac2a..029f6771b214 100644
--- a/fs/ufs/inode.c
+++ b/fs/ufs/inode.c
@@ -517,6 +517,22 @@ const struct address_space_operations ufs_aops = {
.bmap = ufs_bmap
};

+// only 44BSD and UFS2 store BSD chflags in ui_flags
+static void ufs_set_inode_flags(struct inode *inode)
+{
+ unsigned int flavour = UFS_SB(inode->i_sb)->s_flavour;
+ unsigned int flags = UFS_I(inode)->i_flags;
+
+ if (flavour != UFS_MOUNT_UFSTYPE_44BSD &&
+ flavour != UFS_MOUNT_UFSTYPE_UFS2)
+ return;
+
+ if (flags & (UFS_UF_IMMUTABLE | UFS_SF_IMMUTABLE))
+ inode->i_flags |= S_IMMUTABLE;
+ if (flags & (UFS_UF_APPEND | UFS_SF_APPEND))
+ inode->i_flags |= S_APPEND;
+}
+
// on-disk criterion is i_size < fs_maxsymlinklen, not i_blocks
static bool ufs_is_fast_symlink(struct inode *inode)
{
@@ -704,6 +720,7 @@ struct inode *ufs_iget(struct super_block *sb, unsigned long ino)
ufsi->i_dir_start_lookup = 0;
ufsi->i_osync = 0;

+ ufs_set_inode_flags(inode);
ufs_set_inode_ops(inode);

UFSD("EXIT\n");
--
2.55.0