Commit 324ef39a authored by Vyacheslav Dubeyko's avatar Vyacheslav Dubeyko Committed by Linus Torvalds

hfsplus: add support of manipulation by attributes file

Add support of manipulation by attributes file.
Signed-off-by: default avatarVyacheslav Dubeyko <slava@dubeyko.com>
Reported-by: default avatarHin-Tak Leung <htl10@users.sourceforge.net>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Jan Kara <jack@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 127e5f5a
...@@ -5,5 +5,5 @@ ...@@ -5,5 +5,5 @@
obj-$(CONFIG_HFSPLUS_FS) += hfsplus.o obj-$(CONFIG_HFSPLUS_FS) += hfsplus.o
hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o btree.o \ hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o btree.o \
bnode.o brec.o bfind.o tables.o unicode.o wrapper.o bitmap.o part_tbl.o bnode.o brec.o bfind.o tables.o unicode.o wrapper.o bitmap.o part_tbl.o \
attributes.o xattr.o xattr_user.o xattr_security.o xattr_trusted.o
...@@ -24,7 +24,19 @@ int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd) ...@@ -24,7 +24,19 @@ int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd)
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", dprint(DBG_BNODE_REFS, "find_init: %d (%p)\n",
tree->cnid, __builtin_return_address(0)); tree->cnid, __builtin_return_address(0));
mutex_lock(&tree->tree_lock); switch (tree->cnid) {
case HFSPLUS_CAT_CNID:
mutex_lock_nested(&tree->tree_lock, CATALOG_BTREE_MUTEX);
break;
case HFSPLUS_EXT_CNID:
mutex_lock_nested(&tree->tree_lock, EXTENTS_BTREE_MUTEX);
break;
case HFSPLUS_ATTR_CNID:
mutex_lock_nested(&tree->tree_lock, ATTR_BTREE_MUTEX);
break;
default:
BUG();
}
return 0; return 0;
} }
...@@ -38,15 +50,73 @@ void hfs_find_exit(struct hfs_find_data *fd) ...@@ -38,15 +50,73 @@ void hfs_find_exit(struct hfs_find_data *fd)
fd->tree = NULL; fd->tree = NULL;
} }
/* Find the record in bnode that best matches key (not greater than...)*/ int hfs_find_1st_rec_by_cnid(struct hfs_bnode *bnode,
int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd) struct hfs_find_data *fd,
int *begin,
int *end,
int *cur_rec)
{
__be32 cur_cnid, search_cnid;
if (bnode->tree->cnid == HFSPLUS_EXT_CNID) {
cur_cnid = fd->key->ext.cnid;
search_cnid = fd->search_key->ext.cnid;
} else if (bnode->tree->cnid == HFSPLUS_CAT_CNID) {
cur_cnid = fd->key->cat.parent;
search_cnid = fd->search_key->cat.parent;
} else if (bnode->tree->cnid == HFSPLUS_ATTR_CNID) {
cur_cnid = fd->key->attr.cnid;
search_cnid = fd->search_key->attr.cnid;
} else
BUG();
if (cur_cnid == search_cnid) {
(*end) = (*cur_rec);
if ((*begin) == (*end))
return 1;
} else {
if (be32_to_cpu(cur_cnid) < be32_to_cpu(search_cnid))
(*begin) = (*cur_rec) + 1;
else
(*end) = (*cur_rec) - 1;
}
return 0;
}
int hfs_find_rec_by_key(struct hfs_bnode *bnode,
struct hfs_find_data *fd,
int *begin,
int *end,
int *cur_rec)
{ {
int cmpval; int cmpval;
cmpval = bnode->tree->keycmp(fd->key, fd->search_key);
if (!cmpval) {
(*end) = (*cur_rec);
return 1;
}
if (cmpval < 0)
(*begin) = (*cur_rec) + 1;
else
*(end) = (*cur_rec) - 1;
return 0;
}
/* Find the record in bnode that best matches key (not greater than...)*/
int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd,
search_strategy_t rec_found)
{
u16 off, len, keylen; u16 off, len, keylen;
int rec; int rec;
int b, e; int b, e;
int res; int res;
if (!rec_found)
BUG();
b = 0; b = 0;
e = bnode->num_recs - 1; e = bnode->num_recs - 1;
res = -ENOENT; res = -ENOENT;
...@@ -59,17 +129,12 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd) ...@@ -59,17 +129,12 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
goto fail; 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); if (rec_found(bnode, fd, &b, &e, &rec)) {
if (!cmpval) {
e = rec;
res = 0; res = 0;
goto done; goto done;
} }
if (cmpval < 0)
b = rec + 1;
else
e = rec - 1;
} while (b <= e); } while (b <= e);
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);
...@@ -79,19 +144,21 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd) ...@@ -79,19 +144,21 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
} }
hfs_bnode_read(bnode, fd->key, off, keylen); hfs_bnode_read(bnode, fd->key, off, keylen);
} }
done: done:
fd->record = e; fd->record = e;
fd->keyoffset = off; fd->keyoffset = off;
fd->keylength = keylen; fd->keylength = keylen;
fd->entryoffset = off + keylen; fd->entryoffset = off + keylen;
fd->entrylength = len - keylen; fd->entrylength = len - keylen;
fail: fail:
return res; return res;
} }
/* Traverse a B*Tree from the root to a leaf finding best fit to key */ /* Traverse a B*Tree from the root to a leaf finding best fit to key */
/* Return allocated copy of node found, set recnum to best record */ /* Return allocated copy of node found, set recnum to best record */
int hfs_brec_find(struct hfs_find_data *fd) int hfs_brec_find(struct hfs_find_data *fd, search_strategy_t do_key_compare)
{ {
struct hfs_btree *tree; struct hfs_btree *tree;
struct hfs_bnode *bnode; struct hfs_bnode *bnode;
...@@ -122,7 +189,7 @@ int hfs_brec_find(struct hfs_find_data *fd) ...@@ -122,7 +189,7 @@ int hfs_brec_find(struct hfs_find_data *fd)
goto invalid; goto invalid;
bnode->parent = parent; bnode->parent = parent;
res = __hfs_brec_find(bnode, fd); res = __hfs_brec_find(bnode, fd, do_key_compare);
if (!height) if (!height)
break; break;
if (fd->record < 0) if (fd->record < 0)
...@@ -149,7 +216,7 @@ int hfs_brec_read(struct hfs_find_data *fd, void *rec, int rec_len) ...@@ -149,7 +216,7 @@ int hfs_brec_read(struct hfs_find_data *fd, void *rec, int rec_len)
{ {
int res; int res;
res = hfs_brec_find(fd); res = hfs_brec_find(fd, hfs_find_rec_by_key);
if (res) if (res)
return res; return res;
if (fd->entrylength > rec_len) if (fd->entrylength > rec_len)
......
...@@ -62,7 +62,8 @@ void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off) ...@@ -62,7 +62,8 @@ void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off)
tree = node->tree; tree = node->tree;
if (node->type == HFS_NODE_LEAF || if (node->type == HFS_NODE_LEAF ||
tree->attributes & HFS_TREE_VARIDXKEYS) tree->attributes & HFS_TREE_VARIDXKEYS ||
node->tree->cnid == HFSPLUS_ATTR_CNID)
key_len = hfs_bnode_read_u16(node, off) + 2; key_len = hfs_bnode_read_u16(node, off) + 2;
else else
key_len = tree->max_key_len + 2; key_len = tree->max_key_len + 2;
...@@ -314,7 +315,8 @@ void hfs_bnode_dump(struct hfs_bnode *node) ...@@ -314,7 +315,8 @@ void hfs_bnode_dump(struct hfs_bnode *node)
if (i && node->type == HFS_NODE_INDEX) { if (i && node->type == HFS_NODE_INDEX) {
int tmp; int tmp;
if (node->tree->attributes & HFS_TREE_VARIDXKEYS) if (node->tree->attributes & HFS_TREE_VARIDXKEYS ||
node->tree->cnid == HFSPLUS_ATTR_CNID)
tmp = hfs_bnode_read_u16(node, key_off) + 2; tmp = hfs_bnode_read_u16(node, key_off) + 2;
else else
tmp = node->tree->max_key_len + 2; tmp = node->tree->max_key_len + 2;
......
...@@ -36,7 +36,8 @@ u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec) ...@@ -36,7 +36,8 @@ u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec)
return 0; return 0;
if ((node->type == HFS_NODE_INDEX) && if ((node->type == HFS_NODE_INDEX) &&
!(node->tree->attributes & HFS_TREE_VARIDXKEYS)) { !(node->tree->attributes & HFS_TREE_VARIDXKEYS) &&
(node->tree->cnid != HFSPLUS_ATTR_CNID)) {
retval = node->tree->max_key_len + 2; retval = node->tree->max_key_len + 2;
} else { } else {
recoff = hfs_bnode_read_u16(node, recoff = hfs_bnode_read_u16(node,
...@@ -151,12 +152,13 @@ int hfs_brec_insert(struct hfs_find_data *fd, void *entry, int entry_len) ...@@ -151,12 +152,13 @@ int hfs_brec_insert(struct hfs_find_data *fd, void *entry, int entry_len)
/* get index key */ /* get index key */
hfs_bnode_read_key(new_node, fd->search_key, 14); hfs_bnode_read_key(new_node, fd->search_key, 14);
__hfs_brec_find(fd->bnode, fd); __hfs_brec_find(fd->bnode, fd, hfs_find_rec_by_key);
hfs_bnode_put(new_node); hfs_bnode_put(new_node);
new_node = NULL; new_node = NULL;
if (tree->attributes & HFS_TREE_VARIDXKEYS) if ((tree->attributes & HFS_TREE_VARIDXKEYS) ||
(tree->cnid == HFSPLUS_ATTR_CNID))
key_len = be16_to_cpu(fd->search_key->key_len) + 2; key_len = be16_to_cpu(fd->search_key->key_len) + 2;
else { else {
fd->search_key->key_len = fd->search_key->key_len =
...@@ -201,7 +203,7 @@ int hfs_brec_remove(struct hfs_find_data *fd) ...@@ -201,7 +203,7 @@ int hfs_brec_remove(struct hfs_find_data *fd)
hfs_bnode_put(node); hfs_bnode_put(node);
node = fd->bnode = parent; node = fd->bnode = parent;
__hfs_brec_find(node, fd); __hfs_brec_find(node, fd, hfs_find_rec_by_key);
goto again; goto again;
} }
hfs_bnode_write_u16(node, hfs_bnode_write_u16(node,
...@@ -367,12 +369,13 @@ static int hfs_brec_update_parent(struct hfs_find_data *fd) ...@@ -367,12 +369,13 @@ static int hfs_brec_update_parent(struct hfs_find_data *fd)
parent = hfs_bnode_find(tree, node->parent); parent = hfs_bnode_find(tree, node->parent);
if (IS_ERR(parent)) if (IS_ERR(parent))
return PTR_ERR(parent); return PTR_ERR(parent);
__hfs_brec_find(parent, fd); __hfs_brec_find(parent, fd, hfs_find_rec_by_key);
hfs_bnode_dump(parent); hfs_bnode_dump(parent);
rec = fd->record; rec = fd->record;
/* size difference between old and new key */ /* size difference between old and new key */
if (tree->attributes & HFS_TREE_VARIDXKEYS) if ((tree->attributes & HFS_TREE_VARIDXKEYS) ||
(tree->cnid == HFSPLUS_ATTR_CNID))
newkeylen = hfs_bnode_read_u16(node, 14) + 2; newkeylen = hfs_bnode_read_u16(node, 14) + 2;
else else
fd->keylength = newkeylen = tree->max_key_len + 2; fd->keylength = newkeylen = tree->max_key_len + 2;
...@@ -427,7 +430,7 @@ static int hfs_brec_update_parent(struct hfs_find_data *fd) ...@@ -427,7 +430,7 @@ static int hfs_brec_update_parent(struct hfs_find_data *fd)
hfs_bnode_read_key(new_node, fd->search_key, 14); hfs_bnode_read_key(new_node, fd->search_key, 14);
cnid = cpu_to_be32(new_node->this); cnid = cpu_to_be32(new_node->this);
__hfs_brec_find(fd->bnode, fd); __hfs_brec_find(fd->bnode, fd, hfs_find_rec_by_key);
hfs_brec_insert(fd, &cnid, sizeof(cnid)); hfs_brec_insert(fd, &cnid, sizeof(cnid));
hfs_bnode_put(fd->bnode); hfs_bnode_put(fd->bnode);
hfs_bnode_put(new_node); hfs_bnode_put(new_node);
...@@ -495,13 +498,15 @@ static int hfs_btree_inc_height(struct hfs_btree *tree) ...@@ -495,13 +498,15 @@ static int hfs_btree_inc_height(struct hfs_btree *tree)
/* insert old root idx into new root */ /* insert old root idx into new root */
node->parent = tree->root; node->parent = tree->root;
if (node->type == HFS_NODE_LEAF || if (node->type == HFS_NODE_LEAF ||
tree->attributes & HFS_TREE_VARIDXKEYS) tree->attributes & HFS_TREE_VARIDXKEYS ||
tree->cnid == HFSPLUS_ATTR_CNID)
key_size = hfs_bnode_read_u16(node, 14) + 2; key_size = hfs_bnode_read_u16(node, 14) + 2;
else else
key_size = tree->max_key_len + 2; key_size = tree->max_key_len + 2;
hfs_bnode_copy(new_node, 14, node, 14, key_size); hfs_bnode_copy(new_node, 14, node, 14, key_size);
if (!(tree->attributes & HFS_TREE_VARIDXKEYS)) { if (!(tree->attributes & HFS_TREE_VARIDXKEYS) &&
(tree->cnid != HFSPLUS_ATTR_CNID)) {
key_size = tree->max_key_len + 2; key_size = tree->max_key_len + 2;
hfs_bnode_write_u16(new_node, 14, tree->max_key_len); hfs_bnode_write_u16(new_node, 14, tree->max_key_len);
} }
......
...@@ -98,6 +98,14 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id) ...@@ -98,6 +98,14 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)
set_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags); set_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
} }
break; break;
case HFSPLUS_ATTR_CNID:
if (tree->max_key_len != HFSPLUS_ATTR_KEYLEN - sizeof(u16)) {
printk(KERN_ERR "hfs: invalid attributes max_key_len %d\n",
tree->max_key_len);
goto fail_page;
}
tree->keycmp = hfsplus_attr_bin_cmp_key;
break;
default: 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;
......
...@@ -45,7 +45,8 @@ void hfsplus_cat_build_key(struct super_block *sb, hfsplus_btree_key *key, ...@@ -45,7 +45,8 @@ void hfsplus_cat_build_key(struct super_block *sb, hfsplus_btree_key *key,
key->cat.parent = cpu_to_be32(parent); key->cat.parent = cpu_to_be32(parent);
if (str) { if (str) {
hfsplus_asc2uni(sb, &key->cat.name, str->name, str->len); hfsplus_asc2uni(sb, &key->cat.name, HFSPLUS_MAX_STRLEN,
str->name, str->len);
len = be16_to_cpu(key->cat.name.length); len = be16_to_cpu(key->cat.name.length);
} else { } else {
key->cat.name.length = 0; key->cat.name.length = 0;
...@@ -167,7 +168,8 @@ static int hfsplus_fill_cat_thread(struct super_block *sb, ...@@ -167,7 +168,8 @@ static int hfsplus_fill_cat_thread(struct super_block *sb,
entry->type = cpu_to_be16(type); entry->type = cpu_to_be16(type);
entry->thread.reserved = 0; entry->thread.reserved = 0;
entry->thread.parentID = cpu_to_be32(parentid); entry->thread.parentID = cpu_to_be32(parentid);
hfsplus_asc2uni(sb, &entry->thread.nodeName, str->name, str->len); hfsplus_asc2uni(sb, &entry->thread.nodeName, HFSPLUS_MAX_STRLEN,
str->name, str->len);
return 10 + be16_to_cpu(entry->thread.nodeName.length) * 2; return 10 + be16_to_cpu(entry->thread.nodeName.length) * 2;
} }
...@@ -198,7 +200,7 @@ int hfsplus_find_cat(struct super_block *sb, u32 cnid, ...@@ -198,7 +200,7 @@ int hfsplus_find_cat(struct super_block *sb, u32 cnid,
hfsplus_cat_build_key_uni(fd->search_key, hfsplus_cat_build_key_uni(fd->search_key,
be32_to_cpu(tmp.thread.parentID), be32_to_cpu(tmp.thread.parentID),
&tmp.thread.nodeName); &tmp.thread.nodeName);
return hfs_brec_find(fd); return hfs_brec_find(fd, hfs_find_rec_by_key);
} }
int hfsplus_create_cat(u32 cnid, struct inode *dir, int hfsplus_create_cat(u32 cnid, struct inode *dir,
...@@ -221,7 +223,7 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir, ...@@ -221,7 +223,7 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir,
S_ISDIR(inode->i_mode) ? S_ISDIR(inode->i_mode) ?
HFSPLUS_FOLDER_THREAD : HFSPLUS_FILE_THREAD, HFSPLUS_FOLDER_THREAD : HFSPLUS_FILE_THREAD,
dir->i_ino, str); dir->i_ino, str);
err = hfs_brec_find(&fd); err = hfs_brec_find(&fd, hfs_find_rec_by_key);
if (err != -ENOENT) { if (err != -ENOENT) {
if (!err) if (!err)
err = -EEXIST; err = -EEXIST;
...@@ -233,7 +235,7 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir, ...@@ -233,7 +235,7 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir,
hfsplus_cat_build_key(sb, fd.search_key, dir->i_ino, str); hfsplus_cat_build_key(sb, fd.search_key, dir->i_ino, str);
entry_size = hfsplus_cat_build_record(&entry, cnid, inode); entry_size = hfsplus_cat_build_record(&entry, cnid, inode);
err = hfs_brec_find(&fd); err = hfs_brec_find(&fd, hfs_find_rec_by_key);
if (err != -ENOENT) { if (err != -ENOENT) {
/* panic? */ /* panic? */
if (!err) if (!err)
...@@ -253,7 +255,7 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir, ...@@ -253,7 +255,7 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir,
err1: err1:
hfsplus_cat_build_key(sb, fd.search_key, cnid, NULL); hfsplus_cat_build_key(sb, fd.search_key, cnid, NULL);
if (!hfs_brec_find(&fd)) if (!hfs_brec_find(&fd, hfs_find_rec_by_key))
hfs_brec_remove(&fd); hfs_brec_remove(&fd);
err2: err2:
hfs_find_exit(&fd); hfs_find_exit(&fd);
...@@ -279,7 +281,7 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str) ...@@ -279,7 +281,7 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str)
int len; int len;
hfsplus_cat_build_key(sb, fd.search_key, cnid, NULL); hfsplus_cat_build_key(sb, fd.search_key, cnid, NULL);
err = hfs_brec_find(&fd); err = hfs_brec_find(&fd, hfs_find_rec_by_key);
if (err) if (err)
goto out; goto out;
...@@ -296,7 +298,7 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str) ...@@ -296,7 +298,7 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str)
} else } else
hfsplus_cat_build_key(sb, fd.search_key, dir->i_ino, str); hfsplus_cat_build_key(sb, fd.search_key, dir->i_ino, str);
err = hfs_brec_find(&fd); err = hfs_brec_find(&fd, hfs_find_rec_by_key);
if (err) if (err)
goto out; goto out;
...@@ -326,7 +328,7 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str) ...@@ -326,7 +328,7 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str)
goto out; goto out;
hfsplus_cat_build_key(sb, fd.search_key, cnid, NULL); hfsplus_cat_build_key(sb, fd.search_key, cnid, NULL);
err = hfs_brec_find(&fd); err = hfs_brec_find(&fd, hfs_find_rec_by_key);
if (err) if (err)
goto out; goto out;
...@@ -337,6 +339,12 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str) ...@@ -337,6 +339,12 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str)
dir->i_size--; dir->i_size--;
dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC; dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
hfsplus_mark_inode_dirty(dir, HFSPLUS_I_CAT_DIRTY); hfsplus_mark_inode_dirty(dir, HFSPLUS_I_CAT_DIRTY);
if (type == HFSPLUS_FILE || type == HFSPLUS_FOLDER) {
if (HFSPLUS_SB(sb)->attr_tree)
hfsplus_delete_all_attrs(dir, cnid);
}
out: out:
hfs_find_exit(&fd); hfs_find_exit(&fd);
...@@ -363,7 +371,7 @@ int hfsplus_rename_cat(u32 cnid, ...@@ -363,7 +371,7 @@ int hfsplus_rename_cat(u32 cnid,
/* find the old dir entry and read the data */ /* find the old dir entry and read the data */
hfsplus_cat_build_key(sb, src_fd.search_key, src_dir->i_ino, src_name); hfsplus_cat_build_key(sb, src_fd.search_key, src_dir->i_ino, src_name);
err = hfs_brec_find(&src_fd); err = hfs_brec_find(&src_fd, hfs_find_rec_by_key);
if (err) if (err)
goto out; goto out;
if (src_fd.entrylength > sizeof(entry) || src_fd.entrylength < 0) { if (src_fd.entrylength > sizeof(entry) || src_fd.entrylength < 0) {
...@@ -376,7 +384,7 @@ int hfsplus_rename_cat(u32 cnid, ...@@ -376,7 +384,7 @@ int hfsplus_rename_cat(u32 cnid,
/* create new dir entry with the data from the old entry */ /* create new dir entry with the data from the old entry */
hfsplus_cat_build_key(sb, dst_fd.search_key, dst_dir->i_ino, dst_name); hfsplus_cat_build_key(sb, dst_fd.search_key, dst_dir->i_ino, dst_name);
err = hfs_brec_find(&dst_fd); err = hfs_brec_find(&dst_fd, hfs_find_rec_by_key);
if (err != -ENOENT) { if (err != -ENOENT) {
if (!err) if (!err)
err = -EEXIST; err = -EEXIST;
...@@ -391,7 +399,7 @@ int hfsplus_rename_cat(u32 cnid, ...@@ -391,7 +399,7 @@ int hfsplus_rename_cat(u32 cnid,
/* finally remove the old entry */ /* finally remove the old entry */
hfsplus_cat_build_key(sb, src_fd.search_key, src_dir->i_ino, src_name); hfsplus_cat_build_key(sb, src_fd.search_key, src_dir->i_ino, src_name);
err = hfs_brec_find(&src_fd); err = hfs_brec_find(&src_fd, hfs_find_rec_by_key);
if (err) if (err)
goto out; goto out;
err = hfs_brec_remove(&src_fd); err = hfs_brec_remove(&src_fd);
...@@ -402,7 +410,7 @@ int hfsplus_rename_cat(u32 cnid, ...@@ -402,7 +410,7 @@ int hfsplus_rename_cat(u32 cnid,
/* remove old thread entry */ /* remove old thread entry */
hfsplus_cat_build_key(sb, src_fd.search_key, cnid, NULL); hfsplus_cat_build_key(sb, src_fd.search_key, cnid, NULL);
err = hfs_brec_find(&src_fd); err = hfs_brec_find(&src_fd, hfs_find_rec_by_key);
if (err) if (err)
goto out; goto out;
type = hfs_bnode_read_u16(src_fd.bnode, src_fd.entryoffset); type = hfs_bnode_read_u16(src_fd.bnode, src_fd.entryoffset);
...@@ -414,7 +422,7 @@ int hfsplus_rename_cat(u32 cnid, ...@@ -414,7 +422,7 @@ int hfsplus_rename_cat(u32 cnid,
hfsplus_cat_build_key(sb, dst_fd.search_key, cnid, NULL); hfsplus_cat_build_key(sb, dst_fd.search_key, cnid, NULL);
entry_size = hfsplus_fill_cat_thread(sb, &entry, type, entry_size = hfsplus_fill_cat_thread(sb, &entry, type,
dst_dir->i_ino, dst_name); dst_dir->i_ino, dst_name);
err = hfs_brec_find(&dst_fd); err = hfs_brec_find(&dst_fd, hfs_find_rec_by_key);
if (err != -ENOENT) { if (err != -ENOENT) {
if (!err) if (!err)
err = -EEXIST; err = -EEXIST;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "hfsplus_fs.h" #include "hfsplus_fs.h"
#include "hfsplus_raw.h" #include "hfsplus_raw.h"
#include "xattr.h"
static inline void hfsplus_instantiate(struct dentry *dentry, static inline void hfsplus_instantiate(struct dentry *dentry,
struct inode *inode, u32 cnid) struct inode *inode, u32 cnid)
...@@ -138,7 +139,7 @@ static int hfsplus_readdir(struct file *filp, void *dirent, filldir_t filldir) ...@@ -138,7 +139,7 @@ static int hfsplus_readdir(struct file *filp, void *dirent, filldir_t filldir)
if (err) if (err)
return err; return err;
hfsplus_cat_build_key(sb, fd.search_key, inode->i_ino, NULL); hfsplus_cat_build_key(sb, fd.search_key, inode->i_ino, NULL);
err = hfs_brec_find(&fd); err = hfs_brec_find(&fd, hfs_find_rec_by_key);
if (err) if (err)
goto out; goto out;
...@@ -421,6 +422,15 @@ static int hfsplus_symlink(struct inode *dir, struct dentry *dentry, ...@@ -421,6 +422,15 @@ static int hfsplus_symlink(struct inode *dir, struct dentry *dentry,
if (res) if (res)
goto out_err; goto out_err;
res = hfsplus_init_inode_security(inode, dir, &dentry->d_name);
if (res == -EOPNOTSUPP)
res = 0; /* Operation is not supported. */
else if (res) {
/* Try to delete anyway without error analysis. */
hfsplus_delete_cat(inode->i_ino, dir, &dentry->d_name);
goto out_err;
}
hfsplus_instantiate(dentry, inode, inode->i_ino); hfsplus_instantiate(dentry, inode, inode->i_ino);
mark_inode_dirty(inode); mark_inode_dirty(inode);
goto out; goto out;
...@@ -450,15 +460,26 @@ static int hfsplus_mknod(struct inode *dir, struct dentry *dentry, ...@@ -450,15 +460,26 @@ static int hfsplus_mknod(struct inode *dir, struct dentry *dentry,
init_special_inode(inode, mode, rdev); init_special_inode(inode, mode, rdev);
res = hfsplus_create_cat(inode->i_ino, dir, &dentry->d_name, inode); res = hfsplus_create_cat(inode->i_ino, dir, &dentry->d_name, inode);
if (res) { if (res)
clear_nlink(inode); goto failed_mknod;
hfsplus_delete_inode(inode);
iput(inode); res = hfsplus_init_inode_security(inode, dir, &dentry->d_name);
goto out; if (res == -EOPNOTSUPP)
res = 0; /* Operation is not supported. */
else if (res) {
/* Try to delete anyway without error analysis. */
hfsplus_delete_cat(inode->i_ino, dir, &dentry->d_name);
goto failed_mknod;
} }
hfsplus_instantiate(dentry, inode, inode->i_ino); hfsplus_instantiate(dentry, inode, inode->i_ino);
mark_inode_dirty(inode); mark_inode_dirty(inode);
goto out;
failed_mknod:
clear_nlink(inode);
hfsplus_delete_inode(inode);
iput(inode);
out: out:
mutex_unlock(&sbi->vh_mutex); mutex_unlock(&sbi->vh_mutex);
return res; return res;
...@@ -499,15 +520,19 @@ static int hfsplus_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -499,15 +520,19 @@ static int hfsplus_rename(struct inode *old_dir, struct dentry *old_dentry,
} }
const struct inode_operations hfsplus_dir_inode_operations = { const struct inode_operations hfsplus_dir_inode_operations = {
.lookup = hfsplus_lookup, .lookup = hfsplus_lookup,
.create = hfsplus_create, .create = hfsplus_create,
.link = hfsplus_link, .link = hfsplus_link,
.unlink = hfsplus_unlink, .unlink = hfsplus_unlink,
.mkdir = hfsplus_mkdir, .mkdir = hfsplus_mkdir,
.rmdir = hfsplus_rmdir, .rmdir = hfsplus_rmdir,
.symlink = hfsplus_symlink, .symlink = hfsplus_symlink,
.mknod = hfsplus_mknod, .mknod = hfsplus_mknod,
.rename = hfsplus_rename, .rename = hfsplus_rename,
.setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.listxattr = hfsplus_listxattr,
.removexattr = hfsplus_removexattr,
}; };
const struct file_operations hfsplus_dir_operations = { const struct file_operations hfsplus_dir_operations = {
......
...@@ -95,7 +95,7 @@ static void __hfsplus_ext_write_extent(struct inode *inode, ...@@ -95,7 +95,7 @@ static void __hfsplus_ext_write_extent(struct inode *inode,
HFSPLUS_IS_RSRC(inode) ? HFSPLUS_IS_RSRC(inode) ?
HFSPLUS_TYPE_RSRC : HFSPLUS_TYPE_DATA); HFSPLUS_TYPE_RSRC : HFSPLUS_TYPE_DATA);
res = hfs_brec_find(fd); res = hfs_brec_find(fd, hfs_find_rec_by_key);
if (hip->extent_state & HFSPLUS_EXT_NEW) { if (hip->extent_state & HFSPLUS_EXT_NEW) {
if (res != -ENOENT) if (res != -ENOENT)
return; return;
...@@ -154,7 +154,7 @@ static inline int __hfsplus_ext_read_extent(struct hfs_find_data *fd, ...@@ -154,7 +154,7 @@ static inline int __hfsplus_ext_read_extent(struct hfs_find_data *fd,
hfsplus_ext_build_key(fd->search_key, cnid, block, type); hfsplus_ext_build_key(fd->search_key, cnid, block, type);
fd->key->ext.cnid = 0; fd->key->ext.cnid = 0;
res = hfs_brec_find(fd); res = hfs_brec_find(fd, hfs_find_rec_by_key);
if (res && res != -ENOENT) if (res && res != -ENOENT)
return res; return res;
if (fd->key->ext.cnid != fd->search_key->ext.cnid || if (fd->key->ext.cnid != fd->search_key->ext.cnid ||
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#define DBG_SUPER 0x00000010 #define DBG_SUPER 0x00000010
#define DBG_EXTENT 0x00000020 #define DBG_EXTENT 0x00000020
#define DBG_BITMAP 0x00000040 #define DBG_BITMAP 0x00000040
#define DBG_ATTR_MOD 0x00000080
#if 0 #if 0
#define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD) #define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD)
...@@ -46,6 +47,13 @@ typedef int (*btree_keycmp)(const hfsplus_btree_key *, ...@@ -46,6 +47,13 @@ typedef int (*btree_keycmp)(const hfsplus_btree_key *,
#define NODE_HASH_SIZE 256 #define NODE_HASH_SIZE 256
/* B-tree mutex nested subclasses */
enum hfsplus_btree_mutex_classes {
CATALOG_BTREE_MUTEX,
EXTENTS_BTREE_MUTEX,
ATTR_BTREE_MUTEX,
};
/* An HFS+ BTree held in memory */ /* An HFS+ BTree held in memory */
struct hfs_btree { struct hfs_btree {
struct super_block *sb; struct super_block *sb;
...@@ -223,6 +231,7 @@ struct hfsplus_inode_info { ...@@ -223,6 +231,7 @@ struct hfsplus_inode_info {
#define HFSPLUS_I_CAT_DIRTY 1 /* has changes in the catalog tree */ #define HFSPLUS_I_CAT_DIRTY 1 /* has changes in the catalog tree */
#define HFSPLUS_I_EXT_DIRTY 2 /* has changes in the extent tree */ #define HFSPLUS_I_EXT_DIRTY 2 /* has changes in the extent tree */
#define HFSPLUS_I_ALLOC_DIRTY 3 /* has changes in the allocation file */ #define HFSPLUS_I_ALLOC_DIRTY 3 /* has changes in the allocation file */
#define HFSPLUS_I_ATTR_DIRTY 4 /* has changes in the attributes tree */
#define HFSPLUS_IS_RSRC(inode) \ #define HFSPLUS_IS_RSRC(inode) \
test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags) test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags)
...@@ -302,7 +311,7 @@ static inline unsigned short hfsplus_min_io_size(struct super_block *sb) ...@@ -302,7 +311,7 @@ static inline unsigned short hfsplus_min_io_size(struct super_block *sb)
#define hfs_brec_remove hfsplus_brec_remove #define hfs_brec_remove hfsplus_brec_remove
#define hfs_find_init hfsplus_find_init #define hfs_find_init hfsplus_find_init
#define hfs_find_exit hfsplus_find_exit #define hfs_find_exit hfsplus_find_exit
#define __hfs_brec_find __hplusfs_brec_find #define __hfs_brec_find __hfsplus_brec_find
#define hfs_brec_find hfsplus_brec_find #define hfs_brec_find hfsplus_brec_find
#define hfs_brec_read hfsplus_brec_read #define hfs_brec_read hfsplus_brec_read
#define hfs_brec_goto hfsplus_brec_goto #define hfs_brec_goto hfsplus_brec_goto
...@@ -324,10 +333,33 @@ static inline unsigned short hfsplus_min_io_size(struct super_block *sb) ...@@ -324,10 +333,33 @@ static inline unsigned short hfsplus_min_io_size(struct super_block *sb)
*/ */
#define HFSPLUS_IOC_BLESS _IO('h', 0x80) #define HFSPLUS_IOC_BLESS _IO('h', 0x80)
typedef int (*search_strategy_t)(struct hfs_bnode *,
struct hfs_find_data *,
int *, int *, int *);
/* /*
* Functions in any *.c used in other files * Functions in any *.c used in other files
*/ */
/* attributes.c */
int hfsplus_create_attr_tree_cache(void);
void hfsplus_destroy_attr_tree_cache(void);
hfsplus_attr_entry *hfsplus_alloc_attr_entry(void);
void hfsplus_destroy_attr_entry(hfsplus_attr_entry *entry_p);
int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key *,
const hfsplus_btree_key *);
int hfsplus_attr_build_key(struct super_block *, hfsplus_btree_key *,
u32, const char *);
void hfsplus_attr_build_key_uni(hfsplus_btree_key *key,
u32 cnid,
struct hfsplus_attr_unistr *name);
int hfsplus_find_attr(struct super_block *, u32,
const char *, struct hfs_find_data *);
int hfsplus_attr_exists(struct inode *inode, const char *name);
int hfsplus_create_attr(struct inode *, const char *, const void *, size_t);
int hfsplus_delete_attr(struct inode *, const char *);
int hfsplus_delete_all_attrs(struct inode *dir, u32 cnid);
/* bitmap.c */ /* bitmap.c */
int hfsplus_block_allocate(struct super_block *, u32, u32, u32 *); int hfsplus_block_allocate(struct super_block *, u32, u32, u32 *);
int hfsplus_block_free(struct super_block *, u32, u32); int hfsplus_block_free(struct super_block *, u32, u32);
...@@ -369,8 +401,15 @@ int hfs_brec_remove(struct hfs_find_data *); ...@@ -369,8 +401,15 @@ int hfs_brec_remove(struct hfs_find_data *);
/* bfind.c */ /* bfind.c */
int hfs_find_init(struct hfs_btree *, struct hfs_find_data *); int hfs_find_init(struct hfs_btree *, struct hfs_find_data *);
void hfs_find_exit(struct hfs_find_data *); void hfs_find_exit(struct hfs_find_data *);
int __hfs_brec_find(struct hfs_bnode *, struct hfs_find_data *); int hfs_find_1st_rec_by_cnid(struct hfs_bnode *,
int hfs_brec_find(struct hfs_find_data *); struct hfs_find_data *,
int *, int *, int *);
int hfs_find_rec_by_key(struct hfs_bnode *,
struct hfs_find_data *,
int *, int *, int *);
int __hfs_brec_find(struct hfs_bnode *, struct hfs_find_data *,
search_strategy_t);
int hfs_brec_find(struct hfs_find_data *, search_strategy_t);
int hfs_brec_read(struct hfs_find_data *, void *, int); int hfs_brec_read(struct hfs_find_data *, void *, int);
int hfs_brec_goto(struct hfs_find_data *, int); int hfs_brec_goto(struct hfs_find_data *, int);
...@@ -417,11 +456,6 @@ int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end, ...@@ -417,11 +456,6 @@ int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
/* ioctl.c */ /* ioctl.c */
long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
int hfsplus_setxattr(struct dentry *dentry, const char *name,
const void *value, size_t size, int flags);
ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
void *value, size_t size);
ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size);
/* options.c */ /* options.c */
int hfsplus_parse_options(char *, struct hfsplus_sb_info *); int hfsplus_parse_options(char *, struct hfsplus_sb_info *);
...@@ -446,7 +480,7 @@ int hfsplus_strcmp(const struct hfsplus_unistr *, ...@@ -446,7 +480,7 @@ int hfsplus_strcmp(const struct hfsplus_unistr *,
int hfsplus_uni2asc(struct super_block *, int hfsplus_uni2asc(struct super_block *,
const struct hfsplus_unistr *, char *, int *); const struct hfsplus_unistr *, char *, int *);
int hfsplus_asc2uni(struct super_block *, int hfsplus_asc2uni(struct super_block *,
struct hfsplus_unistr *, const char *, int); struct hfsplus_unistr *, int, const char *, int);
int hfsplus_hash_dentry(const struct dentry *dentry, int hfsplus_hash_dentry(const struct dentry *dentry,
const struct inode *inode, struct qstr *str); const struct inode *inode, struct qstr *str);
int hfsplus_compare_dentry(const struct dentry *parent, int hfsplus_compare_dentry(const struct dentry *parent,
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "hfsplus_fs.h" #include "hfsplus_fs.h"
#include "hfsplus_raw.h" #include "hfsplus_raw.h"
#include "xattr.h"
static int hfsplus_readpage(struct file *file, struct page *page) static int hfsplus_readpage(struct file *file, struct page *page)
{ {
...@@ -348,6 +349,18 @@ int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end, ...@@ -348,6 +349,18 @@ int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
error = error2; error = error2;
} }
if (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY, &hip->flags)) {
if (sbi->attr_tree) {
error2 =
filemap_write_and_wait(
sbi->attr_tree->inode->i_mapping);
if (!error)
error = error2;
} else {
printk(KERN_ERR "hfs: sync non-existent attributes tree\n");
}
}
if (test_and_clear_bit(HFSPLUS_I_ALLOC_DIRTY, &hip->flags)) { if (test_and_clear_bit(HFSPLUS_I_ALLOC_DIRTY, &hip->flags)) {
error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping); error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping);
if (!error) if (!error)
...@@ -365,9 +378,10 @@ int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end, ...@@ -365,9 +378,10 @@ int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
static const struct inode_operations hfsplus_file_inode_operations = { static const struct inode_operations hfsplus_file_inode_operations = {
.lookup = hfsplus_file_lookup, .lookup = hfsplus_file_lookup,
.setattr = hfsplus_setattr, .setattr = hfsplus_setattr,
.setxattr = hfsplus_setxattr, .setxattr = generic_setxattr,
.getxattr = hfsplus_getxattr, .getxattr = generic_getxattr,
.listxattr = hfsplus_listxattr, .listxattr = hfsplus_listxattr,
.removexattr = hfsplus_removexattr,
}; };
static const struct file_operations hfsplus_file_operations = { static const struct file_operations hfsplus_file_operations = {
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/xattr.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include "hfsplus_fs.h" #include "hfsplus_fs.h"
...@@ -151,110 +150,3 @@ long hfsplus_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -151,110 +150,3 @@ long hfsplus_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
return -ENOTTY; return -ENOTTY;
} }
} }
int hfsplus_setxattr(struct dentry *dentry, const char *name,
const void *value, size_t size, int flags)
{
struct inode *inode = dentry->d_inode;
struct hfs_find_data fd;
hfsplus_cat_entry entry;
struct hfsplus_cat_file *file;
int res;
if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
return -EOPNOTSUPP;
res = hfs_find_init(HFSPLUS_SB(inode->i_sb)->cat_tree, &fd);
if (res)
return res;
res = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
if (res)
goto out;
hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
sizeof(struct hfsplus_cat_file));
file = &entry.file;
if (!strcmp(name, "hfs.type")) {
if (size == 4)
memcpy(&file->user_info.fdType, value, 4);
else
res = -ERANGE;
} else if (!strcmp(name, "hfs.creator")) {
if (size == 4)
memcpy(&file->user_info.fdCreator, value, 4);
else
res = -ERANGE;
} else
res = -EOPNOTSUPP;
if (!res) {
hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
sizeof(struct hfsplus_cat_file));
hfsplus_mark_inode_dirty(inode, HFSPLUS_I_CAT_DIRTY);
}
out:
hfs_find_exit(&fd);
return res;
}
ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
void *value, size_t size)
{
struct inode *inode = dentry->d_inode;
struct hfs_find_data fd;
hfsplus_cat_entry entry;
struct hfsplus_cat_file *file;
ssize_t res = 0;
if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
return -EOPNOTSUPP;
if (size) {
res = hfs_find_init(HFSPLUS_SB(inode->i_sb)->cat_tree, &fd);
if (res)
return res;
res = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
if (res)
goto out;
hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
sizeof(struct hfsplus_cat_file));
}
file = &entry.file;
if (!strcmp(name, "hfs.type")) {
if (size >= 4) {
memcpy(value, &file->user_info.fdType, 4);
res = 4;
} else
res = size ? -ERANGE : 4;
} else if (!strcmp(name, "hfs.creator")) {
if (size >= 4) {
memcpy(value, &file->user_info.fdCreator, 4);
res = 4;
} else
res = size ? -ERANGE : 4;
} else
res = -EOPNOTSUPP;
out:
if (size)
hfs_find_exit(&fd);
return res;
}
#define HFSPLUS_ATTRLIST_SIZE (sizeof("hfs.creator")+sizeof("hfs.type"))
ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size)
{
struct inode *inode = dentry->d_inode;
if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
return -EOPNOTSUPP;
if (!buffer || !size)
return HFSPLUS_ATTRLIST_SIZE;
if (size < HFSPLUS_ATTRLIST_SIZE)
return -ERANGE;
strcpy(buffer, "hfs.type");
strcpy(buffer + sizeof("hfs.type"), "hfs.creator");
return HFSPLUS_ATTRLIST_SIZE;
}
...@@ -20,6 +20,7 @@ static struct inode *hfsplus_alloc_inode(struct super_block *sb); ...@@ -20,6 +20,7 @@ static struct inode *hfsplus_alloc_inode(struct super_block *sb);
static void hfsplus_destroy_inode(struct inode *inode); static void hfsplus_destroy_inode(struct inode *inode);
#include "hfsplus_fs.h" #include "hfsplus_fs.h"
#include "xattr.h"
static int hfsplus_system_read_inode(struct inode *inode) static int hfsplus_system_read_inode(struct inode *inode)
{ {
...@@ -118,6 +119,7 @@ static int hfsplus_system_write_inode(struct inode *inode) ...@@ -118,6 +119,7 @@ static int hfsplus_system_write_inode(struct inode *inode)
case HFSPLUS_ATTR_CNID: case HFSPLUS_ATTR_CNID:
fork = &vhdr->attr_file; fork = &vhdr->attr_file;
tree = sbi->attr_tree; tree = sbi->attr_tree;
break;
default: default:
return -EIO; return -EIO;
} }
...@@ -191,6 +193,12 @@ static int hfsplus_sync_fs(struct super_block *sb, int wait) ...@@ -191,6 +193,12 @@ static int hfsplus_sync_fs(struct super_block *sb, int wait)
error2 = filemap_write_and_wait(sbi->ext_tree->inode->i_mapping); error2 = filemap_write_and_wait(sbi->ext_tree->inode->i_mapping);
if (!error) if (!error)
error = error2; error = error2;
if (sbi->attr_tree) {
error2 =
filemap_write_and_wait(sbi->attr_tree->inode->i_mapping);
if (!error)
error = error2;
}
error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping); error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping);
if (!error) if (!error)
error = error2; error = error2;
...@@ -281,6 +289,7 @@ static void hfsplus_put_super(struct super_block *sb) ...@@ -281,6 +289,7 @@ static void hfsplus_put_super(struct super_block *sb)
hfsplus_sync_fs(sb, 1); hfsplus_sync_fs(sb, 1);
} }
hfs_btree_close(sbi->attr_tree);
hfs_btree_close(sbi->cat_tree); hfs_btree_close(sbi->cat_tree);
hfs_btree_close(sbi->ext_tree); hfs_btree_close(sbi->ext_tree);
iput(sbi->alloc_file); iput(sbi->alloc_file);
...@@ -477,12 +486,20 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent) ...@@ -477,12 +486,20 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
printk(KERN_ERR "hfs: failed to load catalog file\n"); printk(KERN_ERR "hfs: failed to load catalog file\n");
goto out_close_ext_tree; goto out_close_ext_tree;
} }
if (vhdr->attr_file.total_blocks != 0) {
sbi->attr_tree = hfs_btree_open(sb, HFSPLUS_ATTR_CNID);
if (!sbi->attr_tree) {
printk(KERN_ERR "hfs: failed to load attributes file\n");
goto out_close_cat_tree;
}
}
sb->s_xattr = hfsplus_xattr_handlers;
inode = hfsplus_iget(sb, HFSPLUS_ALLOC_CNID); inode = hfsplus_iget(sb, HFSPLUS_ALLOC_CNID);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
printk(KERN_ERR "hfs: failed to load allocation file\n"); printk(KERN_ERR "hfs: failed to load allocation file\n");
err = PTR_ERR(inode); err = PTR_ERR(inode);
goto out_close_cat_tree; goto out_close_attr_tree;
} }
sbi->alloc_file = inode; sbi->alloc_file = inode;
...@@ -542,10 +559,27 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent) ...@@ -542,10 +559,27 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
} }
err = hfsplus_create_cat(sbi->hidden_dir->i_ino, root, err = hfsplus_create_cat(sbi->hidden_dir->i_ino, root,
&str, sbi->hidden_dir); &str, sbi->hidden_dir);
mutex_unlock(&sbi->vh_mutex); if (err) {
if (err) mutex_unlock(&sbi->vh_mutex);
goto out_put_hidden_dir;
}
err = hfsplus_init_inode_security(sbi->hidden_dir,
root, &str);
if (err == -EOPNOTSUPP)
err = 0; /* Operation is not supported. */
else if (err) {
/*
* Try to delete anyway without
* error analysis.
*/
hfsplus_delete_cat(sbi->hidden_dir->i_ino,
root, &str);
mutex_unlock(&sbi->vh_mutex);
goto out_put_hidden_dir; goto out_put_hidden_dir;
}
mutex_unlock(&sbi->vh_mutex);
hfsplus_mark_inode_dirty(sbi->hidden_dir, hfsplus_mark_inode_dirty(sbi->hidden_dir,
HFSPLUS_I_CAT_DIRTY); HFSPLUS_I_CAT_DIRTY);
} }
...@@ -562,6 +596,8 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent) ...@@ -562,6 +596,8 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
sb->s_root = NULL; sb->s_root = NULL;
out_put_alloc_file: out_put_alloc_file:
iput(sbi->alloc_file); iput(sbi->alloc_file);
out_close_attr_tree:
hfs_btree_close(sbi->attr_tree);
out_close_cat_tree: out_close_cat_tree:
hfs_btree_close(sbi->cat_tree); hfs_btree_close(sbi->cat_tree);
out_close_ext_tree: out_close_ext_tree:
...@@ -635,9 +671,20 @@ static int __init init_hfsplus_fs(void) ...@@ -635,9 +671,20 @@ static int __init init_hfsplus_fs(void)
hfsplus_init_once); hfsplus_init_once);
if (!hfsplus_inode_cachep) if (!hfsplus_inode_cachep)
return -ENOMEM; return -ENOMEM;
err = hfsplus_create_attr_tree_cache();
if (err)
goto destroy_inode_cache;
err = register_filesystem(&hfsplus_fs_type); err = register_filesystem(&hfsplus_fs_type);
if (err) if (err)
kmem_cache_destroy(hfsplus_inode_cachep); goto destroy_attr_tree_cache;
return 0;
destroy_attr_tree_cache:
hfsplus_destroy_attr_tree_cache();
destroy_inode_cache:
kmem_cache_destroy(hfsplus_inode_cachep);
return err; return err;
} }
...@@ -650,6 +697,7 @@ static void __exit exit_hfsplus_fs(void) ...@@ -650,6 +697,7 @@ static void __exit exit_hfsplus_fs(void)
* destroy cache. * destroy cache.
*/ */
rcu_barrier(); rcu_barrier();
hfsplus_destroy_attr_tree_cache();
kmem_cache_destroy(hfsplus_inode_cachep); kmem_cache_destroy(hfsplus_inode_cachep);
} }
......
...@@ -295,7 +295,8 @@ static inline u16 *decompose_unichar(wchar_t uc, int *size) ...@@ -295,7 +295,8 @@ static inline u16 *decompose_unichar(wchar_t uc, int *size)
return hfsplus_decompose_table + (off / 4); return hfsplus_decompose_table + (off / 4);
} }
int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr, int hfsplus_asc2uni(struct super_block *sb,
struct hfsplus_unistr *ustr, int max_unistr_len,
const char *astr, int len) const char *astr, int len)
{ {
int size, dsize, decompose; int size, dsize, decompose;
...@@ -303,7 +304,7 @@ int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr, ...@@ -303,7 +304,7 @@ int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr,
wchar_t c; wchar_t c;
decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags); decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
while (outlen < HFSPLUS_MAX_STRLEN && len > 0) { while (outlen < max_unistr_len && len > 0) {
size = asc2unichar(sb, astr, len, &c); size = asc2unichar(sb, astr, len, &c);
if (decompose) if (decompose)
...@@ -311,7 +312,7 @@ int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr, ...@@ -311,7 +312,7 @@ int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr,
else else
dstr = NULL; dstr = NULL;
if (dstr) { if (dstr) {
if (outlen + dsize > HFSPLUS_MAX_STRLEN) if (outlen + dsize > max_unistr_len)
break; break;
do { do {
ustr->unicode[outlen++] = cpu_to_be16(*dstr++); ustr->unicode[outlen++] = cpu_to_be16(*dstr++);
......
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