diff options
author | Andreas Gruenbacher <agruenba@redhat.com> | 2016-09-29 11:48:32 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2016-10-06 22:17:38 -0400 |
commit | b8020eff7f827018ccd690a13e7da606302715a5 (patch) | |
tree | b4b61c94c67605010a334db11623cf071a3ef8ec | |
parent | 6966f842c044bc602ecc06712ee5891328fde10e (diff) |
hfs: Switch to generic xattr handlers
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | fs/hfs/attr.c | 83 | ||||
-rw-r--r-- | fs/hfs/hfs_fs.h | 6 | ||||
-rw-r--r-- | fs/hfs/inode.c | 7 | ||||
-rw-r--r-- | fs/hfs/super.c | 1 |
4 files changed, 63 insertions, 34 deletions
diff --git a/fs/hfs/attr.c b/fs/hfs/attr.c index d9a86919fdf6..0933600e11c8 100644 --- a/fs/hfs/attr.c +++ b/fs/hfs/attr.c | |||
@@ -13,9 +13,13 @@ | |||
13 | #include "hfs_fs.h" | 13 | #include "hfs_fs.h" |
14 | #include "btree.h" | 14 | #include "btree.h" |
15 | 15 | ||
16 | int hfs_setxattr(struct dentry *unused, struct inode *inode, | 16 | enum hfs_xattr_type { |
17 | const char *name, const void *value, | 17 | HFS_TYPE, |
18 | size_t size, int flags) | 18 | HFS_CREATOR, |
19 | }; | ||
20 | |||
21 | static int __hfs_setxattr(struct inode *inode, enum hfs_xattr_type type, | ||
22 | const void *value, size_t size, int flags) | ||
19 | { | 23 | { |
20 | struct hfs_find_data fd; | 24 | struct hfs_find_data fd; |
21 | hfs_cat_rec rec; | 25 | hfs_cat_rec rec; |
@@ -36,18 +40,22 @@ int hfs_setxattr(struct dentry *unused, struct inode *inode, | |||
36 | sizeof(struct hfs_cat_file)); | 40 | sizeof(struct hfs_cat_file)); |
37 | file = &rec.file; | 41 | file = &rec.file; |
38 | 42 | ||
39 | if (!strcmp(name, "hfs.type")) { | 43 | switch (type) { |
44 | case HFS_TYPE: | ||
40 | if (size == 4) | 45 | if (size == 4) |
41 | memcpy(&file->UsrWds.fdType, value, 4); | 46 | memcpy(&file->UsrWds.fdType, value, 4); |
42 | else | 47 | else |
43 | res = -ERANGE; | 48 | res = -ERANGE; |
44 | } else if (!strcmp(name, "hfs.creator")) { | 49 | break; |
50 | |||
51 | case HFS_CREATOR: | ||
45 | if (size == 4) | 52 | if (size == 4) |
46 | memcpy(&file->UsrWds.fdCreator, value, 4); | 53 | memcpy(&file->UsrWds.fdCreator, value, 4); |
47 | else | 54 | else |
48 | res = -ERANGE; | 55 | res = -ERANGE; |
49 | } else | 56 | break; |
50 | res = -EOPNOTSUPP; | 57 | } |
58 | |||
51 | if (!res) | 59 | if (!res) |
52 | hfs_bnode_write(fd.bnode, &rec, fd.entryoffset, | 60 | hfs_bnode_write(fd.bnode, &rec, fd.entryoffset, |
53 | sizeof(struct hfs_cat_file)); | 61 | sizeof(struct hfs_cat_file)); |
@@ -56,8 +64,8 @@ out: | |||
56 | return res; | 64 | return res; |
57 | } | 65 | } |
58 | 66 | ||
59 | ssize_t hfs_getxattr(struct dentry *unused, struct inode *inode, | 67 | static ssize_t __hfs_getxattr(struct inode *inode, enum hfs_xattr_type type, |
60 | const char *name, void *value, size_t size) | 68 | void *value, size_t size) |
61 | { | 69 | { |
62 | struct hfs_find_data fd; | 70 | struct hfs_find_data fd; |
63 | hfs_cat_rec rec; | 71 | hfs_cat_rec rec; |
@@ -80,41 +88,64 @@ ssize_t hfs_getxattr(struct dentry *unused, struct inode *inode, | |||
80 | } | 88 | } |
81 | file = &rec.file; | 89 | file = &rec.file; |
82 | 90 | ||
83 | if (!strcmp(name, "hfs.type")) { | 91 | switch (type) { |
92 | case HFS_TYPE: | ||
84 | if (size >= 4) { | 93 | if (size >= 4) { |
85 | memcpy(value, &file->UsrWds.fdType, 4); | 94 | memcpy(value, &file->UsrWds.fdType, 4); |
86 | res = 4; | 95 | res = 4; |
87 | } else | 96 | } else |
88 | res = size ? -ERANGE : 4; | 97 | res = size ? -ERANGE : 4; |
89 | } else if (!strcmp(name, "hfs.creator")) { | 98 | break; |
99 | |||
100 | case HFS_CREATOR: | ||
90 | if (size >= 4) { | 101 | if (size >= 4) { |
91 | memcpy(value, &file->UsrWds.fdCreator, 4); | 102 | memcpy(value, &file->UsrWds.fdCreator, 4); |
92 | res = 4; | 103 | res = 4; |
93 | } else | 104 | } else |
94 | res = size ? -ERANGE : 4; | 105 | res = size ? -ERANGE : 4; |
95 | } else | 106 | break; |
96 | res = -ENODATA; | 107 | } |
108 | |||
97 | out: | 109 | out: |
98 | if (size) | 110 | if (size) |
99 | hfs_find_exit(&fd); | 111 | hfs_find_exit(&fd); |
100 | return res; | 112 | return res; |
101 | } | 113 | } |
102 | 114 | ||
103 | #define HFS_ATTRLIST_SIZE (sizeof("hfs.creator")+sizeof("hfs.type")) | 115 | static int hfs_xattr_get(const struct xattr_handler *handler, |
104 | 116 | struct dentry *unused, struct inode *inode, | |
105 | ssize_t hfs_listxattr(struct dentry *dentry, char *buffer, size_t size) | 117 | const char *name, void *value, size_t size) |
106 | { | 118 | { |
107 | struct inode *inode = d_inode(dentry); | 119 | return __hfs_getxattr(inode, handler->flags, value, size); |
120 | } | ||
108 | 121 | ||
109 | if (!S_ISREG(inode->i_mode) || HFS_IS_RSRC(inode)) | 122 | static int hfs_xattr_set(const struct xattr_handler *handler, |
123 | struct dentry *unused, struct inode *inode, | ||
124 | const char *name, const void *value, size_t size, | ||
125 | int flags) | ||
126 | { | ||
127 | if (!value) | ||
110 | return -EOPNOTSUPP; | 128 | return -EOPNOTSUPP; |
111 | 129 | ||
112 | if (!buffer || !size) | 130 | return __hfs_setxattr(inode, handler->flags, value, size, flags); |
113 | return HFS_ATTRLIST_SIZE; | ||
114 | if (size < HFS_ATTRLIST_SIZE) | ||
115 | return -ERANGE; | ||
116 | strcpy(buffer, "hfs.type"); | ||
117 | strcpy(buffer + sizeof("hfs.type"), "hfs.creator"); | ||
118 | |||
119 | return HFS_ATTRLIST_SIZE; | ||
120 | } | 131 | } |
132 | |||
133 | static const struct xattr_handler hfs_creator_handler = { | ||
134 | .name = "hfs.creator", | ||
135 | .flags = HFS_CREATOR, | ||
136 | .get = hfs_xattr_get, | ||
137 | .set = hfs_xattr_set, | ||
138 | }; | ||
139 | |||
140 | static const struct xattr_handler hfs_type_handler = { | ||
141 | .name = "hfs.type", | ||
142 | .flags = HFS_TYPE, | ||
143 | .get = hfs_xattr_get, | ||
144 | .set = hfs_xattr_set, | ||
145 | }; | ||
146 | |||
147 | const struct xattr_handler *hfs_xattr_handlers[] = { | ||
148 | &hfs_creator_handler, | ||
149 | &hfs_type_handler, | ||
150 | NULL | ||
151 | }; | ||
diff --git a/fs/hfs/hfs_fs.h b/fs/hfs/hfs_fs.h index 16f5172ee40d..4cdec5a19347 100644 --- a/fs/hfs/hfs_fs.h +++ b/fs/hfs/hfs_fs.h | |||
@@ -212,11 +212,7 @@ extern void hfs_evict_inode(struct inode *); | |||
212 | extern void hfs_delete_inode(struct inode *); | 212 | extern void hfs_delete_inode(struct inode *); |
213 | 213 | ||
214 | /* attr.c */ | 214 | /* attr.c */ |
215 | extern int hfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name, | 215 | extern const struct xattr_handler *hfs_xattr_handlers[]; |
216 | const void *value, size_t size, int flags); | ||
217 | extern ssize_t hfs_getxattr(struct dentry *dentry, struct inode *inode, | ||
218 | const char *name, void *value, size_t size); | ||
219 | extern ssize_t hfs_listxattr(struct dentry *dentry, char *buffer, size_t size); | ||
220 | 216 | ||
221 | /* mdb.c */ | 217 | /* mdb.c */ |
222 | extern int hfs_mdb_get(struct super_block *); | 218 | extern int hfs_mdb_get(struct super_block *); |
diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c index c6a32415735b..7f44f1a4e4c0 100644 --- a/fs/hfs/inode.c +++ b/fs/hfs/inode.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/mpage.h> | 15 | #include <linux/mpage.h> |
16 | #include <linux/sched.h> | 16 | #include <linux/sched.h> |
17 | #include <linux/uio.h> | 17 | #include <linux/uio.h> |
18 | #include <linux/xattr.h> | ||
18 | 19 | ||
19 | #include "hfs_fs.h" | 20 | #include "hfs_fs.h" |
20 | #include "btree.h" | 21 | #include "btree.h" |
@@ -687,7 +688,7 @@ static const struct file_operations hfs_file_operations = { | |||
687 | static const struct inode_operations hfs_file_inode_operations = { | 688 | static const struct inode_operations hfs_file_inode_operations = { |
688 | .lookup = hfs_file_lookup, | 689 | .lookup = hfs_file_lookup, |
689 | .setattr = hfs_inode_setattr, | 690 | .setattr = hfs_inode_setattr, |
690 | .setxattr = hfs_setxattr, | 691 | .setxattr = generic_setxattr, |
691 | .getxattr = hfs_getxattr, | 692 | .getxattr = generic_getxattr, |
692 | .listxattr = hfs_listxattr, | 693 | .listxattr = generic_listxattr, |
693 | }; | 694 | }; |
diff --git a/fs/hfs/super.c b/fs/hfs/super.c index 1ca95c232bb5..bf6304a350a6 100644 --- a/fs/hfs/super.c +++ b/fs/hfs/super.c | |||
@@ -406,6 +406,7 @@ static int hfs_fill_super(struct super_block *sb, void *data, int silent) | |||
406 | } | 406 | } |
407 | 407 | ||
408 | sb->s_op = &hfs_super_operations; | 408 | sb->s_op = &hfs_super_operations; |
409 | sb->s_xattr = hfs_xattr_handlers; | ||
409 | sb->s_flags |= MS_NODIRATIME; | 410 | sb->s_flags |= MS_NODIRATIME; |
410 | mutex_init(&sbi->bitmap_lock); | 411 | mutex_init(&sbi->bitmap_lock); |
411 | 412 | ||