2001-10-19 18:36:57 +04:00
/*
* Copyright ( C ) 2001 Sistina Software ( UK ) Limited .
*
2001-10-31 15:47:01 +03:00
* This file is released under the LGPL .
2001-10-19 18:36:57 +04:00
*/
# include "ttree.h"
# include "pool.h"
# include "log.h"
struct node {
unsigned k ;
struct node * l , * m , * r ;
void * data ;
} ;
struct ttree {
int klen ;
struct pool * mem ;
struct node * root ;
} ;
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
struct node * * _lookup_single ( struct node * * c , unsigned int k )
2001-10-19 18:36:57 +04:00
{
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
while ( * c ) {
if ( k < ( * c ) - > k )
c = & ( ( * c ) - > l ) ;
2001-10-19 18:36:57 +04:00
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
else if ( k > ( * c ) - > k )
c = & ( ( * c ) - > r ) ;
else {
c = & ( ( * c ) - > m ) ;
break ;
}
2001-10-19 18:36:57 +04:00
}
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
return c ;
2001-10-19 18:36:57 +04:00
}
void * ttree_lookup ( struct ttree * tt , unsigned * key )
{
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
struct node * * c = & tt - > root ;
2001-10-19 18:36:57 +04:00
int count = tt - > klen ;
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
while ( * c & & count ) {
2001-10-21 14:24:10 +04:00
c = _lookup_single ( c , * key + + ) ;
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
count - - ;
2001-10-19 18:36:57 +04:00
}
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
return * c ? ( * c ) - > data : NULL ;
2001-10-19 18:36:57 +04:00
}
2001-10-21 14:24:10 +04:00
static struct node * _node ( struct pool * mem , unsigned int k )
2001-10-19 18:36:57 +04:00
{
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
struct node * n = pool_zalloc ( mem , sizeof ( * n ) ) ;
2001-10-19 18:36:57 +04:00
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
if ( n )
n - > k = k ;
2001-10-19 18:36:57 +04:00
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
return n ;
}
2001-10-19 18:36:57 +04:00
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
int ttree_insert ( struct ttree * tt , unsigned int * key , void * data )
{
struct node * * c = & tt - > root ;
int count = tt - > klen ;
unsigned int k ;
2001-10-19 18:36:57 +04:00
2001-10-25 17:08:29 +04:00
do {
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
k = * key + + ;
c = _lookup_single ( c , k ) ;
2001-10-21 14:24:10 +04:00
count - - ;
2001-10-25 17:08:29 +04:00
} while ( * c & & count ) ;
2001-10-19 18:36:57 +04:00
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
if ( ! * c ) {
count + + ;
2001-10-19 18:36:57 +04:00
while ( count - - ) {
2001-10-21 14:24:10 +04:00
if ( ! ( * c = _node ( tt - > mem , k ) ) ) {
2001-10-19 18:36:57 +04:00
stack ;
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
return 0 ;
2001-10-19 18:36:57 +04:00
}
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
k = * key + + ;
2001-10-19 18:36:57 +04:00
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
if ( count )
c = & ( ( * c ) - > m ) ;
}
}
( * c ) - > data = data ;
2001-10-19 18:36:57 +04:00
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
return 1 ;
}
2001-10-19 18:36:57 +04:00
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
struct ttree * ttree_create ( struct pool * mem , unsigned int klen )
{
struct ttree * tt ;
2001-10-19 18:36:57 +04:00
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
if ( ! ( tt = pool_zalloc ( mem , sizeof ( * tt ) ) ) ) {
stack ;
return NULL ;
2001-10-19 18:36:57 +04:00
}
o Filter for the dev cache that takes values from config file:
devices {
# first match is final, eg. /dev/ide/cdrom
# get's rejected due to the first pattern
filter=["r/cdrom/", # don't touch the music !
"a/hd[a-d][0-9]+/",
"a/ide/",
"a/sd/",
"a/md/",
"a|loop/[0-9]+|", # accept devfs style loop back
"r/loop/", # and reject old style
"a/dasd/",
"a/dac960/",
"a/nbd/",
"a/ida/",
"a/cciss/",
"a/ubd/",
"r/.*/"] # reject all others
}
Alasdair this is ready to roll into the tools now.
2001-10-19 22:20:37 +04:00
tt - > klen = klen ;
tt - > mem = mem ;
return tt ;
2001-10-19 18:36:57 +04:00
}