linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 6/6] export type/creator via xattr
@ 2004-10-20 23:14 Roman Zippel
  2004-10-21  7:26 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Roman Zippel @ 2004-10-20 23:14 UTC (permalink / raw)
  To: Andrew Morton, linux-fsdevel


This exports the hfs type/creator info via xattr.

Signed-off-by: Roman Zippel <zippel@linux-m68k.org>

Index: linux-2.6-hfs/fs/hfs/inode.c
===================================================================
--- linux-2.6-hfs.orig/fs/hfs/inode.c	2004-10-21 00:48:20.610136534 +0200
+++ linux-2.6-hfs/fs/hfs/inode.c	2004-10-21 00:48:21.083055315 +0200
@@ -627,4 +627,7 @@ struct inode_operations hfs_file_inode_o
 	.truncate	= hfs_file_truncate,
 	.setattr	= hfs_inode_setattr,
 	.permission	= hfs_permission,
+	.setxattr	= hfs_setxattr,
+	.getxattr	= hfs_getxattr,
+	.listxattr	= hfs_listxattr,
 };
Index: linux-2.6-hfs/fs/hfs/hfs_fs.h
===================================================================
--- linux-2.6-hfs.orig/fs/hfs/hfs_fs.h	2004-10-21 00:48:19.491328677 +0200
+++ linux-2.6-hfs/fs/hfs/hfs_fs.h	2004-10-21 00:59:59.786706901 +0200
@@ -207,6 +207,13 @@ extern struct inode *hfs_iget(struct sup
 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 *);
Index: linux-2.6-hfs/fs/hfs/attr.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6-hfs/fs/hfs/attr.c	2004-10-21 00:56:40.505096734 +0200
@@ -0,0 +1,121 @@
+/*
+ *  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, "type")) {
+		if (size == 4)
+			memcpy(&file->UsrWds.fdType, value, 4);
+		else
+			res = -ERANGE;
+	} else if (!strcmp(name, "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, "type")) {
+		if (size >= 4) {
+			memcpy(value, &file->UsrWds.fdType, 4);
+			res = 4;
+		} else
+			res = size ? -ERANGE : 4;
+	} else if (!strcmp(name, "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("creator")+sizeof("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 (!size)
+		return HFS_ATTRLIST_SIZE;
+	if (size < HFS_ATTRLIST_SIZE)
+		return -ERANGE;
+	strcpy(buffer, "type");
+	strcpy(buffer + 5, "creator");
+
+	return HFS_ATTRLIST_SIZE;
+}
Index: linux-2.6-hfs/fs/hfsplus/ioctl.c
===================================================================
--- linux-2.6-hfs.orig/fs/hfsplus/ioctl.c	2004-06-16 20:26:38.000000000 +0200
+++ linux-2.6-hfs/fs/hfsplus/ioctl.c	2004-10-21 00:58:17.428369574 +0200
@@ -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, s
 		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, "type")) {
+		if (size == 4)
+			memcpy(&file->user_info.fdType, value, 4);
+		else
+			res = -ERANGE;
+	} else if (!strcmp(name, "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, "type")) {
+		if (size >= 4) {
+			memcpy(value, &file->user_info.fdType, 4);
+			res = 4;
+		} else
+			res = size ? -ERANGE : 4;
+	} else if (!strcmp(name, "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("creator")+sizeof("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 (!size)
+		return HFSPLUS_ATTRLIST_SIZE;
+	if (size < HFSPLUS_ATTRLIST_SIZE)
+		return -ERANGE;
+	strcpy(buffer, "type");
+	strcpy(buffer + 5, "creator");
+
+	return HFSPLUS_ATTRLIST_SIZE;
+}
Index: linux-2.6-hfs/fs/hfsplus/hfsplus_fs.h
===================================================================
--- linux-2.6-hfs.orig/fs/hfsplus/hfsplus_fs.h	2004-10-21 00:48:19.491328677 +0200
+++ linux-2.6-hfs/fs/hfsplus/hfsplus_fs.h	2004-10-21 00:58:29.345313088 +0200
@@ -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 *);
Index: linux-2.6-hfs/fs/hfsplus/inode.c
===================================================================
--- linux-2.6-hfs.orig/fs/hfsplus/inode.c	2004-10-21 00:48:20.610136534 +0200
+++ linux-2.6-hfs/fs/hfsplus/inode.c	2004-10-21 00:48:21.084055144 +0200
@@ -301,6 +301,9 @@ struct inode_operations hfsplus_file_ino
 	.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 = {
Index: linux-2.6-hfs/fs/hfs/Makefile
===================================================================
--- linux-2.6-hfs.orig/fs/hfs/Makefile	2004-03-11 19:33:09.000000000 +0100
+++ linux-2.6-hfs/fs/hfs/Makefile	2004-10-21 00:59:37.649526620 +0200
@@ -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
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 6/6] export type/creator via xattr
  2004-10-20 23:14 [PATCH 6/6] export type/creator via xattr Roman Zippel
@ 2004-10-21  7:26 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2004-10-21  7:26 UTC (permalink / raw)
  To: Roman Zippel; +Cc: Andrew Morton, linux-fsdevel

On Thu, Oct 21, 2004 at 01:14:32AM +0200, Roman Zippel wrote:
> 
> This exports the hfs type/creator info via xattr.

Am I misreading the code or are the attributes missing a hfs. prefix?
Also please try to use the generic xattr helpers that just went into mainline,
we'd like to deprecated the direct xattr calls in some time when everything
is converted.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-10-21  7:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-20 23:14 [PATCH 6/6] export type/creator via xattr Roman Zippel
2004-10-21  7:26 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).