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/mount.h>
18 #include <linux/sched.h>
19 #include <linux/xattr.h>
20 #include <linux/smp_lock.h>
21 #include <asm/uaccess.h>
22 #include "hfsplus_fs.h"
24 long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
26 struct inode *inode = filp->f_path.dentry->d_inode;
31 case HFSPLUS_IOC_EXT2_GETFLAGS:
33 if (HFSPLUS_I(inode).rootflags & HFSPLUS_FLG_IMMUTABLE)
34 flags |= FS_IMMUTABLE_FL; /* EXT2_IMMUTABLE_FL */
35 if (HFSPLUS_I(inode).rootflags & HFSPLUS_FLG_APPEND)
36 flags |= FS_APPEND_FL; /* EXT2_APPEND_FL */
37 if (HFSPLUS_I(inode).userflags & HFSPLUS_FLG_NODUMP)
38 flags |= FS_NODUMP_FL; /* EXT2_NODUMP_FL */
39 return put_user(flags, (int __user *)arg);
40 case HFSPLUS_IOC_EXT2_SETFLAGS: {
42 err = mnt_want_write(filp->f_path.mnt);
48 if (!is_owner_or_cap(inode)) {
52 if (get_user(flags, (int __user *)arg)) {
56 if (flags & (FS_IMMUTABLE_FL|FS_APPEND_FL) ||
57 HFSPLUS_I(inode).rootflags & (HFSPLUS_FLG_IMMUTABLE|HFSPLUS_FLG_APPEND)) {
58 if (!capable(CAP_LINUX_IMMUTABLE)) {
64 /* don't silently ignore unsupported ext2 flags */
65 if (flags & ~(FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NODUMP_FL)) {
69 if (flags & FS_IMMUTABLE_FL) { /* EXT2_IMMUTABLE_FL */
70 inode->i_flags |= S_IMMUTABLE;
71 HFSPLUS_I(inode).rootflags |= HFSPLUS_FLG_IMMUTABLE;
73 inode->i_flags &= ~S_IMMUTABLE;
74 HFSPLUS_I(inode).rootflags &= ~HFSPLUS_FLG_IMMUTABLE;
76 if (flags & FS_APPEND_FL) { /* EXT2_APPEND_FL */
77 inode->i_flags |= S_APPEND;
78 HFSPLUS_I(inode).rootflags |= HFSPLUS_FLG_APPEND;
80 inode->i_flags &= ~S_APPEND;
81 HFSPLUS_I(inode).rootflags &= ~HFSPLUS_FLG_APPEND;
83 if (flags & FS_NODUMP_FL) /* EXT2_NODUMP_FL */
84 HFSPLUS_I(inode).userflags |= HFSPLUS_FLG_NODUMP;
86 HFSPLUS_I(inode).userflags &= ~HFSPLUS_FLG_NODUMP;
88 inode->i_ctime = CURRENT_TIME_SEC;
89 mark_inode_dirty(inode);
91 mnt_drop_write(filp->f_path.mnt);
101 int hfsplus_setxattr(struct dentry *dentry, const char *name,
102 const void *value, size_t size, int flags)
104 struct inode *inode = dentry->d_inode;
105 struct hfs_find_data fd;
106 hfsplus_cat_entry entry;
107 struct hfsplus_cat_file *file;
110 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
113 res = hfs_find_init(HFSPLUS_SB(inode->i_sb).cat_tree, &fd);
116 res = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
119 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
120 sizeof(struct hfsplus_cat_file));
123 if (!strcmp(name, "hfs.type")) {
125 memcpy(&file->user_info.fdType, value, 4);
128 } else if (!strcmp(name, "hfs.creator")) {
130 memcpy(&file->user_info.fdCreator, value, 4);
136 hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
137 sizeof(struct hfsplus_cat_file));
143 ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
144 void *value, size_t size)
146 struct inode *inode = dentry->d_inode;
147 struct hfs_find_data fd;
148 hfsplus_cat_entry entry;
149 struct hfsplus_cat_file *file;
152 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
156 res = hfs_find_init(HFSPLUS_SB(inode->i_sb).cat_tree, &fd);
159 res = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
162 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
163 sizeof(struct hfsplus_cat_file));
167 if (!strcmp(name, "hfs.type")) {
169 memcpy(value, &file->user_info.fdType, 4);
172 res = size ? -ERANGE : 4;
173 } else if (!strcmp(name, "hfs.creator")) {
175 memcpy(value, &file->user_info.fdCreator, 4);
178 res = size ? -ERANGE : 4;
187 #define HFSPLUS_ATTRLIST_SIZE (sizeof("hfs.creator")+sizeof("hfs.type"))
189 ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size)
191 struct inode *inode = dentry->d_inode;
193 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
196 if (!buffer || !size)
197 return HFSPLUS_ATTRLIST_SIZE;
198 if (size < HFSPLUS_ATTRLIST_SIZE)
200 strcpy(buffer, "hfs.type");
201 strcpy(buffer + sizeof("hfs.type"), "hfs.creator");
203 return HFSPLUS_ATTRLIST_SIZE;