Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  linux/fs/hfs/bfind.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Brad Boyer (flar@allandria.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * (C) 2003 Ardis Technologies <roman@ardistech.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Search routines for btrees
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	void *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	fd->tree = tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	fd->bnode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	ptr = kmalloc(tree->max_key_len * 2 + 4, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	if (!ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	fd->search_key = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	fd->key = ptr + tree->max_key_len + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	hfs_dbg(BNODE_REFS, "find_init: %d (%p)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		tree->cnid, __builtin_return_address(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	switch (tree->cnid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	case HFS_CAT_CNID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		mutex_lock_nested(&tree->tree_lock, CATALOG_BTREE_MUTEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	case HFS_EXT_CNID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		mutex_lock_nested(&tree->tree_lock, EXTENTS_BTREE_MUTEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	case HFS_ATTR_CNID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		mutex_lock_nested(&tree->tree_lock, ATTR_BTREE_MUTEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) void hfs_find_exit(struct hfs_find_data *fd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	hfs_bnode_put(fd->bnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	kfree(fd->search_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	hfs_dbg(BNODE_REFS, "find_exit: %d (%p)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		fd->tree->cnid, __builtin_return_address(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	mutex_unlock(&fd->tree->tree_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	fd->tree = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) /* Find the record in bnode that best matches key (not greater than...)*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	int cmpval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	u16 off, len, keylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	int rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	int b, e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	b = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	e = bnode->num_recs - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	res = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		rec = (e + b) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		len = hfs_brec_lenoff(bnode, rec, &off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		keylen = hfs_brec_keylen(bnode, rec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		if (keylen == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			res = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		hfs_bnode_read(bnode, fd->key, off, keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		cmpval = bnode->tree->keycmp(fd->key, fd->search_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		if (!cmpval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			e = rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		if (cmpval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			b = rec + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			e = rec - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	} while (b <= e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (rec != e && e >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		len = hfs_brec_lenoff(bnode, e, &off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		keylen = hfs_brec_keylen(bnode, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		if (keylen == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			res = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		hfs_bnode_read(bnode, fd->key, off, keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	fd->record = e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	fd->keyoffset = off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	fd->keylength = keylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	fd->entryoffset = off + keylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	fd->entrylength = len - keylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* Traverse a B*Tree from the root to a leaf finding best fit to key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* Return allocated copy of node found, set recnum to best record */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int hfs_brec_find(struct hfs_find_data *fd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct hfs_btree *tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct hfs_bnode *bnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	u32 nidx, parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	__be32 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	int height, res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	tree = fd->tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (fd->bnode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		hfs_bnode_put(fd->bnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	fd->bnode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	nidx = tree->root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (!nidx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	height = tree->depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	parent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		bnode = hfs_bnode_find(tree, nidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		if (IS_ERR(bnode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			res = PTR_ERR(bnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			bnode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		if (bnode->height != height)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			goto invalid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		if (bnode->type != (--height ? HFS_NODE_INDEX : HFS_NODE_LEAF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			goto invalid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		bnode->parent = parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		res = __hfs_brec_find(bnode, fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		if (!height)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		if (fd->record < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			goto release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		parent = nidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		hfs_bnode_read(bnode, &data, fd->entryoffset, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		nidx = be32_to_cpu(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		hfs_bnode_put(bnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	fd->bnode = bnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) invalid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	pr_err("inconsistency in B*Tree (%d,%d,%d,%u,%u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	       height, bnode->height, bnode->type, nidx, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	res = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	hfs_bnode_put(bnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) int hfs_brec_read(struct hfs_find_data *fd, void *rec, int rec_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	res = hfs_brec_find(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (fd->entrylength > rec_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	hfs_bnode_read(fd->bnode, rec, fd->entryoffset, fd->entrylength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) int hfs_brec_goto(struct hfs_find_data *fd, int cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	struct hfs_btree *tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	struct hfs_bnode *bnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	int idx, res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	u16 off, len, keylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	bnode = fd->bnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	tree = bnode->tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (cnt < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		cnt = -cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		while (cnt > fd->record) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			cnt -= fd->record + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			fd->record = bnode->num_recs - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			idx = bnode->prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			if (!idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 				res = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			hfs_bnode_put(bnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			bnode = hfs_bnode_find(tree, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			if (IS_ERR(bnode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 				res = PTR_ERR(bnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 				bnode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		fd->record -= cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		while (cnt >= bnode->num_recs - fd->record) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			cnt -= bnode->num_recs - fd->record;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			fd->record = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			idx = bnode->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			if (!idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 				res = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			hfs_bnode_put(bnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			bnode = hfs_bnode_find(tree, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			if (IS_ERR(bnode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 				res = PTR_ERR(bnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 				bnode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		fd->record += cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	len = hfs_brec_lenoff(bnode, fd->record, &off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	keylen = hfs_brec_keylen(bnode, fd->record);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (keylen == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		res = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	fd->keyoffset = off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	fd->keylength = keylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	fd->entryoffset = off + keylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	fd->entrylength = len - keylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	hfs_bnode_read(bnode, fd->key, off, keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	fd->bnode = bnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }