aoe: reserve enough headroom on skbs
[linux/fpc-iii.git] / fs / hfsplus / ioctl.c
blobd3ff5cc317d7948c956194a6e63414206167237a
1 /*
2 * linux/fs/hfsplus/ioctl.c
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)
12 * hfsplus ioctls
15 #include <linux/capability.h>
16 #include <linux/fs.h>
17 #include <linux/mount.h>
18 #include <linux/sched.h>
19 #include <asm/uaccess.h>
20 #include "hfsplus_fs.h"
23 * "Blessing" an HFS+ filesystem writes metadata to the superblock informing
24 * the platform firmware which file to boot from
26 static int hfsplus_ioctl_bless(struct file *file, int __user *user_flags)
28 struct dentry *dentry = file->f_path.dentry;
29 struct inode *inode = dentry->d_inode;
30 struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
31 struct hfsplus_vh *vh = sbi->s_vhdr;
32 struct hfsplus_vh *bvh = sbi->s_backup_vhdr;
33 u32 cnid = (unsigned long)dentry->d_fsdata;
35 if (!capable(CAP_SYS_ADMIN))
36 return -EPERM;
38 mutex_lock(&sbi->vh_mutex);
40 /* Directory containing the bootable system */
41 vh->finder_info[0] = bvh->finder_info[0] =
42 cpu_to_be32(parent_ino(dentry));
45 * Bootloader. Just using the inode here breaks in the case of
46 * hard links - the firmware wants the ID of the hard link file,
47 * but the inode points at the indirect inode
49 vh->finder_info[1] = bvh->finder_info[1] = cpu_to_be32(cnid);
51 /* Per spec, the OS X system folder - same as finder_info[0] here */
52 vh->finder_info[5] = bvh->finder_info[5] =
53 cpu_to_be32(parent_ino(dentry));
55 mutex_unlock(&sbi->vh_mutex);
56 return 0;
59 static int hfsplus_ioctl_getflags(struct file *file, int __user *user_flags)
61 struct inode *inode = file_inode(file);
62 struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
63 unsigned int flags = 0;
65 if (inode->i_flags & S_IMMUTABLE)
66 flags |= FS_IMMUTABLE_FL;
67 if (inode->i_flags & S_APPEND)
68 flags |= FS_APPEND_FL;
69 if (hip->userflags & HFSPLUS_FLG_NODUMP)
70 flags |= FS_NODUMP_FL;
72 return put_user(flags, user_flags);
75 static int hfsplus_ioctl_setflags(struct file *file, int __user *user_flags)
77 struct inode *inode = file_inode(file);
78 struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
79 unsigned int flags;
80 int err = 0;
82 err = mnt_want_write_file(file);
83 if (err)
84 goto out;
86 if (!inode_owner_or_capable(inode)) {
87 err = -EACCES;
88 goto out_drop_write;
91 if (get_user(flags, user_flags)) {
92 err = -EFAULT;
93 goto out_drop_write;
96 mutex_lock(&inode->i_mutex);
98 if ((flags & (FS_IMMUTABLE_FL|FS_APPEND_FL)) ||
99 inode->i_flags & (S_IMMUTABLE|S_APPEND)) {
100 if (!capable(CAP_LINUX_IMMUTABLE)) {
101 err = -EPERM;
102 goto out_unlock_inode;
106 /* don't silently ignore unsupported ext2 flags */
107 if (flags & ~(FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NODUMP_FL)) {
108 err = -EOPNOTSUPP;
109 goto out_unlock_inode;
112 if (flags & FS_IMMUTABLE_FL)
113 inode->i_flags |= S_IMMUTABLE;
114 else
115 inode->i_flags &= ~S_IMMUTABLE;
117 if (flags & FS_APPEND_FL)
118 inode->i_flags |= S_APPEND;
119 else
120 inode->i_flags &= ~S_APPEND;
122 if (flags & FS_NODUMP_FL)
123 hip->userflags |= HFSPLUS_FLG_NODUMP;
124 else
125 hip->userflags &= ~HFSPLUS_FLG_NODUMP;
127 inode->i_ctime = CURRENT_TIME_SEC;
128 mark_inode_dirty(inode);
130 out_unlock_inode:
131 mutex_unlock(&inode->i_mutex);
132 out_drop_write:
133 mnt_drop_write_file(file);
134 out:
135 return err;
138 long hfsplus_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
140 void __user *argp = (void __user *)arg;
142 switch (cmd) {
143 case HFSPLUS_IOC_EXT2_GETFLAGS:
144 return hfsplus_ioctl_getflags(file, argp);
145 case HFSPLUS_IOC_EXT2_SETFLAGS:
146 return hfsplus_ioctl_setflags(file, argp);
147 case HFSPLUS_IOC_BLESS:
148 return hfsplus_ioctl_bless(file, argp);
149 default:
150 return -ENOTTY;