Commit 9f1ad094 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/hch/hfsplus

* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/hch/hfsplus: (29 commits)
  hfsplus: fix getxattr return value
  hfsplus: remove the unused hfsplus_kmap/hfsplus_kunmap helpers
  hfsplus: create correct initial catalog entries for device files
  hfsplus: remove superflous rootflags field in hfsplus_inode_info
  hfsplus: fix link corruption
  hfsplus: validate btree flags
  hfsplus: handle more on-disk corruptions without oopsing
  hfsplus: hfs_bnode_find() can fail, resulting in hfs_bnode_split() breakage
  hfsplus: fix oops on mount with corrupted btree extent records
  hfsplus: fix rename over directories
  hfsplus: convert tree_lock to mutex
  hfsplus: add missing extent locking in hfsplus_write_inode
  hfsplus: protect readdir against removals from open_dir_list
  hfsplus: use atomic bitops for the superblock flags
  hfsplus: add per-superblock lock for volume header updates
  hfsplus: remove the rsrc_inodes list
  hfsplus: do not cache and write next_alloc
  hfsplus: fix error handling in hfsplus_symlink
  hfsplus: merge mknod/mkdir/creat
  hfsplus: clean up hfsplus_write_inode
  ...
parents f6f94e2a 46bf36ec
...@@ -23,7 +23,7 @@ int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd) ...@@ -23,7 +23,7 @@ int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd)
fd->search_key = ptr; fd->search_key = ptr;
fd->key = ptr + tree->max_key_len + 2; fd->key = ptr + tree->max_key_len + 2;
dprint(DBG_BNODE_REFS, "find_init: %d (%p)\n", tree->cnid, __builtin_return_address(0)); dprint(DBG_BNODE_REFS, "find_init: %d (%p)\n", tree->cnid, __builtin_return_address(0));
down(&tree->tree_lock); mutex_lock(&tree->tree_lock);
return 0; return 0;
} }
...@@ -32,7 +32,7 @@ void hfs_find_exit(struct hfs_find_data *fd) ...@@ -32,7 +32,7 @@ void hfs_find_exit(struct hfs_find_data *fd)
hfs_bnode_put(fd->bnode); hfs_bnode_put(fd->bnode);
kfree(fd->search_key); kfree(fd->search_key);
dprint(DBG_BNODE_REFS, "find_exit: %d (%p)\n", fd->tree->cnid, __builtin_return_address(0)); dprint(DBG_BNODE_REFS, "find_exit: %d (%p)\n", fd->tree->cnid, __builtin_return_address(0));
up(&fd->tree->tree_lock); mutex_unlock(&fd->tree->tree_lock);
fd->tree = NULL; fd->tree = NULL;
} }
...@@ -52,6 +52,10 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd) ...@@ -52,6 +52,10 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
rec = (e + b) / 2; rec = (e + b) / 2;
len = hfs_brec_lenoff(bnode, rec, &off); len = hfs_brec_lenoff(bnode, rec, &off);
keylen = hfs_brec_keylen(bnode, rec); keylen = hfs_brec_keylen(bnode, rec);
if (keylen == 0) {
res = -EINVAL;
goto fail;
}
hfs_bnode_read(bnode, fd->key, off, keylen); hfs_bnode_read(bnode, fd->key, off, keylen);
cmpval = bnode->tree->keycmp(fd->key, fd->search_key); cmpval = bnode->tree->keycmp(fd->key, fd->search_key);
if (!cmpval) { if (!cmpval) {
...@@ -67,6 +71,10 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd) ...@@ -67,6 +71,10 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
if (rec != e && e >= 0) { if (rec != e && e >= 0) {
len = hfs_brec_lenoff(bnode, e, &off); len = hfs_brec_lenoff(bnode, e, &off);
keylen = hfs_brec_keylen(bnode, e); keylen = hfs_brec_keylen(bnode, e);
if (keylen == 0) {
res = -EINVAL;
goto fail;
}
hfs_bnode_read(bnode, fd->key, off, keylen); hfs_bnode_read(bnode, fd->key, off, keylen);
} }
done: done:
...@@ -75,6 +83,7 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd) ...@@ -75,6 +83,7 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
fd->keylength = keylen; fd->keylength = keylen;
fd->entryoffset = off + keylen; fd->entryoffset = off + keylen;
fd->entrylength = len - keylen; fd->entrylength = len - keylen;
fail:
return res; return res;
} }
...@@ -198,6 +207,10 @@ int hfs_brec_goto(struct hfs_find_data *fd, int cnt) ...@@ -198,6 +207,10 @@ int hfs_brec_goto(struct hfs_find_data *fd, int cnt)
len = hfs_brec_lenoff(bnode, fd->record, &off); len = hfs_brec_lenoff(bnode, fd->record, &off);
keylen = hfs_brec_keylen(bnode, fd->record); keylen = hfs_brec_keylen(bnode, fd->record);
if (keylen == 0) {
res = -EINVAL;
goto out;
}
fd->keyoffset = off; fd->keyoffset = off;
fd->keylength = keylen; fd->keylength = keylen;
fd->entryoffset = off + keylen; fd->entryoffset = off + keylen;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset, u32 *max) int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset, u32 *max)
{ {
struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
struct page *page; struct page *page;
struct address_space *mapping; struct address_space *mapping;
__be32 *pptr, *curr, *end; __be32 *pptr, *curr, *end;
...@@ -29,8 +30,8 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset, u32 *ma ...@@ -29,8 +30,8 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset, u32 *ma
return size; return size;
dprint(DBG_BITMAP, "block_allocate: %u,%u,%u\n", size, offset, len); dprint(DBG_BITMAP, "block_allocate: %u,%u,%u\n", size, offset, len);
mutex_lock(&HFSPLUS_SB(sb).alloc_file->i_mutex); mutex_lock(&sbi->alloc_mutex);
mapping = HFSPLUS_SB(sb).alloc_file->i_mapping; mapping = sbi->alloc_file->i_mapping;
page = read_mapping_page(mapping, offset / PAGE_CACHE_BITS, NULL); page = read_mapping_page(mapping, offset / PAGE_CACHE_BITS, NULL);
if (IS_ERR(page)) { if (IS_ERR(page)) {
start = size; start = size;
...@@ -150,16 +151,17 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset, u32 *ma ...@@ -150,16 +151,17 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset, u32 *ma
set_page_dirty(page); set_page_dirty(page);
kunmap(page); kunmap(page);
*max = offset + (curr - pptr) * 32 + i - start; *max = offset + (curr - pptr) * 32 + i - start;
HFSPLUS_SB(sb).free_blocks -= *max; sbi->free_blocks -= *max;
sb->s_dirt = 1; sb->s_dirt = 1;
dprint(DBG_BITMAP, "-> %u,%u\n", start, *max); dprint(DBG_BITMAP, "-> %u,%u\n", start, *max);
out: out:
mutex_unlock(&HFSPLUS_SB(sb).alloc_file->i_mutex); mutex_unlock(&sbi->alloc_mutex);
return start; return start;
} }
int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count) int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)
{ {
struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
struct page *page; struct page *page;
struct address_space *mapping; struct address_space *mapping;
__be32 *pptr, *curr, *end; __be32 *pptr, *curr, *end;
...@@ -172,11 +174,11 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count) ...@@ -172,11 +174,11 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)
dprint(DBG_BITMAP, "block_free: %u,%u\n", offset, count); dprint(DBG_BITMAP, "block_free: %u,%u\n", offset, count);
/* are all of the bits in range? */ /* are all of the bits in range? */
if ((offset + count) > HFSPLUS_SB(sb).total_blocks) if ((offset + count) > sbi->total_blocks)
return -2; return -2;
mutex_lock(&HFSPLUS_SB(sb).alloc_file->i_mutex); mutex_lock(&sbi->alloc_mutex);
mapping = HFSPLUS_SB(sb).alloc_file->i_mapping; mapping = sbi->alloc_file->i_mapping;
pnr = offset / PAGE_CACHE_BITS; pnr = offset / PAGE_CACHE_BITS;
page = read_mapping_page(mapping, pnr, NULL); page = read_mapping_page(mapping, pnr, NULL);
pptr = kmap(page); pptr = kmap(page);
...@@ -224,9 +226,9 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count) ...@@ -224,9 +226,9 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)
out: out:
set_page_dirty(page); set_page_dirty(page);
kunmap(page); kunmap(page);
HFSPLUS_SB(sb).free_blocks += len; sbi->free_blocks += len;
sb->s_dirt = 1; sb->s_dirt = 1;
mutex_unlock(&HFSPLUS_SB(sb).alloc_file->i_mutex); mutex_unlock(&sbi->alloc_mutex);
return 0; return 0;
} }
...@@ -42,10 +42,13 @@ u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec) ...@@ -42,10 +42,13 @@ u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec)
recoff = hfs_bnode_read_u16(node, node->tree->node_size - (rec + 1) * 2); recoff = hfs_bnode_read_u16(node, node->tree->node_size - (rec + 1) * 2);
if (!recoff) if (!recoff)
return 0; return 0;
if (node->tree->attributes & HFS_TREE_BIGKEYS)
retval = hfs_bnode_read_u16(node, recoff) + 2; retval = hfs_bnode_read_u16(node, recoff) + 2;
else if (retval > node->tree->max_key_len + 2) {
retval = (hfs_bnode_read_u8(node, recoff) | 1) + 1; printk(KERN_ERR "hfs: keylen %d too large\n",
retval);
retval = 0;
}
} }
return retval; return retval;
} }
...@@ -216,7 +219,7 @@ int hfs_brec_remove(struct hfs_find_data *fd) ...@@ -216,7 +219,7 @@ int hfs_brec_remove(struct hfs_find_data *fd)
static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd) static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd)
{ {
struct hfs_btree *tree; struct hfs_btree *tree;
struct hfs_bnode *node, *new_node; struct hfs_bnode *node, *new_node, *next_node;
struct hfs_bnode_desc node_desc; struct hfs_bnode_desc node_desc;
int num_recs, new_rec_off, new_off, old_rec_off; int num_recs, new_rec_off, new_off, old_rec_off;
int data_start, data_end, size; int data_start, data_end, size;
...@@ -235,6 +238,17 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd) ...@@ -235,6 +238,17 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd)
new_node->type = node->type; new_node->type = node->type;
new_node->height = node->height; new_node->height = node->height;
if (node->next)
next_node = hfs_bnode_find(tree, node->next);
else
next_node = NULL;
if (IS_ERR(next_node)) {
hfs_bnode_put(node);
hfs_bnode_put(new_node);
return next_node;
}
size = tree->node_size / 2 - node->num_recs * 2 - 14; size = tree->node_size / 2 - node->num_recs * 2 - 14;
old_rec_off = tree->node_size - 4; old_rec_off = tree->node_size - 4;
num_recs = 1; num_recs = 1;
...@@ -248,6 +262,8 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd) ...@@ -248,6 +262,8 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd)
/* panic? */ /* panic? */
hfs_bnode_put(node); hfs_bnode_put(node);
hfs_bnode_put(new_node); hfs_bnode_put(new_node);
if (next_node)
hfs_bnode_put(next_node);
return ERR_PTR(-ENOSPC); return ERR_PTR(-ENOSPC);
} }
...@@ -302,8 +318,7 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd) ...@@ -302,8 +318,7 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd)
hfs_bnode_write(node, &node_desc, 0, sizeof(node_desc)); hfs_bnode_write(node, &node_desc, 0, sizeof(node_desc));
/* update next bnode header */ /* update next bnode header */
if (new_node->next) { if (next_node) {
struct hfs_bnode *next_node = hfs_bnode_find(tree, new_node->next);
next_node->prev = new_node->this; next_node->prev = new_node->this;
hfs_bnode_read(next_node, &node_desc, 0, sizeof(node_desc)); hfs_bnode_read(next_node, &node_desc, 0, sizeof(node_desc));
node_desc.prev = cpu_to_be32(next_node->prev); node_desc.prev = cpu_to_be32(next_node->prev);
......
...@@ -30,7 +30,7 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id) ...@@ -30,7 +30,7 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)
if (!tree) if (!tree)
return NULL; return NULL;
init_MUTEX(&tree->tree_lock); mutex_init(&tree->tree_lock);
spin_lock_init(&tree->hash_lock); spin_lock_init(&tree->hash_lock);
tree->sb = sb; tree->sb = sb;
tree->cnid = id; tree->cnid = id;
...@@ -39,10 +39,16 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id) ...@@ -39,10 +39,16 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)
goto free_tree; goto free_tree;
tree->inode = inode; tree->inode = inode;
if (!HFSPLUS_I(tree->inode)->first_blocks) {
printk(KERN_ERR
"hfs: invalid btree extent records (0 size).\n");
goto free_inode;
}
mapping = tree->inode->i_mapping; mapping = tree->inode->i_mapping;
page = read_mapping_page(mapping, 0, NULL); page = read_mapping_page(mapping, 0, NULL);
if (IS_ERR(page)) if (IS_ERR(page))
goto free_tree; goto free_inode;
/* Load the header */ /* Load the header */
head = (struct hfs_btree_header_rec *)(kmap(page) + sizeof(struct hfs_bnode_desc)); head = (struct hfs_btree_header_rec *)(kmap(page) + sizeof(struct hfs_bnode_desc));
...@@ -57,27 +63,56 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id) ...@@ -57,27 +63,56 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)
tree->max_key_len = be16_to_cpu(head->max_key_len); tree->max_key_len = be16_to_cpu(head->max_key_len);
tree->depth = be16_to_cpu(head->depth); tree->depth = be16_to_cpu(head->depth);
/* Set the correct compare function */ /* Verify the tree and set the correct compare function */
if (id == HFSPLUS_EXT_CNID) { switch (id) {
case HFSPLUS_EXT_CNID:
if (tree->max_key_len != HFSPLUS_EXT_KEYLEN - sizeof(u16)) {
printk(KERN_ERR "hfs: invalid extent max_key_len %d\n",
tree->max_key_len);
goto fail_page;
}
if (tree->attributes & HFS_TREE_VARIDXKEYS) {
printk(KERN_ERR "hfs: invalid extent btree flag\n");
goto fail_page;
}
tree->keycmp = hfsplus_ext_cmp_key; tree->keycmp = hfsplus_ext_cmp_key;
} else if (id == HFSPLUS_CAT_CNID) { break;
if ((HFSPLUS_SB(sb).flags & HFSPLUS_SB_HFSX) && case HFSPLUS_CAT_CNID:
if (tree->max_key_len != HFSPLUS_CAT_KEYLEN - sizeof(u16)) {
printk(KERN_ERR "hfs: invalid catalog max_key_len %d\n",
tree->max_key_len);
goto fail_page;
}
if (!(tree->attributes & HFS_TREE_VARIDXKEYS)) {
printk(KERN_ERR "hfs: invalid catalog btree flag\n");
goto fail_page;
}
if (test_bit(HFSPLUS_SB_HFSX, &HFSPLUS_SB(sb)->flags) &&
(head->key_type == HFSPLUS_KEY_BINARY)) (head->key_type == HFSPLUS_KEY_BINARY))
tree->keycmp = hfsplus_cat_bin_cmp_key; tree->keycmp = hfsplus_cat_bin_cmp_key;
else { else {
tree->keycmp = hfsplus_cat_case_cmp_key; tree->keycmp = hfsplus_cat_case_cmp_key;
HFSPLUS_SB(sb).flags |= HFSPLUS_SB_CASEFOLD; set_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
} }
} else { break;
default:
printk(KERN_ERR "hfs: unknown B*Tree requested\n"); printk(KERN_ERR "hfs: unknown B*Tree requested\n");
goto fail_page; goto fail_page;
} }
if (!(tree->attributes & HFS_TREE_BIGKEYS)) {
printk(KERN_ERR "hfs: invalid btree flag\n");
goto fail_page;
}
size = tree->node_size; size = tree->node_size;
if (!is_power_of_2(size)) if (!is_power_of_2(size))
goto fail_page; goto fail_page;
if (!tree->node_count) if (!tree->node_count)
goto fail_page; goto fail_page;
tree->node_size_shift = ffs(size) - 1; tree->node_size_shift = ffs(size) - 1;
tree->pages_per_bnode = (tree->node_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; tree->pages_per_bnode = (tree->node_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
...@@ -87,10 +122,11 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id) ...@@ -87,10 +122,11 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)
return tree; return tree;
fail_page: fail_page:
tree->inode->i_mapping->a_ops = &hfsplus_aops;
page_cache_release(page); page_cache_release(page);
free_tree: free_inode:
tree->inode->i_mapping->a_ops = &hfsplus_aops;
iput(tree->inode); iput(tree->inode);
free_tree:
kfree(tree); kfree(tree);
return NULL; return NULL;
} }
...@@ -192,17 +228,18 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree) ...@@ -192,17 +228,18 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
while (!tree->free_nodes) { while (!tree->free_nodes) {
struct inode *inode = tree->inode; struct inode *inode = tree->inode;
struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
u32 count; u32 count;
int res; int res;
res = hfsplus_file_extend(inode); res = hfsplus_file_extend(inode);
if (res) if (res)
return ERR_PTR(res); return ERR_PTR(res);
HFSPLUS_I(inode).phys_size = inode->i_size = hip->phys_size = inode->i_size =
(loff_t)HFSPLUS_I(inode).alloc_blocks << (loff_t)hip->alloc_blocks <<
HFSPLUS_SB(tree->sb).alloc_blksz_shift; HFSPLUS_SB(tree->sb)->alloc_blksz_shift;
HFSPLUS_I(inode).fs_blocks = HFSPLUS_I(inode).alloc_blocks << hip->fs_blocks =
HFSPLUS_SB(tree->sb).fs_shift; hip->alloc_blocks << HFSPLUS_SB(tree->sb)->fs_shift;
inode_set_bytes(inode, inode->i_size); inode_set_bytes(inode, inode->i_size);
count = inode->i_size >> tree->node_size_shift; count = inode->i_size >> tree->node_size_shift;
tree->free_nodes = count - tree->node_count; tree->free_nodes = count - tree->node_count;
......
...@@ -67,7 +67,7 @@ static void hfsplus_cat_build_key_uni(hfsplus_btree_key *key, u32 parent, ...@@ -67,7 +67,7 @@ static void hfsplus_cat_build_key_uni(hfsplus_btree_key *key, u32 parent,
key->key_len = cpu_to_be16(6 + ustrlen); key->key_len = cpu_to_be16(6 + ustrlen);
} }
static void hfsplus_set_perms(struct inode *inode, struct hfsplus_perm *perms) void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms)
{ {
if (inode->i_flags & S_IMMUTABLE) if (inode->i_flags & S_IMMUTABLE)
perms->rootflags |= HFSPLUS_FLG_IMMUTABLE; perms->rootflags |= HFSPLUS_FLG_IMMUTABLE;
...@@ -77,15 +77,24 @@ static void hfsplus_set_perms(struct inode *inode, struct hfsplus_perm *perms) ...@@ -77,15 +77,24 @@ static void hfsplus_set_perms(struct inode *inode, struct hfsplus_perm *perms)
perms->rootflags |= HFSPLUS_FLG_APPEND; perms->rootflags |= HFSPLUS_FLG_APPEND;
else else
perms->rootflags &= ~HFSPLUS_FLG_APPEND; perms->rootflags &= ~HFSPLUS_FLG_APPEND;
HFSPLUS_I(inode).rootflags = perms->rootflags;
HFSPLUS_I(inode).userflags = perms->userflags; perms->userflags = HFSPLUS_I(inode)->userflags;
perms->mode = cpu_to_be16(inode->i_mode); perms->mode = cpu_to_be16(inode->i_mode);
perms->owner = cpu_to_be32(inode->i_uid); perms->owner = cpu_to_be32(inode->i_uid);
perms->group = cpu_to_be32(inode->i_gid); perms->group = cpu_to_be32(inode->i_gid);
if (S_ISREG(inode->i_mode))
perms->dev = cpu_to_be32(inode->i_nlink);
else if (S_ISBLK(inode->i_mode) || S_ISCHR(inode->i_mode))
perms->dev = cpu_to_be32(inode->i_rdev);
else
perms->dev = 0;
} }
static int hfsplus_cat_build_record(hfsplus_cat_entry *entry, u32 cnid, struct inode *inode) static int hfsplus_cat_build_record(hfsplus_cat_entry *entry, u32 cnid, struct inode *inode)
{ {
struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
if (S_ISDIR(inode->i_mode)) { if (S_ISDIR(inode->i_mode)) {
struct hfsplus_cat_folder *folder; struct hfsplus_cat_folder *folder;
...@@ -93,13 +102,13 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry, u32 cnid, struct i ...@@ -93,13 +102,13 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry, u32 cnid, struct i
memset(folder, 0, sizeof(*folder)); memset(folder, 0, sizeof(*folder));
folder->type = cpu_to_be16(HFSPLUS_FOLDER); folder->type = cpu_to_be16(HFSPLUS_FOLDER);
folder->id = cpu_to_be32(inode->i_ino); folder->id = cpu_to_be32(inode->i_ino);
HFSPLUS_I(inode).create_date = HFSPLUS_I(inode)->create_date =
folder->create_date = folder->create_date =
folder->content_mod_date = folder->content_mod_date =
folder->attribute_mod_date = folder->attribute_mod_date =
folder->access_date = hfsp_now2mt(); folder->access_date = hfsp_now2mt();
hfsplus_set_perms(inode, &folder->permissions); hfsplus_cat_set_perms(inode, &folder->permissions);
if (inode == HFSPLUS_SB(inode->i_sb).hidden_dir) if (inode == sbi->hidden_dir)
/* invisible and namelocked */ /* invisible and namelocked */
folder->user_info.frFlags = cpu_to_be16(0x5000); folder->user_info.frFlags = cpu_to_be16(0x5000);
return sizeof(*folder); return sizeof(*folder);
...@@ -111,19 +120,19 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry, u32 cnid, struct i ...@@ -111,19 +120,19 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry, u32 cnid, struct i
file->type = cpu_to_be16(HFSPLUS_FILE); file->type = cpu_to_be16(HFSPLUS_FILE);
file->flags = cpu_to_be16(HFSPLUS_FILE_THREAD_EXISTS); file->flags = cpu_to_be16(HFSPLUS_FILE_THREAD_EXISTS);
file->id = cpu_to_be32(cnid); file->id = cpu_to_be32(cnid);
HFSPLUS_I(inode).create_date = HFSPLUS_I(inode)->create_date =
file->create_date = file->create_date =
file->content_mod_date = file->content_mod_date =
file->attribute_mod_date = file->attribute_mod_date =
file->access_date = hfsp_now2mt(); file->access_date = hfsp_now2mt();
if (cnid == inode->i_ino) { if (cnid == inode->i_ino) {
hfsplus_set_perms(inode, &file->permissions); hfsplus_cat_set_perms(inode, &file->permissions);
if (S_ISLNK(inode->i_mode)) { if (S_ISLNK(inode->i_mode)) {
file->user_info.fdType = cpu_to_be32(HFSP_SYMLINK_TYPE); file->user_info.fdType = cpu_to_be32(HFSP_SYMLINK_TYPE);
file->user_info.fdCreator = cpu_to_be32(HFSP_SYMLINK_CREATOR); file->user_info.fdCreator = cpu_to_be32(HFSP_SYMLINK_CREATOR);
} else { } else {
file->user_info.fdType = cpu_to_be32(HFSPLUS_SB(inode->i_sb).type); file->user_info.fdType = cpu_to_be32(sbi->type);
file->user_info.fdCreator = cpu_to_be32(HFSPLUS_SB(inode->i_sb).creator); file->user_info.fdCreator = cpu_to_be32(sbi->creator);
} }
if ((file->permissions.rootflags | file->permissions.userflags) & HFSPLUS_FLG_IMMUTABLE) if ((file->permissions.rootflags | file->permissions.userflags) & HFSPLUS_FLG_IMMUTABLE)
file->flags |= cpu_to_be16(HFSPLUS_FILE_LOCKED); file->flags |= cpu_to_be16(HFSPLUS_FILE_LOCKED);
...@@ -131,8 +140,8 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry, u32 cnid, struct i ...@@ -131,8 +140,8 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry, u32 cnid, struct i
file->user_info.fdType = cpu_to_be32(HFSP_HARDLINK_TYPE); file->user_info.fdType = cpu_to_be32(HFSP_HARDLINK_TYPE);
file->user_info.fdCreator = cpu_to_be32(HFSP_HFSPLUS_CREATOR); file->user_info.fdCreator = cpu_to_be32(HFSP_HFSPLUS_CREATOR);
file->user_info.fdFlags = cpu_to_be16(0x100); file->user_info.fdFlags = cpu_to_be16(0x100);
file->create_date = HFSPLUS_I(HFSPLUS_SB(inode->i_sb).hidden_dir).create_date; file->create_date = HFSPLUS_I(sbi->hidden_dir)->create_date;
file->permissions.dev = cpu_to_be32(HFSPLUS_I(inode).dev); file->permissions.dev = cpu_to_be32(HFSPLUS_I(inode)->linkid);
} }
return sizeof(*file); return sizeof(*file);
} }
...@@ -180,15 +189,14 @@ int hfsplus_find_cat(struct super_block *sb, u32 cnid, ...@@ -180,15 +189,14 @@ int hfsplus_find_cat(struct super_block *sb, u32 cnid,
int hfsplus_create_cat(u32 cnid, struct inode *dir, struct qstr *str, struct inode *inode) int hfsplus_create_cat(u32 cnid, struct inode *dir, struct qstr *str, struct inode *inode)
{ {
struct super_block *sb = dir->i_sb;
struct hfs_find_data fd; struct hfs_find_data fd;
struct super_block *sb;
hfsplus_cat_entry entry; hfsplus_cat_entry entry;
int entry_size; int entry_size;
int err; int err;
dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n", str->name, cnid, inode->i_nlink); dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n", str->name, cnid, inode->i_nlink);
sb = dir->i_sb; hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
hfs_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
hfsplus_cat_build_key(sb, fd.search_key, cnid, NULL); hfsplus_cat_build_key(sb, fd.search_key, cnid, NULL);
entry_size = hfsplus_fill_cat_thread(sb, &entry, S_ISDIR(inode->i_mode) ? entry_size = hfsplus_fill_cat_thread(sb, &entry, S_ISDIR(inode->i_mode) ?
...@@ -234,7 +242,7 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir, struct qstr *str, struct ino ...@@ -234,7 +242,7 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir, struct qstr *str, struct ino
int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str) int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str)
{ {
struct super_block *sb; struct super_block *sb = dir->i_sb;
struct hfs_find_data fd; struct hfs_find_data fd;
struct hfsplus_fork_raw fork; struct hfsplus_fork_raw fork;
struct list_head *pos; struct list_head *pos;
...@@ -242,8 +250,7 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str) ...@@ -242,8 +250,7 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str)
u16 type; u16 type;
dprint(DBG_CAT_MOD, "delete_cat: %s,%u\n", str ? str->name : NULL, cnid); dprint(DBG_CAT_MOD, "delete_cat: %s,%u\n", str ? str->name : NULL, cnid);
sb = dir->i_sb; hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
hfs_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
if (!str) { if (!str) {
int len; int len;
...@@ -279,7 +286,7 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str) ...@@ -279,7 +286,7 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str)
hfsplus_free_fork(sb, cnid, &fork, HFSPLUS_TYPE_RSRC); hfsplus_free_fork(sb, cnid, &fork, HFSPLUS_TYPE_RSRC);
} }
list_for_each(pos, &HFSPLUS_I(dir).open_dir_list) { list_for_each(pos, &HFSPLUS_I(dir)->open_dir_list) {
struct hfsplus_readdir_data *rd = struct hfsplus_readdir_data *rd =
list_entry(pos, struct hfsplus_readdir_data, list); list_entry(pos, struct hfsplus_readdir_data, list);
if (fd.tree->keycmp(fd.search_key, (void *)&rd->key) < 0) if (fd.tree->keycmp(fd.search_key, (void *)&rd->key) < 0)
...@@ -312,7 +319,7 @@ int hfsplus_rename_cat(u32 cnid, ...@@ -312,7 +319,7 @@ int hfsplus_rename_cat(u32 cnid,
struct inode *src_dir, struct qstr *src_name, struct inode *src_dir, struct qstr *src_name,
struct inode *dst_dir, struct qstr *dst_name) struct inode *dst_dir, struct qstr *dst_name)
{ {
struct super_block *sb; struct super_block *sb = src_dir->i_sb;
struct hfs_find_data src_fd, dst_fd; struct hfs_find_data src_fd, dst_fd;
hfsplus_cat_entry entry; hfsplus_cat_entry entry;
int entry_size, type; int entry_size, type;
...@@ -320,8 +327,7 @@ int hfsplus_rename_cat(u32 cnid, ...@@ -320,8 +327,7 @@ int hfsplus_rename_cat(u32 cnid,
dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n", cnid, src_dir->i_ino, src_name->name, dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n", cnid, src_dir->i_ino, src_name->name,
dst_dir->i_ino, dst_name->name); dst_dir->i_ino, dst_name->name);
sb = src_dir->i_sb; hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &src_fd);
hfs_find_init(HFSPLUS_SB(sb).cat_tree, &src_fd);
dst_fd = src_fd; dst_fd = src_fd;
/* find the old dir entry and read the data */ /* find the old dir entry and read the data */
......
This diff is collapsed.
This diff is collapsed.
...@@ -62,7 +62,7 @@ struct hfs_btree { ...@@ -62,7 +62,7 @@ struct hfs_btree {
unsigned int depth; unsigned int depth;
//unsigned int map1_size, map_size; //unsigned int map1_size, map_size;
struct semaphore tree_lock; struct mutex tree_lock;
unsigned int pages_per_bnode; unsigned int pages_per_bnode;
spinlock_t hash_lock; spinlock_t hash_lock;
...@@ -121,16 +121,21 @@ struct hfsplus_sb_info { ...@@ -121,16 +121,21 @@ struct hfsplus_sb_info {
u32 sect_count; u32 sect_count;
int fs_shift; int fs_shift;
/* Stuff in host order from Vol Header */ /* immutable data from the volume header */
u32 alloc_blksz; u32 alloc_blksz;
int alloc_blksz_shift; int alloc_blksz_shift;
u32 total_blocks; u32 total_blocks;
u32 data_clump_blocks, rsrc_clump_blocks;
/* mutable data from the volume header, protected by alloc_mutex */
u32 free_blocks; u32 free_blocks;
u32 next_alloc; struct mutex alloc_mutex;
/* mutable data from the volume header, protected by vh_mutex */
u32 next_cnid; u32 next_cnid;
u32 file_count; u32 file_count;
u32 folder_count; u32 folder_count;
u32 data_clump_blocks, rsrc_clump_blocks; struct mutex vh_mutex;
/* Config options */ /* Config options */
u32 creator; u32 creator;
...@@ -143,40 +148,50 @@ struct hfsplus_sb_info { ...@@ -143,40 +148,50 @@ struct hfsplus_sb_info {
int part, session; int part, session;
unsigned long flags; unsigned long flags;
struct hlist_head rsrc_inodes;
}; };
#define HFSPLUS_SB_WRITEBACKUP 0x0001 #define HFSPLUS_SB_WRITEBACKUP 0
#define HFSPLUS_SB_NODECOMPOSE 0x0002 #define HFSPLUS_SB_NODECOMPOSE 1
#define HFSPLUS_SB_FORCE 0x0004 #define HFSPLUS_SB_FORCE 2
#define HFSPLUS_SB_HFSX 0x0008 #define HFSPLUS_SB_HFSX 3
#define HFSPLUS_SB_CASEFOLD 0x0010 #define HFSPLUS_SB_CASEFOLD 4
struct hfsplus_inode_info { struct hfsplus_inode_info {
struct mutex extents_lock;
u32 clump_blocks, alloc_blocks;
sector_t fs_blocks;
/* Allocation extents from catalog record or volume header */
hfsplus_extent_rec first_extents;
u32 first_blocks;
hfsplus_extent_rec cached_extents;
u32 cached_start, cached_blocks;
atomic_t opencnt; atomic_t opencnt;
struct inode *rsrc_inode; /*
* Extent allocation information, protected by extents_lock.
*/
u32 first_blocks;
u32 clump_blocks;
u32 alloc_blocks;
u32 cached_start;
u32 cached_blocks;
hfsplus_extent_rec first_extents;
hfsplus_extent_rec cached_extents;
unsigned long flags; unsigned long flags;
struct mutex extents_lock;
/*
* Immutable data.
*/
struct inode *rsrc_inode;
__be32 create_date; __be32 create_date;
/* Device number in hfsplus_permissions in catalog */
u32 dev;
/* BSD system and user file flags */
u8 rootflags;
u8 userflags;
/*
* Protected by sbi->vh_mutex.
*/
u32 linkid;
/*
* Protected by i_mutex.
*/
sector_t fs_blocks;
u8 userflags; /* BSD user file flags */
struct list_head open_dir_list; struct list_head open_dir_list;
loff_t phys_size; loff_t phys_size;
struct inode vfs_inode; struct inode vfs_inode;
}; };
...@@ -184,8 +199,8 @@ struct hfsplus_inode_info { ...@@ -184,8 +199,8 @@ struct hfsplus_inode_info {
#define HFSPLUS_FLG_EXT_DIRTY 0x0002 #define HFSPLUS_FLG_EXT_DIRTY 0x0002
#define HFSPLUS_FLG_EXT_NEW 0x0004 #define HFSPLUS_FLG_EXT_NEW 0x0004
#define HFSPLUS_IS_DATA(inode) (!(HFSPLUS_I(inode).flags & HFSPLUS_FLG_RSRC)) #define HFSPLUS_IS_DATA(inode) (!(HFSPLUS_I(inode)->flags & HFSPLUS_FLG_RSRC))
#define HFSPLUS_IS_RSRC(inode) (HFSPLUS_I(inode).flags & HFSPLUS_FLG_RSRC) #define HFSPLUS_IS_RSRC(inode) (HFSPLUS_I(inode)->flags & HFSPLUS_FLG_RSRC)
struct hfs_find_data { struct hfs_find_data {
/* filled by caller */ /* filled by caller */
...@@ -311,6 +326,7 @@ int hfsplus_create_cat(u32, struct inode *, struct qstr *, struct inode *); ...@@ -311,6 +326,7 @@ int hfsplus_create_cat(u32, struct inode *, struct qstr *, struct inode *);
int hfsplus_delete_cat(u32, struct inode *, struct qstr *); int hfsplus_delete_cat(u32, struct inode *, struct qstr *);
int hfsplus_rename_cat(u32, struct inode *, struct qstr *, int hfsplus_rename_cat(u32, struct inode *, struct qstr *,
struct inode *, struct qstr *); struct inode *, struct qstr *);
void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms);
/* dir.c */ /* dir.c */
extern const struct inode_operations hfsplus_dir_inode_operations; extern const struct inode_operations hfsplus_dir_inode_operations;
...@@ -372,26 +388,15 @@ int hfsplus_read_wrapper(struct super_block *); ...@@ -372,26 +388,15 @@ int hfsplus_read_wrapper(struct super_block *);
int hfs_part_find(struct super_block *, sector_t *, sector_t *); int hfs_part_find(struct super_block *, sector_t *, sector_t *);
/* access macros */ /* access macros */
/*
static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb) static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
{ {
return sb->s_fs_info; return sb->s_fs_info;
} }
static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode) static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
{ {
return list_entry(inode, struct hfsplus_inode_info, vfs_inode); return list_entry(inode, struct hfsplus_inode_info, vfs_inode);
} }
*/
#define HFSPLUS_SB(super) (*(struct hfsplus_sb_info *)(super)->s_fs_info)
#define HFSPLUS_I(inode) (*list_entry(inode, struct hfsplus_inode_info, vfs_inode))
#if 1
#define hfsplus_kmap(p) ({ struct page *__p = (p); kmap(__p); })
#define hfsplus_kunmap(p) ({ struct page *__p = (p); kunmap(__p); __p; })
#else
#define hfsplus_kmap(p) kmap(p)
#define hfsplus_kunmap(p) kunmap(p)
#endif
#define sb_bread512(sb, sec, data) ({ \ #define sb_bread512(sb, sec, data) ({ \
struct buffer_head *__bh; \ struct buffer_head *__bh; \
...@@ -419,6 +424,4 @@ static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode) ...@@ -419,6 +424,4 @@ static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
#define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec) #define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec)
#define hfsp_now2mt() __hfsp_ut2mt(get_seconds()) #define hfsp_now2mt() __hfsp_ut2mt(get_seconds())
#define kdev_t_to_nr(x) (x)
#endif #endif
...@@ -200,6 +200,7 @@ struct hfsplus_cat_key { ...@@ -200,6 +200,7 @@ struct hfsplus_cat_key {
struct hfsplus_unistr name; struct hfsplus_unistr name;
} __packed; } __packed;
#define HFSPLUS_CAT_KEYLEN (sizeof(struct hfsplus_cat_key))
/* Structs from hfs.h */ /* Structs from hfs.h */
struct hfsp_point { struct hfsp_point {
...@@ -323,7 +324,7 @@ struct hfsplus_ext_key { ...@@ -323,7 +324,7 @@ struct hfsplus_ext_key {
__be32 start_block; __be32 start_block;
} __packed; } __packed;
#define HFSPLUS_EXT_KEYLEN 12 #define HFSPLUS_EXT_KEYLEN sizeof(struct hfsplus_ext_key)
/* HFS+ generic BTree key */ /* HFS+ generic BTree key */
typedef union { typedef union {
......
This diff is collapsed.
...@@ -17,83 +17,98 @@ ...@@ -17,83 +17,98 @@
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/xattr.h> #include <linux/xattr.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include "hfsplus_fs.h" #include "hfsplus_fs.h"
long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) static int hfsplus_ioctl_getflags(struct file *file, int __user *user_flags)
{ {
struct inode *inode = filp->f_path.dentry->d_inode; struct inode *inode = file->f_path.dentry->d_inode;
struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
unsigned int flags = 0;
if (inode->i_flags & S_IMMUTABLE)
flags |= FS_IMMUTABLE_FL;
if (inode->i_flags |= S_APPEND)
flags |= FS_APPEND_FL;
if (hip->userflags & HFSPLUS_FLG_NODUMP)
flags |= FS_NODUMP_FL;
return put_user(flags, user_flags);
}
static int hfsplus_ioctl_setflags(struct file *file, int __user *user_flags)
{
struct inode *inode = file->f_path.dentry->d_inode;
struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
unsigned int flags; unsigned int flags;
int err = 0;
lock_kernel(); err = mnt_want_write(file->f_path.mnt);
switch (cmd) { if (err)
case HFSPLUS_IOC_EXT2_GETFLAGS: goto out;
flags = 0;
if (HFSPLUS_I(inode).rootflags & HFSPLUS_FLG_IMMUTABLE)
flags |= FS_IMMUTABLE_FL; /* EXT2_IMMUTABLE_FL */
if (HFSPLUS_I(inode).rootflags & HFSPLUS_FLG_APPEND)
flags |= FS_APPEND_FL; /* EXT2_APPEND_FL */
if (HFSPLUS_I(inode).userflags & HFSPLUS_FLG_NODUMP)
flags |= FS_NODUMP_FL; /* EXT2_NODUMP_FL */
return put_user(flags, (int __user *)arg);
case HFSPLUS_IOC_EXT2_SETFLAGS: {
int err = 0;
err = mnt_want_write(filp->f_path.mnt);
if (err) {
unlock_kernel();
return err;
}
if (!is_owner_or_cap(inode)) { if (!is_owner_or_cap(inode)) {
err = -EACCES; err = -EACCES;
goto setflags_out; goto out_drop_write;
} }
if (get_user(flags, (int __user *)arg)) {
err = -EFAULT;
goto setflags_out;
}
if (flags & (FS_IMMUTABLE_FL|FS_APPEND_FL) ||
HFSPLUS_I(inode).rootflags & (HFSPLUS_FLG_IMMUTABLE|HFSPLUS_FLG_APPEND)) {
if (!capable(CAP_LINUX_IMMUTABLE)) {
err = -EPERM;
goto setflags_out;
}
}
/* don't silently ignore unsupported ext2 flags */ if (get_user(flags, user_flags)) {
if (flags & ~(FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NODUMP_FL)) { err = -EFAULT;
err = -EOPNOTSUPP; goto out_drop_write;
goto setflags_out; }
}
if (flags & FS_IMMUTABLE_FL) { /* EXT2_IMMUTABLE_FL */ mutex_lock(&inode->i_mutex);
inode->i_flags |= S_IMMUTABLE;
HFSPLUS_I(inode).rootflags |= HFSPLUS_FLG_IMMUTABLE; if ((flags & (FS_IMMUTABLE_FL|FS_APPEND_FL)) ||
} else { inode->i_flags & (S_IMMUTABLE|S_APPEND)) {
inode->i_flags &= ~S_IMMUTABLE; if (!capable(CAP_LINUX_IMMUTABLE)) {
HFSPLUS_I(inode).rootflags &= ~HFSPLUS_FLG_IMMUTABLE; err = -EPERM;
} goto out_unlock_inode;
if (flags & FS_APPEND_FL) { /* EXT2_APPEND_FL */
inode->i_flags |= S_APPEND;
HFSPLUS_I(inode).rootflags |= HFSPLUS_FLG_APPEND;
} else {
inode->i_flags &= ~S_APPEND;
HFSPLUS_I(inode).rootflags &= ~HFSPLUS_FLG_APPEND;
} }
if (flags & FS_NODUMP_FL) /* EXT2_NODUMP_FL */
HFSPLUS_I(inode).userflags |= HFSPLUS_FLG_NODUMP;
else
HFSPLUS_I(inode).userflags &= ~HFSPLUS_FLG_NODUMP;
inode->i_ctime = CURRENT_TIME_SEC;
mark_inode_dirty(inode);
setflags_out:
mnt_drop_write(filp->f_path.mnt);
unlock_kernel();
return err;
} }
/* don't silently ignore unsupported ext2 flags */
if (flags & ~(FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NODUMP_FL)) {
err = -EOPNOTSUPP;
goto out_unlock_inode;
}
if (flags & FS_IMMUTABLE_FL)
inode->i_flags |= S_IMMUTABLE;
else
inode->i_flags &= ~S_IMMUTABLE;
if (flags & FS_APPEND_FL)
inode->i_flags |= S_APPEND;
else
inode->i_flags &= ~S_APPEND;
if (flags & FS_NODUMP_FL)
hip->userflags |= HFSPLUS_FLG_NODUMP;
else
hip->userflags &= ~HFSPLUS_FLG_NODUMP;
inode->i_ctime = CURRENT_TIME_SEC;
mark_inode_dirty(inode);
out_unlock_inode:
mutex_lock(&inode->i_mutex);
out_drop_write:
mnt_drop_write(file->f_path.mnt);
out:
return err;
}
long hfsplus_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
void __user *argp = (void __user *)arg;
switch (cmd) {
case HFSPLUS_IOC_EXT2_GETFLAGS:
return hfsplus_ioctl_getflags(file, argp);
case HFSPLUS_IOC_EXT2_SETFLAGS:
return hfsplus_ioctl_setflags(file, argp);
default: default:
unlock_kernel();
return -ENOTTY; return -ENOTTY;
} }
} }
...@@ -110,7 +125,7 @@ int hfsplus_setxattr(struct dentry *dentry, const char *name, ...@@ -110,7 +125,7 @@ int hfsplus_setxattr(struct dentry *dentry, const char *name,
if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode)) if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
return -EOPNOTSUPP; return -EOPNOTSUPP;
res = hfs_find_init(HFSPLUS_SB(inode->i_sb).cat_tree, &fd); res = hfs_find_init(HFSPLUS_SB(inode->i_sb)->cat_tree, &fd);
if (res) if (res)
return res; return res;
res = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd); res = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
...@@ -153,7 +168,7 @@ ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name, ...@@ -153,7 +168,7 @@ ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (size) { if (size) {
res = hfs_find_init(HFSPLUS_SB(inode->i_sb).cat_tree, &fd); res = hfs_find_init(HFSPLUS_SB(inode->i_sb)->cat_tree, &fd);
if (res) if (res)
return res; return res;
res = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd); res = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
...@@ -177,7 +192,7 @@ ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name, ...@@ -177,7 +192,7 @@ ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
} else } else
res = size ? -ERANGE : 4; res = size ? -ERANGE : 4;
} else } else
res = -ENODATA; res = -EOPNOTSUPP;
out: out:
if (size) if (size)
hfs_find_exit(&fd); hfs_find_exit(&fd);
......
...@@ -143,13 +143,13 @@ int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi) ...@@ -143,13 +143,13 @@ int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi)
kfree(p); kfree(p);
break; break;
case opt_decompose: case opt_decompose:
sbi->flags &= ~HFSPLUS_SB_NODECOMPOSE; clear_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags);
break; break;
case opt_nodecompose: case opt_nodecompose:
sbi->flags |= HFSPLUS_SB_NODECOMPOSE; set_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags);
break; break;
case opt_force: case opt_force:
sbi->flags |= HFSPLUS_SB_FORCE; set_bit(HFSPLUS_SB_FORCE, &sbi->flags);
break; break;
default: default:
return 0; return 0;
...@@ -171,7 +171,7 @@ int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi) ...@@ -171,7 +171,7 @@ int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi)
int hfsplus_show_options(struct seq_file *seq, struct vfsmount *mnt) int hfsplus_show_options(struct seq_file *seq, struct vfsmount *mnt)
{ {
struct hfsplus_sb_info *sbi = &HFSPLUS_SB(mnt->mnt_sb); struct hfsplus_sb_info *sbi = HFSPLUS_SB(mnt->mnt_sb);
if (sbi->creator != HFSPLUS_DEF_CR_TYPE) if (sbi->creator != HFSPLUS_DEF_CR_TYPE)
seq_printf(seq, ",creator=%.4s", (char *)&sbi->creator); seq_printf(seq, ",creator=%.4s", (char *)&sbi->creator);
...@@ -184,7 +184,7 @@ int hfsplus_show_options(struct seq_file *seq, struct vfsmount *mnt) ...@@ -184,7 +184,7 @@ int hfsplus_show_options(struct seq_file *seq, struct vfsmount *mnt)
seq_printf(seq, ",session=%u", sbi->session); seq_printf(seq, ",session=%u", sbi->session);
if (sbi->nls) if (sbi->nls)
seq_printf(seq, ",nls=%s", sbi->nls->charset); seq_printf(seq, ",nls=%s", sbi->nls->charset);
if (sbi->flags & HFSPLUS_SB_NODECOMPOSE) if (test_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags))
seq_printf(seq, ",nodecompose"); seq_printf(seq, ",nodecompose");
return 0; return 0;
} }
...@@ -74,6 +74,7 @@ struct old_pmap { ...@@ -74,6 +74,7 @@ struct old_pmap {
int hfs_part_find(struct super_block *sb, int hfs_part_find(struct super_block *sb,
sector_t *part_start, sector_t *part_size) sector_t *part_start, sector_t *part_size)
{ {
struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
struct buffer_head *bh; struct buffer_head *bh;
__be16 *data; __be16 *data;
int i, size, res; int i, size, res;
...@@ -95,7 +96,7 @@ int hfs_part_find(struct super_block *sb, ...@@ -95,7 +96,7 @@ int hfs_part_find(struct super_block *sb,
for (i = 0; i < size; p++, i++) { for (i = 0; i < size; p++, i++) {
if (p->pdStart && p->pdSize && if (p->pdStart && p->pdSize &&
p->pdFSID == cpu_to_be32(0x54465331)/*"TFS1"*/ && p->pdFSID == cpu_to_be32(0x54465331)/*"TFS1"*/ &&
(HFSPLUS_SB(sb).part < 0 || HFSPLUS_SB(sb).part == i)) { (sbi->part < 0 || sbi->part == i)) {
*part_start += be32_to_cpu(p->pdStart); *part_start += be32_to_cpu(p->pdStart);
*part_size = be32_to_cpu(p->pdSize); *part_size = be32_to_cpu(p->pdSize);
res = 0; res = 0;
...@@ -111,7 +112,7 @@ int hfs_part_find(struct super_block *sb, ...@@ -111,7 +112,7 @@ int hfs_part_find(struct super_block *sb,
size = be32_to_cpu(pm->pmMapBlkCnt); size = be32_to_cpu(pm->pmMapBlkCnt);
for (i = 0; i < size;) { for (i = 0; i < size;) {
if (!memcmp(pm->pmPartType,"Apple_HFS", 9) && if (!memcmp(pm->pmPartType,"Apple_HFS", 9) &&
(HFSPLUS_SB(sb).part < 0 || HFSPLUS_SB(sb).part == i)) { (sbi->part < 0 || sbi->part == i)) {
*part_start += be32_to_cpu(pm->pmPyPartStart); *part_start += be32_to_cpu(pm->pmPyPartStart);
*part_size = be32_to_cpu(pm->pmPartBlkCnt); *part_size = be32_to_cpu(pm->pmPartBlkCnt);
res = 0; res = 0;
......
This diff is collapsed.
...@@ -121,7 +121,7 @@ static u16 *hfsplus_compose_lookup(u16 *p, u16 cc) ...@@ -121,7 +121,7 @@ static u16 *hfsplus_compose_lookup(u16 *p, u16 cc)
int hfsplus_uni2asc(struct super_block *sb, const struct hfsplus_unistr *ustr, char *astr, int *len_p) int hfsplus_uni2asc(struct super_block *sb, const struct hfsplus_unistr *ustr, char *astr, int *len_p)
{ {
const hfsplus_unichr *ip; const hfsplus_unichr *ip;
struct nls_table *nls = HFSPLUS_SB(sb).nls; struct nls_table *nls = HFSPLUS_SB(sb)->nls;
u8 *op; u8 *op;
u16 cc, c0, c1; u16 cc, c0, c1;
u16 *ce1, *ce2; u16 *ce1, *ce2;
...@@ -132,7 +132,7 @@ int hfsplus_uni2asc(struct super_block *sb, const struct hfsplus_unistr *ustr, c ...@@ -132,7 +132,7 @@ int hfsplus_uni2asc(struct super_block *sb, const struct hfsplus_unistr *ustr, c
ustrlen = be16_to_cpu(ustr->length); ustrlen = be16_to_cpu(ustr->length);
len = *len_p; len = *len_p;
ce1 = NULL; ce1 = NULL;
compose = !(HFSPLUS_SB(sb).flags & HFSPLUS_SB_NODECOMPOSE); compose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
while (ustrlen > 0) { while (ustrlen > 0) {
c0 = be16_to_cpu(*ip++); c0 = be16_to_cpu(*ip++);
...@@ -246,7 +246,7 @@ int hfsplus_uni2asc(struct super_block *sb, const struct hfsplus_unistr *ustr, c ...@@ -246,7 +246,7 @@ int hfsplus_uni2asc(struct super_block *sb, const struct hfsplus_unistr *ustr, c
static inline int asc2unichar(struct super_block *sb, const char *astr, int len, static inline int asc2unichar(struct super_block *sb, const char *astr, int len,
wchar_t *uc) wchar_t *uc)
{ {
int size = HFSPLUS_SB(sb).nls->char2uni(astr, len, uc); int size = HFSPLUS_SB(sb)->nls->char2uni(astr, len, uc);
if (size <= 0) { if (size <= 0) {
*uc = '?'; *uc = '?';
size = 1; size = 1;
...@@ -293,7 +293,7 @@ int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr, ...@@ -293,7 +293,7 @@ int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr,
u16 *dstr, outlen = 0; u16 *dstr, outlen = 0;
wchar_t c; wchar_t c;
decompose = !(HFSPLUS_SB(sb).flags & HFSPLUS_SB_NODECOMPOSE); decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
while (outlen < HFSPLUS_MAX_STRLEN && len > 0) { while (outlen < HFSPLUS_MAX_STRLEN && len > 0) {
size = asc2unichar(sb, astr, len, &c); size = asc2unichar(sb, astr, len, &c);
...@@ -330,8 +330,8 @@ int hfsplus_hash_dentry(struct dentry *dentry, struct qstr *str) ...@@ -330,8 +330,8 @@ int hfsplus_hash_dentry(struct dentry *dentry, struct qstr *str)
wchar_t c; wchar_t c;
u16 c2; u16 c2;
casefold = (HFSPLUS_SB(sb).flags & HFSPLUS_SB_CASEFOLD); casefold = test_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
decompose = !(HFSPLUS_SB(sb).flags & HFSPLUS_SB_NODECOMPOSE); decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
hash = init_name_hash(); hash = init_name_hash();
astr = str->name; astr = str->name;
len = str->len; len = str->len;
...@@ -373,8 +373,8 @@ int hfsplus_compare_dentry(struct dentry *dentry, struct qstr *s1, struct qstr * ...@@ -373,8 +373,8 @@ int hfsplus_compare_dentry(struct dentry *dentry, struct qstr *s1, struct qstr *
u16 c1, c2; u16 c1, c2;
wchar_t c; wchar_t c;
casefold = (HFSPLUS_SB(sb).flags & HFSPLUS_SB_CASEFOLD); casefold = test_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
decompose = !(HFSPLUS_SB(sb).flags & HFSPLUS_SB_NODECOMPOSE); decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
astr1 = s1->name; astr1 = s1->name;
len1 = s1->len; len1 = s1->len;
astr2 = s2->name; astr2 = s2->name;
......
...@@ -65,8 +65,8 @@ static int hfsplus_get_last_session(struct super_block *sb, ...@@ -65,8 +65,8 @@ static int hfsplus_get_last_session(struct super_block *sb,
*start = 0; *start = 0;
*size = sb->s_bdev->bd_inode->i_size >> 9; *size = sb->s_bdev->bd_inode->i_size >> 9;
if (HFSPLUS_SB(sb).session >= 0) { if (HFSPLUS_SB(sb)->session >= 0) {
te.cdte_track = HFSPLUS_SB(sb).session; te.cdte_track = HFSPLUS_SB(sb)->session;
te.cdte_format = CDROM_LBA; te.cdte_format = CDROM_LBA;
res = ioctl_by_bdev(sb->s_bdev, CDROMREADTOCENTRY, (unsigned long)&te); res = ioctl_by_bdev(sb->s_bdev, CDROMREADTOCENTRY, (unsigned long)&te);
if (!res && (te.cdte_ctrl & CDROM_DATA_TRACK) == 4) { if (!res && (te.cdte_ctrl & CDROM_DATA_TRACK) == 4) {
...@@ -87,6 +87,7 @@ static int hfsplus_get_last_session(struct super_block *sb, ...@@ -87,6 +87,7 @@ static int hfsplus_get_last_session(struct super_block *sb,
/* Takes in super block, returns true if good data read */ /* Takes in super block, returns true if good data read */
int hfsplus_read_wrapper(struct super_block *sb) int hfsplus_read_wrapper(struct super_block *sb)
{ {
struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
struct buffer_head *bh; struct buffer_head *bh;
struct hfsplus_vh *vhdr; struct hfsplus_vh *vhdr;
struct hfsplus_wd wd; struct hfsplus_wd wd;
...@@ -122,7 +123,7 @@ int hfsplus_read_wrapper(struct super_block *sb) ...@@ -122,7 +123,7 @@ int hfsplus_read_wrapper(struct super_block *sb)
if (vhdr->signature == cpu_to_be16(HFSPLUS_VOLHEAD_SIG)) if (vhdr->signature == cpu_to_be16(HFSPLUS_VOLHEAD_SIG))
break; break;
if (vhdr->signature == cpu_to_be16(HFSPLUS_VOLHEAD_SIGX)) { if (vhdr->signature == cpu_to_be16(HFSPLUS_VOLHEAD_SIGX)) {
HFSPLUS_SB(sb).flags |= HFSPLUS_SB_HFSX; set_bit(HFSPLUS_SB_HFSX, &sbi->flags);
break; break;
} }
brelse(bh); brelse(bh);
...@@ -143,11 +144,11 @@ int hfsplus_read_wrapper(struct super_block *sb) ...@@ -143,11 +144,11 @@ int hfsplus_read_wrapper(struct super_block *sb)
if (blocksize < HFSPLUS_SECTOR_SIZE || if (blocksize < HFSPLUS_SECTOR_SIZE ||
((blocksize - 1) & blocksize)) ((blocksize - 1) & blocksize))
return -EINVAL; return -EINVAL;
HFSPLUS_SB(sb).alloc_blksz = blocksize; sbi->alloc_blksz = blocksize;
HFSPLUS_SB(sb).alloc_blksz_shift = 0; sbi->alloc_blksz_shift = 0;
while ((blocksize >>= 1) != 0) while ((blocksize >>= 1) != 0)
HFSPLUS_SB(sb).alloc_blksz_shift++; sbi->alloc_blksz_shift++;
blocksize = min(HFSPLUS_SB(sb).alloc_blksz, (u32)PAGE_SIZE); blocksize = min(sbi->alloc_blksz, (u32)PAGE_SIZE);
/* align block size to block offset */ /* align block size to block offset */
while (part_start & ((blocksize >> HFSPLUS_SECTOR_SHIFT) - 1)) while (part_start & ((blocksize >> HFSPLUS_SECTOR_SHIFT) - 1))
...@@ -158,23 +159,26 @@ int hfsplus_read_wrapper(struct super_block *sb) ...@@ -158,23 +159,26 @@ int hfsplus_read_wrapper(struct super_block *sb)
return -EINVAL; return -EINVAL;
} }
HFSPLUS_SB(sb).blockoffset = part_start >> sbi->blockoffset =
(sb->s_blocksize_bits - HFSPLUS_SECTOR_SHIFT); part_start >> (sb->s_blocksize_bits - HFSPLUS_SECTOR_SHIFT);
HFSPLUS_SB(sb).sect_count = part_size; sbi->sect_count = part_size;
HFSPLUS_SB(sb).fs_shift = HFSPLUS_SB(sb).alloc_blksz_shift - sbi->fs_shift = sbi->alloc_blksz_shift - sb->s_blocksize_bits;
sb->s_blocksize_bits;
bh = sb_bread512(sb, part_start + HFSPLUS_VOLHEAD_SECTOR, vhdr); bh = sb_bread512(sb, part_start + HFSPLUS_VOLHEAD_SECTOR, vhdr);
if (!bh) if (!bh)
return -EIO; return -EIO;
/* should still be the same... */ /* should still be the same... */
if (vhdr->signature != (HFSPLUS_SB(sb).flags & HFSPLUS_SB_HFSX ? if (test_bit(HFSPLUS_SB_HFSX, &sbi->flags)) {
cpu_to_be16(HFSPLUS_VOLHEAD_SIGX) : if (vhdr->signature != cpu_to_be16(HFSPLUS_VOLHEAD_SIGX))
cpu_to_be16(HFSPLUS_VOLHEAD_SIG))) goto error;
goto error; } else {
HFSPLUS_SB(sb).s_vhbh = bh; if (vhdr->signature != cpu_to_be16(HFSPLUS_VOLHEAD_SIG))
HFSPLUS_SB(sb).s_vhdr = vhdr; goto error;
}
sbi->s_vhbh = bh;
sbi->s_vhdr = vhdr;
return 0; return 0;
error: error:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment