4 * (C) 2003 Ardis Technologies <roman@ardistech.com>
6 * Export hfs data via xattr
11 #include <linux/xattr.h>
16 int hfs_setxattr(struct dentry *dentry, const char *name,
17 const void *value, size_t size, int flags)
19 struct inode *inode = d_inode(dentry);
20 struct hfs_find_data fd;
22 struct hfs_cat_file *file;
25 if (!S_ISREG(inode->i_mode) || HFS_IS_RSRC(inode))
28 res = hfs_find_init(HFS_SB(inode->i_sb)->cat_tree, &fd);
31 fd.search_key->cat = HFS_I(inode)->cat_key;
32 res = hfs_brec_find(&fd);
35 hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
36 sizeof(struct hfs_cat_file));
39 if (!strcmp(name, "hfs.type")) {
41 memcpy(&file->UsrWds.fdType, value, 4);
44 } else if (!strcmp(name, "hfs.creator")) {
46 memcpy(&file->UsrWds.fdCreator, value, 4);
52 hfs_bnode_write(fd.bnode, &rec, fd.entryoffset,
53 sizeof(struct hfs_cat_file));
59 ssize_t hfs_getxattr(struct dentry *dentry, const char *name,
60 void *value, size_t size)
62 struct inode *inode = d_inode(dentry);
63 struct hfs_find_data fd;
65 struct hfs_cat_file *file;
68 if (!S_ISREG(inode->i_mode) || HFS_IS_RSRC(inode))
72 res = hfs_find_init(HFS_SB(inode->i_sb)->cat_tree, &fd);
75 fd.search_key->cat = HFS_I(inode)->cat_key;
76 res = hfs_brec_find(&fd);
79 hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
80 sizeof(struct hfs_cat_file));
84 if (!strcmp(name, "hfs.type")) {
86 memcpy(value, &file->UsrWds.fdType, 4);
89 res = size ? -ERANGE : 4;
90 } else if (!strcmp(name, "hfs.creator")) {
92 memcpy(value, &file->UsrWds.fdCreator, 4);
95 res = size ? -ERANGE : 4;
104 #define HFS_ATTRLIST_SIZE (sizeof("hfs.creator")+sizeof("hfs.type"))
106 ssize_t hfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
108 struct inode *inode = d_inode(dentry);
110 if (!S_ISREG(inode->i_mode) || HFS_IS_RSRC(inode))
113 if (!buffer || !size)
114 return HFS_ATTRLIST_SIZE;
115 if (size < HFS_ATTRLIST_SIZE)
117 strcpy(buffer, "hfs.type");
118 strcpy(buffer + sizeof("hfs.type"), "hfs.creator");
120 return HFS_ATTRLIST_SIZE;