1 // SPDX-License-Identifier: GPL-2.0
5 * (C) 2003 Ardis Technologies <roman@ardistech.com>
7 * Export hfs data via xattr
12 #include <linux/xattr.h>
22 static int __hfs_setxattr(struct inode
*inode
, enum hfs_xattr_type type
,
23 const void *value
, size_t size
, int flags
)
25 struct hfs_find_data fd
;
27 struct hfs_cat_file
*file
;
30 if (!S_ISREG(inode
->i_mode
) || HFS_IS_RSRC(inode
))
33 res
= hfs_find_init(HFS_SB(inode
->i_sb
)->cat_tree
, &fd
);
36 fd
.search_key
->cat
= HFS_I(inode
)->cat_key
;
37 res
= hfs_brec_find(&fd
);
40 hfs_bnode_read(fd
.bnode
, &rec
, fd
.entryoffset
,
41 sizeof(struct hfs_cat_file
));
47 memcpy(&file
->UsrWds
.fdType
, value
, 4);
54 memcpy(&file
->UsrWds
.fdCreator
, value
, 4);
61 hfs_bnode_write(fd
.bnode
, &rec
, fd
.entryoffset
,
62 sizeof(struct hfs_cat_file
));
68 static ssize_t
__hfs_getxattr(struct inode
*inode
, enum hfs_xattr_type type
,
69 void *value
, size_t size
)
71 struct hfs_find_data fd
;
73 struct hfs_cat_file
*file
;
76 if (!S_ISREG(inode
->i_mode
) || HFS_IS_RSRC(inode
))
80 res
= hfs_find_init(HFS_SB(inode
->i_sb
)->cat_tree
, &fd
);
83 fd
.search_key
->cat
= HFS_I(inode
)->cat_key
;
84 res
= hfs_brec_find(&fd
);
87 hfs_bnode_read(fd
.bnode
, &rec
, fd
.entryoffset
,
88 sizeof(struct hfs_cat_file
));
95 memcpy(value
, &file
->UsrWds
.fdType
, 4);
98 res
= size
? -ERANGE
: 4;
103 memcpy(value
, &file
->UsrWds
.fdCreator
, 4);
106 res
= size
? -ERANGE
: 4;
116 static int hfs_xattr_get(const struct xattr_handler
*handler
,
117 struct dentry
*unused
, struct inode
*inode
,
118 const char *name
, void *value
, size_t size
)
120 return __hfs_getxattr(inode
, handler
->flags
, value
, size
);
123 static int hfs_xattr_set(const struct xattr_handler
*handler
,
124 struct dentry
*unused
, struct inode
*inode
,
125 const char *name
, const void *value
, size_t size
,
131 return __hfs_setxattr(inode
, handler
->flags
, value
, size
, flags
);
134 static const struct xattr_handler hfs_creator_handler
= {
135 .name
= "hfs.creator",
136 .flags
= HFS_CREATOR
,
137 .get
= hfs_xattr_get
,
138 .set
= hfs_xattr_set
,
141 static const struct xattr_handler hfs_type_handler
= {
144 .get
= hfs_xattr_get
,
145 .set
= hfs_xattr_set
,
148 const struct xattr_handler
*hfs_xattr_handlers
[] = {
149 &hfs_creator_handler
,