fork/gdu

git clone https://git.julia.blue/fork/gdu

Nicolas Grillyfix: don't materialize dataless files when scanning on macOS (#622)af9492f

subvolume
1.0 KiB34 linesraw
1//go:build darwin
2
3package fs
4
5import (
6	"testing"
7
8	"golang.org/x/sys/unix"
9)
10
11// TestPreventDatalessMaterialization checks that the call reaches the kernel, by
12// reading back the state it is supposed to change.
13//
14// setiopolicy_np with IOPOL_TYPE_VFS_MATERIALIZE_DATALESS_FILES and the
15// vfs.nspace.prevent_materialization sysctl are the same per-process state.
16// x/sys/unix exposes sysctl readers but no writer, which is enough here: we can
17// verify the result even though we cannot produce it.
18//
19// The state is per-process and has no effect outside the test binary.
20func TestPreventDatalessMaterialization(t *testing.T) {
21	const preventMaterializationSysctl = "vfs.nspace.prevent_materialization"
22
23	if err := PreventDatalessMaterialization(); err != nil {
24		t.Fatalf("PreventDatalessMaterialization: %s", err)
25	}
26
27	after, err := unix.SysctlUint32(preventMaterializationSysctl)
28	if err != nil {
29		t.Skipf("cannot read %s: %s", preventMaterializationSysctl, err)
30	}
31	if after != 1 {
32		t.Errorf("%s = %d, want 1", preventMaterializationSysctl, after)
33	}
34}