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 <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 |= FS_IMMUTABLE_FL; /* EXT2_IMMUTABLE_FL */
33 if (HFSPLUS_I(inode).rootflags & HFSPLUS_FLG_APPEND)
34 flags |= FS_APPEND_FL; /* EXT2_APPEND_FL */
35 if (HFSPLUS_I(inode).userflags & HFSPLUS_FLG_NODUMP)
36 flags |= FS_NODUMP_FL; /* EXT2_NODUMP_FL */
37 return put_user(flags, (int __user *)arg);
38 case HFSPLUS_IOC_EXT2_SETFLAGS: {
40 err = mnt_want_write(filp->f_path.mnt);
44 if (!is_owner_or_cap(inode)) {
48 if (get_user(flags, (int __user *)arg)) {
52 if (flags & (FS_IMMUTABLE_FL|FS_APPEND_FL) ||
53 HFSPLUS_I(inode).rootflags & (HFSPLUS_FLG_IMMUTABLE|HFSPLUS_FLG_APPEND)) {
54 if (!capable(CAP_LINUX_IMMUTABLE)) {
60 /* don't silently ignore unsupported ext2 flags */
61 if (flags & ~(FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NODUMP_FL)) {
65 if (flags & FS_IMMUTABLE_FL) { /* EXT2_IMMUTABLE_FL */
66 inode->i_flags |= S_IMMUTABLE;
67 HFSPLUS_I(inode).rootflags |= HFSPLUS_FLG_IMMUTABLE;
69 inode->i_flags &= ~S_IMMUTABLE;
70 HFSPLUS_I(inode).rootflags &= ~HFSPLUS_FLG_IMMUTABLE;
72 if (flags & FS_APPEND_FL) { /* EXT2_APPEND_FL */
73 inode->i_flags |= S_APPEND;
74 HFSPLUS_I(inode).rootflags |= HFSPLUS_FLG_APPEND;
76 inode->i_flags &= ~S_APPEND;
77 HFSPLUS_I(inode).rootflags &= ~HFSPLUS_FLG_APPEND;
79 if (flags & FS_NODUMP_FL) /* EXT2_NODUMP_FL */
80 HFSPLUS_I(inode).userflags |= HFSPLUS_FLG_NODUMP;
82 HFSPLUS_I(inode).userflags &= ~HFSPLUS_FLG_NODUMP;
84 inode->i_ctime = CURRENT_TIME_SEC;
85 mark_inode_dirty(inode);
87 mnt_drop_write(filp->f_path.mnt);
95 int hfsplus_setxattr(struct dentry *dentry, const char *name,
96 const void *value, size_t size, int flags)
98 struct inode *inode = dentry->d_inode;
99 struct hfs_find_data fd;
100 hfsplus_cat_entry entry;
101 struct hfsplus_cat_file *file;
104 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
107 res = hfs_find_init(HFSPLUS_SB(inode->i_sb).cat_tree, &fd);
110 res = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
113 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
114 sizeof(struct hfsplus_cat_file));
117 if (!strcmp(name, "hfs.type")) {
119 memcpy(&file->user_info.fdType, value, 4);
122 } else if (!strcmp(name, "hfs.creator")) {
124 memcpy(&file->user_info.fdCreator, value, 4);
130 hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
131 sizeof(struct hfsplus_cat_file));
137 ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
138 void *value, size_t size)
140 struct inode *inode = dentry->d_inode;
141 struct hfs_find_data fd;
142 hfsplus_cat_entry entry;
143 struct hfsplus_cat_file *file;
146 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
150 res = hfs_find_init(HFSPLUS_SB(inode->i_sb).cat_tree, &fd);
153 res = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
156 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
157 sizeof(struct hfsplus_cat_file));
161 if (!strcmp(name, "hfs.type")) {
163 memcpy(value, &file->user_info.fdType, 4);
166 res = size ? -ERANGE : 4;
167 } else if (!strcmp(name, "hfs.creator")) {
169 memcpy(value, &file->user_info.fdCreator, 4);
172 res = size ? -ERANGE : 4;
181 #define HFSPLUS_ATTRLIST_SIZE (sizeof("hfs.creator")+sizeof("hfs.type"))
183 ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size)
185 struct inode *inode = dentry->d_inode;
187 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
190 if (!buffer || !size)
191 return HFSPLUS_ATTRLIST_SIZE;
192 if (size < HFSPLUS_ATTRLIST_SIZE)
194 strcpy(buffer, "hfs.type");
195 strcpy(buffer + sizeof("hfs.type"), "hfs.creator");
197 return HFSPLUS_ATTRLIST_SIZE;