revert-mm-fix-blkdev-size-calculation-in-generic_write_checks
[linux-2.6/linux-trees-mm.git] / fs / reiser4 / key.c
blob384c318f8b77da7d1036d3eb0512370b03a2a773
1 /* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
3 /* Key manipulations. */
5 #include "debug.h"
6 #include "key.h"
7 #include "super.h"
8 #include "reiser4.h"
10 #include <linux/types.h> /* for __u?? */
12 /* Minimal possible key: all components are zero. It is presumed that this is
13 independent of key scheme. */
14 static const reiser4_key MINIMAL_KEY = {
15 .el = {
16 0ull,
17 ON_LARGE_KEY(0ull,)
18 0ull,
19 0ull
23 /* Maximal possible key: all components are ~0. It is presumed that this is
24 independent of key scheme. */
25 static const reiser4_key MAXIMAL_KEY = {
26 .el = {
27 __constant_cpu_to_le64(~0ull),
28 ON_LARGE_KEY(__constant_cpu_to_le64(~0ull),)
29 __constant_cpu_to_le64(~0ull),
30 __constant_cpu_to_le64(~0ull)
34 /* Initialize key. */
35 void reiser4_key_init(reiser4_key * key /* key to init */ )
37 assert("nikita-1169", key != NULL);
38 memset(key, 0, sizeof *key);
41 /* minimal possible key in the tree. Return pointer to the static storage. */
42 const reiser4_key *reiser4_min_key(void)
44 return &MINIMAL_KEY;
47 /* maximum possible key in the tree. Return pointer to the static storage. */
48 const reiser4_key *reiser4_max_key(void)
50 return &MAXIMAL_KEY;
53 #if REISER4_DEBUG
54 /* debugging aid: print symbolic name of key type */
55 static const char *type_name(unsigned int key_type /* key type */ )
57 switch (key_type) {
58 case KEY_FILE_NAME_MINOR:
59 return "file name";
60 case KEY_SD_MINOR:
61 return "stat data";
62 case KEY_ATTR_NAME_MINOR:
63 return "attr name";
64 case KEY_ATTR_BODY_MINOR:
65 return "attr body";
66 case KEY_BODY_MINOR:
67 return "file body";
68 default:
69 return "unknown";
73 /* debugging aid: print human readable information about key */
74 void reiser4_print_key(const char *prefix /* prefix to print */ ,
75 const reiser4_key * key /* key to print */ )
77 /* turn bold on */
78 /* printf ("\033[1m"); */
79 if (key == NULL)
80 printk("%s: null key\n", prefix);
81 else {
82 if (REISER4_LARGE_KEY)
83 printk("%s: (%Lx:%x:%Lx:%Lx:%Lx:%Lx)", prefix,
84 get_key_locality(key),
85 get_key_type(key),
86 get_key_ordering(key),
87 get_key_band(key),
88 get_key_objectid(key), get_key_offset(key));
89 else
90 printk("%s: (%Lx:%x:%Lx:%Lx:%Lx)", prefix,
91 get_key_locality(key),
92 get_key_type(key),
93 get_key_band(key),
94 get_key_objectid(key), get_key_offset(key));
96 * if this is a key of directory entry, try to decode part of
97 * a name stored in the key, and output it.
99 if (get_key_type(key) == KEY_FILE_NAME_MINOR) {
100 char buf[DE_NAME_BUF_LEN];
101 char *c;
103 c = buf;
104 c = reiser4_unpack_string(get_key_ordering(key), c);
105 reiser4_unpack_string(get_key_fulloid(key), c);
106 printk("[%s", buf);
107 if (is_longname_key(key))
109 * only part of the name is stored in the key.
111 printk("...]\n");
112 else {
114 * whole name is stored in the key.
116 reiser4_unpack_string(get_key_offset(key), buf);
117 printk("%s]\n", buf);
119 } else {
120 printk("[%s]\n", type_name(get_key_type(key)));
123 /* turn bold off */
124 /* printf ("\033[m\017"); */
127 #endif
129 /* Make Linus happy.
130 Local variables:
131 c-indentation-style: "K&R"
132 mode-name: "LC"
133 c-basic-offset: 8
134 tab-width: 8
135 fill-column: 120
136 End: