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>
21 #include <linux/ext2_fs.h>
23 static int ocfs2_get_inode_attr(struct inode *inode, unsigned *flags)
27 status = ocfs2_meta_lock(inode, NULL, NULL, 0);
32 *flags = OCFS2_I(inode)->ip_attr;
33 ocfs2_meta_unlock(inode, 0);
39 static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
42 struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
43 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
44 struct ocfs2_journal_handle *handle = NULL;
45 struct buffer_head *bh = NULL;
49 mutex_lock(&inode->i_mutex);
51 status = ocfs2_meta_lock(inode, NULL, &bh, 1);
62 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
65 if (!S_ISDIR(inode->i_mode))
66 flags &= ~OCFS2_DIRSYNC_FL;
68 handle = ocfs2_start_trans(osb, NULL, OCFS2_INODE_UPDATE_CREDITS);
70 status = PTR_ERR(handle);
75 oldflags = ocfs2_inode->ip_attr;
77 flags |= oldflags & ~mask;
80 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
81 * the relevant capability.
84 if ((oldflags & OCFS2_IMMUTABLE_FL) || ((flags ^ oldflags) &
85 (OCFS2_APPEND_FL | OCFS2_IMMUTABLE_FL))) {
86 if (!capable(CAP_LINUX_IMMUTABLE))
90 ocfs2_inode->ip_attr = flags;
91 ocfs2_set_inode_flags(inode);
93 status = ocfs2_mark_inode_dirty(handle, inode, bh);
97 ocfs2_commit_trans(handle);
99 ocfs2_meta_unlock(inode, 1);
101 mutex_unlock(&inode->i_mutex);
110 int ocfs2_ioctl(struct inode * inode, struct file * filp,
111 unsigned int cmd, unsigned long arg)
117 case OCFS2_IOC_GETFLAGS:
118 status = ocfs2_get_inode_attr(inode, &flags);
122 flags &= OCFS2_FL_VISIBLE;
123 return put_user(flags, (int __user *) arg);
124 case OCFS2_IOC_SETFLAGS:
125 if (get_user(flags, (int __user *) arg))
128 return ocfs2_set_inode_attr(inode, flags,
129 OCFS2_FL_MODIFIABLE);