This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / fs / ext2 / ioctl.c
1 /*
2  * linux/fs/ext2/ioctl.c
3  *
4  * Copyright (C) 1993, 1994, 1995
5  * Remy Card (card@masi.ibp.fr)
6  * Laboratoire MASI - Institut Blaise Pascal
7  * Universite Pierre et Marie Curie (Paris VI)
8  */
9
10 #include "ext2.h"
11 #include <linux/time.h>
12 #include <linux/sched.h>
13 #include <asm/current.h>
14 #include <asm/uaccess.h>
15
16
17 int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
18                 unsigned long arg)
19 {
20         struct ext2_inode_info *ei = EXT2_I(inode);
21         unsigned int flags;
22
23         ext2_debug ("cmd = %u, arg = %lu\n", cmd, arg);
24
25         switch (cmd) {
26         case EXT2_IOC_GETFLAGS:
27                 flags = ei->i_flags & EXT2_FL_USER_VISIBLE;
28                 return put_user(flags, (int __user *) arg);
29         case EXT2_IOC_SETFLAGS: {
30                 unsigned int oldflags;
31
32                 if (IS_RDONLY(inode) ||
33                         (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
34                         return -EROFS;
35
36                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
37                         return -EACCES;
38
39                 if (get_user(flags, (int __user *) arg))
40                         return -EFAULT;
41
42                 if (!S_ISDIR(inode->i_mode))
43                         flags &= ~EXT2_DIRSYNC_FL;
44
45                 oldflags = ei->i_flags;
46
47                 /*
48                  * The IMMUTABLE and APPEND_ONLY flags can only be changed by
49                  * the relevant capability.
50                  *
51                  * This test looks nicer. Thanks to Pauline Middelink
52                  */
53                 if ((oldflags & EXT2_IMMUTABLE_FL) ||
54                         ((flags ^ oldflags) &
55                         (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL))) {
56                         if (!capable(CAP_LINUX_IMMUTABLE))
57                                 return -EPERM;
58                 }
59
60                 flags = flags & EXT2_FL_USER_MODIFIABLE;
61                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
62                 ei->i_flags = flags;
63
64                 ext2_set_inode_flags(inode);
65                 inode->i_ctime = CURRENT_TIME;
66                 mark_inode_dirty(inode);
67                 return 0;
68         }
69         case EXT2_IOC_GETVERSION:
70                 return put_user(inode->i_generation, (int __user *) arg);
71         case EXT2_IOC_SETVERSION:
72                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
73                         return -EPERM;
74                 if (IS_RDONLY(inode) ||
75                         (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
76                         return -EROFS;
77                 if (get_user(inode->i_generation, (int __user *) arg))
78                         return -EFAULT; 
79                 inode->i_ctime = CURRENT_TIME;
80                 mark_inode_dirty(inode);
81                 return 0;
82         default:
83                 return -ENOTTY;
84         }
85 }