[Bug 270632] [ext2fs] files <4096 bytes are corrupted on ext4 filesystems

From: <bugzilla-noreply_at_freebsd.org>
Date: Tue, 04 Apr 2023 02:18:42 UTC

            Bug ID: 270632
           Summary: [ext2fs] files <4096 bytes are corrupted on ext4
           Product: Base System
           Version: 13.2-RELEASE
          Hardware: amd64
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: rajeev_v_pillai@yahoo.com

Files smaller than 4096 bytes (probably the ext4 block-size?) get corrupted
they're written to if the filesystem is ext4. ext2 and ext3 FSes look OK.

$ uname -a
FreeBSD  13.2-RC6 FreeBSD 13.2-RC6 releng/13.2-n254616-a92e3fa2ade5 GENERIC

# Create an ext4 FS somewhere--here on an USB thumb drive (problem first
# on an existing ext4 FS on a HDD).

gpart destroy -F da0
gpart create -s GPT da0
gpart add -t linux-data da0
mke2fs -L thumbdrive -t ext4 /dev/da0p1

# Copy/create a file <= 4096 bytes on FS (files >4096 bytes are unaffected).
mount -t ext2fs /dev/da0p1 /mnt
echo 'hello world' >/mnt/a.txt

# Without unmounting and remounting the FS, edit the file, making a trivial
# eg. replacing any char. with the same one.
# The issue does not occur if you unmount and remount the FS first before
# the file.
ed -s /mnt/a.txt <<\EoF

# Check file
cat /mnt/a.txt
umount /mnt

# Remount & check file again.
mount -r -t ext2fs /dev/da0p1 /mnt

# File contents are replaced with NULs. File size is unchanged. e2fsck shows
# no problems.
hexdump -C /mnt/a.txt
umount /mnt

You are receiving this mail because:
You are the assignee for the bug.