+ /*
+ * When first opening a BTree, we have to read the header node before the
+ * control block is initialized. In this case, totalNodes will be zero,
+ * so skip the bounds checking.
+ */
+ if (btcb->totalNodes != 0) {
+ if (srcDesc->fLink >= btcb->totalNodes) {
+ printf("hfs_swap_BTNode: invalid forward link (0x%08X)\n", srcDesc->fLink);
+ error = fsBTInvalidHeaderErr;
+ goto fail;
+ }
+ if (srcDesc->bLink >= btcb->totalNodes) {
+ printf("hfs_swap_BTNode: invalid backward link (0x%08X)\n", srcDesc->bLink);
+ error = fsBTInvalidHeaderErr;
+ goto fail;
+ }
+ }
+
+ /*
+ * Check srcDesc->kind. Don't swap it because it's only one byte.
+ */
+ if (srcDesc->kind < kBTLeafNode || srcDesc->kind > kBTMapNode) {
+ printf("hfs_swap_BTNode: invalid node kind (%d)\n", srcDesc->kind);
+ error = fsBTInvalidHeaderErr;
+ goto fail;
+ }
+
+ /*
+ * Check srcDesc->height. Don't swap it because it's only one byte.
+ */
+ if (srcDesc->height > btcb->treeDepth) {
+ printf("hfs_swap_BTNode: invalid node height (%d)\n", srcDesc->height);
+ error = fsBTInvalidHeaderErr;
+ goto fail;
+ }
+