]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/fs/ext2/ioctl.c | |
3 | * | |
4 | * Copyright (C) 1993, 1994, 1995 | |
5 | * Remy Card ([email protected]) | |
6 | * Laboratoire MASI - Institut Blaise Pascal | |
7 | * Universite Pierre et Marie Curie (Paris VI) | |
8 | */ | |
9 | ||
10 | #include "ext2.h" | |
16f7e0fe | 11 | #include <linux/capability.h> |
1da177e4 LT |
12 | #include <linux/time.h> |
13 | #include <linux/sched.h> | |
e322ff07 DH |
14 | #include <linux/compat.h> |
15 | #include <linux/smp_lock.h> | |
1da177e4 LT |
16 | #include <asm/current.h> |
17 | #include <asm/uaccess.h> | |
18 | ||
19 | ||
20 | int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, | |
21 | unsigned long arg) | |
22 | { | |
23 | struct ext2_inode_info *ei = EXT2_I(inode); | |
24 | unsigned int flags; | |
25 | ||
26 | ext2_debug ("cmd = %u, arg = %lu\n", cmd, arg); | |
27 | ||
28 | switch (cmd) { | |
29 | case EXT2_IOC_GETFLAGS: | |
30 | flags = ei->i_flags & EXT2_FL_USER_VISIBLE; | |
31 | return put_user(flags, (int __user *) arg); | |
32 | case EXT2_IOC_SETFLAGS: { | |
33 | unsigned int oldflags; | |
34 | ||
35 | if (IS_RDONLY(inode)) | |
36 | return -EROFS; | |
37 | ||
38 | if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER)) | |
39 | return -EACCES; | |
40 | ||
41 | if (get_user(flags, (int __user *) arg)) | |
42 | return -EFAULT; | |
43 | ||
44 | if (!S_ISDIR(inode->i_mode)) | |
45 | flags &= ~EXT2_DIRSYNC_FL; | |
46 | ||
47 | oldflags = ei->i_flags; | |
48 | ||
49 | /* | |
50 | * The IMMUTABLE and APPEND_ONLY flags can only be changed by | |
51 | * the relevant capability. | |
52 | * | |
53 | * This test looks nicer. Thanks to Pauline Middelink | |
54 | */ | |
55 | if ((flags ^ oldflags) & (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_SEC; | |
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 | return -EROFS; | |
76 | if (get_user(inode->i_generation, (int __user *) arg)) | |
77 | return -EFAULT; | |
78 | inode->i_ctime = CURRENT_TIME_SEC; | |
79 | mark_inode_dirty(inode); | |
80 | return 0; | |
81 | default: | |
82 | return -ENOTTY; | |
83 | } | |
84 | } | |
e322ff07 DH |
85 | |
86 | #ifdef CONFIG_COMPAT | |
87 | long ext2_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
88 | { | |
89 | struct inode *inode = file->f_dentry->d_inode; | |
90 | int ret; | |
91 | ||
92 | /* These are just misnamed, they actually get/put from/to user an int */ | |
93 | switch (cmd) { | |
94 | case EXT2_IOC32_GETFLAGS: | |
95 | cmd = EXT2_IOC_GETFLAGS; | |
96 | break; | |
97 | case EXT2_IOC32_SETFLAGS: | |
98 | cmd = EXT2_IOC_SETFLAGS; | |
99 | break; | |
100 | case EXT2_IOC32_GETVERSION: | |
101 | cmd = EXT2_IOC_GETVERSION; | |
102 | break; | |
103 | case EXT2_IOC32_SETVERSION: | |
104 | cmd = EXT2_IOC_SETVERSION; | |
105 | break; | |
106 | default: | |
107 | return -ENOIOCTLCMD; | |
108 | } | |
109 | lock_kernel(); | |
110 | ret = ext2_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg)); | |
111 | unlock_kernel(); | |
112 | return ret; | |
113 | } | |
114 | #endif |