vfs_addr.c 2.5 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 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_path.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. dprintk(DEBUG_VFS, "\n");
  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. const struct address_space_operations v9fs_addr_operations = {
  92. .readpage = v9fs_vfs_readpage,
  93. };