2 * linux/kernel/vserver/inode.c
4 * Virtual Server: File System Support
6 * Copyright (C) 2004-2005 Herbert Pötzl
8 * V0.01 separated from vcontext V0.05
12 #include <linux/config.h>
13 #include <linux/sched.h>
14 #include <linux/vs_context.h>
15 #include <linux/proc_fs.h>
16 #include <linux/devpts_fs.h>
17 #include <linux/namei.h>
18 #include <linux/mount.h>
19 #include <linux/parser.h>
20 #include <linux/vserver/inode.h>
21 #include <linux/vserver/inode_cmd.h>
22 #include <linux/vserver/xid.h>
24 #include <asm/errno.h>
25 #include <asm/uaccess.h>
28 static int __vc_get_iattr(struct inode *in, uint32_t *xid, uint32_t *flags, uint32_t *mask)
30 struct proc_dir_entry *entry;
36 | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
37 | (IS_IUNLINK(in) ? IATTR_IUNLINK : 0)
38 | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
39 *mask = IATTR_IUNLINK | IATTR_IMMUTABLE;
41 if (S_ISDIR(in->i_mode))
42 *mask |= IATTR_BARRIER;
44 if (in->i_sb->s_flags & MS_TAGXID) {
49 switch (in->i_sb->s_magic) {
50 case PROC_SUPER_MAGIC:
51 entry = PROC_I(in)->pde;
53 // check for specific inodes ?
57 *flags |= (entry->vx_flags & IATTR_FLAGS);
59 *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
62 case DEVPTS_SUPER_MAGIC:
73 int vc_get_iattr(uint32_t id, void __user *data)
76 struct vcmd_ctx_iattr_v1 vc_data = { .xid = -1 };
79 if (!vx_check(0, VX_ADMIN))
81 if (copy_from_user (&vc_data, data, sizeof(vc_data)))
84 ret = user_path_walk_link(vc_data.name, &nd);
86 ret = __vc_get_iattr(nd.dentry->d_inode,
87 &vc_data.xid, &vc_data.flags, &vc_data.mask);
91 if (copy_to_user (data, &vc_data, sizeof(vc_data)))
96 static int __vc_set_iattr(struct dentry *de, uint32_t *xid, uint32_t *flags, uint32_t *mask)
98 struct inode *in = de->d_inode;
99 int error = 0, is_proc = 0, has_xid = 0;
101 if (!in || !in->i_sb)
104 is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
105 if ((*mask & IATTR_FLAGS) && !is_proc)
108 has_xid = (in->i_sb->s_flags & MS_TAGXID) ||
109 (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
110 if ((*mask & IATTR_XID) && !has_xid)
114 if (*mask & IATTR_XID)
117 if (*mask & IATTR_FLAGS) {
118 struct proc_dir_entry *entry = PROC_I(in)->pde;
119 unsigned int iflags = PROC_I(in)->vx_flags;
121 iflags = (iflags & ~(*mask & IATTR_FLAGS))
122 | (*flags & IATTR_FLAGS);
123 PROC_I(in)->vx_flags = iflags;
125 entry->vx_flags = iflags;
128 if (*mask & (IATTR_BARRIER | IATTR_IUNLINK | IATTR_IMMUTABLE)) {
131 attr.ia_valid = ATTR_ATTR_FLAG;
133 (IS_IMMUTABLE(in) ? ATTR_FLAG_IMMUTABLE : 0) |
134 (IS_IUNLINK(in) ? ATTR_FLAG_IUNLINK : 0) |
135 (IS_BARRIER(in) ? ATTR_FLAG_BARRIER : 0);
137 if (*mask & IATTR_IMMUTABLE) {
138 if (*flags & IATTR_IMMUTABLE)
139 attr.ia_attr_flags |= ATTR_FLAG_IMMUTABLE;
141 attr.ia_attr_flags &= ~ATTR_FLAG_IMMUTABLE;
143 if (*mask & IATTR_IUNLINK) {
144 if (*flags & IATTR_IUNLINK)
145 attr.ia_attr_flags |= ATTR_FLAG_IUNLINK;
147 attr.ia_attr_flags &= ~ATTR_FLAG_IUNLINK;
149 if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
150 if (*flags & IATTR_BARRIER)
151 attr.ia_attr_flags |= ATTR_FLAG_BARRIER;
153 attr.ia_attr_flags &= ~ATTR_FLAG_BARRIER;
155 if (in->i_op && in->i_op->setattr)
156 error = in->i_op->setattr(de, &attr);
158 error = inode_change_ok(in, &attr);
160 error = inode_setattr(in, &attr);
164 mark_inode_dirty(in);
169 int vc_set_iattr(uint32_t id, void __user *data)
172 struct vcmd_ctx_iattr_v1 vc_data;
175 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_LINUX_IMMUTABLE))
177 if (copy_from_user (&vc_data, data, sizeof(vc_data)))
180 ret = user_path_walk_link(vc_data.name, &nd);
182 ret = __vc_set_iattr(nd.dentry,
183 &vc_data.xid, &vc_data.flags, &vc_data.mask);
187 if (copy_to_user (data, &vc_data, sizeof(vc_data)))
193 #ifdef CONFIG_VSERVER_LEGACY
195 #define PROC_DYNAMIC_FIRST 0xF0000000UL
197 int vx_proc_ioctl(struct inode * inode, struct file * filp,
198 unsigned int cmd, unsigned long arg)
200 struct proc_dir_entry *entry;
204 if (inode->i_ino < PROC_DYNAMIC_FIRST)
207 entry = PROC_I(inode)->pde;
213 /* fixme: if stealth, return -ENOTTY */
215 flags = entry->vx_flags;
216 if (capable(CAP_CONTEXT))
217 error = put_user(flags, (int *) arg);
221 /* fixme: if stealth, return -ENOTTY */
223 if (!capable(CAP_CONTEXT))
226 if (IS_RDONLY(inode))
229 if (get_user(flags, (int *) arg))
232 entry->vx_flags = flags;
243 int vx_parse_xid(char *string, xid_t *xid, int remove)
245 static match_table_t tokens = {
249 substring_t args[MAX_OPT_ARGS];
250 int token, option = 0;
255 token = match_token(string, tokens, args);
256 if (token && xid && !match_int(args, &option))
259 vxdprintk(VXD_CBIT(xid, 7),
260 "vx_parse_xid(»%s«): %d:#%d",
261 string, token, option);
263 if (token && remove) {
264 char *p = strstr(string, "xid=");
268 while (*q != '\0' && *q != ',')
279 void vx_propagate_xid(struct nameidata *nd, struct inode *inode)
282 struct vfsmount *mnt;
291 propagate = (mnt->mnt_flags & MNT_XID);
293 new_xid = mnt->mnt_xid;
295 vxdprintk(VXD_CBIT(xid, 7),
296 "vx_propagate_xid(%p[#%lu.%d]): %d,%d",
297 inode, inode->i_ino, inode->i_xid,
298 new_xid, (propagate)?1:0);
301 inode->i_xid = new_xid;
304 #include <linux/module.h>
306 EXPORT_SYMBOL_GPL(vx_propagate_xid);