read_write.c 16 KB

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