{"record":{"id":"ac5a12e071ac2525","repo":"lima-vm/lima","slug":"filesystem-b-tree-node-w","errorCode":null,"errorMessage":"filesystem B-tree node: %w","messagePattern":"filesystem B-tree node: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apfs/chown.go","lineNumber":522,"sourceCode":"}\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 {\n\t\tif verifyChecksum(blk) != nil {\n\t\t\treturn 0, errors.New(\"filesystem B-tree node checksum failed\")\n\t\t}\n\t\tif err := verifyBTreeNodeType(blk); err != nil {\n\t\t\treturn 0, fmt.Errorf(\"filesystem B-tree node: %w\", err)\n\t\t}\n\t\tflags := le.Uint16(blk[btnFlagsOff:])\n\t\tnkeys := le.Uint32(blk[btnNKeysOff:])\n\t\ttspOff := le.Uint16(blk[btnTableSpaceOff:])\n\t\ttspLen := le.Uint16(blk[btnTableSpaceOff+2:])\n\n\t\ttocStart := btnDataOff + uint32(tspOff)\n\t\tkeyAreaStart := tocStart + uint32(tspLen)\n\n\t\tisLeaf := flags&btnodeLeaf != 0\n\t\tisFixedKV := flags&btnodeFixedKVSize != 0\n\t\tisRoot := flags&btnodeRoot != 0\n\n\t\tvalueAreaEnd := c.blockSize\n\t\tif isRoot {\n\t\t\tvalueAreaEnd -= btreeInfoSize\n\t\t}\n","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/apfs/chown.go#L504-L540","documentation":"This error wraps a failure from verifyBTreeNodeType while walking the directory B-tree in lookupDirEntry. The block's checksum was valid, but the node's on-disk type/magic fields are not a valid B-tree node (wrong object type, unknown flags). It means the walk landed on a block that is not the expected kind of B-tree node.","triggerScenarios":"resolvePath/lookupDirEntry follows an omap or child pointer that resolves to a physical block containing non-B-tree data (e.g. an fs tree where a catalog/omap block was expected), or parsing a volume whose object type constants differ from what the code expects.","commonSituations":"Pointing the reader at the wrong volume superblock or omap root; reading a block from an APFS version with different node layout; an image where the referenced child OID maps to a data block instead of a tree node.","solutions":["Verify you are passing the correct filesystem-tree root physical address and omap tree address","Run fsck_apfs to check the container/volume structure","Confirm the image was produced by a compatible APFS on-disk format version","Re-create/restore the volume if the structure is genuinely damaged"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Ensure you resolved fsRootPhys and omapTreeAddr from the same volume superblock\nif fsRootVol != omapVol {\n    return errors.New(\"fs tree and omap tree come from different volumes\")\n}","typeGuard":"func isBTreeNodeTypeError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"filesystem B-tree node:\")\n}","tryCatchPattern":"fileID, err := c.resolvePath(fsRootPhys, omapTreeAddr, maxXID, path)\nif isBTreeNodeTypeError(err) {\n    return fmt.Errorf(\"bad tree structure, re-resolve roots or fsck: %w\", err)\n}","preventionTips":["Derive both tree addresses from one volume superblock read","Pin the APFS on-disk format/version you support","Reject images whose superblock fields look inconsistent before walking"],"tags":["apfs","b-tree","node-type","validation","corruption"],"backgroundTag":"b-tree-node-type-invalid","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}