2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 10:58:55 +00:00

Cast unix.Statfs_t.Type to int64 when checking for btrfs

Fixes #3687. Uses the cast suggested by @MichaelEischer, except that the
contant isn't cast along, because it's untyped and will be converted by
the compiler as necessary.
This commit is contained in:
greatroar 2022-03-31 22:30:45 +02:00
parent 774c2e75ca
commit c23c0f7c14

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
}