ioctl.c 17 KB

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