vfs_addr.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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/version.h>
  34. #include <linux/pagemap.h>
  35. #include <linux/idr.h>
  36. #include "debug.h"
  37. #include "v9fs.h"
  38. #include "9p.h"
  39. #include "v9fs_vfs.h"
  40. #include "fid.h"
  41. /**
  42. * v9fs_vfs_readpage - read an entire page in from 9P
  43. *
  44. * @file: file being read
  45. * @page: structure to page
  46. *
  47. */
  48. static int v9fs_vfs_readpage(struct file *filp, struct page *page)
  49. {
  50. char *buffer = NULL;
  51. int retval = -EIO;
  52. loff_t offset = page_offset(page);
  53. int count = PAGE_CACHE_SIZE;
  54. struct inode *inode = filp->f_dentry->d_inode;
  55. struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
  56. int rsize = v9ses->maxdata - V9FS_IOHDRSZ;
  57. struct v9fs_fid *v9f = filp->private_data;
  58. struct v9fs_fcall *fcall = NULL;
  59. int fid = v9f->fid;
  60. int total = 0;
  61. int result = 0;
  62. buffer = kmap(page);
  63. do {
  64. if (count < rsize)
  65. rsize = count;
  66. result = v9fs_t_read(v9ses, fid, offset, rsize, &fcall);
  67. if (result < 0) {
  68. printk(KERN_ERR "v9fs_t_read returned %d\n",
  69. result);
  70. kfree(fcall);
  71. goto UnmapAndUnlock;
  72. } else
  73. offset += result;
  74. memcpy(buffer, fcall->params.rread.data, result);
  75. count -= result;
  76. buffer += result;
  77. total += result;
  78. kfree(fcall);
  79. if (result < rsize)
  80. break;
  81. } while (count);
  82. memset(buffer, 0, count);
  83. flush_dcache_page(page);
  84. SetPageUptodate(page);
  85. retval = 0;
  86. UnmapAndUnlock:
  87. kunmap(page);
  88. unlock_page(page);
  89. return retval;
  90. }
  91. struct address_space_operations v9fs_addr_operations = {
  92. .readpage = v9fs_vfs_readpage,
  93. };