1 /* Copyright 2003 by Hans Reiser, licensing governed by
4 /* Black box item implementation */
6 #include "../../forward.h"
7 #include "../../debug.h"
8 #include "../../dformat.h"
9 #include "../../kassign.h"
10 #include "../../coord.h"
11 #include "../../tree.h"
12 #include "../../lock.h"
16 #include "../plugin.h"
19 store_black_box(reiser4_tree
* tree
,
20 const reiser4_key
* key
, void *data
, int length
)
23 reiser4_item_data idata
;
27 memset(&idata
, 0, sizeof idata
);
31 idata
.length
= length
;
32 idata
.iplug
= item_plugin_by_id(BLACK_BOX_ID
);
35 result
= insert_by_key(tree
, key
,
36 &idata
, &coord
, &lh
, LEAF_LEVEL
, CBK_UNIQUE
);
41 item_length_by_coord(&coord
) == length
)));
48 load_black_box(reiser4_tree
* tree
,
49 reiser4_key
* key
, void *data
, int length
, int exact
)
56 result
= coord_by_key(tree
, key
,
57 &coord
, &lh
, ZNODE_READ_LOCK
,
58 exact
? FIND_EXACT
: FIND_MAX_NOT_MORE_THAN
,
59 LEAF_LEVEL
, LEAF_LEVEL
, CBK_UNIQUE
, NULL
);
64 result
= zload(coord
.node
);
66 ilen
= item_length_by_coord(&coord
);
68 memcpy(data
, item_body_by_coord(&coord
), ilen
);
69 unit_key_by_coord(&coord
, key
);
72 * item is larger than buffer provided by the
73 * user. Only issue a warning if @exact is
74 * set. If @exact is false, we are iterating
75 * over all safe-links and here we are reaching
76 * the end of the iteration.
78 warning("nikita-3415",
79 "Wrong black box length: %i > %i",
81 result
= RETERR(-EIO
);
93 update_black_box(reiser4_tree
* tree
,
94 const reiser4_key
* key
, void *data
, int length
)
101 result
= coord_by_key(tree
, key
,
102 &coord
, &lh
, ZNODE_READ_LOCK
,
104 LEAF_LEVEL
, LEAF_LEVEL
, CBK_UNIQUE
, NULL
);
108 result
= zload(coord
.node
);
110 ilen
= item_length_by_coord(&coord
);
111 if (length
<= ilen
) {
112 memcpy(item_body_by_coord(&coord
), data
,
115 warning("nikita-3437",
116 "Wrong black box length: %i < %i",
118 result
= RETERR(-EIO
);
129 int kill_black_box(reiser4_tree
* tree
, const reiser4_key
* key
)
131 return reiser4_cut_tree(tree
, key
, key
, NULL
, 1);
136 c-indentation-style: "K&R"