Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static fsw_status_t
- fsw_hfsplus_bt_search(struct fsw_hfsplus_dnode *bt, /* in */ HFSPlusBTKey *sk, /* in */
- k_cmp_t k_cmp, /* in */ BTNodeDescriptor *btnode, /* out */
- fsw_u32 *rec_num /* out */)
- {
- fsw_u32 node;
- fsw_u16 rec, lo, hi;
- HFSPlusBTKey *tk;
- int cmp;
- fsw_status_t status;
- node = bt->bt_root;
- for (;;) {
- status = fsw_hfsplus_read(bt, (fsw_u64)node * bt->bt_ndsz,
- bt->bt_ndsz, btnode);
- if (status)
- return status;
- if ((void *)btnode + sizeof(BTNodeDescriptor) !=
- (void *)fsw_hfsplus_btnode_get_rec(btnode, bt->bt_ndsz, 0))
- return FSW_VOLUME_CORRUPTED;
- lo = 0;
- hi = fsw_u16_be_swap(btnode->numRecords) - 1;
- while (lo <= hi) {
- rec = (lo + hi) >> 1;
- tk = fsw_hfsplus_btnode_get_rec(btnode, bt->bt_ndsz, rec);
- cmp = k_cmp(tk, sk);
- if (cmp < 0) // (tk < sk)
- lo = rec + 1;
- else if (cmp > 0) // (tk > sk)
- hi = rec - 1;
- else { // (tk == sk)
- if (btnode->kind != kBTLeafNode) {
- hi = rec;
- break;
- }
- *rec_num = rec;
- return FSW_SUCCESS;
- }
- }
- if (btnode->kind != kBTIndexNode)
- break;
- tk = fsw_hfsplus_btnode_get_rec(btnode, bt->bt_ndsz, hi);
- node = fsw_hfsplus_bt_idx_get_child(tk);
- }
- return FSW_NOT_FOUND;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement