fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / fs / hfsplus / btree.c
index 84870a1..a9b9e87 100644 (file)
@@ -22,32 +22,22 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)
        struct hfs_btree_header_rec *head;
        struct address_space *mapping;
        struct page *page;
-       unsigned int shift, size;
+       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("HFS+-fs: 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,14 +54,26 @@ 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;
+       } else {
+               printk(KERN_ERR "hfs: unknown B*Tree requested\n");
+               goto fail_page;
+       }
+
        size = tree->node_size;
        if (!size || size & (size - 1))
                goto fail_page;
        if (!tree->node_count)
                goto fail_page;
-       for (shift = 0; size >>= 1; shift += 1)
-               ;
-       tree->node_size_shift = shift;
+       tree->node_size_shift = ffs(size) - 1;
 
        tree->pages_per_bnode = (tree->node_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
 
@@ -101,7 +103,7 @@ void hfs_btree_close(struct hfs_btree *tree)
                while ((node = tree->node_hash[i])) {
                        tree->node_hash[i] = node->next_hash;
                        if (atomic_read(&node->refcnt))
-                               printk("HFS+: node %d:%d still has %d user(s)!\n",
+                               printk(KERN_CRIT "hfs: node %d:%d still has %d user(s)!\n",
                                        node->tree->cnid, node->this, atomic_read(&node->refcnt));
                        hfs_bnode_free(node);
                        tree->node_hash_cnt--;
@@ -144,7 +146,7 @@ static struct hfs_bnode *hfs_bmap_new_bmap(struct hfs_bnode *prev, u32 idx)
        struct hfs_btree *tree = prev->tree;
        struct hfs_bnode *node;
        struct hfs_bnode_desc desc;
-       u32 cnid;
+       __be32 cnid;
 
        node = hfs_bnode_create(tree, idx);
        if (IS_ERR(node))
@@ -189,10 +191,12 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
                res = hfsplus_file_extend(inode);
                if (res)
                        return ERR_PTR(res);
-               inode->i_blocks = HFSPLUS_I(inode).alloc_blocks <<
-                                 HFSPLUS_SB(tree->sb).fs_shift;
                HFSPLUS_I(inode).phys_size = inode->i_size =
-                       (loff_t)inode->i_blocks << tree->sb->s_blocksize_bits;
+                               (loff_t)HFSPLUS_I(inode).alloc_blocks <<
+                               HFSPLUS_SB(tree->sb).alloc_blksz_shift;
+               HFSPLUS_I(inode).fs_blocks = HFSPLUS_I(inode).alloc_blocks <<
+                                            HFSPLUS_SB(tree->sb).fs_shift;
+               inode_set_bytes(inode, inode->i_size);
                count = inode->i_size >> tree->node_size_shift;
                tree->free_nodes = count - tree->node_count;
                tree->node_count = count;
@@ -223,10 +227,6 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
                                                tree->free_nodes--;
                                                mark_inode_dirty(tree->inode);
                                                hfs_bnode_put(node);
-                                               if (!idx) {
-                                                       printk("unexpected idx %u (%u)\n", idx, node->this);
-                                                       BUG();
-                                               }
                                                return hfs_bnode_create(tree, idx);
                                        }
                                }
@@ -242,7 +242,7 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
                kunmap(*pagep);
                nidx = node->next;
                if (!nidx) {
-                       printk("create new bmap node...\n");
+                       printk(KERN_DEBUG "hfs: create new bmap node...\n");
                        next_node = hfs_bmap_new_bmap(node, idx);
                } else
                        next_node = hfs_bnode_find(tree, nidx);
@@ -268,8 +268,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);
@@ -284,7 +283,7 @@ void hfs_bmap_free(struct hfs_bnode *node)
                hfs_bnode_put(node);
                if (!i) {
                        /* panic */;
-                       printk("HFS: unable to free bnode %u. bmap not found!\n", node->this);
+                       printk(KERN_CRIT "hfs: unable to free bnode %u. bmap not found!\n", node->this);
                        return;
                }
                node = hfs_bnode_find(tree, i);
@@ -292,7 +291,7 @@ void hfs_bmap_free(struct hfs_bnode *node)
                        return;
                if (node->type != HFS_NODE_MAP) {
                        /* panic */;
-                       printk("HFS: invalid bmap found! (%u,%d)\n", node->this, node->type);
+                       printk(KERN_CRIT "hfs: invalid bmap found! (%u,%d)\n", node->this, node->type);
                        hfs_bnode_put(node);
                        return;
                }
@@ -305,7 +304,7 @@ void hfs_bmap_free(struct hfs_bnode *node)
        m = 1 << (~nidx & 7);
        byte = data[off];
        if (!(byte & m)) {
-               printk("HFS: trying to free free bnode %u(%d)\n", node->this, node->type);
+               printk(KERN_CRIT "hfs: trying to free free bnode %u(%d)\n", node->this, node->type);
                kunmap(page);
                hfs_bnode_put(node);
                return;