Linux 2.6.17.7
[linux/fpc-iii.git] / fs / 9p / fid.c
blobb7608af07ce8b44db2c3378f0a1b3f49efb65191
1 /*
2 * V9FS FID Management
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 version 2
8 * as published by the Free Software Foundation.
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.
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
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>
29 #include "debug.h"
30 #include "v9fs.h"
31 #include "9p.h"
32 #include "v9fs_vfs.h"
33 #include "fid.h"
35 /**
36 * v9fs_fid_insert - add a fid to a dentry
37 * @fid: fid to add
38 * @dentry: dentry that it is being added to
42 int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry)
44 struct list_head *fid_list = (struct list_head *)dentry->d_fsdata;
45 dprintk(DEBUG_9P, "fid %d (%p) dentry %s (%p)\n", fid->fid, fid,
46 dentry->d_iname, dentry);
47 if (dentry->d_fsdata == NULL) {
48 dentry->d_fsdata =
49 kmalloc(sizeof(struct list_head), GFP_KERNEL);
50 if (dentry->d_fsdata == NULL) {
51 dprintk(DEBUG_ERROR, "Out of memory\n");
52 return -ENOMEM;
54 fid_list = (struct list_head *)dentry->d_fsdata;
55 INIT_LIST_HEAD(fid_list); /* Initialize list head */
58 fid->uid = current->uid;
59 list_add(&fid->list, fid_list);
60 return 0;
63 /**
64 * v9fs_fid_create - allocate a FID structure
65 * @dentry - dentry to link newly created fid to
69 struct v9fs_fid *v9fs_fid_create(struct v9fs_session_info *v9ses, int fid)
71 struct v9fs_fid *new;
73 dprintk(DEBUG_9P, "fid create fid %d\n", fid);
74 new = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL);
75 if (new == NULL) {
76 dprintk(DEBUG_ERROR, "Out of Memory\n");
77 return ERR_PTR(-ENOMEM);
80 new->fid = fid;
81 new->v9ses = v9ses;
82 new->fidopen = 0;
83 new->fidclunked = 0;
84 new->iounit = 0;
85 new->rdir_pos = 0;
86 new->rdir_fcall = NULL;
87 INIT_LIST_HEAD(&new->list);
89 return new;
92 /**
93 * v9fs_fid_destroy - deallocate a FID structure
94 * @fid: fid to destroy
98 void v9fs_fid_destroy(struct v9fs_fid *fid)
100 list_del(&fid->list);
101 kfree(fid);
105 * v9fs_fid_lookup - retrieve the right fid from a particular dentry
106 * @dentry: dentry to look for fid in
107 * @type: intent of lookup (operation or traversal)
109 * find a fid in the dentry
111 * TODO: only match fids that have the same uid as current user
115 struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry)
117 struct list_head *fid_list = (struct list_head *)dentry->d_fsdata;
118 struct v9fs_fid *return_fid = NULL;
120 dprintk(DEBUG_9P, " dentry: %s (%p)\n", dentry->d_iname, dentry);
122 if (fid_list)
123 return_fid = list_entry(fid_list->next, struct v9fs_fid, list);
125 if (!return_fid) {
126 dprintk(DEBUG_ERROR, "Couldn't find a fid in dentry\n");
129 return return_fid;