dlm: bind connections from known local address when using TCP
[safe/jmp/linux-2.6] / fs / hfsplus / btree.c
index 6712906..050d29c 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <linux/slab.h>
 #include <linux/pagemap.h>
+#include <linux/log2.h>
 
 #include "hfsplus_fs.h"
 #include "hfsplus_raw.h"
@@ -24,30 +25,20 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)
        struct page *page;
        unsigned int size;
 
-       tree = kmalloc(sizeof(*tree), GFP_KERNEL);
+       tree = kzalloc(sizeof(*tree), GFP_KERNEL);
        if (!tree)
                return NULL;
-       memset(tree, 0, sizeof(*tree));
 
        init_MUTEX(&tree->tree_lock);
        spin_lock_init(&tree->hash_lock);
-       /* Set the correct compare function */
        tree->sb = sb;
        tree->cnid = id;
-       if (id == HFSPLUS_EXT_CNID) {
-               tree->keycmp = hfsplus_ext_cmp_key;
-       } else if (id == HFSPLUS_CAT_CNID) {
-               tree->keycmp = hfsplus_cat_cmp_key;
-       } else {
-               printk(KERN_ERR "hfs: unknown B*Tree requested\n");
-               goto free_tree;
-       }
        tree->inode = iget(sb, id);
        if (!tree->inode)
                goto free_tree;
 
        mapping = tree->inode->i_mapping;
-       page = read_cache_page(mapping, 0, (filler_t *)mapping->a_ops->readpage, NULL);
+       page = read_mapping_page(mapping, 0, NULL);
        if (IS_ERR(page))
                goto free_tree;
 
@@ -64,8 +55,24 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)
        tree->max_key_len = be16_to_cpu(head->max_key_len);
        tree->depth = be16_to_cpu(head->depth);
 
+       /* Set the correct compare function */
+       if (id == HFSPLUS_EXT_CNID) {
+               tree->keycmp = hfsplus_ext_cmp_key;
+       } else if (id == HFSPLUS_CAT_CNID) {
+               if ((HFSPLUS_SB(sb).flags & HFSPLUS_SB_HFSX) &&
+                   (head->key_type == HFSPLUS_KEY_BINARY))
+                       tree->keycmp = hfsplus_cat_bin_cmp_key;
+               else {
+                       tree->keycmp = hfsplus_cat_case_cmp_key;
+                       HFSPLUS_SB(sb).flags |= HFSPLUS_SB_CASEFOLD;
+               }
+       } else {
+               printk(KERN_ERR "hfs: unknown B*Tree requested\n");
+               goto fail_page;
+       }
+
        size = tree->node_size;
-       if (!size || size & (size - 1))
+       if (!is_power_of_2(size))
                goto fail_page;
        if (!tree->node_count)
                goto fail_page;
@@ -264,8 +271,7 @@ void hfs_bmap_free(struct hfs_bnode *node)
        u8 *data, byte, m;
 
        dprint(DBG_BNODE_MOD, "btree_free_node: %u\n", node->this);
-       if (!node->this)
-               BUG();
+       BUG_ON(!node->this);
        tree = node->tree;
        nidx = node->this;
        node = hfs_bnode_find(tree, 0);