blob: ab2458b6c9033cbf7ba713d31a39046c4764fa6e [file] [log] [blame]
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -07001/*
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05002 * linux/fs/9p/error.c
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -07003 *
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05004 * Error string handling
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -07005 *
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05006 * 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.
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -07009 *
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
Eric Van Hensbergen42e8c502006-03-25 03:07:28 -080014 * it under the terms of the GNU General Public License version 2
15 * as published by the Free Software Foundation.
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -070016 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to:
24 * Free Software Foundation
25 * 51 Franklin Street, Fifth Floor
26 * Boston, MA 02111-1301 USA
27 *
28 */
29
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050030#include <linux/module.h>
31#include <linux/list.h>
32#include <linux/jhash.h>
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -070033#include <linux/errno.h>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050034#include <net/9p/9p.h>
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -070035
36struct errormap {
37 char *name;
38 int val;
39
Latchesar Ionkov531b1092006-01-08 01:05:00 -080040 int namelen;
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -070041 struct hlist_node list;
42};
43
44#define ERRHASHSZ 32
45static struct hlist_head hash_errmap[ERRHASHSZ];
46
47/* FixMe - reduce to a reasonable size */
48static struct errormap errmap[] = {
Eric Van Hensbergen1346f512005-09-09 13:04:25 -070049 {"Operation not permitted", EPERM},
50 {"wstat prohibited", EPERM},
51 {"No such file or directory", ENOENT},
Eric Van Hensbergencb2e87a2005-09-09 13:04:28 -070052 {"directory entry not found", ENOENT},
Eric Van Hensbergen1346f512005-09-09 13:04:25 -070053 {"file not found", ENOENT},
54 {"Interrupted system call", EINTR},
55 {"Input/output error", EIO},
56 {"No such device or address", ENXIO},
57 {"Argument list too long", E2BIG},
58 {"Bad file descriptor", EBADF},
59 {"Resource temporarily unavailable", EAGAIN},
60 {"Cannot allocate memory", ENOMEM},
61 {"Permission denied", EACCES},
62 {"Bad address", EFAULT},
63 {"Block device required", ENOTBLK},
64 {"Device or resource busy", EBUSY},
65 {"File exists", EEXIST},
66 {"Invalid cross-device link", EXDEV},
67 {"No such device", ENODEV},
68 {"Not a directory", ENOTDIR},
69 {"Is a directory", EISDIR},
70 {"Invalid argument", EINVAL},
71 {"Too many open files in system", ENFILE},
72 {"Too many open files", EMFILE},
73 {"Text file busy", ETXTBSY},
74 {"File too large", EFBIG},
75 {"No space left on device", ENOSPC},
76 {"Illegal seek", ESPIPE},
77 {"Read-only file system", EROFS},
78 {"Too many links", EMLINK},
79 {"Broken pipe", EPIPE},
80 {"Numerical argument out of domain", EDOM},
81 {"Numerical result out of range", ERANGE},
82 {"Resource deadlock avoided", EDEADLK},
83 {"File name too long", ENAMETOOLONG},
84 {"No locks available", ENOLCK},
85 {"Function not implemented", ENOSYS},
86 {"Directory not empty", ENOTEMPTY},
87 {"Too many levels of symbolic links", ELOOP},
88 {"No message of desired type", ENOMSG},
89 {"Identifier removed", EIDRM},
90 {"No data available", ENODATA},
91 {"Machine is not on the network", ENONET},
92 {"Package not installed", ENOPKG},
93 {"Object is remote", EREMOTE},
94 {"Link has been severed", ENOLINK},
95 {"Communication error on send", ECOMM},
96 {"Protocol error", EPROTO},
97 {"Bad message", EBADMSG},
98 {"File descriptor in bad state", EBADFD},
99 {"Streams pipe error", ESTRPIPE},
100 {"Too many users", EUSERS},
101 {"Socket operation on non-socket", ENOTSOCK},
102 {"Message too long", EMSGSIZE},
103 {"Protocol not available", ENOPROTOOPT},
104 {"Protocol not supported", EPROTONOSUPPORT},
105 {"Socket type not supported", ESOCKTNOSUPPORT},
106 {"Operation not supported", EOPNOTSUPP},
107 {"Protocol family not supported", EPFNOSUPPORT},
108 {"Network is down", ENETDOWN},
109 {"Network is unreachable", ENETUNREACH},
110 {"Network dropped connection on reset", ENETRESET},
111 {"Software caused connection abort", ECONNABORTED},
112 {"Connection reset by peer", ECONNRESET},
113 {"No buffer space available", ENOBUFS},
114 {"Transport endpoint is already connected", EISCONN},
115 {"Transport endpoint is not connected", ENOTCONN},
116 {"Cannot send after transport endpoint shutdown", ESHUTDOWN},
117 {"Connection timed out", ETIMEDOUT},
118 {"Connection refused", ECONNREFUSED},
119 {"Host is down", EHOSTDOWN},
120 {"No route to host", EHOSTUNREACH},
121 {"Operation already in progress", EALREADY},
122 {"Operation now in progress", EINPROGRESS},
123 {"Is a named type file", EISNAM},
124 {"Remote I/O error", EREMOTEIO},
125 {"Disk quota exceeded", EDQUOT},
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -0700126/* errors from fossil, vacfs, and u9fs */
127 {"fid unknown or out of range", EBADF},
128 {"permission denied", EACCES},
129 {"file does not exist", ENOENT},
130 {"authentication failed", ECONNREFUSED},
131 {"bad offset in directory read", ESPIPE},
132 {"bad use of fid", EBADF},
133 {"wstat can't convert between files and directories", EPERM},
134 {"directory is not empty", ENOTEMPTY},
135 {"file exists", EEXIST},
136 {"file already exists", EEXIST},
137 {"file or directory already exists", EEXIST},
138 {"fid already in use", EBADF},
139 {"file in use", ETXTBSY},
140 {"i/o error", EIO},
141 {"file already open for I/O", ETXTBSY},
142 {"illegal mode", EINVAL},
143 {"illegal name", ENAMETOOLONG},
144 {"not a directory", ENOTDIR},
Eric Van Hensbergen73c592b2005-09-09 13:04:26 -0700145 {"not a member of proposed group", EPERM},
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -0700146 {"not owner", EACCES},
147 {"only owner can change group in wstat", EACCES},
148 {"read only file system", EROFS},
149 {"no access to special file", EPERM},
150 {"i/o count too large", EIO},
151 {"unknown group", EINVAL},
152 {"unknown user", EINVAL},
153 {"bogus wstat buffer", EPROTO},
154 {"exclusive use file already open", EAGAIN},
155 {"corrupted directory entry", EIO},
156 {"corrupted file entry", EIO},
157 {"corrupted block label", EIO},
158 {"corrupted meta data", EIO},
159 {"illegal offset", EINVAL},
160 {"illegal path element", ENOENT},
161 {"root of file system is corrupted", EIO},
162 {"corrupted super block", EIO},
163 {"protocol botch", EPROTO},
164 {"file system is full", ENOSPC},
165 {"file is in use", EAGAIN},
166 {"directory entry is not allocated", ENOENT},
167 {"file is read only", EROFS},
168 {"file has been removed", EIDRM},
169 {"only support truncation to zero length", EPERM},
170 {"cannot remove root", EPERM},
171 {"file too big", EFBIG},
172 {"venti i/o error", EIO},
173 /* these are not errors */
174 {"u9fs rhostsauth: no authentication required", 0},
175 {"u9fs authnone: no authentication required", 0},
176 {NULL, -1}
177};
178
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500179/**
180 * p9_error_init - preload
181 * @errstr: error string
182 *
183 */
184
185int p9_error_init(void)
186{
187 struct errormap *c;
188 int bucket;
189
190 /* initialize hash table */
191 for (bucket = 0; bucket < ERRHASHSZ; bucket++)
192 INIT_HLIST_HEAD(&hash_errmap[bucket]);
193
194 /* load initial error map into hash table */
195 for (c = errmap; c->name != NULL; c++) {
196 c->namelen = strlen(c->name);
197 bucket = jhash(c->name, c->namelen, 0) % ERRHASHSZ;
198 INIT_HLIST_NODE(&c->list);
199 hlist_add_head(&c->list, &hash_errmap[bucket]);
200 }
201
202 return 1;
203}
204EXPORT_SYMBOL(p9_error_init);
205
206/**
207 * errstr2errno - convert error string to error number
208 * @errstr: error string
209 *
210 */
211
212int p9_errstr2errno(char *errstr, int len)
213{
214 int errno;
215 struct hlist_node *p;
216 struct errormap *c;
217 int bucket;
218
219 errno = 0;
220 p = NULL;
221 c = NULL;
222 bucket = jhash(errstr, len, 0) % ERRHASHSZ;
223 hlist_for_each_entry(c, p, &hash_errmap[bucket], list) {
224 if (c->namelen == len && !memcmp(c->name, errstr, len)) {
225 errno = c->val;
226 break;
227 }
228 }
229
230 if (errno == 0) {
231 /* TODO: if error isn't found, add it dynamically */
232 errstr[len] = 0;
233 printk(KERN_ERR "%s: errstr :%s: not found\n", __FUNCTION__,
234 errstr);
235 errno = 1;
236 }
237
238 return -errno;
239}
240EXPORT_SYMBOL(p9_errstr2errno);