Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * V9FS FID Management |
| 3 | * |
Eric Van Hensbergen | 46f6dac | 2006-03-02 02:54:33 -0800 | [diff] [blame] | 4 | * Copyright (C) 2005, 2006 by Eric Van Hensbergen <ericvh@gmail.com> |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
Eric Van Hensbergen | 42e8c50 | 2006-03-25 03:07:28 -0800 | [diff] [blame] | 7 | * it under the terms of the GNU General Public License version 2 |
| 8 | * as published by the Free Software Foundation. |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 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 | |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/fs.h> |
| 26 | #include <linux/idr.h> |
| 27 | |
| 28 | #include "debug.h" |
| 29 | #include "v9fs.h" |
| 30 | #include "9p.h" |
| 31 | #include "v9fs_vfs.h" |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 32 | #include "fid.h" |
| 33 | |
| 34 | /** |
| 35 | * v9fs_fid_insert - add a fid to a dentry |
| 36 | * @fid: fid to add |
| 37 | * @dentry: dentry that it is being added to |
| 38 | * |
| 39 | */ |
| 40 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 41 | int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry) |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 42 | { |
| 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) { |
| 47 | dentry->d_fsdata = |
| 48 | kmalloc(sizeof(struct list_head), GFP_KERNEL); |
| 49 | if (dentry->d_fsdata == NULL) { |
| 50 | dprintk(DEBUG_ERROR, "Out of memory\n"); |
| 51 | return -ENOMEM; |
| 52 | } |
| 53 | fid_list = (struct list_head *)dentry->d_fsdata; |
| 54 | INIT_LIST_HEAD(fid_list); /* Initialize list head */ |
| 55 | } |
| 56 | |
| 57 | fid->uid = current->uid; |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 58 | list_add(&fid->list, fid_list); |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * v9fs_fid_create - allocate a FID structure |
| 64 | * @dentry - dentry to link newly created fid to |
| 65 | * |
| 66 | */ |
| 67 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 68 | struct v9fs_fid *v9fs_fid_create(struct v9fs_session_info *v9ses, int fid) |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 69 | { |
| 70 | struct v9fs_fid *new; |
| 71 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 72 | dprintk(DEBUG_9P, "fid create fid %d\n", fid); |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 73 | new = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL); |
| 74 | if (new == NULL) { |
| 75 | dprintk(DEBUG_ERROR, "Out of Memory\n"); |
| 76 | return ERR_PTR(-ENOMEM); |
| 77 | } |
| 78 | |
Latchesar Ionkov | 0b8dd17 | 2005-09-27 21:45:24 -0700 | [diff] [blame] | 79 | new->fid = fid; |
| 80 | new->v9ses = v9ses; |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 81 | new->fidopen = 0; |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 82 | new->fidclunked = 0; |
| 83 | new->iounit = 0; |
Latchesar Ionkov | 0b8dd17 | 2005-09-27 21:45:24 -0700 | [diff] [blame] | 84 | new->rdir_pos = 0; |
| 85 | new->rdir_fcall = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 86 | INIT_LIST_HEAD(&new->list); |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 87 | |
Eric Van Hensbergen | 46f6dac | 2006-03-02 02:54:33 -0800 | [diff] [blame] | 88 | return new; |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** |
| 92 | * v9fs_fid_destroy - deallocate a FID structure |
| 93 | * @fid: fid to destroy |
| 94 | * |
| 95 | */ |
| 96 | |
| 97 | void v9fs_fid_destroy(struct v9fs_fid *fid) |
| 98 | { |
| 99 | list_del(&fid->list); |
| 100 | kfree(fid); |
| 101 | } |
| 102 | |
| 103 | /** |
| 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) |
| 107 | * |
Eric Van Hensbergen | 46f6dac | 2006-03-02 02:54:33 -0800 | [diff] [blame] | 108 | * find a fid in the dentry |
| 109 | * |
| 110 | * TODO: only match fids that have the same uid as current user |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 111 | * |
| 112 | */ |
| 113 | |
Latchesar Ionkov | 0b8dd17 | 2005-09-27 21:45:24 -0700 | [diff] [blame] | 114 | struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry) |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 115 | { |
| 116 | struct list_head *fid_list = (struct list_head *)dentry->d_fsdata; |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 117 | struct v9fs_fid *return_fid = NULL; |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 118 | |
Latchesar Ionkov | 0b8dd17 | 2005-09-27 21:45:24 -0700 | [diff] [blame] | 119 | dprintk(DEBUG_9P, " dentry: %s (%p)\n", dentry->d_iname, dentry); |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 120 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 121 | if (fid_list) |
| 122 | return_fid = list_entry(fid_list->next, struct v9fs_fid, list); |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 123 | |
| 124 | if (!return_fid) { |
Eric Van Hensbergen | 46f6dac | 2006-03-02 02:54:33 -0800 | [diff] [blame] | 125 | dprintk(DEBUG_ERROR, "Couldn't find a fid in dentry\n"); |
Eric Van Hensbergen | 3ed8491 | 2005-09-09 13:04:24 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | return return_fid; |
| 129 | } |