Files
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

107 lines
3.8 KiB
Go

package platform
import "testing"
// A volume is recorded bound to its folder's inode and birth time, and names its volume only
// while those are the folder's; a folder without a birth time, or a volume of another form,
// records none.
func TestVolumeOf(t *testing.T) {
for _, c := range []struct{ vol, id, want string }{
{"uuid:A", "16777234:207:1794.5", "uuid:A:207:1794.5"},
{"fsid:0a0b", "2049:12:1.2", "fsid:0a0b:12:1.2"},
{"", "16777234:207:1794.5", ""},
{"uuid:A", "16777234:207", ""},
{"uuid:A", "", ""},
{"A", "16777234:207:1794.5", ""},
{"uuid:A:B", "16777234:207:1794.5", ""},
} {
if got := VolumeOf(c.vol, c.id); got != c.want {
t.Errorf("VolumeOf(%q, %q) = %q, want %q", c.vol, c.id, got, c.want)
}
}
for _, c := range []struct{ id, recorded, want string }{
{"16777234:207:1794.5", "uuid:A:207:1794.5", "uuid:A"},
{"99:207:1794.5", "uuid:A:207:1794.5", "uuid:A"}, // renumbered: the binding is the inode's
{"16777234:208:1794.5", "uuid:A:207:1794.5", ""}, // another folder's, as an older devvm's move leaves it
{"16777234:207:1794.5", "", ""},
{"16777234:207:1794.5", ":207:1794.5", ""},
{"16777234:207", "uuid:A:207", ""},
} {
if got := RecordedVolume(c.id, c.recorded); got != c.want {
t.Errorf("RecordedVolume(%q, %q) = %q, want %q", c.id, c.recorded, got, c.want)
}
}
}
// A moved folder is the recorded one on a renumbered disk only with the recorded volume, inode
// and birth time, its alone, on a volume mounted for writing; a parent is on the recorded disk
// by its volume when both are known, else by its device.
func TestMovedFolderAndRecordedDisk(t *testing.T) {
was, rec := "9:207:1794.5", "uuid:A:207:1794.5"
now := FolderStat{ID: "7:207:1794.5", Unique: true}
ro, notUnique, other := now, now, now
ro.ReadOnly, notUnique.Unique, other.ID = true, false, "7:208:1794.5"
for _, c := range []struct {
name string
now FolderStat
vol string
want bool
}{
{"the recorded volume", now, "uuid:A", true},
{"another volume", now, "uuid:B", false},
{"no volume", now, "", false},
{"read-only or a snapshot", ro, "uuid:A", false},
{"an identity that isn't its alone", notUnique, "uuid:A", false},
{"another inode", other, "uuid:A", false},
} {
if got := MovedFolder(was, rec, c.now, c.vol); got != c.want {
t.Errorf("%s: MovedFolder = %v, want %v", c.name, got, c.want)
}
}
if MovedFolder(was, "", now, "uuid:A") || MayHaveMoved(was, "", now) {
t.Error("a record without a volume matched")
}
for _, c := range []struct {
recorded, dev, vol string
want bool
}{
{rec, "7", "uuid:A", true},
{rec, "9", "uuid:B", false},
{rec, "7", "", false},
{rec, "9", "", true},
{"", "9", "uuid:A", true},
{"", "7", "uuid:A", false},
} {
if got := OnRecordedDisk(was, c.recorded, c.dev, c.vol); got != c.want {
t.Errorf("OnRecordedDisk(%q, %q, %q) = %v, want %v", c.recorded, c.dev, c.vol, got, c.want)
}
}
// A record with no device can't tell another disk: the same disk, so the folder's gone.
for _, id := range []string{"", "12"} {
if !OnRecordedDisk(id, "", "7", "") {
t.Errorf("OnRecordedDisk(%q) with no device recorded = false", id)
}
}
}
// A folder at its own path on a disk numbered anew keeps the volume recorded for it when that's
// the volume it's on, or when either can't be told; on another volume it's another folder.
func TestKeepsVolume(t *testing.T) {
was, rec := "9:207:1794.5", "uuid:A:207:1794.5"
for _, c := range []struct {
recorded, vol string
want bool
}{
{rec, "uuid:A", true},
{rec, "uuid:B", false},
{rec, "fsid:0a", false},
{rec, "", true},
{"", "uuid:B", true},
{"uuid:A:208:1794.5", "uuid:B", true}, // bound to another folder: no volume recorded
} {
if got := KeepsVolume(was, c.recorded, c.vol); got != c.want {
t.Errorf("KeepsVolume(%q, %q) = %v, want %v", c.recorded, c.vol, got, c.want)
}
}
}