From 6577f1b1463137e5c1912d1778b736ed4e64f89f Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Wed, 9 Sep 2020 11:47:02 +0200 Subject: [PATCH] test_helpers: print warning when not running on ext4 ext4 reuses inode numbers, tmpfs does not. --- tests/test_helpers/helpers.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go index 6119065..212c44c 100644 --- a/tests/test_helpers/helpers.go +++ b/tests/test_helpers/helpers.go @@ -51,6 +51,9 @@ func doInit() { // Something like /tmp/gocryptfs-test-parent-1234 testParentDir := fmt.Sprintf("%s/gocryptfs-test-parent-%d", os.TempDir(), os.Getuid()) os.MkdirAll(testParentDir, 0755) + if !isExt4(testParentDir) { + fmt.Printf("test_helpers: warning: testParentDir %q does not reside on ext4, we will miss failures caused by ino reuse\n", testParentDir) + } var err error TmpDir, err = ioutil.TempDir(testParentDir, "") if err != nil { @@ -116,6 +119,23 @@ func ResetTmpDir(createDirIV bool) { } } +// isExt4 finds out if `path` resides on an ext4 filesystem, as reported by +// statfs. +func isExt4(path string) bool { + // From man statfs + const EXT4_SUPER_MAGIC = 0xef53 + + var fs syscall.Statfs_t + err := syscall.Statfs(path, &fs) + if err != nil { + return false + } + if fs.Type == EXT4_SUPER_MAGIC { + return true + } + return false +} + // InitFS creates a new empty cipherdir and calls // // gocryptfs -q -init -extpass "echo test" -scryptn=10 $extraArgs $cipherdir