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>
23 #include <linux/ext2_fs.h>
25 static int ocfs2_get_inode_attr(struct inode *inode, unsigned *flags)
29 status = ocfs2_meta_lock(inode, NULL, 0);
34 ocfs2_get_inode_flags(OCFS2_I(inode));
35 *flags = OCFS2_I(inode)->ip_attr;
36 ocfs2_meta_unlock(inode, 0);
42 static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
45 struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
46 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
47 handle_t *handle = NULL;
48 struct buffer_head *bh = NULL;
52 mutex_lock(&inode->i_mutex);
54 status = ocfs2_meta_lock(inode, &bh, 1);
65 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
68 if (!S_ISDIR(inode->i_mode))
69 flags &= ~OCFS2_DIRSYNC_FL;
71 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
73 status = PTR_ERR(handle);
78 oldflags = ocfs2_inode->ip_attr;
80 flags |= oldflags & ~mask;
83 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
84 * the relevant capability.
87 if ((oldflags & OCFS2_IMMUTABLE_FL) || ((flags ^ oldflags) &
88 (OCFS2_APPEND_FL | OCFS2_IMMUTABLE_FL))) {
89 if (!capable(CAP_LINUX_IMMUTABLE))
93 ocfs2_inode->ip_attr = flags;
94 ocfs2_set_inode_flags(inode);
96 status = ocfs2_mark_inode_dirty(handle, inode, bh);
100 ocfs2_commit_trans(osb, handle);
102 ocfs2_meta_unlock(inode, 1);
104 mutex_unlock(&inode->i_mutex);
113 int ocfs2_ioctl(struct inode * inode, struct file * filp,
114 unsigned int cmd, unsigned long arg)
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 return ocfs2_set_inode_attr(inode, flags,
132 OCFS2_FL_MODIFIABLE);
139 long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg)
141 struct inode *inode = file->f_path.dentry->d_inode;
145 case OCFS2_IOC32_GETFLAGS:
146 cmd = OCFS2_IOC_GETFLAGS;
148 case OCFS2_IOC32_SETFLAGS:
149 cmd = OCFS2_IOC_SETFLAGS;
156 ret = ocfs2_ioctl(inode, file, cmd, arg);