{"record":{"id":"0ab95cd3dac2614f","repo":"lima-vm/lima","slug":"looking-up-q-in-directory-cnid-d-w","errorCode":null,"errorMessage":"looking up %#q in directory (cnid %d): %w","messagePattern":"looking up %#q in directory \\(cnid (.+?)\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apfs/chown.go","lineNumber":499,"sourceCode":"\t}\n\t// Non-hashed key: compare names directly.\n\tentryName := c.readDrecName(blk, keyStart+8)\n\treturn strings.Compare(entryName, targetName)\n}\n\n// resolvePath walks path components from the volume root, returning\n// the inode number of the final path element.\nfunc (c *container) resolvePath(fsRootPhys, omapTreeAddr, maxXID uint64, path string) (uint64, error) {\n\tparts := strings.Split(strings.Trim(path, \"/\"), \"/\")\n\tcnid := uint64(rootDirInodeNum)\n\n\tfor _, name := range parts {\n\t\tif name == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tfileID, err := c.lookupDirEntry(fsRootPhys, omapTreeAddr, maxXID, cnid, name)\n\t\tif err != nil {\n\t\t\treturn 0, fmt.Errorf(\"looking up %#q in directory (cnid %d): %w\", name, cnid, err)\n\t\t}\n\t\tcnid = fileID\n\t}\n\treturn cnid, nil\n}\n\n// lookupDirEntry searches the filesystem B-tree for a directory record\n// matching parentCNID and name, returning the file_id from j_drec_val_t.\nfunc (c *container) lookupDirEntry(fsRootPhys, omapTreeAddr, maxXID, parentCNID uint64, name string) (uint64, error) {\n\ttargetKeyHeader := (uint64(apfsTypeDirRec) << objTypeShift) | (parentCNID & objIDMask)\n\ttargetHash := drecNameHash(name)\n\n\tblk, err := c.readBlock(fsRootPhys)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\n\tfor {","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/apfs/chown.go#L481-L517","documentation":"resolvePath walks each path component of a Chown target from the volume root, calling lookupDirEntry for each name against the current directory CNID. This error wraps any per-component failure — most commonly 'directory entry \"name\" not found', but also checksum/type failures or child OID resolution errors inside the filesystem B-tree. The message includes the component name and the parent CNID to pinpoint where the walk stopped.","triggerScenarios":"Calling apfs.Chown with a path containing a component that does not exist in the target volume, a typo or wrong case (lookup is case-insensitive only via hash, exact otherwise), a component being a file rather than a directory, or metadata corruption along the B-tree path.","commonSituations":"Path typos in automation scripts, targeting files that exist on the system volume but not the data volume (or vice versa), paths relative to the volume root that need a different prefix, or images where the file was removed before the image was taken.","solutions":["Verify each path component exists on the target volume (mount the image read-only or inspect on a macOS host).","Confirm you targeted the correct volumeRole — the path is resolved from that volume's root.","Remember paths are relative to the volume root; strip the mount-point prefix (e.g. use 'Library/...' not 'System/Volumes/Data/Library/...').","Check name case/spelling and that no intermediate component is a file.","Run fsck_apfs if you suspect directory B-tree corruption."],"exampleFix":"// before\nerr := apfs.Chown(disk, apfs.VolRoleData, uid, gid, \"System/Volumes/Data/Library/LaunchDaemons/x.plist\")\n// after\nerr := apfs.Chown(disk, apfs.VolRoleData, uid, gid, \"Library/LaunchDaemons/x.plist\")","handlingStrategy":"validation","validationCode":"func sanitizeChownPath(p string) error {\n\tp = strings.TrimPrefix(p, \"/\")\n\tif p == \"\" || strings.Contains(p, \"..\") {\n\t\treturn fmt.Errorf(\"invalid chown path %q\", p)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"if err := apfs.Chown(diskPath, role, uid, gid, paths...); err != nil {\n\tvar msg string\n\tif strings.Contains(err.Error(), \"looking up \") && strings.Contains(err.Error(), \"not found\") {\n\t\treturn fmt.Errorf(\"a path component does not exist on the target volume; check spelling and volumeRole: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Verify target paths exist on the image (mount read-only or inspect on a macOS host) before Chown.","Strip mount-point prefixes; paths are relative to the volume root.","Target the volumeRole where the file actually lives (Data vs System volume).","Log the full wrapped error chain — it names the exact failing component and CNID."],"tags":["apfs","path-resolution","filesystem"],"backgroundTag":"apfs-path-not-found","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}