read_write.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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/dnotify.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 > file->f_maxcount))
  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. dnotify_parent(file->f_dentry, DN_ACCESS);
  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. dnotify_parent(file->f_dentry, DN_MODIFY);
  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. fnv = NULL;
  430. if (type == READ) {
  431. fn = file->f_op->read;
  432. fnv = file->f_op->readv;
  433. } else {
  434. fn = (io_fn_t)file->f_op->write;
  435. fnv = file->f_op->writev;
  436. }
  437. if (fnv) {
  438. ret = fnv(file, iov, nr_segs, pos);
  439. goto out;
  440. }
  441. /* Do it by hand, with file-ops */
  442. ret = 0;
  443. vector = iov;
  444. while (nr_segs > 0) {
  445. void __user * base;
  446. size_t len;
  447. ssize_t nr;
  448. base = vector->iov_base;
  449. len = vector->iov_len;
  450. vector++;
  451. nr_segs--;
  452. nr = fn(file, base, len, pos);
  453. if (nr < 0) {
  454. if (!ret) ret = nr;
  455. break;
  456. }
  457. ret += nr;
  458. if (nr != len)
  459. break;
  460. }
  461. out:
  462. if (iov != iovstack)
  463. kfree(iov);
  464. if ((ret + (type == READ)) > 0)
  465. dnotify_parent(file->f_dentry,
  466. (type == READ) ? DN_ACCESS : DN_MODIFY);
  467. return ret;
  468. Efault:
  469. ret = -EFAULT;
  470. goto out;
  471. }
  472. ssize_t vfs_readv(struct file *file, const struct iovec __user *vec,
  473. unsigned long vlen, loff_t *pos)
  474. {
  475. if (!(file->f_mode & FMODE_READ))
  476. return -EBADF;
  477. if (!file->f_op || (!file->f_op->readv && !file->f_op->read))
  478. return -EINVAL;
  479. return do_readv_writev(READ, file, vec, vlen, pos);
  480. }
  481. EXPORT_SYMBOL(vfs_readv);
  482. ssize_t vfs_writev(struct file *file, const struct iovec __user *vec,
  483. unsigned long vlen, loff_t *pos)
  484. {
  485. if (!(file->f_mode & FMODE_WRITE))
  486. return -EBADF;
  487. if (!file->f_op || (!file->f_op->writev && !file->f_op->write))
  488. return -EINVAL;
  489. return do_readv_writev(WRITE, file, vec, vlen, pos);
  490. }
  491. EXPORT_SYMBOL(vfs_writev);
  492. asmlinkage ssize_t
  493. sys_readv(unsigned long fd, const struct iovec __user *vec, unsigned long vlen)
  494. {
  495. struct file *file;
  496. ssize_t ret = -EBADF;
  497. int fput_needed;
  498. file = fget_light(fd, &fput_needed);
  499. if (file) {
  500. loff_t pos = file_pos_read(file);
  501. ret = vfs_readv(file, vec, vlen, &pos);
  502. file_pos_write(file, pos);
  503. fput_light(file, fput_needed);
  504. }
  505. if (ret > 0)
  506. current->rchar += ret;
  507. current->syscr++;
  508. return ret;
  509. }
  510. asmlinkage ssize_t
  511. sys_writev(unsigned long fd, const struct iovec __user *vec, unsigned long vlen)
  512. {
  513. struct file *file;
  514. ssize_t ret = -EBADF;
  515. int fput_needed;
  516. file = fget_light(fd, &fput_needed);
  517. if (file) {
  518. loff_t pos = file_pos_read(file);
  519. ret = vfs_writev(file, vec, vlen, &pos);
  520. file_pos_write(file, pos);
  521. fput_light(file, fput_needed);
  522. }
  523. if (ret > 0)
  524. current->wchar += ret;
  525. current->syscw++;
  526. return ret;
  527. }
  528. static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
  529. size_t count, loff_t max)
  530. {
  531. struct file * in_file, * out_file;
  532. struct inode * in_inode, * out_inode;
  533. loff_t pos;
  534. ssize_t retval;
  535. int fput_needed_in, fput_needed_out;
  536. /*
  537. * Get input file, and verify that it is ok..
  538. */
  539. retval = -EBADF;
  540. in_file = fget_light(in_fd, &fput_needed_in);
  541. if (!in_file)
  542. goto out;
  543. if (!(in_file->f_mode & FMODE_READ))
  544. goto fput_in;
  545. retval = -EINVAL;
  546. in_inode = in_file->f_dentry->d_inode;
  547. if (!in_inode)
  548. goto fput_in;
  549. if (!in_file->f_op || !in_file->f_op->sendfile)
  550. goto fput_in;
  551. retval = -ESPIPE;
  552. if (!ppos)
  553. ppos = &in_file->f_pos;
  554. else
  555. if (!(in_file->f_mode & FMODE_PREAD))
  556. goto fput_in;
  557. retval = rw_verify_area(READ, in_file, ppos, count);
  558. if (retval)
  559. goto fput_in;
  560. retval = security_file_permission (in_file, MAY_READ);
  561. if (retval)
  562. goto fput_in;
  563. /*
  564. * Get output file, and verify that it is ok..
  565. */
  566. retval = -EBADF;
  567. out_file = fget_light(out_fd, &fput_needed_out);
  568. if (!out_file)
  569. goto fput_in;
  570. if (!(out_file->f_mode & FMODE_WRITE))
  571. goto fput_out;
  572. retval = -EINVAL;
  573. if (!out_file->f_op || !out_file->f_op->sendpage)
  574. goto fput_out;
  575. out_inode = out_file->f_dentry->d_inode;
  576. retval = rw_verify_area(WRITE, out_file, &out_file->f_pos, count);
  577. if (retval)
  578. goto fput_out;
  579. retval = security_file_permission (out_file, MAY_WRITE);
  580. if (retval)
  581. goto fput_out;
  582. if (!max)
  583. max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
  584. pos = *ppos;
  585. retval = -EINVAL;
  586. if (unlikely(pos < 0))
  587. goto fput_out;
  588. if (unlikely(pos + count > max)) {
  589. retval = -EOVERFLOW;
  590. if (pos >= max)
  591. goto fput_out;
  592. count = max - pos;
  593. }
  594. retval = in_file->f_op->sendfile(in_file, ppos, count, file_send_actor, out_file);
  595. if (retval > 0) {
  596. current->rchar += retval;
  597. current->wchar += retval;
  598. }
  599. current->syscr++;
  600. current->syscw++;
  601. if (*ppos > max)
  602. retval = -EOVERFLOW;
  603. fput_out:
  604. fput_light(out_file, fput_needed_out);
  605. fput_in:
  606. fput_light(in_file, fput_needed_in);
  607. out:
  608. return retval;
  609. }
  610. asmlinkage ssize_t sys_sendfile(int out_fd, int in_fd, off_t __user *offset, size_t count)
  611. {
  612. loff_t pos;
  613. off_t off;
  614. ssize_t ret;
  615. if (offset) {
  616. if (unlikely(get_user(off, offset)))
  617. return -EFAULT;
  618. pos = off;
  619. ret = do_sendfile(out_fd, in_fd, &pos, count, MAX_NON_LFS);
  620. if (unlikely(put_user(pos, offset)))
  621. return -EFAULT;
  622. return ret;
  623. }
  624. return do_sendfile(out_fd, in_fd, NULL, count, 0);
  625. }
  626. asmlinkage ssize_t sys_sendfile64(int out_fd, int in_fd, loff_t __user *offset, size_t count)
  627. {
  628. loff_t pos;
  629. ssize_t ret;
  630. if (offset) {
  631. if (unlikely(copy_from_user(&pos, offset, sizeof(loff_t))))
  632. return -EFAULT;
  633. ret = do_sendfile(out_fd, in_fd, &pos, count, 0);
  634. if (unlikely(put_user(pos, offset)))
  635. return -EFAULT;
  636. return ret;
  637. }
  638. return do_sendfile(out_fd, in_fd, NULL, count, 0);
  639. }