/* SPDX-License-Identifier: GPL-2.0-only */ /* * This file is part of UBIFS. * * Copyright (C) 2006-2008 Nokia Corporation. * * Authors: Artem Bityutskiy (Битюцкий Артём) * Adrian Hunter
*/
/* * This header contains various key-related definitions and helper function. * UBIFS allows several key schemes, so we access key fields only via these * helpers. At the moment only one key scheme is supported. * * Simple key scheme * ~~~~~~~~~~~~~~~~~ * * Keys are 64-bits long. First 32-bits are inode number (parent inode number * in case of direntry key). Next 3 bits are node type. The last 29 bits are * 4KiB offset in case of inode node, and direntry hash in case of a direntry * node. We use "r5" hash borrowed from reiserfs.
*/
/* * Lot's of the key helpers require a struct ubifs_info *c as the first parameter. * But we are not using it at all currently. That's designed for future extensions of * different c->key_format. But right now, there is only one key type, UBIFS_SIMPLE_KEY_FMT.
*/
#ifndef __UBIFS_KEY_H__ #define __UBIFS_KEY_H__
/** * key_mask_hash - mask a valid hash value. * @val: value to be masked * * We use hash values as offset in directories, so values %0 and %1 are * reserved for "." and "..". %2 is reserved for "end of readdir" marker. This * function makes sure the reserved values are not used.
*/ staticinline uint32_t key_mask_hash(uint32_t hash)
{
hash &= UBIFS_S_KEY_HASH_MASK; if (unlikely(hash <= 2))
hash += 3; return hash;
}
/** * key_r5_hash - R5 hash function (borrowed from reiserfs). * @s: direntry name * @len: name length
*/ staticinline uint32_t key_r5_hash(constchar *s, int len)
{
uint32_t a = 0; constsignedchar *str = (constsignedchar *)s;
while (len--) {
a += *str << 4;
a += *str >> 4;
a *= 11;
str++;
}
return key_mask_hash(a);
}
/** * key_test_hash - testing hash function. * @str: direntry name * @len: name length
*/ staticinline uint32_t key_test_hash(constchar *str, int len)
{
uint32_t a = 0;
/** * highest_data_key - get the highest possible data key for an inode. * @c: UBIFS file-system description object * @key: key to initialize * @inum: inode number
*/ staticinlinevoid highest_data_key(conststruct ubifs_info *c, union ubifs_key *key, ino_t inum)
{
data_key_init(c, key, inum, UBIFS_S_KEY_BLOCK_MASK);
}
/** * trun_key_init - initialize truncation node key. * @c: UBIFS file-system description object * @key: key to initialize * @inum: inode number * * Note, UBIFS does not have truncation keys on the media and this function is * only used for purposes of replay.
*/ staticinlinevoid trun_key_init(conststruct ubifs_info *c, union ubifs_key *key, ino_t inum)
{
key->u32[0] = inum;
key->u32[1] = UBIFS_TRUN_KEY << UBIFS_S_KEY_BLOCK_BITS;
}
/** * invalid_key_init - initialize invalid node key. * @c: UBIFS file-system description object * @key: key to initialize * * This is a helper function which marks a @key object as invalid.
*/ staticinlinevoid invalid_key_init(conststruct ubifs_info *c, union ubifs_key *key)
{
key->u32[0] = 0xDEADBEAF;
key->u32[1] = UBIFS_INVALID_KEY;
}
/** * key_type - get key type. * @c: UBIFS file-system description object * @key: key to get type of
*/ staticinlineint key_type(conststruct ubifs_info *c, constunion ubifs_key *key)
{ return key->u32[1] >> UBIFS_S_KEY_BLOCK_BITS;
}
/** * key_type_flash - get type of a on-flash formatted key. * @c: UBIFS file-system description object * @k: key to get type of
*/ staticinlineint key_type_flash(conststruct ubifs_info *c, constvoid *k)
{ constunion ubifs_key *key = k;
/** * key_block - get data block number. * @c: UBIFS file-system description object * @key: the key to get the block number from
*/ staticinlineunsignedint key_block(conststruct ubifs_info *c, constunion ubifs_key *key)
{ return key->u32[1] & UBIFS_S_KEY_BLOCK_MASK;
}
/** * key_block_flash - get data block number from an on-flash formatted key. * @c: UBIFS file-system description object * @k: the key to get the block number from
*/ staticinlineunsignedint key_block_flash(conststruct ubifs_info *c, constvoid *k)
{ constunion ubifs_key *key = k;
/** * key_read - transform a key to in-memory format. * @c: UBIFS file-system description object * @from: the key to transform * @to: the key to store the result
*/ staticinlinevoid key_read(conststruct ubifs_info *c, constvoid *from, union ubifs_key *to)
{ constunion ubifs_key *f = from;
/** * key_write - transform a key from in-memory format. * @c: UBIFS file-system description object * @from: the key to transform * @to: the key to store the result
*/ staticinlinevoid key_write(conststruct ubifs_info *c, constunion ubifs_key *from, void *to)
{ union ubifs_key *t = to;
/** * key_write_idx - transform a key from in-memory format for the index. * @c: UBIFS file-system description object * @from: the key to transform * @to: the key to store the result
*/ staticinlinevoid key_write_idx(conststruct ubifs_info *c, constunion ubifs_key *from, void *to)
{ union ubifs_key *t = to;
/** * key_copy - copy a key. * @c: UBIFS file-system description object * @from: the key to copy from * @to: the key to copy to
*/ staticinlinevoid key_copy(conststruct ubifs_info *c, constunion ubifs_key *from, union ubifs_key *to)
{
to->u64[0] = from->u64[0];
}
/** * keys_cmp - compare keys. * @c: UBIFS file-system description object * @key1: the first key to compare * @key2: the second key to compare * * This function compares 2 keys and returns %-1 if @key1 is less than * @key2, %0 if the keys are equivalent and %1 if @key1 is greater than @key2.
*/ staticinlineint keys_cmp(conststruct ubifs_info *c, constunion ubifs_key *key1, constunion ubifs_key *key2)
{ if (key1->u32[0] < key2->u32[0]) return -1; if (key1->u32[0] > key2->u32[0]) return 1; if (key1->u32[1] < key2->u32[1]) return -1; if (key1->u32[1] > key2->u32[1]) return 1;
return 0;
}
/** * keys_eq - determine if keys are equivalent. * @c: UBIFS file-system description object * @key1: the first key to compare * @key2: the second key to compare * * This function compares 2 keys and returns %1 if @key1 is equal to @key2 and * %0 if not.
*/ staticinlineint keys_eq(conststruct ubifs_info *c, constunion ubifs_key *key1, constunion ubifs_key *key2)
{ if (key1->u32[0] != key2->u32[0]) return 0; if (key1->u32[1] != key2->u32[1]) return 0; return 1;
}
/** * is_hash_key - is a key vulnerable to hash collisions. * @c: UBIFS file-system description object * @key: key * * This function returns %1 if @key is a hashed key or %0 otherwise.
*/ staticinlineint is_hash_key(conststruct ubifs_info *c, constunion ubifs_key *key)
{ int type = key_type(c, key);
return type == UBIFS_DENT_KEY || type == UBIFS_XENT_KEY;
}
/** * key_max_inode_size - get maximum file size allowed by current key format. * @c: UBIFS file-system description object
*/ staticinlineunsignedlonglong key_max_inode_size(conststruct ubifs_info *c)
{ switch (c->key_fmt) { case UBIFS_SIMPLE_KEY_FMT: return (1ULL << UBIFS_S_KEY_BLOCK_BITS) * UBIFS_BLOCK_SIZE; default: return 0;
}
}
#endif/* !__UBIFS_KEY_H__ */
Messung V0.5
¤ Dauer der Verarbeitung: 0.22 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.