ioctl.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/fs/hfsplus/ioctl.c
  4. *
  5. * Copyright (C) 2003
  6. * Ethan Benson <erbenson@alaska.net>
  7. * partially derived from linux/fs/ext2/ioctl.c
  8. * Copyright (C) 1993, 1994, 1995
  9. * Remy Card (card@masi.ibp.fr)
  10. * Laboratoire MASI - Institut Blaise Pascal
  11. * Universite Pierre et Marie Curie (Paris VI)
  12. *
  13. * hfsplus ioctls
  14. */
  15. #include <linux/capability.h>
  16. #include <linux/fs.h>
  17. #include <linux/mount.h>
  18. #include <linux/sched.h>
  19. #include <linux/uaccess.h>
  20. #include "hfsplus_fs.h"
  21. /*
  22. * "Blessing" an HFS+ filesystem writes metadata to the superblock informing
  23. * the platform firmware which file to boot from
  24. */
  25. static int hfsplus_ioctl_bless(struct file *file, int __user *user_flags)
  26. {
  27. struct dentry *dentry = file->f_path.dentry;
  28. struct inode *inode = d_inode(dentry);
  29. struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
  30. struct hfsplus_vh *vh = sbi->s_vhdr;
  31. struct hfsplus_vh *bvh = sbi->s_backup_vhdr;
  32. u32 cnid = (unsigned long)dentry->d_fsdata;
  33. if (!capable(CAP_SYS_ADMIN))
  34. return -EPERM;
  35. mutex_lock(&sbi->vh_mutex);
  36. /* Directory containing the bootable system */
  37. vh->finder_info[0] = bvh->finder_info[0] =
  38. cpu_to_be32(d_parent_ino(dentry));
  39. /*
  40. * Bootloader. Just using the inode here breaks in the case of
  41. * hard links - the firmware wants the ID of the hard link file,
  42. * but the inode points at the indirect inode
  43. */
  44. vh->finder_info[1] = bvh->finder_info[1] = cpu_to_be32(cnid);
  45. /* Per spec, the OS X system folder - same as finder_info[0] here */
  46. vh->finder_info[5] = bvh->finder_info[5] =
  47. cpu_to_be32(d_parent_ino(dentry));
  48. mutex_unlock(&sbi->vh_mutex);
  49. return 0;
  50. }
  51. long hfsplus_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  52. {
  53. void __user *argp = (void __user *)arg;
  54. switch (cmd) {
  55. case HFSPLUS_IOC_BLESS:
  56. return hfsplus_ioctl_bless(file, argp);
  57. default:
  58. return -ENOTTY;
  59. }
  60. }