minix: replace inode uid,gid,mode init with helper
[safe/jmp/linux-2.6] / fs / ubifs / key.h
index 9ee6508..0f530c6 100644 (file)
 #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.
+ */
+static inline 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
@@ -54,16 +70,7 @@ static inline uint32_t key_r5_hash(const char *s, int len)
                str++;
        }
 
-       a &= UBIFS_S_KEY_HASH_MASK;
-
-       /*
-        * 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.
-        */
-       if (unlikely(a >= 0 && a <= 2))
-               a += 3;
-       return a;
+       return key_mask_hash(a);
 }
 
 /**
@@ -77,10 +84,7 @@ static inline uint32_t key_test_hash(const char *str, int len)
 
        len = min_t(uint32_t, len, 4);
        memcpy(&a, str, len);
-       a &= UBIFS_S_KEY_HASH_MASK;
-       if (unlikely(a >= 0 && a <= 2))
-               a += 3;
-       return a;
+       return key_mask_hash(a);
 }
 
 /**
@@ -225,23 +229,6 @@ static inline void xent_key_init(const struct ubifs_info *c,
 }
 
 /**
- * xent_key_init_hash - initialize extended attribute entry key without
- *                      re-calculating hash function.
- * @c: UBIFS file-system description object
- * @key: key to initialize
- * @inum: host inode number
- * @hash: extended attribute entry name hash
- */
-static inline void xent_key_init_hash(const struct ubifs_info *c,
-                                     union ubifs_key *key, ino_t inum,
-                                     uint32_t hash)
-{
-       ubifs_assert(!(hash & ~UBIFS_S_KEY_HASH_MASK));
-       key->u32[0] = inum;
-       key->u32[1] = hash | (UBIFS_XENT_KEY << UBIFS_S_KEY_HASH_BITS);
-}
-
-/**
  * xent_key_init_flash - initialize on-flash extended attribute entry key.
  * @c: UBIFS file-system description object
  * @k: key to initialize
@@ -291,22 +278,15 @@ static inline void data_key_init(const struct ubifs_info *c,
 }
 
 /**
- * data_key_init_flash - initialize on-flash data key.
+ * highest_data_key - get the highest possible data key for an inode.
  * @c: UBIFS file-system description object
- * @k: key to initialize
+ * @key: key to initialize
  * @inum: inode number
- * @block: block number
  */
-static inline void data_key_init_flash(const struct ubifs_info *c, void *k,
-                                      ino_t inum, unsigned int block)
+static inline void highest_data_key(const struct ubifs_info *c,
+                                  union ubifs_key *key, ino_t inum)
 {
-       union ubifs_key *key = k;
-
-       ubifs_assert(!(block & ~UBIFS_S_KEY_BLOCK_MASK));
-       key->j32[0] = cpu_to_le32(inum);
-       key->j32[1] = cpu_to_le32(block |
-                                 (UBIFS_DATA_KEY << UBIFS_S_KEY_BLOCK_BITS));
-       memset(k + 8, 0, UBIFS_MAX_KEY_LEN - 8);
+       data_key_init(c, key, inum, UBIFS_S_KEY_BLOCK_MASK);
 }
 
 /**
@@ -345,7 +325,7 @@ static inline int key_type_flash(const struct ubifs_info *c, const void *k)
 {
        const union ubifs_key *key = k;
 
-       return le32_to_cpu(key->u32[1]) >> UBIFS_S_KEY_BLOCK_BITS;
+       return le32_to_cpu(key->j32[1]) >> UBIFS_S_KEY_BLOCK_BITS;
 }
 
 /**
@@ -377,8 +357,8 @@ static inline ino_t key_inum_flash(const struct ubifs_info *c, const void *k)
  * @c: UBIFS file-system description object
  * @key: the key to get hash from
  */
-static inline int key_hash(const struct ubifs_info *c,
-                          const union ubifs_key *key)
+static inline uint32_t key_hash(const struct ubifs_info *c,
+                               const union ubifs_key *key)
 {
        return key->u32[1] & UBIFS_S_KEY_HASH_MASK;
 }
@@ -388,7 +368,7 @@ static inline int key_hash(const struct ubifs_info *c,
  * @c: UBIFS file-system description object
  * @k: the key to get hash from
  */
-static inline int key_hash_flash(const struct ubifs_info *c, const void *k)
+static inline uint32_t key_hash_flash(const struct ubifs_info *c, const void *k)
 {
        const union ubifs_key *key = k;
 
@@ -416,7 +396,7 @@ static inline unsigned int key_block_flash(const struct ubifs_info *c,
 {
        const union ubifs_key *key = k;
 
-       return le32_to_cpu(key->u32[1]) & UBIFS_S_KEY_BLOCK_MASK;
+       return le32_to_cpu(key->j32[1]) & UBIFS_S_KEY_BLOCK_MASK;
 }
 
 /**
@@ -550,4 +530,5 @@ static inline unsigned long long key_max_inode_size(const struct ubifs_info *c)
                return 0;
        }
 }
+
 #endif /* !__UBIFS_KEY_H__ */