allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / fs / ocfs2 / ioctl.c
blobf3ad21ad9aedff0374b0e4e394347670e5c851a8
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 "inode.h"
18 #include "journal.h"
20 #include "ocfs2_fs.h"
21 #include "ioctl.h"
23 #include <linux/ext2_fs.h>
25 static int ocfs2_get_inode_attr(struct inode *inode, unsigned *flags)
27 int status;
29 status = ocfs2_meta_lock(inode, NULL, 0);
30 if (status < 0) {
31 mlog_errno(status);
32 return status;
34 ocfs2_get_inode_flags(OCFS2_I(inode));
35 *flags = OCFS2_I(inode)->ip_attr;
36 ocfs2_meta_unlock(inode, 0);
38 mlog_exit(status);
39 return status;
42 static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
43 unsigned mask)
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;
49 unsigned oldflags;
50 int status;
52 mutex_lock(&inode->i_mutex);
54 status = ocfs2_meta_lock(inode, &bh, 1);
55 if (status < 0) {
56 mlog_errno(status);
57 goto bail;
60 status = -EROFS;
61 if (IS_RDONLY(inode))
62 goto bail_unlock;
64 status = -EACCES;
65 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
66 goto bail_unlock;
68 if (!S_ISDIR(inode->i_mode))
69 flags &= ~OCFS2_DIRSYNC_FL;
71 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
72 if (IS_ERR(handle)) {
73 status = PTR_ERR(handle);
74 mlog_errno(status);
75 goto bail_unlock;
78 oldflags = ocfs2_inode->ip_attr;
79 flags = flags & mask;
80 flags |= oldflags & ~mask;
83 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
84 * the relevant capability.
86 status = -EPERM;
87 if ((oldflags & OCFS2_IMMUTABLE_FL) || ((flags ^ oldflags) &
88 (OCFS2_APPEND_FL | OCFS2_IMMUTABLE_FL))) {
89 if (!capable(CAP_LINUX_IMMUTABLE))
90 goto bail_unlock;
93 ocfs2_inode->ip_attr = flags;
94 ocfs2_set_inode_flags(inode);
96 status = ocfs2_mark_inode_dirty(handle, inode, bh);
97 if (status < 0)
98 mlog_errno(status);
100 ocfs2_commit_trans(osb, handle);
101 bail_unlock:
102 ocfs2_meta_unlock(inode, 1);
103 bail:
104 mutex_unlock(&inode->i_mutex);
106 if (bh)
107 brelse(bh);
109 mlog_exit(status);
110 return status;
113 int ocfs2_ioctl(struct inode * inode, struct file * filp,
114 unsigned int cmd, unsigned long arg)
116 unsigned int flags;
117 int status;
119 switch (cmd) {
120 case OCFS2_IOC_GETFLAGS:
121 status = ocfs2_get_inode_attr(inode, &flags);
122 if (status < 0)
123 return status;
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))
129 return -EFAULT;
131 return ocfs2_set_inode_attr(inode, flags,
132 OCFS2_FL_MODIFIABLE);
133 default:
134 return -ENOTTY;
138 #ifdef CONFIG_COMPAT
139 long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg)
141 struct inode *inode = file->f_path.dentry->d_inode;
142 int ret;
144 switch (cmd) {
145 case OCFS2_IOC32_GETFLAGS:
146 cmd = OCFS2_IOC_GETFLAGS;
147 break;
148 case OCFS2_IOC32_SETFLAGS:
149 cmd = OCFS2_IOC_SETFLAGS;
150 break;
151 default:
152 return -ENOIOCTLCMD;
155 lock_kernel();
156 ret = ocfs2_ioctl(inode, file, cmd, arg);
157 unlock_kernel();
158 return ret;
160 #endif