2 * linux/fs/hfsplus/ioctl.c
5 * Ethan Benson <erbenson@alaska.net>
6 * partially derived from linux/fs/ext2/ioctl.c
7 * Copyright (C) 1993, 1994, 1995
8 * Remy Card (card@masi.ibp.fr)
9 * Laboratoire MASI - Institut Blaise Pascal
10 * Universite Pierre et Marie Curie (Paris VI)
15 #include <linux/capability.h>
17 #include <linux/sched.h>
18 #include <linux/xattr.h>
19 #include <linux/mount.h>
20 #include <asm/uaccess.h>
21 #include "hfsplus_fs.h"
23 int hfsplus_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
29 case HFSPLUS_IOC_EXT2_GETFLAGS:
31 if (HFSPLUS_I(inode).rootflags & HFSPLUS_FLG_IMMUTABLE)
32 flags |= EXT2_FLAG_IMMUTABLE; /* EXT2_IMMUTABLE_FL */
33 if (HFSPLUS_I(inode).rootflags & HFSPLUS_FLG_APPEND)
34 flags |= EXT2_FLAG_APPEND; /* EXT2_APPEND_FL */
35 if (HFSPLUS_I(inode).userflags & HFSPLUS_FLG_NODUMP)
36 flags |= EXT2_FLAG_NODUMP; /* EXT2_NODUMP_FL */
37 return put_user(flags, (int __user *)arg);
38 case HFSPLUS_IOC_EXT2_SETFLAGS: {
39 if (IS_RDONLY(inode) ||
40 (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
43 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
46 if (get_user(flags, (int __user *)arg))
49 if (flags & (EXT2_FLAG_IMMUTABLE|EXT2_FLAG_APPEND) ||
50 HFSPLUS_I(inode).rootflags & (HFSPLUS_FLG_IMMUTABLE|HFSPLUS_FLG_APPEND)) {
51 if (!capable(CAP_LINUX_IMMUTABLE))
55 /* don't silently ignore unsupported ext2 flags */
56 if (flags & ~(EXT2_FLAG_IMMUTABLE|EXT2_FLAG_APPEND|
60 if (flags & EXT2_FLAG_IMMUTABLE) { /* EXT2_IMMUTABLE_FL */
61 inode->i_flags |= S_IMMUTABLE;
62 HFSPLUS_I(inode).rootflags |= HFSPLUS_FLG_IMMUTABLE;
64 inode->i_flags &= ~S_IMMUTABLE;
65 HFSPLUS_I(inode).rootflags &= ~HFSPLUS_FLG_IMMUTABLE;
67 if (flags & EXT2_FLAG_APPEND) { /* EXT2_APPEND_FL */
68 inode->i_flags |= S_APPEND;
69 HFSPLUS_I(inode).rootflags |= HFSPLUS_FLG_APPEND;
71 inode->i_flags &= ~S_APPEND;
72 HFSPLUS_I(inode).rootflags &= ~HFSPLUS_FLG_APPEND;
74 if (flags & EXT2_FLAG_NODUMP) /* EXT2_NODUMP_FL */
75 HFSPLUS_I(inode).userflags |= HFSPLUS_FLG_NODUMP;
77 HFSPLUS_I(inode).userflags &= ~HFSPLUS_FLG_NODUMP;
79 inode->i_ctime = CURRENT_TIME_SEC;
80 mark_inode_dirty(inode);
88 int hfsplus_setxattr(struct dentry *dentry, const char *name,
89 const void *value, size_t size, int flags)
91 struct inode *inode = dentry->d_inode;
92 struct hfs_find_data fd;
93 hfsplus_cat_entry entry;
94 struct hfsplus_cat_file *file;
97 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
100 res = hfs_find_init(HFSPLUS_SB(inode->i_sb).cat_tree, &fd);
103 res = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
106 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
107 sizeof(struct hfsplus_cat_file));
110 if (!strcmp(name, "hfs.type")) {
112 memcpy(&file->user_info.fdType, value, 4);
115 } else if (!strcmp(name, "hfs.creator")) {
117 memcpy(&file->user_info.fdCreator, value, 4);
123 hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
124 sizeof(struct hfsplus_cat_file));
130 ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
131 void *value, size_t size)
133 struct inode *inode = dentry->d_inode;
134 struct hfs_find_data fd;
135 hfsplus_cat_entry entry;
136 struct hfsplus_cat_file *file;
139 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
143 res = hfs_find_init(HFSPLUS_SB(inode->i_sb).cat_tree, &fd);
146 res = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
149 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
150 sizeof(struct hfsplus_cat_file));
154 if (!strcmp(name, "hfs.type")) {
156 memcpy(value, &file->user_info.fdType, 4);
159 res = size ? -ERANGE : 4;
160 } else if (!strcmp(name, "hfs.creator")) {
162 memcpy(value, &file->user_info.fdCreator, 4);
165 res = size ? -ERANGE : 4;
174 #define HFSPLUS_ATTRLIST_SIZE (sizeof("hfs.creator")+sizeof("hfs.type"))
176 ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size)
178 struct inode *inode = dentry->d_inode;
180 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
183 if (!buffer || !size)
184 return HFSPLUS_ATTRLIST_SIZE;
185 if (size < HFSPLUS_ATTRLIST_SIZE)
187 strcpy(buffer, "hfs.type");
188 strcpy(buffer + sizeof("hfs.type"), "hfs.creator");
190 return HFSPLUS_ATTRLIST_SIZE;