cleanup: run indent with the Linux Kernel style across all code
Over the years, the reiserfs kernel code has been gradually cleaned up to be more readable. This patch does the same to the progs code. Signed-off-by: Jeff Mahoney <jeffm@suse.com>
This commit is contained in:
1 parent
b23d40f723
commit
47cff72748
51 files changed
+27279
-25108
No files matched your search
+506
-492
File diff suppressed because it is too large.
Load diff
+1445
-938
File diff suppressed because it is too large.
Load diff
+1910
-1766
File diff suppressed because it is too large.
Load diff
+102
-135
@@ -24,8 +24,6 @@
|
||||
|
||||
#include <asm/types.h>
|
||||
|
||||
|
||||
|
||||
#define DELTA 0x9E3779B9
|
||||
#define FULLROUNDS 10 /* 32 is overkill, 16 is strong crypto */
|
||||
#define PARTROUNDS 6 /* 6 gets complete mixing */
|
||||
@@ -55,113 +53,82 @@ typedef __u32 u32;
|
||||
h1 += b1; \
|
||||
} while(0)
|
||||
|
||||
|
||||
u32 keyed_hash(const signed char *msg, int len)
|
||||
{
|
||||
u32 k[] = { 0x9464a485, 0x542e1a94, 0x3e846bff, 0xb75bcfc3};
|
||||
u32 k[] = { 0x9464a485, 0x542e1a94, 0x3e846bff, 0xb75bcfc3 };
|
||||
|
||||
u32 h0 = k[0], h1 = k[1];
|
||||
u32 a, b, c, d;
|
||||
u32 pad;
|
||||
int i;
|
||||
|
||||
|
||||
pad = (u32)len | ((u32)len << 8);
|
||||
pad = (u32) len | ((u32) len << 8);
|
||||
pad |= pad << 16;
|
||||
|
||||
while(len >= 16)
|
||||
{
|
||||
a = (u32)msg[ 0] |
|
||||
(u32)msg[ 1] << 8 |
|
||||
(u32)msg[ 2] << 16|
|
||||
(u32)msg[ 3] << 24;
|
||||
b = (u32)msg[ 4] |
|
||||
(u32)msg[ 5] << 8 |
|
||||
(u32)msg[ 6] << 16|
|
||||
(u32)msg[ 7] << 24;
|
||||
c = (u32)msg[ 8] |
|
||||
(u32)msg[ 9] << 8 |
|
||||
(u32)msg[10] << 16|
|
||||
(u32)msg[11] << 24;
|
||||
d = (u32)msg[12] |
|
||||
(u32)msg[13] << 8 |
|
||||
(u32)msg[14] << 16|
|
||||
(u32)msg[15] << 24;
|
||||
|
||||
while (len >= 16) {
|
||||
a = (u32) msg[0] |
|
||||
(u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
|
||||
b = (u32) msg[4] |
|
||||
(u32) msg[5] << 8 | (u32) msg[6] << 16 | (u32) msg[7] << 24;
|
||||
c = (u32) msg[8] |
|
||||
(u32) msg[9] << 8 |
|
||||
(u32) msg[10] << 16 | (u32) msg[11] << 24;
|
||||
d = (u32) msg[12] |
|
||||
(u32) msg[13] << 8 |
|
||||
(u32) msg[14] << 16 | (u32) msg[15] << 24;
|
||||
|
||||
TEACORE(PARTROUNDS);
|
||||
|
||||
len -= 16;
|
||||
msg += 16;
|
||||
}
|
||||
|
||||
if (len >= 12)
|
||||
{
|
||||
if (len >= 12) {
|
||||
if (len >= 16)
|
||||
*(int *)0 = 0;
|
||||
*(int *)0 = 0;
|
||||
|
||||
a = (u32)msg[ 0] |
|
||||
(u32)msg[ 1] << 8 |
|
||||
(u32)msg[ 2] << 16|
|
||||
(u32)msg[ 3] << 24;
|
||||
b = (u32)msg[ 4] |
|
||||
(u32)msg[ 5] << 8 |
|
||||
(u32)msg[ 6] << 16|
|
||||
(u32)msg[ 7] << 24;
|
||||
c = (u32)msg[ 8] |
|
||||
(u32)msg[ 9] << 8 |
|
||||
(u32)msg[10] << 16|
|
||||
(u32)msg[11] << 24;
|
||||
a = (u32) msg[0] |
|
||||
(u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
|
||||
b = (u32) msg[4] |
|
||||
(u32) msg[5] << 8 | (u32) msg[6] << 16 | (u32) msg[7] << 24;
|
||||
c = (u32) msg[8] |
|
||||
(u32) msg[9] << 8 |
|
||||
(u32) msg[10] << 16 | (u32) msg[11] << 24;
|
||||
|
||||
d = pad;
|
||||
for(i = 12; i < len; i++)
|
||||
{
|
||||
for (i = 12; i < len; i++) {
|
||||
d <<= 8;
|
||||
d |= msg[i];
|
||||
}
|
||||
}
|
||||
else if (len >= 8)
|
||||
{
|
||||
} else if (len >= 8) {
|
||||
if (len >= 12)
|
||||
*(int *)0 = 0;
|
||||
a = (u32)msg[ 0] |
|
||||
(u32)msg[ 1] << 8 |
|
||||
(u32)msg[ 2] << 16|
|
||||
(u32)msg[ 3] << 24;
|
||||
b = (u32)msg[ 4] |
|
||||
(u32)msg[ 5] << 8 |
|
||||
(u32)msg[ 6] << 16|
|
||||
(u32)msg[ 7] << 24;
|
||||
*(int *)0 = 0;
|
||||
a = (u32) msg[0] |
|
||||
(u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
|
||||
b = (u32) msg[4] |
|
||||
(u32) msg[5] << 8 | (u32) msg[6] << 16 | (u32) msg[7] << 24;
|
||||
|
||||
c = d = pad;
|
||||
for(i = 8; i < len; i++)
|
||||
{
|
||||
for (i = 8; i < len; i++) {
|
||||
c <<= 8;
|
||||
c |= msg[i];
|
||||
}
|
||||
}
|
||||
else if (len >= 4)
|
||||
{
|
||||
} else if (len >= 4) {
|
||||
if (len >= 8)
|
||||
*(int *)0 = 0;
|
||||
a = (u32)msg[ 0] |
|
||||
(u32)msg[ 1] << 8 |
|
||||
(u32)msg[ 2] << 16|
|
||||
(u32)msg[ 3] << 24;
|
||||
*(int *)0 = 0;
|
||||
a = (u32) msg[0] |
|
||||
(u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
|
||||
|
||||
b = c = d = pad;
|
||||
for(i = 4; i < len; i++)
|
||||
{
|
||||
for (i = 4; i < len; i++) {
|
||||
b <<= 8;
|
||||
b |= msg[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (len >= 4)
|
||||
*(int *)0 = 0;
|
||||
*(int *)0 = 0;
|
||||
a = b = c = d = pad;
|
||||
for(i = 0; i < len; i++)
|
||||
{
|
||||
for (i = 0; i < len; i++) {
|
||||
a <<= 8;
|
||||
a |= msg[i];
|
||||
}
|
||||
@@ -169,83 +136,83 @@ u32 keyed_hash(const signed char *msg, int len)
|
||||
|
||||
TEACORE(FULLROUNDS);
|
||||
|
||||
return h0^h1;
|
||||
return h0 ^ h1;
|
||||
}
|
||||
|
||||
|
||||
u32 yura_hash (const signed char *msg, int len)
|
||||
u32 yura_hash(const signed char *msg, int len)
|
||||
{
|
||||
int j, pow;
|
||||
u32 a, c;
|
||||
int i;
|
||||
|
||||
for (pow=1,i=1; i < len; i++) pow = pow * 10;
|
||||
|
||||
if (len == 1)
|
||||
a = msg[0]-48;
|
||||
else
|
||||
a = (msg[0] - 48) * pow;
|
||||
|
||||
for (i=1; i < len; i++) {
|
||||
c = msg[i] - 48;
|
||||
for (pow=1,j=i; j < len-1; j++) pow = pow * 10;
|
||||
a = a + c * pow;
|
||||
}
|
||||
|
||||
for (; i < 40; i++) {
|
||||
c = '0' - 48;
|
||||
for (pow=1,j=i; j < len-1; j++) pow = pow * 10;
|
||||
a = a + c * pow;
|
||||
}
|
||||
|
||||
for (; i < 256; i++) {
|
||||
c = i;
|
||||
for (pow=1,j=i; j < len-1; j++) pow = pow * 10;
|
||||
a = a + c * pow;
|
||||
}
|
||||
|
||||
a = a << 7;
|
||||
return a;
|
||||
int j, pow;
|
||||
u32 a, c;
|
||||
int i;
|
||||
|
||||
for (pow = 1, i = 1; i < len; i++)
|
||||
pow = pow * 10;
|
||||
|
||||
if (len == 1)
|
||||
a = msg[0] - 48;
|
||||
else
|
||||
a = (msg[0] - 48) * pow;
|
||||
|
||||
for (i = 1; i < len; i++) {
|
||||
c = msg[i] - 48;
|
||||
for (pow = 1, j = i; j < len - 1; j++)
|
||||
pow = pow * 10;
|
||||
a = a + c * pow;
|
||||
}
|
||||
|
||||
for (; i < 40; i++) {
|
||||
c = '0' - 48;
|
||||
for (pow = 1, j = i; j < len - 1; j++)
|
||||
pow = pow * 10;
|
||||
a = a + c * pow;
|
||||
}
|
||||
|
||||
for (; i < 256; i++) {
|
||||
c = i;
|
||||
for (pow = 1, j = i; j < len - 1; j++)
|
||||
pow = pow * 10;
|
||||
a = a + c * pow;
|
||||
}
|
||||
|
||||
a = a << 7;
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
u32 r5_hash (const signed char *msg, int len)
|
||||
u32 r5_hash(const signed char *msg, int len)
|
||||
{
|
||||
u32 a=0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i ++) {
|
||||
a += msg[i] << 4;
|
||||
a += msg[i] >> 4;
|
||||
a *= 11;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
u32 a = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
a += msg[i] << 4;
|
||||
a += msg[i] >> 4;
|
||||
a *= 11;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main (void)
|
||||
int main(void)
|
||||
{
|
||||
char * name = 0;
|
||||
size_t n = 0;
|
||||
char *name = 0;
|
||||
size_t n = 0;
|
||||
|
||||
while (1) {
|
||||
getline (&name, &n, stdin);
|
||||
if (!strcmp (name, "\n"))
|
||||
break;
|
||||
name [strlen (name) - 1] = 0;
|
||||
printf ("tea %lu\n, r5 %lu\nyura %lu\n",
|
||||
keyed_hash (name, strlen (name)) & 0x7fffff80,
|
||||
r5_hash (name, strlen (name)) & 0x7fffff80,
|
||||
yura_hash (name, strlen (name)) & 0x7fffff80);
|
||||
free (name);
|
||||
name = 0;
|
||||
n = 0;
|
||||
}
|
||||
while (1) {
|
||||
getline(&name, &n, stdin);
|
||||
if (!strcmp(name, "\n"))
|
||||
break;
|
||||
name[strlen(name) - 1] = 0;
|
||||
printf("tea %lu\n, r5 %lu\nyura %lu\n",
|
||||
keyed_hash(name, strlen(name)) & 0x7fffff80,
|
||||
r5_hash(name, strlen(name)) & 0x7fffff80,
|
||||
yura_hash(name, strlen(name)) & 0x7fffff80);
|
||||
free(name);
|
||||
name = 0;
|
||||
n = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+764
-708
File diff suppressed because it is too large.
Load diff
+728
-698
File diff suppressed because it is too large.
Load diff
+971
-882
File diff suppressed because it is too large.
Load diff
+965
-950
File diff suppressed because it is too large.
Load diff
+876
-813
File diff suppressed because it is too large.
Load diff
+1177
-1137
File diff suppressed because it is too large.
Load diff
+270
-252
@@ -37,14 +37,12 @@
|
||||
*/
|
||||
#include "includes.h"
|
||||
|
||||
|
||||
/* Does the buffer contain a disk block which is in the tree. */
|
||||
inline int B_IS_IN_TREE (struct buffer_head * p_s_bh)
|
||||
inline int B_IS_IN_TREE(struct buffer_head *p_s_bh)
|
||||
{
|
||||
return ( get_blkh_level (B_BLK_HEAD (p_s_bh)) != FREE_LEVEL );
|
||||
return (get_blkh_level(B_BLK_HEAD(p_s_bh)) != FREE_LEVEL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Compare keys using REISERFS_SHORT_KEY_LEN fields.
|
||||
Returns: -1 if key1 < key2
|
||||
@@ -52,78 +50,75 @@ inline int B_IS_IN_TREE (struct buffer_head * p_s_bh)
|
||||
1 if key1 > key2
|
||||
*/
|
||||
|
||||
int comp_short_keys (const void * k1, const void * k2)
|
||||
int comp_short_keys(const void *k1, const void *k2)
|
||||
{
|
||||
int n_key_length = REISERFS_SHORT_KEY_LEN;
|
||||
__u32 * p_s_key1 = (__u32 *)k1;
|
||||
__u32 * p_s_key2 = (__u32 *)k2;
|
||||
__u32 u1, u2;
|
||||
int n_key_length = REISERFS_SHORT_KEY_LEN;
|
||||
__u32 *p_s_key1 = (__u32 *) k1;
|
||||
__u32 *p_s_key2 = (__u32 *) k2;
|
||||
__u32 u1, u2;
|
||||
|
||||
for( ; n_key_length--; ++p_s_key1, ++p_s_key2 ) {
|
||||
u1 = d32_get(p_s_key1, 0) ;
|
||||
u2 = d32_get(p_s_key2, 0) ;
|
||||
if ( u1 < u2 )
|
||||
return -1;
|
||||
if ( u1 > u2 )
|
||||
return 1;
|
||||
}
|
||||
for (; n_key_length--; ++p_s_key1, ++p_s_key2) {
|
||||
u1 = d32_get(p_s_key1, 0);
|
||||
u2 = d32_get(p_s_key2, 0);
|
||||
if (u1 < u2)
|
||||
return -1;
|
||||
if (u1 > u2)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int comp_keys_3 (const void * p1, const void * p2)
|
||||
int comp_keys_3(const void *p1, const void *p2)
|
||||
{
|
||||
int retval;
|
||||
const struct reiserfs_key *k1 = p1;
|
||||
const struct reiserfs_key *k2 = p2;
|
||||
loff_t off1, off2;
|
||||
int retval;
|
||||
const struct reiserfs_key *k1 = p1;
|
||||
const struct reiserfs_key *k2 = p2;
|
||||
loff_t off1, off2;
|
||||
|
||||
retval = comp_short_keys (k1, k2);
|
||||
if (retval)
|
||||
return retval;
|
||||
off1 = get_offset(k1) ;
|
||||
off2 = get_offset(k2) ;
|
||||
if (off1 < off2)
|
||||
return -1;
|
||||
retval = comp_short_keys(k1, k2);
|
||||
if (retval)
|
||||
return retval;
|
||||
off1 = get_offset(k1);
|
||||
off2 = get_offset(k2);
|
||||
if (off1 < off2)
|
||||
return -1;
|
||||
|
||||
if (off1 > off2)
|
||||
return 1;
|
||||
if (off1 > off2)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Compare keys using all 4 key fields.
|
||||
Returns: -1 if key1 < key2
|
||||
0 if key1 = key2
|
||||
1 if key1 > key2
|
||||
*/
|
||||
int comp_keys (const void * p1, const void * p2)
|
||||
int comp_keys(const void *p1, const void *p2)
|
||||
{
|
||||
int retval;
|
||||
const struct reiserfs_key *k1 = p1;
|
||||
const struct reiserfs_key *k2 = p2;
|
||||
__u32 u1, u2;
|
||||
int retval;
|
||||
const struct reiserfs_key *k1 = p1;
|
||||
const struct reiserfs_key *k2 = p2;
|
||||
__u32 u1, u2;
|
||||
|
||||
retval = comp_keys_3 (k1, k2);
|
||||
if (retval)
|
||||
return retval;
|
||||
retval = comp_keys_3(k1, k2);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
u1 = get_type (k1);
|
||||
u2 = get_type (k2);
|
||||
u1 = get_type(k1);
|
||||
u2 = get_type(k2);
|
||||
|
||||
if (u1 < u2)
|
||||
return -1;
|
||||
if (u1 < u2)
|
||||
return -1;
|
||||
|
||||
if (u1 > u2)
|
||||
return 1;
|
||||
if (u1 > u2)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Binary search toolkit function *
|
||||
* Search for an item in the array by the item key *
|
||||
@@ -138,42 +133,51 @@ int comp_keys (const void * p1, const void * p2)
|
||||
there are no possible items, and we have not found it. With each examination we
|
||||
cut the number of possible items it could be by one more than half rounded down,
|
||||
or we find it. */
|
||||
int bin_search (
|
||||
void * p_v_key, /* Key to search for. */
|
||||
void * p_v_base, /* First item in the array. */
|
||||
int p_n_num, /* Number of items in the array. */
|
||||
int p_n_width, /* Item size in the array.
|
||||
searched. Lest the reader be
|
||||
confused, note that this is crafted
|
||||
as a general function, and when it
|
||||
is applied specifically to the array
|
||||
of item headers in a node, p_n_width
|
||||
is actually the item header size not
|
||||
the item size. */
|
||||
unsigned int * p_n_pos /* Number of the searched
|
||||
for element. */
|
||||
) {
|
||||
int n_rbound, n_lbound, n_j;
|
||||
int bin_search(void *p_v_key, /* Key to search for. */
|
||||
void *p_v_base, /* First item in the array. */
|
||||
int p_n_num, /* Number of items in the array. */
|
||||
int p_n_width, /* Item size in the array.
|
||||
searched. Lest the reader be
|
||||
confused, note that this is crafted
|
||||
as a general function, and when it
|
||||
is applied specifically to the array
|
||||
of item headers in a node, p_n_width
|
||||
is actually the item header size not
|
||||
the item size. */
|
||||
unsigned int *p_n_pos /* Number of the searched
|
||||
for element. */
|
||||
)
|
||||
{
|
||||
int n_rbound, n_lbound, n_j;
|
||||
|
||||
for ( n_j = ((n_rbound = p_n_num - 1) + (n_lbound = 0))/2; n_lbound <= n_rbound; n_j = (n_rbound + n_lbound)/2 )
|
||||
switch( COMP_KEYS((struct reiserfs_key *)((char * )p_v_base + n_j * p_n_width), p_v_key) ) {
|
||||
case -1: n_lbound = n_j + 1; continue;
|
||||
case 1: n_rbound = n_j - 1; continue;
|
||||
case 0: *p_n_pos = n_j; return ITEM_FOUND; /* Key found in the array. */
|
||||
}
|
||||
for (n_j = ((n_rbound = p_n_num - 1) + (n_lbound = 0)) / 2;
|
||||
n_lbound <= n_rbound; n_j = (n_rbound + n_lbound) / 2)
|
||||
switch (COMP_KEYS
|
||||
((struct reiserfs_key *)((char *)p_v_base +
|
||||
n_j * p_n_width), p_v_key)) {
|
||||
case -1:
|
||||
n_lbound = n_j + 1;
|
||||
continue;
|
||||
case 1:
|
||||
n_rbound = n_j - 1;
|
||||
continue;
|
||||
case 0:
|
||||
*p_n_pos = n_j;
|
||||
return ITEM_FOUND; /* Key found in the array. */
|
||||
}
|
||||
|
||||
/* bin_search did not find given key, it returns position of key,
|
||||
that is minimal and greater than the given one. */
|
||||
*p_n_pos = n_lbound;
|
||||
return ITEM_NOT_FOUND;
|
||||
/* bin_search did not find given key, it returns position of key,
|
||||
that is minimal and greater than the given one. */
|
||||
*p_n_pos = n_lbound;
|
||||
return ITEM_NOT_FOUND;
|
||||
}
|
||||
|
||||
/* Minimal possible key. It is never in the tree. */
|
||||
struct reiserfs_key MIN_KEY = {0, 0, {{0, 0},}};
|
||||
struct reiserfs_key MIN_KEY = { 0, 0, {{0, 0},} };
|
||||
|
||||
/* Maximal possible key. It is never in the tree. */
|
||||
struct reiserfs_key MAX_KEY = {0xffffffff, 0xffffffff, {{0xffffffff, 0xffffffff},}};
|
||||
|
||||
struct reiserfs_key MAX_KEY =
|
||||
{ 0xffffffff, 0xffffffff, {{0xffffffff, 0xffffffff},} };
|
||||
|
||||
/* Get delimiting key of the buffer by looking for it in the buffers in the
|
||||
path, starting from the bottom of the path, and going upwards. We must
|
||||
@@ -181,73 +185,82 @@ struct reiserfs_key MAX_KEY = {0xffffffff, 0xffffffff, {{0xffffffff, 0xffffffff
|
||||
there is no delimiting key in the tree (buffer is first or last buffer in
|
||||
tree), and in this case we return a special key, either MIN_KEY or
|
||||
MAX_KEY. */
|
||||
struct reiserfs_key *get_lkey (struct reiserfs_path *p_s_chk_path,
|
||||
reiserfs_filsys_t * fs)
|
||||
struct reiserfs_key *get_lkey(struct reiserfs_path *p_s_chk_path,
|
||||
reiserfs_filsys_t *fs)
|
||||
{
|
||||
struct reiserfs_super_block * sb;
|
||||
int n_position, n_path_offset = p_s_chk_path->path_length;
|
||||
struct buffer_head * p_s_parent;
|
||||
|
||||
sb = fs->fs_ondisk_sb;
|
||||
struct reiserfs_super_block *sb;
|
||||
int n_position, n_path_offset = p_s_chk_path->path_length;
|
||||
struct buffer_head *p_s_parent;
|
||||
|
||||
/* While not higher in path than first element. */
|
||||
while ( n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET ) {
|
||||
/* Parent at the path is not in the tree now. */
|
||||
if ( ! B_IS_IN_TREE(p_s_parent = PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)) )
|
||||
return &MAX_KEY;
|
||||
/* Check whether position in the parent is correct. */
|
||||
if ( (n_position = PATH_OFFSET_POSITION(p_s_chk_path, n_path_offset)) > B_NR_ITEMS(p_s_parent) )
|
||||
return &MAX_KEY;
|
||||
/* Check whether parent at the path really points to the child. */
|
||||
if ( get_dc_child_blocknr (B_N_CHILD (p_s_parent, n_position)) !=
|
||||
PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset + 1)->b_blocknr )
|
||||
return &MAX_KEY;
|
||||
/* Return delimiting key if position in the parent is not equal to zero. */
|
||||
if ( n_position )
|
||||
return B_N_PDELIM_KEY(p_s_parent, n_position - 1);
|
||||
}
|
||||
/* Return MIN_KEY if we are in the root of the buffer tree. */
|
||||
if ( PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->b_blocknr ==
|
||||
get_sb_root_block (sb) )
|
||||
return &MIN_KEY;
|
||||
return &MAX_KEY;
|
||||
sb = fs->fs_ondisk_sb;
|
||||
|
||||
/* While not higher in path than first element. */
|
||||
while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
|
||||
/* Parent at the path is not in the tree now. */
|
||||
if (!B_IS_IN_TREE
|
||||
(p_s_parent =
|
||||
PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)))
|
||||
return &MAX_KEY;
|
||||
/* Check whether position in the parent is correct. */
|
||||
if ((n_position =
|
||||
PATH_OFFSET_POSITION(p_s_chk_path,
|
||||
n_path_offset)) >
|
||||
B_NR_ITEMS(p_s_parent))
|
||||
return &MAX_KEY;
|
||||
/* Check whether parent at the path really points to the child. */
|
||||
if (get_dc_child_blocknr(B_N_CHILD(p_s_parent, n_position)) !=
|
||||
PATH_OFFSET_PBUFFER(p_s_chk_path,
|
||||
n_path_offset + 1)->b_blocknr)
|
||||
return &MAX_KEY;
|
||||
/* Return delimiting key if position in the parent is not equal to zero. */
|
||||
if (n_position)
|
||||
return B_N_PDELIM_KEY(p_s_parent, n_position - 1);
|
||||
}
|
||||
/* Return MIN_KEY if we are in the root of the buffer tree. */
|
||||
if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->
|
||||
b_blocknr == get_sb_root_block(sb))
|
||||
return &MIN_KEY;
|
||||
return &MAX_KEY;
|
||||
}
|
||||
|
||||
|
||||
/* Get delimiting key of the buffer at the path and its right neighbor. */
|
||||
struct reiserfs_key *get_rkey (struct reiserfs_path *p_s_chk_path,
|
||||
reiserfs_filsys_t * fs)
|
||||
struct reiserfs_key *get_rkey(struct reiserfs_path *p_s_chk_path,
|
||||
reiserfs_filsys_t *fs)
|
||||
{
|
||||
struct reiserfs_super_block * sb;
|
||||
int n_position,
|
||||
n_path_offset = p_s_chk_path->path_length;
|
||||
struct buffer_head * p_s_parent;
|
||||
struct reiserfs_super_block *sb;
|
||||
int n_position, n_path_offset = p_s_chk_path->path_length;
|
||||
struct buffer_head *p_s_parent;
|
||||
|
||||
sb = fs->fs_ondisk_sb;
|
||||
sb = fs->fs_ondisk_sb;
|
||||
|
||||
while ( n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET ) {
|
||||
/* Parent at the path is not in the tree now. */
|
||||
if ( ! B_IS_IN_TREE(p_s_parent = PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)) )
|
||||
return &MIN_KEY;
|
||||
/* Check whether position in the parrent is correct. */
|
||||
if ( (n_position = PATH_OFFSET_POSITION(p_s_chk_path, n_path_offset)) > B_NR_ITEMS(p_s_parent) )
|
||||
return &MIN_KEY;
|
||||
/* Check whether parent at the path really points to the child. */
|
||||
if ( get_dc_child_blocknr (B_N_CHILD (p_s_parent, n_position)) !=
|
||||
PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset + 1)->b_blocknr )
|
||||
return &MIN_KEY;
|
||||
/* Return delimiting key if position in the parent is not the last one. */
|
||||
if ( n_position != B_NR_ITEMS(p_s_parent) )
|
||||
return B_N_PDELIM_KEY(p_s_parent, n_position);
|
||||
}
|
||||
/* Return MAX_KEY if we are in the root of the buffer tree. */
|
||||
if ( PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->b_blocknr ==
|
||||
get_sb_root_block (sb) )
|
||||
return &MAX_KEY;
|
||||
return &MIN_KEY;
|
||||
while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
|
||||
/* Parent at the path is not in the tree now. */
|
||||
if (!B_IS_IN_TREE
|
||||
(p_s_parent =
|
||||
PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)))
|
||||
return &MIN_KEY;
|
||||
/* Check whether position in the parrent is correct. */
|
||||
if ((n_position =
|
||||
PATH_OFFSET_POSITION(p_s_chk_path,
|
||||
n_path_offset)) >
|
||||
B_NR_ITEMS(p_s_parent))
|
||||
return &MIN_KEY;
|
||||
/* Check whether parent at the path really points to the child. */
|
||||
if (get_dc_child_blocknr(B_N_CHILD(p_s_parent, n_position)) !=
|
||||
PATH_OFFSET_PBUFFER(p_s_chk_path,
|
||||
n_path_offset + 1)->b_blocknr)
|
||||
return &MIN_KEY;
|
||||
/* Return delimiting key if position in the parent is not the last one. */
|
||||
if (n_position != B_NR_ITEMS(p_s_parent))
|
||||
return B_N_PDELIM_KEY(p_s_parent, n_position);
|
||||
}
|
||||
/* Return MAX_KEY if we are in the root of the buffer tree. */
|
||||
if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->
|
||||
b_blocknr == get_sb_root_block(sb))
|
||||
return &MAX_KEY;
|
||||
return &MIN_KEY;
|
||||
}
|
||||
|
||||
|
||||
/* Check whether a key is contained in the tree rooted from a buffer at a
|
||||
path. This works by looking at the left and right delimiting keys for the
|
||||
buffer in the last path_element in the path. These delimiting keys are
|
||||
@@ -255,31 +268,30 @@ struct reiserfs_key *get_rkey (struct reiserfs_path *p_s_chk_path,
|
||||
the first or last node in the tree order then one of the delimiting keys
|
||||
may be absent, and in this case get_lkey and get_rkey return a special key
|
||||
which is MIN_KEY or MAX_KEY. */
|
||||
static inline int key_in_buffer (
|
||||
struct reiserfs_path * p_s_chk_path, /* Path which should be checked. */
|
||||
struct reiserfs_key * p_s_key, /* Key which should be checked. */
|
||||
reiserfs_filsys_t * fs /* Super block pointer. */
|
||||
) {
|
||||
static inline int key_in_buffer(struct reiserfs_path *p_s_chk_path, /* Path which should be checked. */
|
||||
struct reiserfs_key *p_s_key, /* Key which should be checked. */
|
||||
reiserfs_filsys_t *fs /* Super block pointer. */
|
||||
)
|
||||
{
|
||||
|
||||
if ( COMP_KEYS(get_lkey(p_s_chk_path, fs), p_s_key) == 1 )
|
||||
return 0;
|
||||
if ( COMP_KEYS(p_s_key, get_rkey(p_s_chk_path, fs)) != -1 )
|
||||
return 0;
|
||||
return 1;
|
||||
if (COMP_KEYS(get_lkey(p_s_chk_path, fs), p_s_key) == 1)
|
||||
return 0;
|
||||
if (COMP_KEYS(p_s_key, get_rkey(p_s_chk_path, fs)) != -1)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Release all buffers in the path. */
|
||||
void pathrelse (struct reiserfs_path *p_s_search_path)
|
||||
void pathrelse(struct reiserfs_path *p_s_search_path)
|
||||
{
|
||||
int n_path_offset = p_s_search_path->path_length;
|
||||
|
||||
while ( n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET )
|
||||
brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
|
||||
int n_path_offset = p_s_search_path->path_length;
|
||||
|
||||
p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
|
||||
while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET)
|
||||
brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
|
||||
|
||||
p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Algorithm SearchByKey *
|
||||
* look for item in internal tree on the disk by its key *
|
||||
@@ -302,115 +314,121 @@ void pathrelse (struct reiserfs_path *p_s_search_path)
|
||||
key. search_by_key returns a path that must be checked for the
|
||||
correctness of the top of the path but need not be checked for the
|
||||
correctness of the bottom of the path */
|
||||
int search_by_key (reiserfs_filsys_t * fs,
|
||||
struct reiserfs_key *p_s_key, /* Key to search */
|
||||
struct reiserfs_path *p_s_search_path,/* This structure was
|
||||
allocated and
|
||||
initialized by the
|
||||
calling
|
||||
function. It is
|
||||
filled up by this
|
||||
function. */
|
||||
int n_stop_level) /* How far down the tree to search.*/
|
||||
{
|
||||
struct reiserfs_super_block * sb;
|
||||
unsigned int n_block_number,
|
||||
expected_level,
|
||||
n_block_size = fs->fs_blocksize;
|
||||
struct buffer_head * p_s_bh;
|
||||
struct reiserfs_path_element * p_s_last_element;
|
||||
int n_retval;
|
||||
int search_by_key(reiserfs_filsys_t *fs, struct reiserfs_key *p_s_key, /* Key to search */
|
||||
struct reiserfs_path *p_s_search_path, /* This structure was
|
||||
allocated and
|
||||
initialized by the
|
||||
calling
|
||||
function. It is
|
||||
filled up by this
|
||||
function. */
|
||||
int n_stop_level)
|
||||
{ /* How far down the tree to search. */
|
||||
struct reiserfs_super_block *sb;
|
||||
unsigned int n_block_number,
|
||||
expected_level, n_block_size = fs->fs_blocksize;
|
||||
struct buffer_head *p_s_bh;
|
||||
struct reiserfs_path_element *p_s_last_element;
|
||||
int n_retval;
|
||||
|
||||
sb = fs->fs_ondisk_sb;
|
||||
n_block_number = get_sb_root_block(sb);
|
||||
expected_level = get_sb_tree_height(sb);
|
||||
|
||||
sb = fs->fs_ondisk_sb;
|
||||
n_block_number = get_sb_root_block (sb);
|
||||
expected_level = get_sb_tree_height (sb);
|
||||
|
||||
/* As we add each node to a path we increase its count. This
|
||||
means that we must be careful to release all nodes in a path
|
||||
before we either discard the path struct or re-use the path
|
||||
struct, as we do here. */
|
||||
pathrelse (p_s_search_path);
|
||||
/* As we add each node to a path we increase its count. This
|
||||
means that we must be careful to release all nodes in a path
|
||||
before we either discard the path struct or re-use the path
|
||||
struct, as we do here. */
|
||||
pathrelse(p_s_search_path);
|
||||
|
||||
/* With each iteration of this loop we search through the items in
|
||||
the current node, and calculate the next current node(next path
|
||||
element) for the next iteration of this loop.. */
|
||||
while (1) {
|
||||
|
||||
/* With each iteration of this loop we search through the items in
|
||||
the current node, and calculate the next current node(next path
|
||||
element) for the next iteration of this loop.. */
|
||||
while ( 1 ) {
|
||||
/* prep path to have another element added to it. */
|
||||
p_s_last_element =
|
||||
PATH_OFFSET_PELEMENT(p_s_search_path,
|
||||
++p_s_search_path->path_length);
|
||||
expected_level--;
|
||||
|
||||
/* prep path to have another element added to it. */
|
||||
p_s_last_element = PATH_OFFSET_PELEMENT(p_s_search_path, ++p_s_search_path->path_length);
|
||||
expected_level --;
|
||||
/* Read the next tree node, and set the last element in the
|
||||
path to have a pointer to it. */
|
||||
if (!(p_s_bh = p_s_last_element->pe_buffer =
|
||||
bread(fs->fs_dev, n_block_number, n_block_size))) {
|
||||
p_s_search_path->path_length--;
|
||||
pathrelse(p_s_search_path);
|
||||
return IO_ERROR;
|
||||
}
|
||||
|
||||
/* Read the next tree node, and set the last element in the
|
||||
path to have a pointer to it. */
|
||||
if ( ! (p_s_bh = p_s_last_element->pe_buffer =
|
||||
bread (fs->fs_dev, n_block_number, n_block_size)) ) {
|
||||
p_s_search_path->path_length --;
|
||||
pathrelse(p_s_search_path);
|
||||
return IO_ERROR;
|
||||
/* It is possible that schedule occured. We must check whether
|
||||
the key to search is still in the tree rooted from the
|
||||
current buffer. If not then repeat search from the root. */
|
||||
if (!B_IS_IN_TREE(p_s_bh) ||
|
||||
!key_in_buffer(p_s_search_path, p_s_key, fs))
|
||||
reiserfs_panic
|
||||
("search_by_key: something wrong with the tree");
|
||||
|
||||
/* make sure, that the node contents look like a node of
|
||||
certain level */
|
||||
if (!is_tree_node(p_s_bh, expected_level)) {
|
||||
print_block(stderr, 0, p_s_bh, 3, -1, -1);
|
||||
reiserfs_panic("search_by_key: expected level %d",
|
||||
expected_level);
|
||||
}
|
||||
|
||||
/* ok, we have acquired next formatted node in the tree */
|
||||
n_retval =
|
||||
bin_search(p_s_key, B_N_PITEM_HEAD(p_s_bh, 0),
|
||||
B_NR_ITEMS(p_s_bh),
|
||||
is_leaf_node(p_s_bh) ? IH_SIZE : KEY_SIZE,
|
||||
&(p_s_last_element->pe_position));
|
||||
if (get_blkh_level(B_BLK_HEAD(p_s_bh)) == n_stop_level)
|
||||
return n_retval;
|
||||
|
||||
/* we are not in the stop level */
|
||||
if (n_retval == ITEM_FOUND)
|
||||
/* item has been found, so we choose the pointer which is
|
||||
to the right of the found one */
|
||||
p_s_last_element->pe_position++;
|
||||
|
||||
/* if item was not found we choose the position which is to
|
||||
the left of the found item. This requires no code,
|
||||
bin_search did it already. */
|
||||
|
||||
/* So we have chosen a position in the current node which is
|
||||
an internal node. Now we calculate child block number by
|
||||
position in the node. */
|
||||
n_block_number =
|
||||
get_dc_child_blocknr(B_N_CHILD
|
||||
(p_s_bh,
|
||||
p_s_last_element->pe_position));
|
||||
}
|
||||
|
||||
/* It is possible that schedule occured. We must check whether
|
||||
the key to search is still in the tree rooted from the
|
||||
current buffer. If not then repeat search from the root. */
|
||||
if (!B_IS_IN_TREE (p_s_bh) ||
|
||||
! key_in_buffer(p_s_search_path, p_s_key, fs))
|
||||
reiserfs_panic ("search_by_key: something wrong with the tree");
|
||||
|
||||
/* make sure, that the node contents look like a node of
|
||||
certain level */
|
||||
if (!is_tree_node (p_s_bh, expected_level)) {
|
||||
print_block (stderr, 0, p_s_bh, 3, -1, -1);
|
||||
reiserfs_panic ("search_by_key: expected level %d", expected_level);
|
||||
}
|
||||
|
||||
/* ok, we have acquired next formatted node in the tree */
|
||||
n_retval = bin_search (p_s_key, B_N_PITEM_HEAD(p_s_bh, 0), B_NR_ITEMS(p_s_bh),
|
||||
is_leaf_node (p_s_bh) ? IH_SIZE : KEY_SIZE, &(p_s_last_element->pe_position));
|
||||
if (get_blkh_level (B_BLK_HEAD (p_s_bh)) == n_stop_level)
|
||||
return n_retval;
|
||||
|
||||
/* we are not in the stop level */
|
||||
if (n_retval == ITEM_FOUND)
|
||||
/* item has been found, so we choose the pointer which is
|
||||
to the right of the found one */
|
||||
p_s_last_element->pe_position++;
|
||||
|
||||
/* if item was not found we choose the position which is to
|
||||
the left of the found item. This requires no code,
|
||||
bin_search did it already.*/
|
||||
|
||||
/* So we have chosen a position in the current node which is
|
||||
an internal node. Now we calculate child block number by
|
||||
position in the node. */
|
||||
n_block_number = get_dc_child_blocknr (B_N_CHILD (p_s_bh, p_s_last_element->pe_position));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int bin_search_in_dir_item (struct item_head * ih, struct reiserfs_de_head * deh,
|
||||
struct reiserfs_key *key, int * pos_in_item)
|
||||
int bin_search_in_dir_item(struct item_head *ih, struct reiserfs_de_head *deh,
|
||||
struct reiserfs_key *key, int *pos_in_item)
|
||||
{
|
||||
int rbound, lbound, j;
|
||||
int rbound, lbound, j;
|
||||
|
||||
lbound = 0;
|
||||
rbound = get_ih_entry_count (ih) - 1;
|
||||
lbound = 0;
|
||||
rbound = get_ih_entry_count(ih) - 1;
|
||||
|
||||
for (j = (rbound + lbound) / 2; lbound <= rbound; j = (rbound + lbound) / 2) {
|
||||
if (get_offset (key) < get_deh_offset (deh + j)) {
|
||||
rbound = j - 1;
|
||||
continue;
|
||||
for (j = (rbound + lbound) / 2; lbound <= rbound;
|
||||
j = (rbound + lbound) / 2) {
|
||||
if (get_offset(key) < get_deh_offset(deh + j)) {
|
||||
rbound = j - 1;
|
||||
continue;
|
||||
}
|
||||
if (get_offset(key) > get_deh_offset(deh + j)) {
|
||||
lbound = j + 1;
|
||||
continue;
|
||||
}
|
||||
/* key found */
|
||||
*pos_in_item = j;
|
||||
return POSITION_FOUND;
|
||||
}
|
||||
if (get_offset (key) > get_deh_offset (deh + j)) {
|
||||
lbound = j + 1;
|
||||
continue;
|
||||
}
|
||||
/* key found */
|
||||
*pos_in_item = j;
|
||||
return POSITION_FOUND;
|
||||
}
|
||||
|
||||
*pos_in_item = lbound;
|
||||
return POSITION_NOT_FOUND;
|
||||
|
||||
*pos_in_item = lbound;
|
||||
return POSITION_NOT_FOUND;
|
||||
}
|
||||
Reference in new issue
Block a user