4 * (C) 2003 Ardis Technologies <roman@ardistech.com>
6 * Export hfs data via xattr
11 #include <linux/xattr.h>
21 static int __hfs_setxattr(struct inode
*inode
, enum hfs_xattr_type type
,
22 const void *value
, size_t size
, int flags
)
24 struct hfs_find_data fd
;
26 struct hfs_cat_file
*file
;
29 if (!S_ISREG(inode
->i_mode
) || HFS_IS_RSRC(inode
))
32 res
= hfs_find_init(HFS_SB(inode
->i_sb
)->cat_tree
, &fd
);
35 fd
.search_key
->cat
= HFS_I(inode
)->cat_key
;
36 res
= hfs_brec_find(&fd
);
39 hfs_bnode_read(fd
.bnode
, &rec
, fd
.entryoffset
,
40 sizeof(struct hfs_cat_file
));
46 memcpy(&file
->UsrWds
.fdType
, value
, 4);
53 memcpy(&file
->UsrWds
.fdCreator
, value
, 4);
60 hfs_bnode_write(fd
.bnode
, &rec
, fd
.entryoffset
,
61 sizeof(struct hfs_cat_file
));
67 static ssize_t
__hfs_getxattr(struct inode
*inode
, enum hfs_xattr_type type
,
68 void *value
, size_t size
)
70 struct hfs_find_data fd
;
72 struct hfs_cat_file
*file
;
75 if (!S_ISREG(inode
->i_mode
) || HFS_IS_RSRC(inode
))
79 res
= hfs_find_init(HFS_SB(inode
->i_sb
)->cat_tree
, &fd
);
82 fd
.search_key
->cat
= HFS_I(inode
)->cat_key
;
83 res
= hfs_brec_find(&fd
);
86 hfs_bnode_read(fd
.bnode
, &rec
, fd
.entryoffset
,
87 sizeof(struct hfs_cat_file
));
94 memcpy(value
, &file
->UsrWds
.fdType
, 4);
97 res
= size
? -ERANGE
: 4;
102 memcpy(value
, &file
->UsrWds
.fdCreator
, 4);
105 res
= size
? -ERANGE
: 4;
115 static int hfs_xattr_get(const struct xattr_handler
*handler
,
116 struct dentry
*unused
, struct inode
*inode
,
117 const char *name
, void *value
, size_t size
)
119 return __hfs_getxattr(inode
, handler
->flags
, value
, size
);
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
,
130 return __hfs_setxattr(inode
, handler
->flags
, value
, size
, flags
);
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
,
140 static const struct xattr_handler hfs_type_handler
= {
143 .get
= hfs_xattr_get
,
144 .set
= hfs_xattr_set
,
147 const struct xattr_handler
*hfs_xattr_handlers
[] = {
148 &hfs_creator_handler
,