Linux Audio

Check our new training course

Loading...
v3.5.6
 
  1/*
  2 *  linux/fs/hfs/attr.c
  3 *
  4 * (C) 2003 Ardis Technologies <roman@ardistech.com>
  5 *
  6 * Export hfs data via xattr
  7 */
  8
  9
 10#include <linux/fs.h>
 11#include <linux/xattr.h>
 12
 13#include "hfs_fs.h"
 14#include "btree.h"
 15
 16int hfs_setxattr(struct dentry *dentry, const char *name,
 17		 const void *value, size_t size, int flags)
 
 
 
 
 
 18{
 19	struct inode *inode = dentry->d_inode;
 20	struct hfs_find_data fd;
 21	hfs_cat_rec rec;
 22	struct hfs_cat_file *file;
 23	int res;
 24
 25	if (!S_ISREG(inode->i_mode) || HFS_IS_RSRC(inode))
 26		return -EOPNOTSUPP;
 27
 28	res = hfs_find_init(HFS_SB(inode->i_sb)->cat_tree, &fd);
 29	if (res)
 30		return res;
 31	fd.search_key->cat = HFS_I(inode)->cat_key;
 32	res = hfs_brec_find(&fd);
 33	if (res)
 34		goto out;
 35	hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
 36			sizeof(struct hfs_cat_file));
 37	file = &rec.file;
 38
 39	if (!strcmp(name, "hfs.type")) {
 
 40		if (size == 4)
 41			memcpy(&file->UsrWds.fdType, value, 4);
 42		else
 43			res = -ERANGE;
 44	} else if (!strcmp(name, "hfs.creator")) {
 
 
 45		if (size == 4)
 46			memcpy(&file->UsrWds.fdCreator, value, 4);
 47		else
 48			res = -ERANGE;
 49	} else
 50		res = -EOPNOTSUPP;
 
 51	if (!res)
 52		hfs_bnode_write(fd.bnode, &rec, fd.entryoffset,
 53				sizeof(struct hfs_cat_file));
 54out:
 55	hfs_find_exit(&fd);
 56	return res;
 57}
 58
 59ssize_t hfs_getxattr(struct dentry *dentry, const char *name,
 60			 void *value, size_t size)
 61{
 62	struct inode *inode = dentry->d_inode;
 63	struct hfs_find_data fd;
 64	hfs_cat_rec rec;
 65	struct hfs_cat_file *file;
 66	ssize_t res = 0;
 67
 68	if (!S_ISREG(inode->i_mode) || HFS_IS_RSRC(inode))
 69		return -EOPNOTSUPP;
 70
 71	if (size) {
 72		res = hfs_find_init(HFS_SB(inode->i_sb)->cat_tree, &fd);
 73		if (res)
 74			return res;
 75		fd.search_key->cat = HFS_I(inode)->cat_key;
 76		res = hfs_brec_find(&fd);
 77		if (res)
 78			goto out;
 79		hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
 80				sizeof(struct hfs_cat_file));
 81	}
 82	file = &rec.file;
 83
 84	if (!strcmp(name, "hfs.type")) {
 
 85		if (size >= 4) {
 86			memcpy(value, &file->UsrWds.fdType, 4);
 87			res = 4;
 88		} else
 89			res = size ? -ERANGE : 4;
 90	} else if (!strcmp(name, "hfs.creator")) {
 
 
 91		if (size >= 4) {
 92			memcpy(value, &file->UsrWds.fdCreator, 4);
 93			res = 4;
 94		} else
 95			res = size ? -ERANGE : 4;
 96	} else
 97		res = -ENODATA;
 
 98out:
 99	if (size)
100		hfs_find_exit(&fd);
101	return res;
102}
103
104#define HFS_ATTRLIST_SIZE (sizeof("hfs.creator")+sizeof("hfs.type"))
105
106ssize_t hfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
107{
108	struct inode *inode = dentry->d_inode;
 
109
110	if (!S_ISREG(inode->i_mode) || HFS_IS_RSRC(inode))
 
 
 
 
 
 
111		return -EOPNOTSUPP;
112
113	if (!buffer || !size)
114		return HFS_ATTRLIST_SIZE;
115	if (size < HFS_ATTRLIST_SIZE)
116		return -ERANGE;
117	strcpy(buffer, "hfs.type");
118	strcpy(buffer + sizeof("hfs.type"), "hfs.creator");
119
120	return HFS_ATTRLIST_SIZE;
121}
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 *  linux/fs/hfs/attr.c
  4 *
  5 * (C) 2003 Ardis Technologies <roman@ardistech.com>
  6 *
  7 * Export hfs data via xattr
  8 */
  9
 10
 11#include <linux/fs.h>
 12#include <linux/xattr.h>
 13
 14#include "hfs_fs.h"
 15#include "btree.h"
 16
 17enum hfs_xattr_type {
 18	HFS_TYPE,
 19	HFS_CREATOR,
 20};
 21
 22static int __hfs_setxattr(struct inode *inode, enum hfs_xattr_type type,
 23			  const void *value, size_t size, int flags)
 24{
 
 25	struct hfs_find_data fd;
 26	hfs_cat_rec rec;
 27	struct hfs_cat_file *file;
 28	int res;
 29
 30	if (!S_ISREG(inode->i_mode) || HFS_IS_RSRC(inode))
 31		return -EOPNOTSUPP;
 32
 33	res = hfs_find_init(HFS_SB(inode->i_sb)->cat_tree, &fd);
 34	if (res)
 35		return res;
 36	fd.search_key->cat = HFS_I(inode)->cat_key;
 37	res = hfs_brec_find(&fd);
 38	if (res)
 39		goto out;
 40	hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
 41			sizeof(struct hfs_cat_file));
 42	file = &rec.file;
 43
 44	switch (type) {
 45	case HFS_TYPE:
 46		if (size == 4)
 47			memcpy(&file->UsrWds.fdType, value, 4);
 48		else
 49			res = -ERANGE;
 50		break;
 51
 52	case HFS_CREATOR:
 53		if (size == 4)
 54			memcpy(&file->UsrWds.fdCreator, value, 4);
 55		else
 56			res = -ERANGE;
 57		break;
 58	}
 59
 60	if (!res)
 61		hfs_bnode_write(fd.bnode, &rec, fd.entryoffset,
 62				sizeof(struct hfs_cat_file));
 63out:
 64	hfs_find_exit(&fd);
 65	return res;
 66}
 67
 68static ssize_t __hfs_getxattr(struct inode *inode, enum hfs_xattr_type type,
 69			      void *value, size_t size)
 70{
 
 71	struct hfs_find_data fd;
 72	hfs_cat_rec rec;
 73	struct hfs_cat_file *file;
 74	ssize_t res = 0;
 75
 76	if (!S_ISREG(inode->i_mode) || HFS_IS_RSRC(inode))
 77		return -EOPNOTSUPP;
 78
 79	if (size) {
 80		res = hfs_find_init(HFS_SB(inode->i_sb)->cat_tree, &fd);
 81		if (res)
 82			return res;
 83		fd.search_key->cat = HFS_I(inode)->cat_key;
 84		res = hfs_brec_find(&fd);
 85		if (res)
 86			goto out;
 87		hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
 88				sizeof(struct hfs_cat_file));
 89	}
 90	file = &rec.file;
 91
 92	switch (type) {
 93	case HFS_TYPE:
 94		if (size >= 4) {
 95			memcpy(value, &file->UsrWds.fdType, 4);
 96			res = 4;
 97		} else
 98			res = size ? -ERANGE : 4;
 99		break;
100
101	case HFS_CREATOR:
102		if (size >= 4) {
103			memcpy(value, &file->UsrWds.fdCreator, 4);
104			res = 4;
105		} else
106			res = size ? -ERANGE : 4;
107		break;
108	}
109
110out:
111	if (size)
112		hfs_find_exit(&fd);
113	return res;
114}
115
116static 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)
119{
120	return __hfs_getxattr(inode, handler->flags, value, size);
121}
122
123static int hfs_xattr_set(const struct xattr_handler *handler,
124			 struct mnt_idmap *idmap,
125			 struct dentry *unused, struct inode *inode,
126			 const char *name, const void *value, size_t size,
127			 int flags)
128{
129	if (!value)
130		return -EOPNOTSUPP;
131
132	return __hfs_setxattr(inode, handler->flags, value, size, flags);
 
 
 
 
 
 
 
133}
134
135static const struct xattr_handler hfs_creator_handler = {
136	.name = "hfs.creator",
137	.flags = HFS_CREATOR,
138	.get = hfs_xattr_get,
139	.set = hfs_xattr_set,
140};
141
142static const struct xattr_handler hfs_type_handler = {
143	.name = "hfs.type",
144	.flags = HFS_TYPE,
145	.get = hfs_xattr_get,
146	.set = hfs_xattr_set,
147};
148
149const struct xattr_handler * const hfs_xattr_handlers[] = {
150	&hfs_creator_handler,
151	&hfs_type_handler,
152	NULL
153};