ioctl.c 17 KB

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