4 * Copyright (C) 2005, 2006 by Eric Van Hensbergen <ericvh@gmail.com>
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.
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.
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
24 #include <linux/config.h>
25 #include <linux/module.h>
26 #include <linux/errno.h>
28 #include <linux/idr.h>
37 * v9fs_fid_insert - add a fid to a dentry
39 * @dentry: dentry that it is being added to
43 int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry)
45 struct list_head *fid_list = (struct list_head *)dentry->d_fsdata;
46 dprintk(DEBUG_9P, "fid %d (%p) dentry %s (%p)\n", fid->fid, fid,
47 dentry->d_iname, dentry);
48 if (dentry->d_fsdata == NULL) {
50 kmalloc(sizeof(struct list_head), GFP_KERNEL);
51 if (dentry->d_fsdata == NULL) {
52 dprintk(DEBUG_ERROR, "Out of memory\n");
55 fid_list = (struct list_head *)dentry->d_fsdata;
56 INIT_LIST_HEAD(fid_list); /* Initialize list head */
59 fid->uid = current->uid;
60 list_add(&fid->list, fid_list);
65 * v9fs_fid_create - allocate a FID structure
66 * @dentry - dentry to link newly created fid to
70 struct v9fs_fid *v9fs_fid_create(struct v9fs_session_info *v9ses, int fid)
74 dprintk(DEBUG_9P, "fid create fid %d\n", fid);
75 new = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL);
77 dprintk(DEBUG_ERROR, "Out of Memory\n");
78 return ERR_PTR(-ENOMEM);
87 new->rdir_fcall = NULL;
88 INIT_LIST_HEAD(&new->list);
94 * v9fs_fid_destroy - deallocate a FID structure
95 * @fid: fid to destroy
99 void v9fs_fid_destroy(struct v9fs_fid *fid)
101 list_del(&fid->list);
106 * v9fs_fid_lookup - retrieve the right fid from a particular dentry
107 * @dentry: dentry to look for fid in
108 * @type: intent of lookup (operation or traversal)
110 * find a fid in the dentry
112 * TODO: only match fids that have the same uid as current user
116 struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry)
118 struct list_head *fid_list = (struct list_head *)dentry->d_fsdata;
119 struct v9fs_fid *return_fid = NULL;
121 dprintk(DEBUG_9P, " dentry: %s (%p)\n", dentry->d_iname, dentry);
124 return_fid = list_entry(fid_list->next, struct v9fs_fid, list);
127 dprintk(DEBUG_ERROR, "Couldn't find a fid in dentry\n");