diff options
-rw-r--r-- | fs/9p/debug.h | 70 | ||||
-rw-r--r-- | fs/9p/error.c | 93 | ||||
-rw-r--r-- | fs/9p/error.h | 181 | ||||
-rw-r--r-- | fs/9p/fid.c | 241 | ||||
-rw-r--r-- | fs/9p/fid.h | 57 |
5 files changed, 642 insertions, 0 deletions
diff --git a/fs/9p/debug.h b/fs/9p/debug.h new file mode 100644 index 000000000000..4445f06919d9 --- /dev/null +++ b/fs/9p/debug.h | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | * linux/fs/9p/debug.h - V9FS Debug Definitions | ||
3 | * | ||
4 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> | ||
5 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to: | ||
19 | * Free Software Foundation | ||
20 | * 51 Franklin Street, Fifth Floor | ||
21 | * Boston, MA 02111-1301 USA | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | #define DEBUG_ERROR (1<<0) | ||
26 | #define DEBUG_CURRENT (1<<1) | ||
27 | #define DEBUG_9P (1<<2) | ||
28 | #define DEBUG_VFS (1<<3) | ||
29 | #define DEBUG_CONV (1<<4) | ||
30 | #define DEBUG_MUX (1<<5) | ||
31 | #define DEBUG_TRANS (1<<6) | ||
32 | #define DEBUG_SLABS (1<<7) | ||
33 | |||
34 | #define DEBUG_DUMP_PKT 0 | ||
35 | |||
36 | extern int v9fs_debug_level; | ||
37 | |||
38 | #define dprintk(level, format, arg...) \ | ||
39 | do { \ | ||
40 | if((v9fs_debug_level & level)==level) \ | ||
41 | printk(KERN_NOTICE "-- %s (%d): " \ | ||
42 | format , __FUNCTION__, current->pid , ## arg); \ | ||
43 | } while(0) | ||
44 | |||
45 | #define eprintk(level, format, arg...) \ | ||
46 | do { \ | ||
47 | printk(level "v9fs: %s (%d): " \ | ||
48 | format , __FUNCTION__, current->pid , ## arg); \ | ||
49 | } while(0) | ||
50 | |||
51 | #if DEBUG_DUMP_PKT | ||
52 | static inline void dump_data(const unsigned char *data, unsigned int datalen) | ||
53 | { | ||
54 | int i, j; | ||
55 | int len = datalen; | ||
56 | |||
57 | printk(KERN_DEBUG "data "); | ||
58 | for (i = 0; i < len; i += 4) { | ||
59 | for (j = 0; (j < 4) && (i + j < len); j++) | ||
60 | printk(KERN_DEBUG "%02x", data[i + j]); | ||
61 | printk(KERN_DEBUG " "); | ||
62 | } | ||
63 | printk(KERN_DEBUG "\n"); | ||
64 | } | ||
65 | #else /* DEBUG_DUMP_PKT */ | ||
66 | static inline void dump_data(const unsigned char *data, unsigned int datalen) | ||
67 | { | ||
68 | |||
69 | } | ||
70 | #endif /* DEBUG_DUMP_PKT */ | ||
diff --git a/fs/9p/error.c b/fs/9p/error.c new file mode 100644 index 000000000000..fee5d19179c5 --- /dev/null +++ b/fs/9p/error.c | |||
@@ -0,0 +1,93 @@ | |||
1 | /* | ||
2 | * linux/fs/9p/error.c | ||
3 | * | ||
4 | * Error string handling | ||
5 | * | ||
6 | * Plan 9 uses error strings, Unix uses error numbers. These functions | ||
7 | * try to help manage that and provide for dynamically adding error | ||
8 | * mappings. | ||
9 | * | ||
10 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> | ||
11 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | * | ||
18 | * This program is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | * GNU General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU General Public License | ||
24 | * along with this program; if not, write to: | ||
25 | * Free Software Foundation | ||
26 | * 51 Franklin Street, Fifth Floor | ||
27 | * Boston, MA 02111-1301 USA | ||
28 | * | ||
29 | */ | ||
30 | |||
31 | #include <linux/config.h> | ||
32 | #include <linux/module.h> | ||
33 | |||
34 | #include <linux/list.h> | ||
35 | #include <linux/jhash.h> | ||
36 | |||
37 | #include "debug.h" | ||
38 | #include "error.h" | ||
39 | |||
40 | /** | ||
41 | * v9fs_error_init - preload | ||
42 | * @errstr: error string | ||
43 | * | ||
44 | */ | ||
45 | |||
46 | int v9fs_error_init(void) | ||
47 | { | ||
48 | struct errormap *c; | ||
49 | int bucket; | ||
50 | |||
51 | /* initialize hash table */ | ||
52 | for (bucket = 0; bucket < ERRHASHSZ; bucket++) | ||
53 | INIT_HLIST_HEAD(&hash_errmap[bucket]); | ||
54 | |||
55 | /* load initial error map into hash table */ | ||
56 | for (c = errmap; c->name != NULL; c++) { | ||
57 | bucket = jhash(c->name, strlen(c->name), 0) % ERRHASHSZ; | ||
58 | INIT_HLIST_NODE(&c->list); | ||
59 | hlist_add_head(&c->list, &hash_errmap[bucket]); | ||
60 | } | ||
61 | |||
62 | return 1; | ||
63 | } | ||
64 | |||
65 | /** | ||
66 | * errstr2errno - convert error string to error number | ||
67 | * @errstr: error string | ||
68 | * | ||
69 | */ | ||
70 | |||
71 | int v9fs_errstr2errno(char *errstr) | ||
72 | { | ||
73 | int errno = 0; | ||
74 | struct hlist_node *p = NULL; | ||
75 | struct errormap *c = NULL; | ||
76 | int bucket = jhash(errstr, strlen(errstr), 0) % ERRHASHSZ; | ||
77 | |||
78 | hlist_for_each_entry(c, p, &hash_errmap[bucket], list) { | ||
79 | if (!strcmp(c->name, errstr)) { | ||
80 | errno = c->val; | ||
81 | break; | ||
82 | } | ||
83 | } | ||
84 | |||
85 | if (errno == 0) { | ||
86 | /* TODO: if error isn't found, add it dynamically */ | ||
87 | printk(KERN_ERR "%s: errstr :%s: not found\n", __FUNCTION__, | ||
88 | errstr); | ||
89 | errno = 1; | ||
90 | } | ||
91 | |||
92 | return -errno; | ||
93 | } | ||
diff --git a/fs/9p/error.h b/fs/9p/error.h new file mode 100644 index 000000000000..4bf2cf5aa1bb --- /dev/null +++ b/fs/9p/error.h | |||
@@ -0,0 +1,181 @@ | |||
1 | /* | ||
2 | * linux/fs/9p/error.h | ||
3 | * | ||
4 | * Huge Nasty Error Table | ||
5 | * | ||
6 | * Plan 9 uses error strings, Unix uses error numbers. This table tries to | ||
7 | * match UNIX strings and Plan 9 strings to unix error numbers. It is used | ||
8 | * to preload the dynamic error table which can also track user-specific error | ||
9 | * strings. | ||
10 | * | ||
11 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> | ||
12 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or modify | ||
15 | * it under the terms of the GNU General Public License as published by | ||
16 | * the Free Software Foundation; either version 2 of the License, or | ||
17 | * (at your option) any later version. | ||
18 | * | ||
19 | * This program is distributed in the hope that it will be useful, | ||
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | * GNU General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License | ||
25 | * along with this program; if not, write to: | ||
26 | * Free Software Foundation | ||
27 | * 51 Franklin Street, Fifth Floor | ||
28 | * Boston, MA 02111-1301 USA | ||
29 | * | ||
30 | */ | ||
31 | |||
32 | #include <linux/errno.h> | ||
33 | |||
34 | struct errormap { | ||
35 | char *name; | ||
36 | int val; | ||
37 | |||
38 | struct hlist_node list; | ||
39 | }; | ||
40 | |||
41 | #define ERRHASHSZ 32 | ||
42 | static struct hlist_head hash_errmap[ERRHASHSZ]; | ||
43 | |||
44 | /* FixMe - reduce to a reasonable size */ | ||
45 | static struct errormap errmap[] = { | ||
46 | {"Operation not permitted", 1}, | ||
47 | {"wstat prohibited", 1}, | ||
48 | {"No such file or directory", 2}, | ||
49 | {"file not found", 2}, | ||
50 | {"Interrupted system call", 4}, | ||
51 | {"Input/output error", 5}, | ||
52 | {"No such device or address", 6}, | ||
53 | {"Argument list too long", 7}, | ||
54 | {"Bad file descriptor", 9}, | ||
55 | {"Resource temporarily unavailable", 11}, | ||
56 | {"Cannot allocate memory", 12}, | ||
57 | {"Permission denied", 13}, | ||
58 | {"Bad address", 14}, | ||
59 | {"Block device required", 15}, | ||
60 | {"Device or resource busy", 16}, | ||
61 | {"File exists", 17}, | ||
62 | {"Invalid cross-device link", 18}, | ||
63 | {"No such device", 19}, | ||
64 | {"Not a directory", 20}, | ||
65 | {"Is a directory", 21}, | ||
66 | {"Invalid argument", 22}, | ||
67 | {"Too many open files in system", 23}, | ||
68 | {"Too many open files", 24}, | ||
69 | {"Text file busy", 26}, | ||
70 | {"File too large", 27}, | ||
71 | {"No space left on device", 28}, | ||
72 | {"Illegal seek", 29}, | ||
73 | {"Read-only file system", 30}, | ||
74 | {"Too many links", 31}, | ||
75 | {"Broken pipe", 32}, | ||
76 | {"Numerical argument out of domain", 33}, | ||
77 | {"Numerical result out of range", 34}, | ||
78 | {"Resource deadlock avoided", 35}, | ||
79 | {"File name too long", 36}, | ||
80 | {"No locks available", 37}, | ||
81 | {"Function not implemented", 38}, | ||
82 | {"Directory not empty", 39}, | ||
83 | {"Too many levels of symbolic links", 40}, | ||
84 | {"Unknown error 41", 41}, | ||
85 | {"No message of desired type", 42}, | ||
86 | {"Identifier removed", 43}, | ||
87 | {"File locking deadlock error", 58}, | ||
88 | {"No data available", 61}, | ||
89 | {"Machine is not on the network", 64}, | ||
90 | {"Package not installed", 65}, | ||
91 | {"Object is remote", 66}, | ||
92 | {"Link has been severed", 67}, | ||
93 | {"Communication error on send", 70}, | ||
94 | {"Protocol error", 71}, | ||
95 | {"Bad message", 74}, | ||
96 | {"File descriptor in bad state", 77}, | ||
97 | {"Streams pipe error", 86}, | ||
98 | {"Too many users", 87}, | ||
99 | {"Socket operation on non-socket", 88}, | ||
100 | {"Message too long", 90}, | ||
101 | {"Protocol not available", 92}, | ||
102 | {"Protocol not supported", 93}, | ||
103 | {"Socket type not supported", 94}, | ||
104 | {"Operation not supported", 95}, | ||
105 | {"Protocol family not supported", 96}, | ||
106 | {"Network is down", 100}, | ||
107 | {"Network is unreachable", 101}, | ||
108 | {"Network dropped connection on reset", 102}, | ||
109 | {"Software caused connection abort", 103}, | ||
110 | {"Connection reset by peer", 104}, | ||
111 | {"No buffer space available", 105}, | ||
112 | {"Transport endpoint is already connected", 106}, | ||
113 | {"Transport endpoint is not connected", 107}, | ||
114 | {"Cannot send after transport endpoint shutdown", 108}, | ||
115 | {"Connection timed out", 110}, | ||
116 | {"Connection refused", 111}, | ||
117 | {"Host is down", 112}, | ||
118 | {"No route to host", 113}, | ||
119 | {"Operation already in progress", 114}, | ||
120 | {"Operation now in progress", 115}, | ||
121 | {"Is a named type file", 120}, | ||
122 | {"Remote I/O error", 121}, | ||
123 | {"Disk quota exceeded", 122}, | ||
124 | {"Operation canceled", 125}, | ||
125 | {"Unknown error 126", 126}, | ||
126 | {"Unknown error 127", 127}, | ||
127 | /* errors from fossil, vacfs, and u9fs */ | ||
128 | {"fid unknown or out of range", EBADF}, | ||
129 | {"permission denied", EACCES}, | ||
130 | {"file does not exist", ENOENT}, | ||
131 | {"authentication failed", ECONNREFUSED}, | ||
132 | {"bad offset in directory read", ESPIPE}, | ||
133 | {"bad use of fid", EBADF}, | ||
134 | {"wstat can't convert between files and directories", EPERM}, | ||
135 | {"directory is not empty", ENOTEMPTY}, | ||
136 | {"file exists", EEXIST}, | ||
137 | {"file already exists", EEXIST}, | ||
138 | {"file or directory already exists", EEXIST}, | ||
139 | {"fid already in use", EBADF}, | ||
140 | {"file in use", ETXTBSY}, | ||
141 | {"i/o error", EIO}, | ||
142 | {"file already open for I/O", ETXTBSY}, | ||
143 | {"illegal mode", EINVAL}, | ||
144 | {"illegal name", ENAMETOOLONG}, | ||
145 | {"not a directory", ENOTDIR}, | ||
146 | {"not a member of proposed group", EINVAL}, | ||
147 | {"not owner", EACCES}, | ||
148 | {"only owner can change group in wstat", EACCES}, | ||
149 | {"read only file system", EROFS}, | ||
150 | {"no access to special file", EPERM}, | ||
151 | {"i/o count too large", EIO}, | ||
152 | {"unknown group", EINVAL}, | ||
153 | {"unknown user", EINVAL}, | ||
154 | {"bogus wstat buffer", EPROTO}, | ||
155 | {"exclusive use file already open", EAGAIN}, | ||
156 | {"corrupted directory entry", EIO}, | ||
157 | {"corrupted file entry", EIO}, | ||
158 | {"corrupted block label", EIO}, | ||
159 | {"corrupted meta data", EIO}, | ||
160 | {"illegal offset", EINVAL}, | ||
161 | {"illegal path element", ENOENT}, | ||
162 | {"root of file system is corrupted", EIO}, | ||
163 | {"corrupted super block", EIO}, | ||
164 | {"protocol botch", EPROTO}, | ||
165 | {"file system is full", ENOSPC}, | ||
166 | {"file is in use", EAGAIN}, | ||
167 | {"directory entry is not allocated", ENOENT}, | ||
168 | {"file is read only", EROFS}, | ||
169 | {"file has been removed", EIDRM}, | ||
170 | {"only support truncation to zero length", EPERM}, | ||
171 | {"cannot remove root", EPERM}, | ||
172 | {"file too big", EFBIG}, | ||
173 | {"venti i/o error", EIO}, | ||
174 | /* these are not errors */ | ||
175 | {"u9fs rhostsauth: no authentication required", 0}, | ||
176 | {"u9fs authnone: no authentication required", 0}, | ||
177 | {NULL, -1} | ||
178 | }; | ||
179 | |||
180 | extern int v9fs_error_init(void); | ||
181 | extern int v9fs_errstr2errno(char *errstr); | ||
diff --git a/fs/9p/fid.c b/fs/9p/fid.c new file mode 100644 index 000000000000..821c9c4d76aa --- /dev/null +++ b/fs/9p/fid.c | |||
@@ -0,0 +1,241 @@ | |||
1 | /* | ||
2 | * V9FS FID Management | ||
3 | * | ||
4 | * Copyright (C) 2005 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 | |||
24 | #include <linux/config.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/errno.h> | ||
27 | #include <linux/fs.h> | ||
28 | #include <linux/idr.h> | ||
29 | |||
30 | #include "debug.h" | ||
31 | #include "v9fs.h" | ||
32 | #include "9p.h" | ||
33 | #include "v9fs_vfs.h" | ||
34 | #include "transport.h" | ||
35 | #include "mux.h" | ||
36 | #include "conv.h" | ||
37 | #include "fid.h" | ||
38 | |||
39 | /** | ||
40 | * v9fs_fid_insert - add a fid to a dentry | ||
41 | * @fid: fid to add | ||
42 | * @dentry: dentry that it is being added to | ||
43 | * | ||
44 | */ | ||
45 | |||
46 | static int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry) | ||
47 | { | ||
48 | struct list_head *fid_list = (struct list_head *)dentry->d_fsdata; | ||
49 | dprintk(DEBUG_9P, "fid %d (%p) dentry %s (%p)\n", fid->fid, fid, | ||
50 | dentry->d_iname, dentry); | ||
51 | if (dentry->d_fsdata == NULL) { | ||
52 | dentry->d_fsdata = | ||
53 | kmalloc(sizeof(struct list_head), GFP_KERNEL); | ||
54 | if (dentry->d_fsdata == NULL) { | ||
55 | dprintk(DEBUG_ERROR, "Out of memory\n"); | ||
56 | return -ENOMEM; | ||
57 | } | ||
58 | fid_list = (struct list_head *)dentry->d_fsdata; | ||
59 | INIT_LIST_HEAD(fid_list); /* Initialize list head */ | ||
60 | } | ||
61 | |||
62 | fid->uid = current->uid; | ||
63 | fid->pid = current->pid; | ||
64 | list_add(&fid->list, fid_list); | ||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | /** | ||
69 | * v9fs_fid_create - allocate a FID structure | ||
70 | * @dentry - dentry to link newly created fid to | ||
71 | * | ||
72 | */ | ||
73 | |||
74 | struct v9fs_fid *v9fs_fid_create(struct dentry *dentry) | ||
75 | { | ||
76 | struct v9fs_fid *new; | ||
77 | |||
78 | new = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL); | ||
79 | if (new == NULL) { | ||
80 | dprintk(DEBUG_ERROR, "Out of Memory\n"); | ||
81 | return ERR_PTR(-ENOMEM); | ||
82 | } | ||
83 | |||
84 | new->fid = -1; | ||
85 | new->fidopen = 0; | ||
86 | new->fidcreate = 0; | ||
87 | new->fidclunked = 0; | ||
88 | new->iounit = 0; | ||
89 | |||
90 | if (v9fs_fid_insert(new, dentry) == 0) | ||
91 | return new; | ||
92 | else { | ||
93 | dprintk(DEBUG_ERROR, "Problems inserting to dentry\n"); | ||
94 | kfree(new); | ||
95 | return NULL; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | /** | ||
100 | * v9fs_fid_destroy - deallocate a FID structure | ||
101 | * @fid: fid to destroy | ||
102 | * | ||
103 | */ | ||
104 | |||
105 | void v9fs_fid_destroy(struct v9fs_fid *fid) | ||
106 | { | ||
107 | list_del(&fid->list); | ||
108 | kfree(fid); | ||
109 | } | ||
110 | |||
111 | /** | ||
112 | * v9fs_fid_lookup - retrieve the right fid from a particular dentry | ||
113 | * @dentry: dentry to look for fid in | ||
114 | * @type: intent of lookup (operation or traversal) | ||
115 | * | ||
116 | * search list of fids associated with a dentry for a fid with a matching | ||
117 | * thread id or uid. If that fails, look up the dentry's parents to see if you | ||
118 | * can find a matching fid. | ||
119 | * | ||
120 | */ | ||
121 | |||
122 | struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry, int type) | ||
123 | { | ||
124 | struct list_head *fid_list = (struct list_head *)dentry->d_fsdata; | ||
125 | struct v9fs_fid *current_fid = NULL; | ||
126 | struct v9fs_fid *temp = NULL; | ||
127 | struct v9fs_fid *return_fid = NULL; | ||
128 | int found_parent = 0; | ||
129 | int found_user = 0; | ||
130 | |||
131 | dprintk(DEBUG_9P, " dentry: %s (%p) type %d\n", dentry->d_iname, dentry, | ||
132 | type); | ||
133 | |||
134 | if (fid_list && !list_empty(fid_list)) { | ||
135 | list_for_each_entry_safe(current_fid, temp, fid_list, list) { | ||
136 | if (current_fid->uid == current->uid) { | ||
137 | if (return_fid == NULL) { | ||
138 | if ((type == FID_OP) | ||
139 | || (!current_fid->fidopen)) { | ||
140 | return_fid = current_fid; | ||
141 | found_user = 1; | ||
142 | } | ||
143 | } | ||
144 | } | ||
145 | if (current_fid->pid == current->real_parent->pid) { | ||
146 | if ((return_fid == NULL) || (found_parent) | ||
147 | || (found_user)) { | ||
148 | if ((type == FID_OP) | ||
149 | || (!current_fid->fidopen)) { | ||
150 | return_fid = current_fid; | ||
151 | found_parent = 1; | ||
152 | found_user = 0; | ||
153 | } | ||
154 | } | ||
155 | } | ||
156 | if (current_fid->pid == current->pid) { | ||
157 | if ((type == FID_OP) || | ||
158 | (!current_fid->fidopen)) { | ||
159 | return_fid = current_fid; | ||
160 | found_parent = 0; | ||
161 | found_user = 0; | ||
162 | } | ||
163 | } | ||
164 | } | ||
165 | } | ||
166 | |||
167 | /* we are at the root but didn't match */ | ||
168 | if ((!return_fid) && (dentry->d_parent == dentry)) { | ||
169 | /* TODO: clone attach with new uid */ | ||
170 | return_fid = current_fid; | ||
171 | } | ||
172 | |||
173 | if (!return_fid) { | ||
174 | struct dentry *par = current->fs->pwd->d_parent; | ||
175 | int count = 1; | ||
176 | while (par != NULL) { | ||
177 | if (par == dentry) | ||
178 | break; | ||
179 | count++; | ||
180 | if (par == par->d_parent) { | ||
181 | dprintk(DEBUG_ERROR, | ||
182 | "got to root without finding dentry\n"); | ||
183 | break; | ||
184 | } | ||
185 | par = par->d_parent; | ||
186 | } | ||
187 | |||
188 | /* XXX - there may be some duplication we can get rid of */ | ||
189 | if (par == dentry) { | ||
190 | /* we need to fid_lookup the starting point */ | ||
191 | int fidnum = -1; | ||
192 | int oldfid = -1; | ||
193 | int result = -1; | ||
194 | struct v9fs_session_info *v9ses = | ||
195 | v9fs_inode2v9ses(current->fs->pwd->d_inode); | ||
196 | |||
197 | current_fid = | ||
198 | v9fs_fid_lookup(current->fs->pwd, FID_WALK); | ||
199 | if (current_fid == NULL) { | ||
200 | dprintk(DEBUG_ERROR, | ||
201 | "process cwd doesn't have a fid\n"); | ||
202 | return return_fid; | ||
203 | } | ||
204 | oldfid = current_fid->fid; | ||
205 | par = current->fs->pwd; | ||
206 | /* TODO: take advantage of multiwalk */ | ||
207 | |||
208 | fidnum = v9fs_get_idpool(&v9ses->fidpool); | ||
209 | if (fidnum < 0) { | ||
210 | dprintk(DEBUG_ERROR, | ||
211 | "could not get a new fid num\n"); | ||
212 | return return_fid; | ||
213 | } | ||
214 | |||
215 | while (par != dentry) { | ||
216 | result = | ||
217 | v9fs_t_walk(v9ses, oldfid, fidnum, "..", | ||
218 | NULL); | ||
219 | if (result < 0) { | ||
220 | dprintk(DEBUG_ERROR, | ||
221 | "problem walking to parent\n"); | ||
222 | |||
223 | break; | ||
224 | } | ||
225 | oldfid = fidnum; | ||
226 | if (par == par->d_parent) { | ||
227 | dprintk(DEBUG_ERROR, | ||
228 | "can't find dentry\n"); | ||
229 | break; | ||
230 | } | ||
231 | par = par->d_parent; | ||
232 | } | ||
233 | if (par == dentry) { | ||
234 | return_fid = v9fs_fid_create(dentry); | ||
235 | return_fid->fid = fidnum; | ||
236 | } | ||
237 | } | ||
238 | } | ||
239 | |||
240 | return return_fid; | ||
241 | } | ||
diff --git a/fs/9p/fid.h b/fs/9p/fid.h new file mode 100644 index 000000000000..7db478ccca36 --- /dev/null +++ b/fs/9p/fid.h | |||
@@ -0,0 +1,57 @@ | |||
1 | /* | ||
2 | * V9FS FID Management | ||
3 | * | ||
4 | * Copyright (C) 2005 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 | |||
24 | #include <linux/list.h> | ||
25 | |||
26 | #define FID_OP 0 | ||
27 | #define FID_WALK 1 | ||
28 | |||
29 | struct v9fs_fid { | ||
30 | struct list_head list; /* list of fids associated with a dentry */ | ||
31 | struct list_head active; /* XXX - debug */ | ||
32 | |||
33 | u32 fid; | ||
34 | unsigned char fidopen; /* set when fid is opened */ | ||
35 | unsigned char fidcreate; /* set when fid was just created */ | ||
36 | unsigned char fidclunked; /* set when fid has already been clunked */ | ||
37 | |||
38 | struct v9fs_qid qid; | ||
39 | u32 iounit; | ||
40 | |||
41 | /* readdir stuff */ | ||
42 | int rdir_fpos; | ||
43 | loff_t rdir_pos; | ||
44 | struct v9fs_fcall *rdir_fcall; | ||
45 | |||
46 | /* management stuff */ | ||
47 | pid_t pid; /* thread associated with this fid */ | ||
48 | uid_t uid; /* user associated with this fid */ | ||
49 | |||
50 | /* private data */ | ||
51 | struct file *filp; /* backpointer to File struct for open files */ | ||
52 | struct v9fs_session_info *v9ses; /* session info for this FID */ | ||
53 | }; | ||
54 | |||
55 | struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry, int type); | ||
56 | void v9fs_fid_destroy(struct v9fs_fid *fid); | ||
57 | struct v9fs_fid *v9fs_fid_create(struct dentry *); | ||