fid.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * V9FS FID Management
  3. *
  4. * Copyright (C) 2005, 2006 by Eric Van Hensbergen <ericvh@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2
  8. * as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to:
  17. * Free Software Foundation
  18. * 51 Franklin Street, Fifth Floor
  19. * Boston, MA 02111-1301 USA
  20. *
  21. */
  22. #include <linux/module.h>
  23. #include <linux/errno.h>
  24. #include <linux/fs.h>
  25. #include <linux/idr.h>
  26. #include "debug.h"
  27. #include "v9fs.h"
  28. #include "9p.h"
  29. #include "v9fs_vfs.h"
  30. #include "fid.h"
  31. /**
  32. * v9fs_fid_insert - add a fid to a dentry
  33. * @fid: fid to add
  34. * @dentry: dentry that it is being added to
  35. *
  36. */
  37. int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry)
  38. {
  39. struct list_head *fid_list = (struct list_head *)dentry->d_fsdata;
  40. dprintk(DEBUG_9P, "fid %d (%p) dentry %s (%p)\n", fid->fid, fid,
  41. dentry->d_iname, dentry);
  42. if (dentry->d_fsdata == NULL) {
  43. dentry->d_fsdata =
  44. kmalloc(sizeof(struct list_head), GFP_KERNEL);
  45. if (dentry->d_fsdata == NULL) {
  46. dprintk(DEBUG_ERROR, "Out of memory\n");
  47. return -ENOMEM;
  48. }
  49. fid_list = (struct list_head *)dentry->d_fsdata;
  50. INIT_LIST_HEAD(fid_list); /* Initialize list head */
  51. }
  52. fid->uid = current->uid;
  53. list_add(&fid->list, fid_list);
  54. return 0;
  55. }
  56. /**
  57. * v9fs_fid_create - allocate a FID structure
  58. * @dentry - dentry to link newly created fid to
  59. *
  60. */
  61. struct v9fs_fid *v9fs_fid_create(struct v9fs_session_info *v9ses, int fid)
  62. {
  63. struct v9fs_fid *new;
  64. dprintk(DEBUG_9P, "fid create fid %d\n", fid);
  65. new = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL);
  66. if (new == NULL) {
  67. dprintk(DEBUG_ERROR, "Out of Memory\n");
  68. return ERR_PTR(-ENOMEM);
  69. }
  70. new->fid = fid;
  71. new->v9ses = v9ses;
  72. new->fidopen = 0;
  73. new->fidclunked = 0;
  74. new->iounit = 0;
  75. new->rdir_pos = 0;
  76. new->rdir_fcall = NULL;
  77. INIT_LIST_HEAD(&new->list);
  78. return new;
  79. }
  80. /**
  81. * v9fs_fid_destroy - deallocate a FID structure
  82. * @fid: fid to destroy
  83. *
  84. */
  85. void v9fs_fid_destroy(struct v9fs_fid *fid)
  86. {
  87. list_del(&fid->list);
  88. kfree(fid);
  89. }
  90. /**
  91. * v9fs_fid_lookup - retrieve the right fid from a particular dentry
  92. * @dentry: dentry to look for fid in
  93. * @type: intent of lookup (operation or traversal)
  94. *
  95. * find a fid in the dentry
  96. *
  97. * TODO: only match fids that have the same uid as current user
  98. *
  99. */
  100. struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry)
  101. {
  102. struct list_head *fid_list = (struct list_head *)dentry->d_fsdata;
  103. struct v9fs_fid *return_fid = NULL;
  104. dprintk(DEBUG_9P, " dentry: %s (%p)\n", dentry->d_iname, dentry);
  105. if (fid_list)
  106. return_fid = list_entry(fid_list->next, struct v9fs_fid, list);
  107. if (!return_fid) {
  108. dprintk(DEBUG_ERROR, "Couldn't find a fid in dentry\n");
  109. }
  110. return return_fid;
  111. }