vfs_addr.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * linux/fs/9p/vfs_addr.c
  3. *
  4. * This file contians vfs address (mmap) ops for 9P2000.
  5. *
  6. * Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com>
  7. * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to:
  20. * Free Software Foundation
  21. * 51 Franklin Street, Fifth Floor
  22. * Boston, MA 02111-1301 USA
  23. *
  24. */
  25. #include <linux/module.h>
  26. #include <linux/errno.h>
  27. #include <linux/fs.h>
  28. #include <linux/file.h>
  29. #include <linux/stat.h>
  30. #include <linux/string.h>
  31. #include <linux/smp_lock.h>
  32. #include <linux/inet.h>
  33. #include <linux/pagemap.h>
  34. #include <linux/idr.h>
  35. #include "debug.h"
  36. #include "v9fs.h"
  37. #include "9p.h"
  38. #include "v9fs_vfs.h"
  39. #include "fid.h"
  40. /**
  41. * v9fs_vfs_readpage - read an entire page in from 9P
  42. *
  43. * @file: file being read
  44. * @page: structure to page
  45. *
  46. */
  47. static int v9fs_vfs_readpage(struct file *filp, struct page *page)
  48. {
  49. char *buffer = NULL;
  50. int retval = -EIO;
  51. loff_t offset = page_offset(page);
  52. int count = PAGE_CACHE_SIZE;
  53. struct inode *inode = filp->f_dentry->d_inode;
  54. struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
  55. int rsize = v9ses->maxdata - V9FS_IOHDRSZ;
  56. struct v9fs_fid *v9f = filp->private_data;
  57. struct v9fs_fcall *fcall = NULL;
  58. int fid = v9f->fid;
  59. int total = 0;
  60. int result = 0;
  61. buffer = kmap(page);
  62. do {
  63. if (count < rsize)
  64. rsize = count;
  65. result = v9fs_t_read(v9ses, fid, offset, rsize, &fcall);
  66. if (result < 0) {
  67. printk(KERN_ERR "v9fs_t_read returned %d\n",
  68. result);
  69. kfree(fcall);
  70. goto UnmapAndUnlock;
  71. } else
  72. offset += result;
  73. memcpy(buffer, fcall->params.rread.data, result);
  74. count -= result;
  75. buffer += result;
  76. total += result;
  77. kfree(fcall);
  78. if (result < rsize)
  79. break;
  80. } while (count);
  81. memset(buffer, 0, count);
  82. flush_dcache_page(page);
  83. SetPageUptodate(page);
  84. retval = 0;
  85. UnmapAndUnlock:
  86. kunmap(page);
  87. unlock_page(page);
  88. return retval;
  89. }
  90. const struct address_space_operations v9fs_addr_operations = {
  91. .readpage = v9fs_vfs_readpage,
  92. };