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/module.h>
24 #include <linux/errno.h>
26 #include <linux/idr.h>
35 * v9fs_fid_insert - add a fid to a dentry
37 * @dentry: dentry that it is being added to
41 int v9fs_fid_insert(struct v9fs_fid
*fid
, struct dentry
*dentry
)
43 struct list_head
*fid_list
= (struct list_head
*)dentry
->d_fsdata
;
44 dprintk(DEBUG_9P
, "fid %d (%p) dentry %s (%p)\n", fid
->fid
, fid
,
45 dentry
->d_iname
, dentry
);
46 if (dentry
->d_fsdata
== NULL
) {
48 kmalloc(sizeof(struct list_head
), GFP_KERNEL
);
49 if (dentry
->d_fsdata
== NULL
) {
50 dprintk(DEBUG_ERROR
, "Out of memory\n");
53 fid_list
= (struct list_head
*)dentry
->d_fsdata
;
54 INIT_LIST_HEAD(fid_list
); /* Initialize list head */
57 fid
->uid
= current
->uid
;
58 list_add(&fid
->list
, fid_list
);
63 * v9fs_fid_create - allocate a FID structure
64 * @dentry - dentry to link newly created fid to
68 struct v9fs_fid
*v9fs_fid_create(struct v9fs_session_info
*v9ses
, int fid
)
72 dprintk(DEBUG_9P
, "fid create fid %d\n", fid
);
73 new = kmalloc(sizeof(struct v9fs_fid
), GFP_KERNEL
);
75 dprintk(DEBUG_ERROR
, "Out of Memory\n");
76 return ERR_PTR(-ENOMEM
);
85 new->rdir_fcall
= NULL
;
86 INIT_LIST_HEAD(&new->list
);
92 * v9fs_fid_destroy - deallocate a FID structure
93 * @fid: fid to destroy
97 void v9fs_fid_destroy(struct v9fs_fid
*fid
)
104 * v9fs_fid_lookup - retrieve the right fid from a particular dentry
105 * @dentry: dentry to look for fid in
106 * @type: intent of lookup (operation or traversal)
108 * find a fid in the dentry
110 * TODO: only match fids that have the same uid as current user
114 struct v9fs_fid
*v9fs_fid_lookup(struct dentry
*dentry
)
116 struct list_head
*fid_list
= (struct list_head
*)dentry
->d_fsdata
;
117 struct v9fs_fid
*return_fid
= NULL
;
119 dprintk(DEBUG_9P
, " dentry: %s (%p)\n", dentry
->d_iname
, dentry
);
122 return_fid
= list_entry(fid_list
->next
, struct v9fs_fid
, list
);
125 dprintk(DEBUG_ERROR
, "Couldn't find a fid in dentry\n");