Files
devvm/internal/platform/folderstat_linux_test.go
w3cjandClaude Opus 5.5 4ccdbf8125 fix(vm): folder identity's last checks: a renumbered folder keeps its volume
From the volume UUID commit's security review. A folder at its own
recorded path on a disk numbered anew (platform.SameFolder's renumbered
case) must now also be on the volume its state records, when both are
known (platform.KeepsVolume): the finder checks it (finder.sameFolder,
Env.keepsVolume, so a launch refuses with vm_other_folder) and so does
recordFolder under the state's lock, so a copy of the disk with a volume
ID of its own mounted at the folder's path is another folder. A volume
that can't be told leaves the device's rule, as for a state that
records none. mountedBy and mountsRepo keep the check without volumes
(madeFor), which errs towards warning.

hereOf reads the folder's identity, uniqueness, owner and volume from
one open folder (platform.StatFolder, now with Owner), so the folder
checked as the user's is the one matched and recorded. StatFolder is
one function for macOS and Linux (folderstat_unix.go) over each
system's openFolder, which SameFolder's renumbered case uses too, in
place of openFolderID and darwin's copy.

devvm ls and devvm space look volumes up through the run's Env
(Env.FolderOf, Inventory.List(ctx, e)), each mount once a run, in
place of diskutil for each VM; FolderOf, parentVolume and movedAway go.
FolderDevice is unexported (folderDevice), so only platform reads a
device; OnRecordedDisk takes a record without a device as on any disk.

The folder-ids rule tracks names assigned from such names, however
many steps on, and maps keyed by an identity, indexed or in a map's
literal, without counting a struct literal's field; its loop is
sitesWhereIn, shared with sitesWhere. The hdiutil e2e check makes sure
macOS gave the disk a new number, attaching up to three images first,
and is skipped when it never does. The design notes say who can forge
a volume ID and what it gets them.

Tests: TestKeepsVolume, OnRecordedDisk without a device,
TestRenumberedOnAnotherVolume (a launch and recordFolder),
TestListLooksUpVolumesOnce, StatFolder's Owner on both systems, the
folder-ids rule's new cases, and fixture_v010_renumbered.txtar (another
volume at its own path refused with nothing recorded; ls calls the
moved folder gone by its recorded volume, where it said not_connected).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-19 07:15:53 -07:00

44 lines
1.1 KiB
Go

package platform
import (
"os"
"path/filepath"
"slices"
"testing"
"golang.org/x/sys/unix"
)
// A folder read with no link on its path: its FolderID, and a volume, the same at each read,
// only on a file system whose f_fsid is its own (ext4, btrfs, ZFS), never on tmpfs or XFS; a
// folder whose path has a link isn't read.
func TestStatFolder(t *testing.T) {
dir, err := filepath.EvalSymlinks(t.TempDir())
if err != nil {
t.Fatal(err)
}
s, err := StatFolder(dir)
if err != nil {
t.Fatal(err)
}
id, _ := FolderID(dir)
var fs unix.Statfs_t
if err := unix.Statfs(dir, &fs); err != nil {
t.Fatal(err)
}
own := slices.Contains(fsidOwn(), fs.Type) && fs.Flags&unix.ST_RDONLY == 0
if s.ID != id || (s.Volume != "") != own || int(s.Owner) != os.Getuid() {
t.Errorf("StatFolder = %+v on a file system of type %#x, FolderID %s", s, fs.Type, id)
}
if again, _ := StatFolder(dir); again != s {
t.Errorf("again = %+v, want %+v", again, s)
}
link := filepath.Join(dir, "link")
if err := os.Symlink(dir, link); err != nil {
t.Fatal(err)
}
if _, err := StatFolder(link); err == nil {
t.Error("a folder read through a link")
}
}