fid.c 3.2 KB

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