vfs_addr.c 2.6 KB

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