Merge pull request #3693 from greatroar/cast-btrfs-super-magic

Cast unix.Statfs_t.Type to int64 when checking for btrfs
This commit is contained in:
Alexander Neumann
2022-04-01 08:09:46 +02:00
committed by GitHub

View File

@@ -59,9 +59,13 @@ func supportsNoatime(t *testing.T, f *os.File) bool {
err := unix.Fstatfs(int(f.Fd()), &fsinfo)
rtest.OK(t, err)
return fsinfo.Type == unix.BTRFS_SUPER_MAGIC ||
fsinfo.Type == unix.EXT2_SUPER_MAGIC ||
fsinfo.Type == unix.EXT3_SUPER_MAGIC ||
fsinfo.Type == unix.EXT4_SUPER_MAGIC ||
fsinfo.Type == unix.TMPFS_MAGIC
// The funky cast works around a compiler error on 32-bit archs:
// "unix.BTRFS_SUPER_MAGIC (untyped int constant 2435016766) overflows int32".
// https://github.com/golang/go/issues/52061
typ := int64(uint(fsinfo.Type))
return typ == unix.BTRFS_SUPER_MAGIC ||
typ == unix.EXT2_SUPER_MAGIC ||
typ == unix.EXT3_SUPER_MAGIC ||
typ == unix.EXT4_SUPER_MAGIC ||
typ == unix.TMPFS_MAGIC
}