Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  *  linux/fs/hfsplus/ioctl.c
0004  *
0005  * Copyright (C) 2003
0006  * Ethan Benson <erbenson@alaska.net>
0007  * partially derived from linux/fs/ext2/ioctl.c
0008  * Copyright (C) 1993, 1994, 1995
0009  * Remy Card (card@masi.ibp.fr)
0010  * Laboratoire MASI - Institut Blaise Pascal
0011  * Universite Pierre et Marie Curie (Paris VI)
0012  *
0013  * hfsplus ioctls
0014  */
0015 
0016 #include <linux/capability.h>
0017 #include <linux/fs.h>
0018 #include <linux/mount.h>
0019 #include <linux/sched.h>
0020 #include <linux/uaccess.h>
0021 #include "hfsplus_fs.h"
0022 
0023 /*
0024  * "Blessing" an HFS+ filesystem writes metadata to the superblock informing
0025  * the platform firmware which file to boot from
0026  */
0027 static int hfsplus_ioctl_bless(struct file *file, int __user *user_flags)
0028 {
0029     struct dentry *dentry = file->f_path.dentry;
0030     struct inode *inode = d_inode(dentry);
0031     struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
0032     struct hfsplus_vh *vh = sbi->s_vhdr;
0033     struct hfsplus_vh *bvh = sbi->s_backup_vhdr;
0034     u32 cnid = (unsigned long)dentry->d_fsdata;
0035 
0036     if (!capable(CAP_SYS_ADMIN))
0037         return -EPERM;
0038 
0039     mutex_lock(&sbi->vh_mutex);
0040 
0041     /* Directory containing the bootable system */
0042     vh->finder_info[0] = bvh->finder_info[0] =
0043         cpu_to_be32(parent_ino(dentry));
0044 
0045     /*
0046      * Bootloader. Just using the inode here breaks in the case of
0047      * hard links - the firmware wants the ID of the hard link file,
0048      * but the inode points at the indirect inode
0049      */
0050     vh->finder_info[1] = bvh->finder_info[1] = cpu_to_be32(cnid);
0051 
0052     /* Per spec, the OS X system folder - same as finder_info[0] here */
0053     vh->finder_info[5] = bvh->finder_info[5] =
0054         cpu_to_be32(parent_ino(dentry));
0055 
0056     mutex_unlock(&sbi->vh_mutex);
0057     return 0;
0058 }
0059 
0060 long hfsplus_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
0061 {
0062     void __user *argp = (void __user *)arg;
0063 
0064     switch (cmd) {
0065     case HFSPLUS_IOC_BLESS:
0066         return hfsplus_ioctl_bless(file, argp);
0067     default:
0068         return -ENOTTY;
0069     }
0070 }