ACPI: apply quirk_ich6_lpc_acpi to more ICH8 and ICH9
[wrt350n-kernel.git] / fs / ocfs2 / ioctl.c
blob87dcece7e1b5cc1d0439da96c7fffe5199af1311
1 /*
2 * linux/fs/ocfs2/ioctl.c
4 * Copyright (C) 2006 Herbert Poetzl
5 * adapted from Remy Card's ext2/ioctl.c
6 */
8 #include <linux/fs.h>
9 #include <linux/mount.h>
11 #define MLOG_MASK_PREFIX ML_INODE
12 #include <cluster/masklog.h>
14 #include "ocfs2.h"
15 #include "alloc.h"
16 #include "dlmglue.h"
17 #include "file.h"
18 #include "inode.h"
19 #include "journal.h"
21 #include "ocfs2_fs.h"
22 #include "ioctl.h"
24 #include <linux/ext2_fs.h>
26 static int ocfs2_get_inode_attr(struct inode *inode, unsigned *flags)
28 int status;
30 status = ocfs2_meta_lock(inode, NULL, 0);
31 if (status < 0) {
32 mlog_errno(status);
33 return status;
35 ocfs2_get_inode_flags(OCFS2_I(inode));
36 *flags = OCFS2_I(inode)->ip_attr;
37 ocfs2_meta_unlock(inode, 0);
39 mlog_exit(status);
40 return status;
43 static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
44 unsigned mask)
46 struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
47 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
48 handle_t *handle = NULL;
49 struct buffer_head *bh = NULL;
50 unsigned oldflags;
51 int status;
53 mutex_lock(&inode->i_mutex);
55 status = ocfs2_meta_lock(inode, &bh, 1);
56 if (status < 0) {
57 mlog_errno(status);
58 goto bail;
61 status = -EROFS;
62 if (IS_RDONLY(inode))
63 goto bail_unlock;
65 status = -EACCES;
66 if (!is_owner_or_cap(inode))
67 goto bail_unlock;
69 if (!S_ISDIR(inode->i_mode))
70 flags &= ~OCFS2_DIRSYNC_FL;
72 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
73 if (IS_ERR(handle)) {
74 status = PTR_ERR(handle);
75 mlog_errno(status);
76 goto bail_unlock;
79 oldflags = ocfs2_inode->ip_attr;
80 flags = flags & mask;
81 flags |= oldflags & ~mask;
84 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
85 * the relevant capability.
87 status = -EPERM;
88 if ((oldflags & OCFS2_IMMUTABLE_FL) || ((flags ^ oldflags) &
89 (OCFS2_APPEND_FL | OCFS2_IMMUTABLE_FL))) {
90 if (!capable(CAP_LINUX_IMMUTABLE))
91 goto bail_unlock;
94 ocfs2_inode->ip_attr = flags;
95 ocfs2_set_inode_flags(inode);
97 status = ocfs2_mark_inode_dirty(handle, inode, bh);
98 if (status < 0)
99 mlog_errno(status);
101 ocfs2_commit_trans(osb, handle);
102 bail_unlock:
103 ocfs2_meta_unlock(inode, 1);
104 bail:
105 mutex_unlock(&inode->i_mutex);
107 if (bh)
108 brelse(bh);
110 mlog_exit(status);
111 return status;
114 int ocfs2_ioctl(struct inode * inode, struct file * filp,
115 unsigned int cmd, unsigned long arg)
117 unsigned int flags;
118 int status;
119 struct ocfs2_space_resv sr;
121 switch (cmd) {
122 case OCFS2_IOC_GETFLAGS:
123 status = ocfs2_get_inode_attr(inode, &flags);
124 if (status < 0)
125 return status;
127 flags &= OCFS2_FL_VISIBLE;
128 return put_user(flags, (int __user *) arg);
129 case OCFS2_IOC_SETFLAGS:
130 if (get_user(flags, (int __user *) arg))
131 return -EFAULT;
133 return ocfs2_set_inode_attr(inode, flags,
134 OCFS2_FL_MODIFIABLE);
135 case OCFS2_IOC_RESVSP:
136 case OCFS2_IOC_RESVSP64:
137 case OCFS2_IOC_UNRESVSP:
138 case OCFS2_IOC_UNRESVSP64:
139 if (copy_from_user(&sr, (int __user *) arg, sizeof(sr)))
140 return -EFAULT;
142 return ocfs2_change_file_space(filp, cmd, &sr);
143 default:
144 return -ENOTTY;
148 #ifdef CONFIG_COMPAT
149 long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg)
151 struct inode *inode = file->f_path.dentry->d_inode;
152 int ret;
154 switch (cmd) {
155 case OCFS2_IOC32_GETFLAGS:
156 cmd = OCFS2_IOC_GETFLAGS;
157 break;
158 case OCFS2_IOC32_SETFLAGS:
159 cmd = OCFS2_IOC_SETFLAGS;
160 break;
161 case OCFS2_IOC_RESVSP:
162 case OCFS2_IOC_RESVSP64:
163 case OCFS2_IOC_UNRESVSP:
164 case OCFS2_IOC_UNRESVSP64:
165 break;
166 default:
167 return -ENOIOCTLCMD;
170 lock_kernel();
171 ret = ocfs2_ioctl(inode, file, cmd, arg);
172 unlock_kernel();
173 return ret;
175 #endif