read_write.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /*
  2. * linux/fs/read_write.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. */
  6. #include <linux/slab.h>
  7. #include <linux/stat.h>
  8. #include <linux/fcntl.h>
  9. #include <linux/file.h>
  10. #include <linux/uio.h>
  11. #include <linux/smp_lock.h>
  12. #include <linux/fsnotify.h>
  13. #include <linux/security.h>
  14. #include <linux/module.h>
  15. #include <linux/syscalls.h>
  16. #include <asm/uaccess.h>
  17. #include <asm/unistd.h>
  18. struct file_operations generic_ro_fops = {
  19. .llseek = generic_file_llseek,
  20. .read = generic_file_read,
  21. .mmap = generic_file_readonly_mmap,
  22. .sendfile = generic_file_sendfile,
  23. };
  24. EXPORT_SYMBOL(generic_ro_fops);
  25. loff_t generic_file_llseek(struct file *file, loff_t offset, int origin)
  26. {
  27. long long retval;
  28. struct inode *inode = file->f_mapping->host;
  29. down(&inode->i_sem);
  30. switch (origin) {
  31. case 2:
  32. offset += inode->i_size;
  33. break;
  34. case 1:
  35. offset += file->f_pos;
  36. }
  37. retval = -EINVAL;
  38. if (offset>=0 && offset<=inode->i_sb->s_maxbytes) {
  39. if (offset != file->f_pos) {
  40. file->f_pos = offset;
  41. file->f_version = 0;
  42. }
  43. retval = offset;
  44. }
  45. up(&inode->i_sem);
  46. return retval;
  47. }
  48. EXPORT_SYMBOL(generic_file_llseek);
  49. loff_t remote_llseek(struct file *file, loff_t offset, int origin)
  50. {
  51. long long retval;
  52. lock_kernel();
  53. switch (origin) {
  54. case 2:
  55. offset += i_size_read(file->f_dentry->d_inode);
  56. break;
  57. case 1:
  58. offset += file->f_pos;
  59. }
  60. retval = -EINVAL;
  61. if (offset>=0 && offset<=file->f_dentry->d_inode->i_sb->s_maxbytes) {
  62. if (offset != file->f_pos) {
  63. file->f_pos = offset;
  64. file->f_version = 0;
  65. }
  66. retval = offset;
  67. }
  68. unlock_kernel();
  69. return retval;
  70. }
  71. EXPORT_SYMBOL(remote_llseek);
  72. loff_t no_llseek(struct file *file, loff_t offset, int origin)
  73. {
  74. return -ESPIPE;
  75. }
  76. EXPORT_SYMBOL(no_llseek);
  77. loff_t default_llseek(struct file *file, loff_t offset, int origin)
  78. {
  79. long long retval;
  80. lock_kernel();
  81. switch (origin) {
  82. case 2:
  83. offset += i_size_read(file->f_dentry->d_inode);
  84. break;
  85. case 1:
  86. offset += file->f_pos;
  87. }
  88. retval = -EINVAL;
  89. if (offset >= 0) {
  90. if (offset != file->f_pos) {
  91. file->f_pos = offset;
  92. file->f_version = 0;
  93. }
  94. retval = offset;
  95. }
  96. unlock_kernel();
  97. return retval;
  98. }
  99. EXPORT_SYMBOL(default_llseek);
  100. loff_t vfs_llseek(struct file *file, loff_t offset, int origin)
  101. {
  102. loff_t (*fn)(struct file *, loff_t, int);
  103. fn = no_llseek;
  104. if (file->f_mode & FMODE_LSEEK) {
  105. fn = default_llseek;
  106. if (file->f_op && file->f_op->llseek)
  107. fn = file->f_op->llseek;
  108. }
  109. return fn(file, offset, origin);
  110. }
  111. EXPORT_SYMBOL(vfs_llseek);
  112. asmlinkage off_t sys_lseek(unsigned int fd, off_t offset, unsigned int origin)
  113. {
  114. off_t retval;
  115. struct file * file;
  116. int fput_needed;
  117. retval = -EBADF;
  118. file = fget_light(fd, &fput_needed);
  119. if (!file)
  120. goto bad;
  121. retval = -EINVAL;
  122. if (origin <= 2) {
  123. loff_t res = vfs_llseek(file, offset, origin);
  124. retval = res;
  125. if (res != (loff_t)retval)
  126. retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */
  127. }
  128. fput_light(file, fput_needed);
  129. bad:
  130. return retval;
  131. }
  132. #ifdef __ARCH_WANT_SYS_LLSEEK
  133. asmlinkage long sys_llseek(unsigned int fd, unsigned long offset_high,
  134. unsigned long offset_low, loff_t __user * result,
  135. unsigned int origin)
  136. {
  137. int retval;
  138. struct file * file;
  139. loff_t offset;
  140. int fput_needed;
  141. retval = -EBADF;
  142. file = fget_light(fd, &fput_needed);
  143. if (!file)
  144. goto bad;
  145. retval = -EINVAL;
  146. if (origin > 2)
  147. goto out_putf;
  148. offset = vfs_llseek(file, ((loff_t) offset_high << 32) | offset_low,
  149. origin);
  150. retval = (int)offset;
  151. if (offset >= 0) {
  152. retval = -EFAULT;
  153. if (!copy_to_user(result, &offset, sizeof(offset)))
  154. retval = 0;
  155. }
  156. out_putf:
  157. fput_light(file, fput_needed);
  158. bad:
  159. return retval;
  160. }
  161. #endif
  162. int rw_verify_area(int read_write, struct file *file, loff_t *ppos, size_t count)
  163. {
  164. struct inode *inode;
  165. loff_t pos;
  166. if (unlikely(count > INT_MAX))
  167. goto Einval;
  168. pos = *ppos;
  169. if (unlikely((pos < 0) || (loff_t) (pos + count) < 0))
  170. goto Einval;
  171. inode = file->f_dentry->d_inode;
  172. if (inode->i_flock && MANDATORY_LOCK(inode))
  173. return locks_mandatory_area(read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE, inode, file, pos, count);
  174. return 0;
  175. Einval:
  176. return -EINVAL;
  177. }
  178. static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
  179. {
  180. set_current_state(TASK_UNINTERRUPTIBLE);
  181. if (!kiocbIsKicked(iocb))
  182. schedule();
  183. else
  184. kiocbClearKicked(iocb);
  185. __set_current_state(TASK_RUNNING);
  186. }
  187. ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos)
  188. {
  189. struct kiocb kiocb;
  190. ssize_t ret;
  191. init_sync_kiocb(&kiocb, filp);
  192. kiocb.ki_pos = *ppos;
  193. while (-EIOCBRETRY ==
  194. (ret = filp->f_op->aio_read(&kiocb, buf, len, kiocb.ki_pos)))
  195. wait_on_retry_sync_kiocb(&kiocb);
  196. if (-EIOCBQUEUED == ret)
  197. ret = wait_on_sync_kiocb(&kiocb);
  198. *ppos = kiocb.ki_pos;
  199. return ret;
  200. }
  201. EXPORT_SYMBOL(do_sync_read);
  202. ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
  203. {
  204. ssize_t ret;
  205. if (!(file->f_mode & FMODE_READ))
  206. return -EBADF;
  207. if (!file->f_op || (!file->f_op->read && !file->f_op->aio_read))
  208. return -EINVAL;
  209. if (unlikely(!access_ok(VERIFY_WRITE, buf, count)))
  210. return -EFAULT;
  211. ret = rw_verify_area(READ, file, pos, count);
  212. if (!ret) {
  213. ret = security_file_permission (file, MAY_READ);
  214. if (!ret) {
  215. if (file->f_op->read)
  216. ret = file->f_op->read(file, buf, count, pos);
  217. else
  218. ret = do_sync_read(file, buf, count, pos);
  219. if (ret > 0) {
  220. fsnotify_access(file->f_dentry);
  221. current->rchar += ret;
  222. }
  223. current->syscr++;
  224. }
  225. }
  226. return ret;
  227. }
  228. EXPORT_SYMBOL(vfs_read);
  229. ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
  230. {
  231. struct kiocb kiocb;
  232. ssize_t ret;
  233. init_sync_kiocb(&kiocb, filp);
  234. kiocb.ki_pos = *ppos;
  235. while (-EIOCBRETRY ==
  236. (ret = filp->f_op->aio_write(&kiocb, buf, len, kiocb.ki_pos)))
  237. wait_on_retry_sync_kiocb(&kiocb);
  238. if (-EIOCBQUEUED == ret)
  239. ret = wait_on_sync_kiocb(&kiocb);
  240. *ppos = kiocb.ki_pos;
  241. return ret;
  242. }
  243. EXPORT_SYMBOL(do_sync_write);
  244. ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_t *pos)
  245. {
  246. ssize_t ret;
  247. if (!(file->f_mode & FMODE_WRITE))
  248. return -EBADF;
  249. if (!file->f_op || (!file->f_op->write && !file->f_op->aio_write))
  250. return -EINVAL;
  251. if (unlikely(!access_ok(VERIFY_READ, buf, count)))
  252. return -EFAULT;
  253. ret = rw_verify_area(WRITE, file, pos, count);
  254. if (!ret) {
  255. ret = security_file_permission (file, MAY_WRITE);
  256. if (!ret) {
  257. if (file->f_op->write)
  258. ret = file->f_op->write(file, buf, count, pos);
  259. else
  260. ret = do_sync_write(file, buf, count, pos);
  261. if (ret > 0) {
  262. fsnotify_modify(file->f_dentry);
  263. current->wchar += ret;
  264. }
  265. current->syscw++;
  266. }
  267. }
  268. return ret;
  269. }
  270. EXPORT_SYMBOL(vfs_write);
  271. static inline loff_t file_pos_read(struct file *file)
  272. {
  273. return file->f_pos;
  274. }
  275. static inline void file_pos_write(struct file *file, loff_t pos)
  276. {
  277. file->f_pos = pos;
  278. }
  279. asmlinkage ssize_t sys_read(unsigned int fd, char __user * buf, size_t count)
  280. {
  281. struct file *file;
  282. ssize_t ret = -EBADF;
  283. int fput_needed;
  284. file = fget_light(fd, &fput_needed);
  285. if (file) {
  286. loff_t pos = file_pos_read(file);
  287. ret = vfs_read(file, buf, count, &pos);
  288. file_pos_write(file, pos);
  289. fput_light(file, fput_needed);
  290. }
  291. return ret;
  292. }
  293. EXPORT_SYMBOL_GPL(sys_read);
  294. asmlinkage ssize_t sys_write(unsigned int fd, const char __user * buf, size_t count)
  295. {
  296. struct file *file;
  297. ssize_t ret = -EBADF;
  298. int fput_needed;
  299. file = fget_light(fd, &fput_needed);
  300. if (file) {
  301. loff_t pos = file_pos_read(file);
  302. ret = vfs_write(file, buf, count, &pos);
  303. file_pos_write(file, pos);
  304. fput_light(file, fput_needed);
  305. }
  306. return ret;
  307. }
  308. asmlinkage ssize_t sys_pread64(unsigned int fd, char __user *buf,
  309. size_t count, loff_t pos)
  310. {
  311. struct file *file;
  312. ssize_t ret = -EBADF;
  313. int fput_needed;
  314. if (pos < 0)
  315. return -EINVAL;
  316. file = fget_light(fd, &fput_needed);
  317. if (file) {
  318. ret = -ESPIPE;
  319. if (file->f_mode & FMODE_PREAD)
  320. ret = vfs_read(file, buf, count, &pos);
  321. fput_light(file, fput_needed);
  322. }
  323. return ret;
  324. }
  325. asmlinkage ssize_t sys_pwrite64(unsigned int fd, const char __user *buf,
  326. size_t count, loff_t pos)
  327. {
  328. struct file *file;
  329. ssize_t ret = -EBADF;
  330. int fput_needed;
  331. if (pos < 0)
  332. return -EINVAL;
  333. file = fget_light(fd, &fput_needed);
  334. if (file) {
  335. ret = -ESPIPE;
  336. if (file->f_mode & FMODE_PWRITE)
  337. ret = vfs_write(file, buf, count, &pos);
  338. fput_light(file, fput_needed);
  339. }
  340. return ret;
  341. }
  342. /*
  343. * Reduce an iovec's length in-place. Return the resulting number of segments
  344. */
  345. unsigned long iov_shorten(struct iovec *iov, unsigned long nr_segs, size_t to)
  346. {
  347. unsigned long seg = 0;
  348. size_t len = 0;
  349. while (seg < nr_segs) {
  350. seg++;
  351. if (len + iov->iov_len >= to) {
  352. iov->iov_len = to - len;
  353. break;
  354. }
  355. len += iov->iov_len;
  356. iov++;
  357. }
  358. return seg;
  359. }
  360. EXPORT_SYMBOL(iov_shorten);
  361. /* A write operation does a read from user space and vice versa */
  362. #define vrfy_dir(type) ((type) == READ ? VERIFY_WRITE : VERIFY_READ)
  363. static ssize_t do_readv_writev(int type, struct file *file,
  364. const struct iovec __user * uvector,
  365. unsigned long nr_segs, loff_t *pos)
  366. {
  367. typedef ssize_t (*io_fn_t)(struct file *, char __user *, size_t, loff_t *);
  368. typedef ssize_t (*iov_fn_t)(struct file *, const struct iovec *, unsigned long, loff_t *);
  369. size_t tot_len;
  370. struct iovec iovstack[UIO_FASTIOV];
  371. struct iovec *iov=iovstack, *vector;
  372. ssize_t ret;
  373. int seg;
  374. io_fn_t fn;
  375. iov_fn_t fnv;
  376. /*
  377. * SuS says "The readv() function *may* fail if the iovcnt argument
  378. * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
  379. * traditionally returned zero for zero segments, so...
  380. */
  381. ret = 0;
  382. if (nr_segs == 0)
  383. goto out;
  384. /*
  385. * First get the "struct iovec" from user memory and
  386. * verify all the pointers
  387. */
  388. ret = -EINVAL;
  389. if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0))
  390. goto out;
  391. if (!file->f_op)
  392. goto out;
  393. if (nr_segs > UIO_FASTIOV) {
  394. ret = -ENOMEM;
  395. iov = kmalloc(nr_segs*sizeof(struct iovec), GFP_KERNEL);
  396. if (!iov)
  397. goto out;
  398. }
  399. ret = -EFAULT;
  400. if (copy_from_user(iov, uvector, nr_segs*sizeof(*uvector)))
  401. goto out;
  402. /*
  403. * Single unix specification:
  404. * We should -EINVAL if an element length is not >= 0 and fitting an
  405. * ssize_t. The total length is fitting an ssize_t
  406. *
  407. * Be careful here because iov_len is a size_t not an ssize_t
  408. */
  409. tot_len = 0;
  410. ret = -EINVAL;
  411. for (seg = 0; seg < nr_segs; seg++) {
  412. void __user *buf = iov[seg].iov_base;
  413. ssize_t len = (ssize_t)iov[seg].iov_len;
  414. if (len < 0) /* size_t not fitting an ssize_t .. */
  415. goto out;
  416. if (unlikely(!access_ok(vrfy_dir(type), buf, len)))
  417. goto Efault;
  418. tot_len += len;
  419. if ((ssize_t)tot_len < 0) /* maths overflow on the ssize_t */
  420. goto out;
  421. }
  422. if (tot_len == 0) {
  423. ret = 0;
  424. goto out;
  425. }
  426. ret = rw_verify_area(type, file, pos, tot_len);
  427. if (ret)
  428. goto out;
  429. ret = security_file_permission(file, type == READ ? MAY_READ : MAY_WRITE);
  430. if (ret)
  431. goto out;
  432. fnv = NULL;
  433. if (type == READ) {
  434. fn = file->f_op->read;
  435. fnv = file->f_op->readv;
  436. } else {
  437. fn = (io_fn_t)file->f_op->write;
  438. fnv = file->f_op->writev;
  439. }
  440. if (fnv) {
  441. ret = fnv(file, iov, nr_segs, pos);
  442. goto out;
  443. }
  444. /* Do it by hand, with file-ops */
  445. ret = 0;
  446. vector = iov;
  447. while (nr_segs > 0) {
  448. void __user * base;
  449. size_t len;
  450. ssize_t nr;
  451. base = vector->iov_base;
  452. len = vector->iov_len;
  453. vector++;
  454. nr_segs--;
  455. nr = fn(file, base, len, pos);
  456. if (nr < 0) {
  457. if (!ret) ret = nr;
  458. break;
  459. }
  460. ret += nr;
  461. if (nr != len)
  462. break;
  463. }
  464. out:
  465. if (iov != iovstack)
  466. kfree(iov);
  467. if ((ret + (type == READ)) > 0) {
  468. if (type == READ)
  469. fsnotify_access(file->f_dentry);
  470. else
  471. fsnotify_modify(file->f_dentry);
  472. }
  473. return ret;
  474. Efault:
  475. ret = -EFAULT;
  476. goto out;
  477. }
  478. ssize_t vfs_readv(struct file *file, const struct iovec __user *vec,
  479. unsigned long vlen, loff_t *pos)
  480. {
  481. if (!(file->f_mode & FMODE_READ))
  482. return -EBADF;
  483. if (!file->f_op || (!file->f_op->readv && !file->f_op->read))
  484. return -EINVAL;
  485. return do_readv_writev(READ, file, vec, vlen, pos);
  486. }
  487. EXPORT_SYMBOL(vfs_readv);
  488. ssize_t vfs_writev(struct file *file, const struct iovec __user *vec,
  489. unsigned long vlen, loff_t *pos)
  490. {
  491. if (!(file->f_mode & FMODE_WRITE))
  492. return -EBADF;
  493. if (!file->f_op || (!file->f_op->writev && !file->f_op->write))
  494. return -EINVAL;
  495. return do_readv_writev(WRITE, file, vec, vlen, pos);
  496. }
  497. EXPORT_SYMBOL(vfs_writev);
  498. asmlinkage ssize_t
  499. sys_readv(unsigned long fd, const struct iovec __user *vec, unsigned long vlen)
  500. {
  501. struct file *file;
  502. ssize_t ret = -EBADF;
  503. int fput_needed;
  504. file = fget_light(fd, &fput_needed);
  505. if (file) {
  506. loff_t pos = file_pos_read(file);
  507. ret = vfs_readv(file, vec, vlen, &pos);
  508. file_pos_write(file, pos);
  509. fput_light(file, fput_needed);
  510. }
  511. if (ret > 0)
  512. current->rchar += ret;
  513. current->syscr++;
  514. return ret;
  515. }
  516. asmlinkage ssize_t
  517. sys_writev(unsigned long fd, const struct iovec __user *vec, unsigned long vlen)
  518. {
  519. struct file *file;
  520. ssize_t ret = -EBADF;
  521. int fput_needed;
  522. file = fget_light(fd, &fput_needed);
  523. if (file) {
  524. loff_t pos = file_pos_read(file);
  525. ret = vfs_writev(file, vec, vlen, &pos);
  526. file_pos_write(file, pos);
  527. fput_light(file, fput_needed);
  528. }
  529. if (ret > 0)
  530. current->wchar += ret;
  531. current->syscw++;
  532. return ret;
  533. }
  534. static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
  535. size_t count, loff_t max)
  536. {
  537. struct file * in_file, * out_file;
  538. struct inode * in_inode, * out_inode;
  539. loff_t pos;
  540. ssize_t retval;
  541. int fput_needed_in, fput_needed_out;
  542. /*
  543. * Get input file, and verify that it is ok..
  544. */
  545. retval = -EBADF;
  546. in_file = fget_light(in_fd, &fput_needed_in);
  547. if (!in_file)
  548. goto out;
  549. if (!(in_file->f_mode & FMODE_READ))
  550. goto fput_in;
  551. retval = -EINVAL;
  552. in_inode = in_file->f_dentry->d_inode;
  553. if (!in_inode)
  554. goto fput_in;
  555. if (!in_file->f_op || !in_file->f_op->sendfile)
  556. goto fput_in;
  557. retval = -ESPIPE;
  558. if (!ppos)
  559. ppos = &in_file->f_pos;
  560. else
  561. if (!(in_file->f_mode & FMODE_PREAD))
  562. goto fput_in;
  563. retval = rw_verify_area(READ, in_file, ppos, count);
  564. if (retval)
  565. goto fput_in;
  566. retval = security_file_permission (in_file, MAY_READ);
  567. if (retval)
  568. goto fput_in;
  569. /*
  570. * Get output file, and verify that it is ok..
  571. */
  572. retval = -EBADF;
  573. out_file = fget_light(out_fd, &fput_needed_out);
  574. if (!out_file)
  575. goto fput_in;
  576. if (!(out_file->f_mode & FMODE_WRITE))
  577. goto fput_out;
  578. retval = -EINVAL;
  579. if (!out_file->f_op || !out_file->f_op->sendpage)
  580. goto fput_out;
  581. out_inode = out_file->f_dentry->d_inode;
  582. retval = rw_verify_area(WRITE, out_file, &out_file->f_pos, count);
  583. if (retval)
  584. goto fput_out;
  585. retval = security_file_permission (out_file, MAY_WRITE);
  586. if (retval)
  587. goto fput_out;
  588. if (!max)
  589. max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
  590. pos = *ppos;
  591. retval = -EINVAL;
  592. if (unlikely(pos < 0))
  593. goto fput_out;
  594. if (unlikely(pos + count > max)) {
  595. retval = -EOVERFLOW;
  596. if (pos >= max)
  597. goto fput_out;
  598. count = max - pos;
  599. }
  600. retval = in_file->f_op->sendfile(in_file, ppos, count, file_send_actor, out_file);
  601. if (retval > 0) {
  602. current->rchar += retval;
  603. current->wchar += retval;
  604. }
  605. current->syscr++;
  606. current->syscw++;
  607. if (*ppos > max)
  608. retval = -EOVERFLOW;
  609. fput_out:
  610. fput_light(out_file, fput_needed_out);
  611. fput_in:
  612. fput_light(in_file, fput_needed_in);
  613. out:
  614. return retval;
  615. }
  616. asmlinkage ssize_t sys_sendfile(int out_fd, int in_fd, off_t __user *offset, size_t count)
  617. {
  618. loff_t pos;
  619. off_t off;
  620. ssize_t ret;
  621. if (offset) {
  622. if (unlikely(get_user(off, offset)))
  623. return -EFAULT;
  624. pos = off;
  625. ret = do_sendfile(out_fd, in_fd, &pos, count, MAX_NON_LFS);
  626. if (unlikely(put_user(pos, offset)))
  627. return -EFAULT;
  628. return ret;
  629. }
  630. return do_sendfile(out_fd, in_fd, NULL, count, 0);
  631. }
  632. asmlinkage ssize_t sys_sendfile64(int out_fd, int in_fd, loff_t __user *offset, size_t count)
  633. {
  634. loff_t pos;
  635. ssize_t ret;
  636. if (offset) {
  637. if (unlikely(copy_from_user(&pos, offset, sizeof(loff_t))))
  638. return -EFAULT;
  639. ret = do_sendfile(out_fd, in_fd, &pos, count, 0);
  640. if (unlikely(put_user(pos, offset)))
  641. return -EFAULT;
  642. return ret;
  643. }
  644. return do_sendfile(out_fd, in_fd, NULL, count, 0);
  645. }