fid.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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/config.h>
  23. #include <linux/module.h>
  24. #include <linux/errno.h>
  25. #include <linux/fs.h>
  26. #include <linux/idr.h>
  27. #include "debug.h"
  28. #include "v9fs.h"
  29. #include "9p.h"
  30. #include "v9fs_vfs.h"
  31. #include "fid.h"
  32. /**
  33. * v9fs_fid_insert - add a fid to a dentry
  34. * @fid: fid to add
  35. * @dentry: dentry that it is being added to
  36. *
  37. */
  38. int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry)
  39. {
  40. struct list_head *fid_list = (struct list_head *)dentry->d_fsdata;
  41. dprintk(DEBUG_9P, "fid %d (%p) dentry %s (%p)\n", fid->fid, fid,
  42. dentry->d_iname, dentry);
  43. if (dentry->d_fsdata == NULL) {
  44. dentry->d_fsdata =
  45. kmalloc(sizeof(struct list_head), GFP_KERNEL);
  46. if (dentry->d_fsdata == NULL) {
  47. dprintk(DEBUG_ERROR, "Out of memory\n");
  48. return -ENOMEM;
  49. }
  50. fid_list = (struct list_head *)dentry->d_fsdata;
  51. INIT_LIST_HEAD(fid_list); /* Initialize list head */
  52. }
  53. fid->uid = current->uid;
  54. list_add(&fid->list, fid_list);
  55. return 0;
  56. }
  57. /**
  58. * v9fs_fid_create - allocate a FID structure
  59. * @dentry - dentry to link newly created fid to
  60. *
  61. */
  62. struct v9fs_fid *v9fs_fid_create(struct v9fs_session_info *v9ses, int fid)
  63. {
  64. struct v9fs_fid *new;
  65. dprintk(DEBUG_9P, "fid create fid %d\n", fid);
  66. new = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL);
  67. if (new == NULL) {
  68. dprintk(DEBUG_ERROR, "Out of Memory\n");
  69. return ERR_PTR(-ENOMEM);
  70. }
  71. new->fid = fid;
  72. new->v9ses = v9ses;
  73. new->fidopen = 0;
  74. new->fidclunked = 0;
  75. new->iounit = 0;
  76. new->rdir_pos = 0;
  77. new->rdir_fcall = NULL;
  78. INIT_LIST_HEAD(&new->list);
  79. return new;
  80. }
  81. /**
  82. * v9fs_fid_destroy - deallocate a FID structure
  83. * @fid: fid to destroy
  84. *
  85. */
  86. void v9fs_fid_destroy(struct v9fs_fid *fid)
  87. {
  88. list_del(&fid->list);
  89. kfree(fid);
  90. }
  91. /**
  92. * v9fs_fid_lookup - retrieve the right fid from a particular dentry
  93. * @dentry: dentry to look for fid in
  94. * @type: intent of lookup (operation or traversal)
  95. *
  96. * find a fid in the dentry
  97. *
  98. * TODO: only match fids that have the same uid as current user
  99. *
  100. */
  101. struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry)
  102. {
  103. struct list_head *fid_list = (struct list_head *)dentry->d_fsdata;
  104. struct v9fs_fid *return_fid = NULL;
  105. dprintk(DEBUG_9P, " dentry: %s (%p)\n", dentry->d_iname, dentry);
  106. if (fid_list)
  107. return_fid = list_entry(fid_list->next, struct v9fs_fid, list);
  108. if (!return_fid) {
  109. dprintk(DEBUG_ERROR, "Couldn't find a fid in dentry\n");
  110. }
  111. return return_fid;
  112. }