Commit 3a9e3908 authored by Roman Zippel's avatar Roman Zippel Committed by Linus Torvalds

[PATCH] hfs: export type/creator via xattr

This exports the hfs type/creator info via xattr.
Signed-off-by: default avatarRoman Zippel <zippel@linux-m68k.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent a0003bd2
......@@ -5,6 +5,6 @@
obj-$(CONFIG_HFS_FS) += hfs.o
hfs-objs := bitmap.o bfind.o bnode.o brec.o btree.o \
catalog.o dir.o extent.o inode.o mdb.o \
catalog.o dir.o extent.o inode.o attr.o mdb.o \
part_tbl.o string.o super.o sysdep.o trans.o
/*
* linux/fs/hfs/attr.c
*
* (C) 2003 Ardis Technologies <roman@ardistech.com>
*
* Export hfs data via xattr
*/
#include <linux/fs.h>
#include <linux/xattr.h>
#include "hfs_fs.h"
#include "btree.h"
int hfs_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;
hfs_cat_rec rec;
struct hfs_cat_file *file;
int res;
if (!S_ISREG(inode->i_mode) || HFS_IS_RSRC(inode))
return -EOPNOTSUPP;
res = hfs_find_init(HFS_SB(inode->i_sb)->cat_tree, &fd);
if (res)
return res;
fd.search_key->cat = HFS_I(inode)->cat_key;
res = hfs_brec_find(&fd);
if (res)
goto out;
hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
sizeof(struct hfs_cat_file));
file = &rec.file;
if (!strcmp(name, "hfs.type")) {
if (size == 4)
memcpy(&file->UsrWds.fdType, value, 4);
else
res = -ERANGE;
} else if (!strcmp(name, "hfs.creator")) {
if (size == 4)
memcpy(&file->UsrWds.fdCreator, value, 4);
else
res = -ERANGE;
} else
res = -EOPNOTSUPP;
if (!res)
hfs_bnode_write(fd.bnode, &rec, fd.entryoffset,
sizeof(struct hfs_cat_file));
out:
hfs_find_exit(&fd);
return res;
}
ssize_t hfs_getxattr(struct dentry *dentry, const char *name,
void *value, size_t size)
{
struct inode *inode = dentry->d_inode;
struct hfs_find_data fd;
hfs_cat_rec rec;
struct hfs_cat_file *file;
ssize_t res = 0;
if (!S_ISREG(inode->i_mode) || HFS_IS_RSRC(inode))
return -EOPNOTSUPP;
if (size) {
res = hfs_find_init(HFS_SB(inode->i_sb)->cat_tree, &fd);
if (res)
return res;
fd.search_key->cat = HFS_I(inode)->cat_key;
res = hfs_brec_find(&fd);
if (res)
goto out;
hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
sizeof(struct hfs_cat_file));
}
file = &rec.file;
if (!strcmp(name, "hfs.type")) {
if (size >= 4) {
memcpy(value, &file->UsrWds.fdType, 4);
res = 4;
} else
res = size ? -ERANGE : 4;
} else if (!strcmp(name, "hfs.creator")) {
if (size >= 4) {
memcpy(value, &file->UsrWds.fdCreator, 4);
res = 4;
} else
res = size ? -ERANGE : 4;
} else
res = -ENODATA;
out:
if (size)
hfs_find_exit(&fd);
return res;
}
#define HFS_ATTRLIST_SIZE (sizeof("hfs.creator")+sizeof("hfs.type"))
ssize_t hfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
{
struct inode *inode = dentry->d_inode;
if (!S_ISREG(inode->i_mode) || HFS_IS_RSRC(inode))
return -EOPNOTSUPP;
if (!buffer || !size)
return HFS_ATTRLIST_SIZE;
if (size < HFS_ATTRLIST_SIZE)
return -ERANGE;
strcpy(buffer, "hfs.type");
strcpy(buffer + sizeof("hfs.type"), "hfs.creator");
return HFS_ATTRLIST_SIZE;
}
......@@ -207,6 +207,13 @@ extern struct inode *hfs_iget(struct super_block *, struct hfs_cat_key *, hfs_ca
extern void hfs_clear_inode(struct inode *);
extern void hfs_delete_inode(struct inode *);
/* attr.c */
extern int hfs_setxattr(struct dentry *dentry, const char *name,
const void *value, size_t size, int flags);
extern ssize_t hfs_getxattr(struct dentry *dentry, const char *name,
void *value, size_t size);
extern ssize_t hfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
/* mdb.c */
extern int hfs_mdb_get(struct super_block *);
extern void hfs_mdb_commit(struct super_block *);
......
......@@ -627,4 +627,7 @@ struct inode_operations hfs_file_inode_operations = {
.truncate = hfs_file_truncate,
.setattr = hfs_inode_setattr,
.permission = hfs_permission,
.setxattr = hfs_setxattr,
.getxattr = hfs_getxattr,
.listxattr = hfs_listxattr,
};
......@@ -341,6 +341,11 @@ void hfsplus_delete_inode(struct inode *);
/* ioctl.c */
int hfsplus_ioctl(struct inode *inode, 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 */
int parse_options(char *, struct hfsplus_sb_info *);
......
......@@ -301,6 +301,9 @@ struct inode_operations hfsplus_file_inode_operations = {
.lookup = hfsplus_file_lookup,
.truncate = hfsplus_file_truncate,
.permission = hfsplus_permission,
.setxattr = hfsplus_setxattr,
.getxattr = hfsplus_getxattr,
.listxattr = hfsplus_listxattr,
};
struct file_operations hfsplus_file_operations = {
......
......@@ -14,6 +14,7 @@
#include <linux/fs.h>
#include <linux/sched.h>
#include <linux/xattr.h>
#include <asm/uaccess.h>
#include "hfsplus_fs.h"
......@@ -80,3 +81,108 @@ int hfsplus_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
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));
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 = -ENODATA;
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;
}
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