ioctl.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*
  2. * linux/fs/ioctl.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. */
  6. #include <linux/syscalls.h>
  7. #include <linux/mm.h>
  8. #include <linux/capability.h>
  9. #include <linux/file.h>
  10. #include <linux/fs.h>
  11. #include <linux/security.h>
  12. #include <linux/export.h>
  13. #include <linux/uaccess.h>
  14. #include <linux/writeback.h>
  15. #include <linux/buffer_head.h>
  16. #include <linux/falloc.h>
  17. #include <linux/sched/signal.h>
  18. #include "internal.h"
  19. #include <asm/ioctls.h>
  20. /* So that the fiemap access checks can't overflow on 32 bit machines. */
  21. #define FIEMAP_MAX_EXTENTS (UINT_MAX / sizeof(struct fiemap_extent))
  22. /**
  23. * vfs_ioctl - call filesystem specific ioctl methods
  24. * @filp: open file to invoke ioctl method on
  25. * @cmd: ioctl command to execute
  26. * @arg: command-specific argument for ioctl
  27. *
  28. * Invokes filesystem specific ->unlocked_ioctl, if one exists; otherwise
  29. * returns -ENOTTY.
  30. *
  31. * Returns 0 on success, -errno on error.
  32. */
  33. long vfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  34. {
  35. int error = -ENOTTY;
  36. if (!filp->f_op->unlocked_ioctl)
  37. goto out;
  38. error = filp->f_op->unlocked_ioctl(filp, cmd, arg);
  39. if (error == -ENOIOCTLCMD)
  40. error = -ENOTTY;
  41. out:
  42. return error;
  43. }
  44. static int ioctl_fibmap(struct file *filp, int __user *p)
  45. {
  46. struct address_space *mapping = filp->f_mapping;
  47. int res, block;
  48. /* do we support this mess? */
  49. if (!mapping->a_ops->bmap)
  50. return -EINVAL;
  51. if (!capable(CAP_SYS_RAWIO))
  52. return -EPERM;
  53. res = get_user(block, p);
  54. if (res)
  55. return res;
  56. res = mapping->a_ops->bmap(mapping, block);
  57. return put_user(res, p);
  58. }
  59. /**
  60. * fiemap_fill_next_extent - Fiemap helper function
  61. * @fieinfo: Fiemap context passed into ->fiemap
  62. * @logical: Extent logical start offset, in bytes
  63. * @phys: Extent physical start offset, in bytes
  64. * @len: Extent length, in bytes
  65. * @flags: FIEMAP_EXTENT flags that describe this extent
  66. *
  67. * Called from file system ->fiemap callback. Will populate extent
  68. * info as passed in via arguments and copy to user memory. On
  69. * success, extent count on fieinfo is incremented.
  70. *
  71. * Returns 0 on success, -errno on error, 1 if this was the last
  72. * extent that will fit in user array.
  73. */
  74. #define SET_UNKNOWN_FLAGS (FIEMAP_EXTENT_DELALLOC)
  75. #define SET_NO_UNMOUNTED_IO_FLAGS (FIEMAP_EXTENT_DATA_ENCRYPTED)
  76. #define SET_NOT_ALIGNED_FLAGS (FIEMAP_EXTENT_DATA_TAIL|FIEMAP_EXTENT_DATA_INLINE)
  77. int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical,
  78. u64 phys, u64 len, u32 flags)
  79. {
  80. struct fiemap_extent extent;
  81. struct fiemap_extent __user *dest = fieinfo->fi_extents_start;
  82. /* only count the extents */
  83. if (fieinfo->fi_extents_max == 0) {
  84. fieinfo->fi_extents_mapped++;
  85. return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0;
  86. }
  87. if (fieinfo->fi_extents_mapped >= fieinfo->fi_extents_max)
  88. return 1;
  89. if (flags & SET_UNKNOWN_FLAGS)
  90. flags |= FIEMAP_EXTENT_UNKNOWN;
  91. if (flags & SET_NO_UNMOUNTED_IO_FLAGS)
  92. flags |= FIEMAP_EXTENT_ENCODED;
  93. if (flags & SET_NOT_ALIGNED_FLAGS)
  94. flags |= FIEMAP_EXTENT_NOT_ALIGNED;
  95. memset(&extent, 0, sizeof(extent));
  96. extent.fe_logical = logical;
  97. extent.fe_physical = phys;
  98. extent.fe_length = len;
  99. extent.fe_flags = flags;
  100. dest += fieinfo->fi_extents_mapped;
  101. if (copy_to_user(dest, &extent, sizeof(extent)))
  102. return -EFAULT;
  103. fieinfo->fi_extents_mapped++;
  104. if (fieinfo->fi_extents_mapped == fieinfo->fi_extents_max)
  105. return 1;
  106. return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0;
  107. }
  108. EXPORT_SYMBOL(fiemap_fill_next_extent);
  109. /**
  110. * fiemap_check_flags - check validity of requested flags for fiemap
  111. * @fieinfo: Fiemap context passed into ->fiemap
  112. * @fs_flags: Set of fiemap flags that the file system understands
  113. *
  114. * Called from file system ->fiemap callback. This will compute the
  115. * intersection of valid fiemap flags and those that the fs supports. That
  116. * value is then compared against the user supplied flags. In case of bad user
  117. * flags, the invalid values will be written into the fieinfo structure, and
  118. * -EBADR is returned, which tells ioctl_fiemap() to return those values to
  119. * userspace. For this reason, a return code of -EBADR should be preserved.
  120. *
  121. * Returns 0 on success, -EBADR on bad flags.
  122. */
  123. int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags)
  124. {
  125. u32 incompat_flags;
  126. incompat_flags = fieinfo->fi_flags & ~(FIEMAP_FLAGS_COMPAT & fs_flags);
  127. if (incompat_flags) {
  128. fieinfo->fi_flags = incompat_flags;
  129. return -EBADR;
  130. }
  131. return 0;
  132. }
  133. EXPORT_SYMBOL(fiemap_check_flags);
  134. static int fiemap_check_ranges(struct super_block *sb,
  135. u64 start, u64 len, u64 *new_len)
  136. {
  137. u64 maxbytes = (u64) sb->s_maxbytes;
  138. *new_len = len;
  139. if (len == 0)
  140. return -EINVAL;
  141. if (start > maxbytes)
  142. return -EFBIG;
  143. /*
  144. * Shrink request scope to what the fs can actually handle.
  145. */
  146. if (len > maxbytes || (maxbytes - len) < start)
  147. *new_len = maxbytes - start;
  148. return 0;
  149. }
  150. static int ioctl_fiemap(struct file *filp, unsigned long arg)
  151. {
  152. struct fiemap fiemap;
  153. struct fiemap __user *ufiemap = (struct fiemap __user *) arg;
  154. struct fiemap_extent_info fieinfo = { 0, };
  155. struct inode *inode = file_inode(filp);
  156. struct super_block *sb = inode->i_sb;
  157. u64 len;
  158. int error;
  159. if (!inode->i_op->fiemap)
  160. return -EOPNOTSUPP;
  161. if (copy_from_user(&fiemap, ufiemap, sizeof(fiemap)))
  162. return -EFAULT;
  163. if (fiemap.fm_extent_count > FIEMAP_MAX_EXTENTS)
  164. return -EINVAL;
  165. error = fiemap_check_ranges(sb, fiemap.fm_start, fiemap.fm_length,
  166. &len);
  167. if (error)
  168. return error;
  169. fieinfo.fi_flags = fiemap.fm_flags;
  170. fieinfo.fi_extents_max = fiemap.fm_extent_count;
  171. fieinfo.fi_extents_start = ufiemap->fm_extents;
  172. if (fiemap.fm_extent_count != 0 &&
  173. !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start,
  174. fieinfo.fi_extents_max * sizeof(struct fiemap_extent)))
  175. return -EFAULT;
  176. if (fieinfo.fi_flags & FIEMAP_FLAG_SYNC)
  177. filemap_write_and_wait(inode->i_mapping);
  178. error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len);
  179. fiemap.fm_flags = fieinfo.fi_flags;
  180. fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;
  181. if (copy_to_user(ufiemap, &fiemap, sizeof(fiemap)))
  182. error = -EFAULT;
  183. return error;
  184. }
  185. static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd,
  186. u64 off, u64 olen, u64 destoff)
  187. {
  188. struct fd src_file = fdget(srcfd);
  189. int ret;
  190. if (!src_file.file)
  191. return -EBADF;
  192. ret = -EXDEV;
  193. if (src_file.file->f_path.mnt != dst_file->f_path.mnt)
  194. goto fdput;
  195. ret = do_clone_file_range(src_file.file, off, dst_file, destoff, olen);
  196. fdput:
  197. fdput(src_file);
  198. return ret;
  199. }
  200. static long ioctl_file_clone_range(struct file *file, void __user *argp)
  201. {
  202. struct file_clone_range args;
  203. if (copy_from_user(&args, argp, sizeof(args)))
  204. return -EFAULT;
  205. return ioctl_file_clone(file, args.src_fd, args.src_offset,
  206. args.src_length, args.dest_offset);
  207. }
  208. #ifdef CONFIG_BLOCK
  209. static inline sector_t logical_to_blk(struct inode *inode, loff_t offset)
  210. {
  211. return (offset >> inode->i_blkbits);
  212. }
  213. static inline loff_t blk_to_logical(struct inode *inode, sector_t blk)
  214. {
  215. return (blk << inode->i_blkbits);
  216. }
  217. /**
  218. * __generic_block_fiemap - FIEMAP for block based inodes (no locking)
  219. * @inode: the inode to map
  220. * @fieinfo: the fiemap info struct that will be passed back to userspace
  221. * @start: where to start mapping in the inode
  222. * @len: how much space to map
  223. * @get_block: the fs's get_block function
  224. *
  225. * This does FIEMAP for block based inodes. Basically it will just loop
  226. * through get_block until we hit the number of extents we want to map, or we
  227. * go past the end of the file and hit a hole.
  228. *
  229. * If it is possible to have data blocks beyond a hole past @inode->i_size, then
  230. * please do not use this function, it will stop at the first unmapped block
  231. * beyond i_size.
  232. *
  233. * If you use this function directly, you need to do your own locking. Use
  234. * generic_block_fiemap if you want the locking done for you.
  235. */
  236. int __generic_block_fiemap(struct inode *inode,
  237. struct fiemap_extent_info *fieinfo, loff_t start,
  238. loff_t len, get_block_t *get_block)
  239. {
  240. struct buffer_head map_bh;
  241. sector_t start_blk, last_blk;
  242. loff_t isize = i_size_read(inode);
  243. u64 logical = 0, phys = 0, size = 0;
  244. u32 flags = FIEMAP_EXTENT_MERGED;
  245. bool past_eof = false, whole_file = false;
  246. int ret = 0;
  247. ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC);
  248. if (ret)
  249. return ret;
  250. /*
  251. * Either the i_mutex or other appropriate locking needs to be held
  252. * since we expect isize to not change at all through the duration of
  253. * this call.
  254. */
  255. if (len >= isize) {
  256. whole_file = true;
  257. len = isize;
  258. }
  259. /*
  260. * Some filesystems can't deal with being asked to map less than
  261. * blocksize, so make sure our len is at least block length.
  262. */
  263. if (logical_to_blk(inode, len) == 0)
  264. len = blk_to_logical(inode, 1);
  265. start_blk = logical_to_blk(inode, start);
  266. last_blk = logical_to_blk(inode, start + len - 1);
  267. do {
  268. /*
  269. * we set b_size to the total size we want so it will map as
  270. * many contiguous blocks as possible at once
  271. */
  272. memset(&map_bh, 0, sizeof(struct buffer_head));
  273. map_bh.b_size = len;
  274. ret = get_block(inode, start_blk, &map_bh, 0);
  275. if (ret)
  276. break;
  277. /* HOLE */
  278. if (!buffer_mapped(&map_bh)) {
  279. start_blk++;
  280. /*
  281. * We want to handle the case where there is an
  282. * allocated block at the front of the file, and then
  283. * nothing but holes up to the end of the file properly,
  284. * to make sure that extent at the front gets properly
  285. * marked with FIEMAP_EXTENT_LAST
  286. */
  287. if (!past_eof &&
  288. blk_to_logical(inode, start_blk) >= isize)
  289. past_eof = 1;
  290. /*
  291. * First hole after going past the EOF, this is our
  292. * last extent
  293. */
  294. if (past_eof && size) {
  295. flags = FIEMAP_EXTENT_MERGED|FIEMAP_EXTENT_LAST;
  296. ret = fiemap_fill_next_extent(fieinfo, logical,
  297. phys, size,
  298. flags);
  299. } else if (size) {
  300. ret = fiemap_fill_next_extent(fieinfo, logical,
  301. phys, size, flags);
  302. size = 0;
  303. }
  304. /* if we have holes up to/past EOF then we're done */
  305. if (start_blk > last_blk || past_eof || ret)
  306. break;
  307. } else {
  308. /*
  309. * We have gone over the length of what we wanted to
  310. * map, and it wasn't the entire file, so add the extent
  311. * we got last time and exit.
  312. *
  313. * This is for the case where say we want to map all the
  314. * way up to the second to the last block in a file, but
  315. * the last block is a hole, making the second to last
  316. * block FIEMAP_EXTENT_LAST. In this case we want to
  317. * see if there is a hole after the second to last block
  318. * so we can mark it properly. If we found data after
  319. * we exceeded the length we were requesting, then we
  320. * are good to go, just add the extent to the fieinfo
  321. * and break
  322. */
  323. if (start_blk > last_blk && !whole_file) {
  324. ret = fiemap_fill_next_extent(fieinfo, logical,
  325. phys, size,
  326. flags);
  327. break;
  328. }
  329. /*
  330. * if size != 0 then we know we already have an extent
  331. * to add, so add it.
  332. */
  333. if (size) {
  334. ret = fiemap_fill_next_extent(fieinfo, logical,
  335. phys, size,
  336. flags);
  337. if (ret)
  338. break;
  339. }
  340. logical = blk_to_logical(inode, start_blk);
  341. phys = blk_to_logical(inode, map_bh.b_blocknr);
  342. size = map_bh.b_size;
  343. flags = FIEMAP_EXTENT_MERGED;
  344. start_blk += logical_to_blk(inode, size);
  345. /*
  346. * If we are past the EOF, then we need to make sure as
  347. * soon as we find a hole that the last extent we found
  348. * is marked with FIEMAP_EXTENT_LAST
  349. */
  350. if (!past_eof && logical + size >= isize)
  351. past_eof = true;
  352. }
  353. cond_resched();
  354. if (fatal_signal_pending(current)) {
  355. ret = -EINTR;
  356. break;
  357. }
  358. } while (1);
  359. /* If ret is 1 then we just hit the end of the extent array */
  360. if (ret == 1)
  361. ret = 0;
  362. return ret;
  363. }
  364. EXPORT_SYMBOL(__generic_block_fiemap);
  365. /**
  366. * generic_block_fiemap - FIEMAP for block based inodes
  367. * @inode: The inode to map
  368. * @fieinfo: The mapping information
  369. * @start: The initial block to map
  370. * @len: The length of the extect to attempt to map
  371. * @get_block: The block mapping function for the fs
  372. *
  373. * Calls __generic_block_fiemap to map the inode, after taking
  374. * the inode's mutex lock.
  375. */
  376. int generic_block_fiemap(struct inode *inode,
  377. struct fiemap_extent_info *fieinfo, u64 start,
  378. u64 len, get_block_t *get_block)
  379. {
  380. int ret;
  381. inode_lock(inode);
  382. ret = __generic_block_fiemap(inode, fieinfo, start, len, get_block);
  383. inode_unlock(inode);
  384. return ret;
  385. }
  386. EXPORT_SYMBOL(generic_block_fiemap);
  387. #endif /* CONFIG_BLOCK */
  388. /*
  389. * This provides compatibility with legacy XFS pre-allocation ioctls
  390. * which predate the fallocate syscall.
  391. *
  392. * Only the l_start, l_len and l_whence fields of the 'struct space_resv'
  393. * are used here, rest are ignored.
  394. */
  395. int ioctl_preallocate(struct file *filp, void __user *argp)
  396. {
  397. struct inode *inode = file_inode(filp);
  398. struct space_resv sr;
  399. if (copy_from_user(&sr, argp, sizeof(sr)))
  400. return -EFAULT;
  401. switch (sr.l_whence) {
  402. case SEEK_SET:
  403. break;
  404. case SEEK_CUR:
  405. sr.l_start += filp->f_pos;
  406. break;
  407. case SEEK_END:
  408. sr.l_start += i_size_read(inode);
  409. break;
  410. default:
  411. return -EINVAL;
  412. }
  413. return vfs_fallocate(filp, FALLOC_FL_KEEP_SIZE, sr.l_start, sr.l_len);
  414. }
  415. static int file_ioctl(struct file *filp, unsigned int cmd,
  416. unsigned long arg)
  417. {
  418. struct inode *inode = file_inode(filp);
  419. int __user *p = (int __user *)arg;
  420. switch (cmd) {
  421. case FIBMAP:
  422. return ioctl_fibmap(filp, p);
  423. case FIONREAD:
  424. return put_user(i_size_read(inode) - filp->f_pos, p);
  425. case FS_IOC_RESVSP:
  426. case FS_IOC_RESVSP64:
  427. return ioctl_preallocate(filp, p);
  428. }
  429. return vfs_ioctl(filp, cmd, arg);
  430. }
  431. static int ioctl_fionbio(struct file *filp, int __user *argp)
  432. {
  433. unsigned int flag;
  434. int on, error;
  435. error = get_user(on, argp);
  436. if (error)
  437. return error;
  438. flag = O_NONBLOCK;
  439. #ifdef __sparc__
  440. /* SunOS compatibility item. */
  441. if (O_NONBLOCK != O_NDELAY)
  442. flag |= O_NDELAY;
  443. #endif
  444. spin_lock(&filp->f_lock);
  445. if (on)
  446. filp->f_flags |= flag;
  447. else
  448. filp->f_flags &= ~flag;
  449. spin_unlock(&filp->f_lock);
  450. return error;
  451. }
  452. static int ioctl_fioasync(unsigned int fd, struct file *filp,
  453. int __user *argp)
  454. {
  455. unsigned int flag;
  456. int on, error;
  457. error = get_user(on, argp);
  458. if (error)
  459. return error;
  460. flag = on ? FASYNC : 0;
  461. /* Did FASYNC state change ? */
  462. if ((flag ^ filp->f_flags) & FASYNC) {
  463. if (filp->f_op->fasync)
  464. /* fasync() adjusts filp->f_flags */
  465. error = filp->f_op->fasync(fd, filp, on);
  466. else
  467. error = -ENOTTY;
  468. }
  469. return error < 0 ? error : 0;
  470. }
  471. static int ioctl_fsfreeze(struct file *filp)
  472. {
  473. struct super_block *sb = file_inode(filp)->i_sb;
  474. if (!capable(CAP_SYS_ADMIN))
  475. return -EPERM;
  476. /* If filesystem doesn't support freeze feature, return. */
  477. if (sb->s_op->freeze_fs == NULL && sb->s_op->freeze_super == NULL)
  478. return -EOPNOTSUPP;
  479. /* Freeze */
  480. if (sb->s_op->freeze_super)
  481. return sb->s_op->freeze_super(sb);
  482. return freeze_super(sb);
  483. }
  484. static int ioctl_fsthaw(struct file *filp)
  485. {
  486. struct super_block *sb = file_inode(filp)->i_sb;
  487. if (!capable(CAP_SYS_ADMIN))
  488. return -EPERM;
  489. /* Thaw */
  490. if (sb->s_op->thaw_super)
  491. return sb->s_op->thaw_super(sb);
  492. return thaw_super(sb);
  493. }
  494. static int ioctl_file_dedupe_range(struct file *file, void __user *arg)
  495. {
  496. struct file_dedupe_range __user *argp = arg;
  497. struct file_dedupe_range *same = NULL;
  498. int ret;
  499. unsigned long size;
  500. u16 count;
  501. if (get_user(count, &argp->dest_count)) {
  502. ret = -EFAULT;
  503. goto out;
  504. }
  505. size = offsetof(struct file_dedupe_range __user, info[count]);
  506. if (size > PAGE_SIZE) {
  507. ret = -ENOMEM;
  508. goto out;
  509. }
  510. same = memdup_user(argp, size);
  511. if (IS_ERR(same)) {
  512. ret = PTR_ERR(same);
  513. same = NULL;
  514. goto out;
  515. }
  516. same->dest_count = count;
  517. ret = vfs_dedupe_file_range(file, same);
  518. if (ret)
  519. goto out;
  520. ret = copy_to_user(argp, same, size);
  521. if (ret)
  522. ret = -EFAULT;
  523. out:
  524. kfree(same);
  525. return ret;
  526. }
  527. /*
  528. * When you add any new common ioctls to the switches above and below
  529. * please update compat_sys_ioctl() too.
  530. *
  531. * do_vfs_ioctl() is not for drivers and not intended to be EXPORT_SYMBOL()'d.
  532. * It's just a simple helper for sys_ioctl and compat_sys_ioctl.
  533. */
  534. int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
  535. unsigned long arg)
  536. {
  537. int error = 0;
  538. int __user *argp = (int __user *)arg;
  539. struct inode *inode = file_inode(filp);
  540. switch (cmd) {
  541. case FIOCLEX:
  542. set_close_on_exec(fd, 1);
  543. break;
  544. case FIONCLEX:
  545. set_close_on_exec(fd, 0);
  546. break;
  547. case FIONBIO:
  548. error = ioctl_fionbio(filp, argp);
  549. break;
  550. case FIOASYNC:
  551. error = ioctl_fioasync(fd, filp, argp);
  552. break;
  553. case FIOQSIZE:
  554. if (S_ISDIR(inode->i_mode) || S_ISREG(inode->i_mode) ||
  555. S_ISLNK(inode->i_mode)) {
  556. loff_t res = inode_get_bytes(inode);
  557. error = copy_to_user(argp, &res, sizeof(res)) ?
  558. -EFAULT : 0;
  559. } else
  560. error = -ENOTTY;
  561. break;
  562. case FIFREEZE:
  563. error = ioctl_fsfreeze(filp);
  564. break;
  565. case FITHAW:
  566. error = ioctl_fsthaw(filp);
  567. break;
  568. case FS_IOC_FIEMAP:
  569. return ioctl_fiemap(filp, arg);
  570. case FIGETBSZ:
  571. return put_user(inode->i_sb->s_blocksize, argp);
  572. case FICLONE:
  573. return ioctl_file_clone(filp, arg, 0, 0, 0);
  574. case FICLONERANGE:
  575. return ioctl_file_clone_range(filp, argp);
  576. case FIDEDUPERANGE:
  577. return ioctl_file_dedupe_range(filp, argp);
  578. default:
  579. if (S_ISREG(inode->i_mode))
  580. error = file_ioctl(filp, cmd, arg);
  581. else
  582. error = vfs_ioctl(filp, cmd, arg);
  583. break;
  584. }
  585. return error;
  586. }
  587. SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
  588. {
  589. int error;
  590. struct fd f = fdget(fd);
  591. if (!f.file)
  592. return -EBADF;
  593. error = security_file_ioctl(f.file, cmd, arg);
  594. if (!error)
  595. error = do_vfs_ioctl(f.file, fd, cmd, arg);
  596. fdput(f);
  597. return error;
  598. }