2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* linux/fs/hfsplus/ioctl.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003
|
|
|
|
* Ethan Benson <erbenson@alaska.net>
|
|
|
|
* partially derived from linux/fs/ext2/ioctl.c
|
|
|
|
* Copyright (C) 1993, 1994, 1995
|
|
|
|
* Remy Card (card@masi.ibp.fr)
|
|
|
|
* Laboratoire MASI - Institut Blaise Pascal
|
|
|
|
* Universite Pierre et Marie Curie (Paris VI)
|
|
|
|
*
|
|
|
|
* hfsplus ioctls
|
|
|
|
*/
|
|
|
|
|
2006-01-11 20:17:46 +00:00
|
|
|
#include <linux/capability.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/fs.h>
|
2008-02-15 22:37:46 +00:00
|
|
|
#include <linux/mount.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/sched.h>
|
2016-12-24 19:46:01 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "hfsplus_fs.h"
|
|
|
|
|
2012-02-06 20:14:40 +00:00
|
|
|
/*
|
|
|
|
* "Blessing" an HFS+ filesystem writes metadata to the superblock informing
|
|
|
|
* the platform firmware which file to boot from
|
|
|
|
*/
|
|
|
|
static int hfsplus_ioctl_bless(struct file *file, int __user *user_flags)
|
|
|
|
{
|
|
|
|
struct dentry *dentry = file->f_path.dentry;
|
2015-03-17 22:25:59 +00:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2012-02-06 20:14:40 +00:00
|
|
|
struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
|
|
|
|
struct hfsplus_vh *vh = sbi->s_vhdr;
|
|
|
|
struct hfsplus_vh *bvh = sbi->s_backup_vhdr;
|
2012-06-17 21:05:25 +00:00
|
|
|
u32 cnid = (unsigned long)dentry->d_fsdata;
|
2012-02-06 20:14:40 +00:00
|
|
|
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
mutex_lock(&sbi->vh_mutex);
|
|
|
|
|
|
|
|
/* Directory containing the bootable system */
|
|
|
|
vh->finder_info[0] = bvh->finder_info[0] =
|
|
|
|
cpu_to_be32(parent_ino(dentry));
|
|
|
|
|
2012-06-17 21:05:25 +00:00
|
|
|
/*
|
|
|
|
* Bootloader. Just using the inode here breaks in the case of
|
|
|
|
* hard links - the firmware wants the ID of the hard link file,
|
|
|
|
* but the inode points at the indirect inode
|
|
|
|
*/
|
|
|
|
vh->finder_info[1] = bvh->finder_info[1] = cpu_to_be32(cnid);
|
2012-02-06 20:14:40 +00:00
|
|
|
|
|
|
|
/* Per spec, the OS X system folder - same as finder_info[0] here */
|
|
|
|
vh->finder_info[5] = bvh->finder_info[5] =
|
|
|
|
cpu_to_be32(parent_ino(dentry));
|
|
|
|
|
|
|
|
mutex_unlock(&sbi->vh_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-01 03:41:31 +00:00
|
|
|
static int hfsplus_ioctl_getflags(struct file *file, int __user *user_flags)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2013-01-23 22:07:38 +00:00
|
|
|
struct inode *inode = file_inode(file);
|
2010-10-01 03:43:31 +00:00
|
|
|
struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
|
2010-10-01 03:41:31 +00:00
|
|
|
unsigned int flags = 0;
|
|
|
|
|
2010-10-14 13:54:33 +00:00
|
|
|
if (inode->i_flags & S_IMMUTABLE)
|
2010-10-01 03:41:31 +00:00
|
|
|
flags |= FS_IMMUTABLE_FL;
|
2010-12-16 12:44:51 +00:00
|
|
|
if (inode->i_flags & S_APPEND)
|
2010-10-01 03:41:31 +00:00
|
|
|
flags |= FS_APPEND_FL;
|
2010-10-01 03:43:31 +00:00
|
|
|
if (hip->userflags & HFSPLUS_FLG_NODUMP)
|
2010-10-01 03:41:31 +00:00
|
|
|
flags |= FS_NODUMP_FL;
|
|
|
|
|
|
|
|
return put_user(flags, user_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hfsplus_ioctl_setflags(struct file *file, int __user *user_flags)
|
|
|
|
{
|
2013-01-23 22:07:38 +00:00
|
|
|
struct inode *inode = file_inode(file);
|
2010-10-01 03:43:31 +00:00
|
|
|
struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
|
2015-04-16 19:47:04 +00:00
|
|
|
unsigned int flags, new_fl = 0;
|
2010-10-01 03:41:31 +00:00
|
|
|
int err = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-11-23 16:57:51 +00:00
|
|
|
err = mnt_want_write_file(file);
|
2010-10-01 03:41:31 +00:00
|
|
|
if (err)
|
2010-10-01 03:41:35 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-03-23 23:43:26 +00:00
|
|
|
if (!inode_owner_or_capable(inode)) {
|
2010-10-01 03:41:31 +00:00
|
|
|
err = -EACCES;
|
|
|
|
goto out_drop_write;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-10-01 03:41:31 +00:00
|
|
|
if (get_user(flags, user_flags)) {
|
|
|
|
err = -EFAULT;
|
|
|
|
goto out_drop_write;
|
|
|
|
}
|
|
|
|
|
2016-01-22 20:40:57 +00:00
|
|
|
inode_lock(inode);
|
2010-10-01 03:41:35 +00:00
|
|
|
|
2010-10-14 13:54:33 +00:00
|
|
|
if ((flags & (FS_IMMUTABLE_FL|FS_APPEND_FL)) ||
|
|
|
|
inode->i_flags & (S_IMMUTABLE|S_APPEND)) {
|
2010-10-01 03:41:31 +00:00
|
|
|
if (!capable(CAP_LINUX_IMMUTABLE)) {
|
|
|
|
err = -EPERM;
|
2010-10-01 03:41:35 +00:00
|
|
|
goto out_unlock_inode;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-01 03:41:31 +00:00
|
|
|
|
|
|
|
/* don't silently ignore unsupported ext2 flags */
|
|
|
|
if (flags & ~(FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NODUMP_FL)) {
|
|
|
|
err = -EOPNOTSUPP;
|
2010-10-01 03:41:35 +00:00
|
|
|
goto out_unlock_inode;
|
2010-10-01 03:41:31 +00:00
|
|
|
}
|
2010-10-14 13:54:33 +00:00
|
|
|
|
|
|
|
if (flags & FS_IMMUTABLE_FL)
|
2015-04-16 19:47:04 +00:00
|
|
|
new_fl |= S_IMMUTABLE;
|
2010-10-14 13:54:33 +00:00
|
|
|
|
|
|
|
if (flags & FS_APPEND_FL)
|
2015-04-16 19:47:04 +00:00
|
|
|
new_fl |= S_APPEND;
|
|
|
|
|
|
|
|
inode_set_flags(inode, new_fl, S_IMMUTABLE | S_APPEND);
|
2010-10-14 13:54:33 +00:00
|
|
|
|
2010-10-01 03:41:31 +00:00
|
|
|
if (flags & FS_NODUMP_FL)
|
2010-10-01 03:43:31 +00:00
|
|
|
hip->userflags |= HFSPLUS_FLG_NODUMP;
|
2010-10-01 03:41:31 +00:00
|
|
|
else
|
2010-10-01 03:43:31 +00:00
|
|
|
hip->userflags &= ~HFSPLUS_FLG_NODUMP;
|
2010-10-01 03:41:31 +00:00
|
|
|
|
2016-09-14 14:48:05 +00:00
|
|
|
inode->i_ctime = current_time(inode);
|
2010-10-01 03:41:31 +00:00
|
|
|
mark_inode_dirty(inode);
|
|
|
|
|
2010-10-01 03:41:35 +00:00
|
|
|
out_unlock_inode:
|
2016-01-22 20:40:57 +00:00
|
|
|
inode_unlock(inode);
|
2010-10-01 03:41:31 +00:00
|
|
|
out_drop_write:
|
2011-12-09 13:06:57 +00:00
|
|
|
mnt_drop_write_file(file);
|
2010-10-01 03:41:35 +00:00
|
|
|
out:
|
2010-10-01 03:41:31 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
long hfsplus_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
void __user *argp = (void __user *)arg;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case HFSPLUS_IOC_EXT2_GETFLAGS:
|
|
|
|
return hfsplus_ioctl_getflags(file, argp);
|
|
|
|
case HFSPLUS_IOC_EXT2_SETFLAGS:
|
|
|
|
return hfsplus_ioctl_setflags(file, argp);
|
2012-02-06 20:14:40 +00:00
|
|
|
case HFSPLUS_IOC_BLESS:
|
|
|
|
return hfsplus_ioctl_bless(file, argp);
|
2005-04-16 22:20:36 +00:00
|
|
|
default:
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
}
|