package host import ( "context" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/rootstate" "path/filepath" ) // Rebase only the journal's deny-only descriptor set. The retained inventory // proves which filesystem its old device number named; the old file inode is // never an ownership grant. Unmapped or ambiguous filesystems refuse recovery. func (k LinuxStopKernel) rebootStopFiles(ctx context.Context, in StopInventory, files []hostbox.StopFileIdentity) ([]hostbox.StopFileIdentity, error) { type filesystem struct { id string device uint64 } devices := map[uint64]filesystem{} for _, e := range in.Entries { if e.Kind != "path" || e.Materialization != "materialized" { continue } if err := ctx.Err(); err != nil { return nil, err } root := k.ManagedRoots[e.ManagedRoot] if !filepath.IsAbs(root) || !filepath.IsLocal(e.RelativePath) { return nil, ErrClaimStopInventory } f, err := hostbox.OpenInventoryFile(filepath.Join(root, e.RelativePath)) if err != nil { return nil, err } err = hostbox.VerifyInventoryFile(f, e) if err == nil { err = hostbox.VerifyInventoryIdentity(root, e) } now, captureErr := rootstate.ObjectIdentity(f) f.Close() if err != nil { return nil, err } if captureErr != nil { return nil, captureErr } next := filesystem{e.Identity.Filesystem, now.Device} if prior, ok := devices[e.Device]; ok && prior != next { return nil, ErrClaimStopInventory } devices[e.Device] = next } out := make([]hostbox.StopFileIdentity, 0, len(files)) for _, f := range files { current, ok := devices[f.Device] if !ok || f.Inode == 0 { return nil, ErrClaimStopInventory } out = append(out, hostbox.StopFileIdentity{Device: current.device, Inode: f.Inode}) } return out, nil }