This commit was manufactured by cvs2svn to create branch
[linux-2.6.git] / fs / hfsplus / ioctl.c
1 /*
2  *  linux/fs/hfsplus/ioctl.c
3  *
4  * Copyright (C) 2003
5  * Ethan Benson <erbenson@alaska.net>
6  * partially derived from linux/fs/ext2/ioctl.c
7  * Copyright (C) 1993, 1994, 1995
8  * Remy Card (card@masi.ibp.fr)
9  * Laboratoire MASI - Institut Blaise Pascal
10  * Universite Pierre et Marie Curie (Paris VI)
11  *
12  * hfsplus ioctls
13  */
14
15 #include <linux/fs.h>
16 #include <linux/sched.h>
17 #include <asm/uaccess.h>
18 #include "hfsplus_fs.h"
19
20 int hfsplus_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
21                   unsigned long arg)
22 {
23         unsigned int flags;
24
25         switch (cmd) {
26         case HFSPLUS_IOC_EXT2_GETFLAGS:
27                 flags = 0;
28                 if (HFSPLUS_I(inode).rootflags & HFSPLUS_FLG_IMMUTABLE)
29                         flags |= EXT2_FLAG_IMMUTABLE; /* EXT2_IMMUTABLE_FL */
30                 if (HFSPLUS_I(inode).rootflags & HFSPLUS_FLG_APPEND)
31                         flags |= EXT2_FLAG_APPEND; /* EXT2_APPEND_FL */
32                 if (HFSPLUS_I(inode).userflags & HFSPLUS_FLG_NODUMP)
33                         flags |= EXT2_FLAG_NODUMP; /* EXT2_NODUMP_FL */
34                 return put_user(flags, (int __user *)arg);
35         case HFSPLUS_IOC_EXT2_SETFLAGS: {
36                 if (IS_RDONLY(inode) ||
37                         (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
38                         return -EROFS;
39
40                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
41                         return -EACCES;
42
43                 if (get_user(flags, (int __user *)arg))
44                         return -EFAULT;
45
46                 if (flags & (EXT2_FLAG_IMMUTABLE|EXT2_FLAG_APPEND) ||
47                     HFSPLUS_I(inode).rootflags & (HFSPLUS_FLG_IMMUTABLE|HFSPLUS_FLG_APPEND)) {
48                         if (!capable(CAP_LINUX_IMMUTABLE))
49                                 return -EPERM;
50                 }
51
52                 /* don't silently ignore unsupported ext2 flags */
53                 if (flags & ~(EXT2_FLAG_IMMUTABLE|EXT2_FLAG_APPEND|
54                               EXT2_FLAG_NODUMP))
55                         return -EOPNOTSUPP;
56
57                 if (flags & EXT2_FLAG_IMMUTABLE) { /* EXT2_IMMUTABLE_FL */
58                         inode->i_flags |= S_IMMUTABLE;
59                         HFSPLUS_I(inode).rootflags |= HFSPLUS_FLG_IMMUTABLE;
60                 } else {
61                         inode->i_flags &= ~S_IMMUTABLE;
62                         HFSPLUS_I(inode).rootflags &= ~HFSPLUS_FLG_IMMUTABLE;
63                 }
64                 if (flags & EXT2_FLAG_APPEND) { /* EXT2_APPEND_FL */
65                         inode->i_flags |= S_APPEND;
66                         HFSPLUS_I(inode).rootflags |= HFSPLUS_FLG_APPEND;
67                 } else {
68                         inode->i_flags &= ~S_APPEND;
69                         HFSPLUS_I(inode).rootflags &= ~HFSPLUS_FLG_APPEND;
70                 }
71                 if (flags & EXT2_FLAG_NODUMP) /* EXT2_NODUMP_FL */
72                         HFSPLUS_I(inode).userflags |= HFSPLUS_FLG_NODUMP;
73                 else
74                         HFSPLUS_I(inode).userflags &= ~HFSPLUS_FLG_NODUMP;
75
76                 inode->i_ctime = CURRENT_TIME;
77                 mark_inode_dirty(inode);
78                 return 0;
79         }
80         default:
81                 return -ENOTTY;
82         }
83 }