Lines Matching +full:key +full:-

1 /* SPDX-License-Identifier: GPL-2.0-only */
5 * Copyright (C) 2006-2008 Nokia Corporation.
12 * This header contains various key-related definitions and helper function.
13 * UBIFS allows several key schemes, so we access key fields only via these
14 * helpers. At the moment only one key scheme is supported.
16 * Simple key scheme
19 * Keys are 64-bits long. First 32-bits are inode number (parent inode number
20 * in case of direntry key). Next 3 bits are node type. The last 29 bits are
26 * Lot's of the key helpers require a struct ubifs_info *c as the first parameter.
28 * different c->key_format. But right now, there is only one key type, UBIFS_SIMPLE_KEY_FMT.
35 * key_mask_hash - mask a valid hash value.
51 * key_r5_hash - R5 hash function (borrowed from reiserfs).
60 while (len--) { in key_r5_hash()
71 * key_test_hash - testing hash function.
85 * ino_key_init - initialize inode key.
86 * @c: UBIFS file-system description object
87 * @key: key to initialize
91 union ubifs_key *key, ino_t inum) in ino_key_init() argument
93 key->u32[0] = inum; in ino_key_init()
94 key->u32[1] = UBIFS_INO_KEY << UBIFS_S_KEY_BLOCK_BITS; in ino_key_init()
98 * ino_key_init_flash - initialize on-flash inode key.
99 * @c: UBIFS file-system description object
100 * @k: key to initialize
106 union ubifs_key *key = k; in ino_key_init_flash() local
108 key->j32[0] = cpu_to_le32(inum); in ino_key_init_flash()
109 key->j32[1] = cpu_to_le32(UBIFS_INO_KEY << UBIFS_S_KEY_BLOCK_BITS); in ino_key_init_flash()
110 memset(k + 8, 0, UBIFS_MAX_KEY_LEN - 8); in ino_key_init_flash()
114 * lowest_ino_key - get the lowest possible inode key.
115 * @c: UBIFS file-system description object
116 * @key: key to initialize
120 union ubifs_key *key, ino_t inum) in lowest_ino_key() argument
122 key->u32[0] = inum; in lowest_ino_key()
123 key->u32[1] = 0; in lowest_ino_key()
127 * highest_ino_key - get the highest possible inode key.
128 * @c: UBIFS file-system description object
129 * @key: key to initialize
133 union ubifs_key *key, ino_t inum) in highest_ino_key() argument
135 key->u32[0] = inum; in highest_ino_key()
136 key->u32[1] = 0xffffffff; in highest_ino_key()
140 * dent_key_init - initialize directory entry key.
141 * @c: UBIFS file-system description object
142 * @key: key to initialize
147 union ubifs_key *key, ino_t inum, in dent_key_init() argument
150 uint32_t hash = c->key_hash(fname_name(nm), fname_len(nm)); in dent_key_init()
153 key->u32[0] = inum; in dent_key_init()
154 key->u32[1] = hash | (UBIFS_DENT_KEY << UBIFS_S_KEY_HASH_BITS); in dent_key_init()
158 * dent_key_init_hash - initialize directory entry key without re-calculating
160 * @c: UBIFS file-system description object
161 * @key: key to initialize
166 union ubifs_key *key, ino_t inum, in dent_key_init_hash() argument
170 key->u32[0] = inum; in dent_key_init_hash()
171 key->u32[1] = hash | (UBIFS_DENT_KEY << UBIFS_S_KEY_HASH_BITS); in dent_key_init_hash()
175 * dent_key_init_flash - initialize on-flash directory entry key.
176 * @c: UBIFS file-system description object
177 * @k: key to initialize
185 union ubifs_key *key = k; in dent_key_init_flash() local
186 uint32_t hash = c->key_hash(fname_name(nm), fname_len(nm)); in dent_key_init_flash()
189 key->j32[0] = cpu_to_le32(inum); in dent_key_init_flash()
190 key->j32[1] = cpu_to_le32(hash | in dent_key_init_flash()
192 memset(k + 8, 0, UBIFS_MAX_KEY_LEN - 8); in dent_key_init_flash()
196 * lowest_dent_key - get the lowest possible directory entry key.
197 * @c: UBIFS file-system description object
198 * @key: where to store the lowest key
202 union ubifs_key *key, ino_t inum) in lowest_dent_key() argument
204 key->u32[0] = inum; in lowest_dent_key()
205 key->u32[1] = UBIFS_DENT_KEY << UBIFS_S_KEY_HASH_BITS; in lowest_dent_key()
209 * xent_key_init - initialize extended attribute entry key.
210 * @c: UBIFS file-system description object
211 * @key: key to initialize
216 union ubifs_key *key, ino_t inum, in xent_key_init() argument
219 uint32_t hash = c->key_hash(fname_name(nm), fname_len(nm)); in xent_key_init()
222 key->u32[0] = inum; in xent_key_init()
223 key->u32[1] = hash | (UBIFS_XENT_KEY << UBIFS_S_KEY_HASH_BITS); in xent_key_init()
227 * xent_key_init_flash - initialize on-flash extended attribute entry key.
228 * @c: UBIFS file-system description object
229 * @k: key to initialize
236 union ubifs_key *key = k; in xent_key_init_flash() local
237 uint32_t hash = c->key_hash(fname_name(nm), fname_len(nm)); in xent_key_init_flash()
240 key->j32[0] = cpu_to_le32(inum); in xent_key_init_flash()
241 key->j32[1] = cpu_to_le32(hash | in xent_key_init_flash()
243 memset(k + 8, 0, UBIFS_MAX_KEY_LEN - 8); in xent_key_init_flash()
247 * lowest_xent_key - get the lowest possible extended attribute entry key.
248 * @c: UBIFS file-system description object
249 * @key: where to store the lowest key
253 union ubifs_key *key, ino_t inum) in lowest_xent_key() argument
255 key->u32[0] = inum; in lowest_xent_key()
256 key->u32[1] = UBIFS_XENT_KEY << UBIFS_S_KEY_HASH_BITS; in lowest_xent_key()
260 * data_key_init - initialize data key.
261 * @c: UBIFS file-system description object
262 * @key: key to initialize
267 union ubifs_key *key, ino_t inum, in data_key_init() argument
271 key->u32[0] = inum; in data_key_init()
272 key->u32[1] = block | (UBIFS_DATA_KEY << UBIFS_S_KEY_BLOCK_BITS); in data_key_init()
276 * highest_data_key - get the highest possible data key for an inode.
277 * @c: UBIFS file-system description object
278 * @key: key to initialize
282 union ubifs_key *key, ino_t inum) in highest_data_key() argument
284 data_key_init(c, key, inum, UBIFS_S_KEY_BLOCK_MASK); in highest_data_key()
288 * trun_key_init - initialize truncation node key.
289 * @c: UBIFS file-system description object
290 * @key: key to initialize
297 union ubifs_key *key, ino_t inum) in trun_key_init() argument
299 key->u32[0] = inum; in trun_key_init()
300 key->u32[1] = UBIFS_TRUN_KEY << UBIFS_S_KEY_BLOCK_BITS; in trun_key_init()
304 * invalid_key_init - initialize invalid node key.
305 * @c: UBIFS file-system description object
306 * @key: key to initialize
308 * This is a helper function which marks a @key object as invalid.
311 union ubifs_key *key) in invalid_key_init() argument
313 key->u32[0] = 0xDEADBEAF; in invalid_key_init()
314 key->u32[1] = UBIFS_INVALID_KEY; in invalid_key_init()
318 * key_type - get key type.
319 * @c: UBIFS file-system description object
320 * @key: key to get type of
323 const union ubifs_key *key) in key_type() argument
325 return key->u32[1] >> UBIFS_S_KEY_BLOCK_BITS; in key_type()
329 * key_type_flash - get type of a on-flash formatted key.
330 * @c: UBIFS file-system description object
331 * @k: key to get type of
335 const union ubifs_key *key = k; in key_type_flash() local
337 return le32_to_cpu(key->j32[1]) >> UBIFS_S_KEY_BLOCK_BITS; in key_type_flash()
341 * key_inum - fetch inode number from key.
342 * @c: UBIFS file-system description object
343 * @k: key to fetch inode number from
347 const union ubifs_key *key = k; in key_inum() local
349 return key->u32[0]; in key_inum()
353 * key_inum_flash - fetch inode number from an on-flash formatted key.
354 * @c: UBIFS file-system description object
355 * @k: key to fetch inode number from
359 const union ubifs_key *key = k; in key_inum_flash() local
361 return le32_to_cpu(key->j32[0]); in key_inum_flash()
365 * key_hash - get directory entry hash.
366 * @c: UBIFS file-system description object
367 * @key: the key to get hash from
370 const union ubifs_key *key) in key_hash() argument
372 return key->u32[1] & UBIFS_S_KEY_HASH_MASK; in key_hash()
376 * key_hash_flash - get directory entry hash from an on-flash formatted key.
377 * @c: UBIFS file-system description object
378 * @k: the key to get hash from
382 const union ubifs_key *key = k; in key_hash_flash() local
384 return le32_to_cpu(key->j32[1]) & UBIFS_S_KEY_HASH_MASK; in key_hash_flash()
388 * key_block - get data block number.
389 * @c: UBIFS file-system description object
390 * @key: the key to get the block number from
393 const union ubifs_key *key) in key_block() argument
395 return key->u32[1] & UBIFS_S_KEY_BLOCK_MASK; in key_block()
399 * key_block_flash - get data block number from an on-flash formatted key.
400 * @c: UBIFS file-system description object
401 * @k: the key to get the block number from
406 const union ubifs_key *key = k; in key_block_flash() local
408 return le32_to_cpu(key->j32[1]) & UBIFS_S_KEY_BLOCK_MASK; in key_block_flash()
412 * key_read - transform a key to in-memory format.
413 * @c: UBIFS file-system description object
414 * @from: the key to transform
415 * @to: the key to store the result
422 to->u32[0] = le32_to_cpu(f->j32[0]); in key_read()
423 to->u32[1] = le32_to_cpu(f->j32[1]); in key_read()
427 * key_write - transform a key from in-memory format.
428 * @c: UBIFS file-system description object
429 * @from: the key to transform
430 * @to: the key to store the result
437 t->j32[0] = cpu_to_le32(from->u32[0]); in key_write()
438 t->j32[1] = cpu_to_le32(from->u32[1]); in key_write()
439 memset(to + 8, 0, UBIFS_MAX_KEY_LEN - 8); in key_write()
443 * key_write_idx - transform a key from in-memory format for the index.
444 * @c: UBIFS file-system description object
445 * @from: the key to transform
446 * @to: the key to store the result
453 t->j32[0] = cpu_to_le32(from->u32[0]); in key_write_idx()
454 t->j32[1] = cpu_to_le32(from->u32[1]); in key_write_idx()
458 * key_copy - copy a key.
459 * @c: UBIFS file-system description object
460 * @from: the key to copy from
461 * @to: the key to copy to
466 to->u64[0] = from->u64[0]; in key_copy()
470 * keys_cmp - compare keys.
471 * @c: UBIFS file-system description object
472 * @key1: the first key to compare
473 * @key2: the second key to compare
475 * This function compares 2 keys and returns %-1 if @key1 is less than
482 if (key1->u32[0] < key2->u32[0]) in keys_cmp()
483 return -1; in keys_cmp()
484 if (key1->u32[0] > key2->u32[0]) in keys_cmp()
486 if (key1->u32[1] < key2->u32[1]) in keys_cmp()
487 return -1; in keys_cmp()
488 if (key1->u32[1] > key2->u32[1]) in keys_cmp()
495 * keys_eq - determine if keys are equivalent.
496 * @c: UBIFS file-system description object
497 * @key1: the first key to compare
498 * @key2: the second key to compare
507 if (key1->u32[0] != key2->u32[0]) in keys_eq()
509 if (key1->u32[1] != key2->u32[1]) in keys_eq()
515 * is_hash_key - is a key vulnerable to hash collisions.
516 * @c: UBIFS file-system description object
517 * @key: key
519 * This function returns %1 if @key is a hashed key or %0 otherwise.
522 const union ubifs_key *key) in is_hash_key() argument
524 int type = key_type(c, key); in is_hash_key()
530 * key_max_inode_size - get maximum file size allowed by current key format.
531 * @c: UBIFS file-system description object
535 switch (c->key_fmt) { in key_max_inode_size()