lib/std/fs/test.zig: Some filesystems support 8 EiB files

Btrfs at least supports 16 EiB files (limited in practice to 8EiB by the
Linux VFS code which uses signed 64-bit offsets).  So fix the fs.zig test
case to expect either a FileTooBig or success from truncating a file to
8EiB.  And test that beyond that size the offset is interpreted as a
negative number.

Fixes #24242
This commit is contained in:
Pat Tullmann 2025-06-22 20:48:35 -07:00 committed by Alex Rønne Petersen
parent 640a130651
commit 710632b45c

View file

@ -1435,14 +1435,17 @@ test "setEndPos" {
try testing.expectEqual(0, try f.preadAll(&buffer, 0));
// Invalid file length should error gracefully. Actual limit is host
// and file-system dependent, but 1PB should fail most everywhere.
// Except MacOS APFS limit is 8 exabytes.
// and file-system dependent, but 1PB should fail on filesystems like
// EXT4 and NTFS. But XFS or Btrfs support up to 8EiB files.
f.setEndPos(0x4_0000_0000_0000) catch |err| if (err != error.FileTooBig) {
return err;
};
try testing.expectError(error.FileTooBig, f.setEndPos(std.math.maxInt(u63))); // Maximum signed value
f.setEndPos(std.math.maxInt(u63)) catch |err| if (err != error.FileTooBig) {
return err;
};
try testing.expectError(error.FileTooBig, f.setEndPos(std.math.maxInt(u63) + 1));
try testing.expectError(error.FileTooBig, f.setEndPos(std.math.maxInt(u64)));
}