2 * linux/fs/ocfs2/ioctl.c
4 * Copyright (C) 2006 Herbert Poetzl
5 * adapted from Remy Card's ext2/ioctl.c
9 #include <linux/mount.h>
11 #define MLOG_MASK_PREFIX ML_INODE
12 #include <cluster/masklog.h>
25 #include <linux/ext2_fs.h>
27 static int ocfs2_get_inode_attr(struct inode *inode, unsigned *flags)
31 status = ocfs2_inode_lock(inode, NULL, 0);
36 ocfs2_get_inode_flags(OCFS2_I(inode));
37 *flags = OCFS2_I(inode)->ip_attr;
38 ocfs2_inode_unlock(inode, 0);
44 static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
47 struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
48 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
49 handle_t *handle = NULL;
50 struct buffer_head *bh = NULL;
54 mutex_lock(&inode->i_mutex);
56 status = ocfs2_inode_lock(inode, &bh, 1);
63 if (!is_owner_or_cap(inode))
66 if (!S_ISDIR(inode->i_mode))
67 flags &= ~OCFS2_DIRSYNC_FL;
69 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
71 status = PTR_ERR(handle);
76 oldflags = ocfs2_inode->ip_attr;
78 flags |= oldflags & ~mask;
81 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
82 * the relevant capability.
85 if ((oldflags & OCFS2_IMMUTABLE_FL) || ((flags ^ oldflags) &
86 (OCFS2_APPEND_FL | OCFS2_IMMUTABLE_FL))) {
87 if (!capable(CAP_LINUX_IMMUTABLE))
91 ocfs2_inode->ip_attr = flags;
92 ocfs2_set_inode_flags(inode);
94 status = ocfs2_mark_inode_dirty(handle, inode, bh);
98 ocfs2_commit_trans(osb, handle);
100 ocfs2_inode_unlock(inode, 1);
102 mutex_unlock(&inode->i_mutex);
110 long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
112 struct inode *inode = filp->f_path.dentry->d_inode;
116 struct ocfs2_space_resv sr;
117 struct ocfs2_new_group_input input;
120 case OCFS2_IOC_GETFLAGS:
121 status = ocfs2_get_inode_attr(inode, &flags);
125 flags &= OCFS2_FL_VISIBLE;
126 return put_user(flags, (int __user *) arg);
127 case OCFS2_IOC_SETFLAGS:
128 if (get_user(flags, (int __user *) arg))
131 status = mnt_want_write(filp->f_path.mnt);
134 status = ocfs2_set_inode_attr(inode, flags,
135 OCFS2_FL_MODIFIABLE);
136 mnt_drop_write(filp->f_path.mnt);
138 case OCFS2_IOC_RESVSP:
139 case OCFS2_IOC_RESVSP64:
140 case OCFS2_IOC_UNRESVSP:
141 case OCFS2_IOC_UNRESVSP64:
142 if (copy_from_user(&sr, (int __user *) arg, sizeof(sr)))
145 return ocfs2_change_file_space(filp, cmd, &sr);
146 case OCFS2_IOC_GROUP_EXTEND:
147 if (!capable(CAP_SYS_RESOURCE))
150 if (get_user(new_clusters, (int __user *)arg))
153 return ocfs2_group_extend(inode, new_clusters);
154 case OCFS2_IOC_GROUP_ADD:
155 case OCFS2_IOC_GROUP_ADD64:
156 if (!capable(CAP_SYS_RESOURCE))
159 if (copy_from_user(&input, (int __user *) arg, sizeof(input)))
162 return ocfs2_group_add(inode, &input);
169 long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg)
172 case OCFS2_IOC32_GETFLAGS:
173 cmd = OCFS2_IOC_GETFLAGS;
175 case OCFS2_IOC32_SETFLAGS:
176 cmd = OCFS2_IOC_SETFLAGS;
178 case OCFS2_IOC_RESVSP:
179 case OCFS2_IOC_RESVSP64:
180 case OCFS2_IOC_UNRESVSP:
181 case OCFS2_IOC_UNRESVSP64:
182 case OCFS2_IOC_GROUP_EXTEND:
183 case OCFS2_IOC_GROUP_ADD:
184 case OCFS2_IOC_GROUP_ADD64:
190 return ocfs2_ioctl(file, cmd, arg);