blob: 126fd0dceea2e7c01117d1b1c6a5ab70b550daa0 [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
Joe Perches5d385152011-11-28 10:40:46 -080030#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050032#include <linux/module.h>
33#include <linux/list.h>
34#include <linux/jhash.h>
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -070035#include <linux/errno.h>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050036#include <net/9p/9p.h>
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -070037
Eric Van Hensbergenee443992008-03-05 07:08:09 -060038/**
39 * struct errormap - map string errors from Plan 9 to Linux numeric ids
40 * @name: string sent over 9P
41 * @val: numeric id most closely representing @name
42 * @namelen: length of string
43 * @list: hash-table list for string lookup
44 */
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -070045struct errormap {
46 char *name;
47 int val;
48
Latchesar Ionkov531b1092006-01-08 01:05:00 -080049 int namelen;
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -070050 struct hlist_node list;
51};
52
53#define ERRHASHSZ 32
54static struct hlist_head hash_errmap[ERRHASHSZ];
55
56/* FixMe - reduce to a reasonable size */
57static struct errormap errmap[] = {
Eric Van Hensbergen1346f512005-09-09 13:04:25 -070058 {"Operation not permitted", EPERM},
59 {"wstat prohibited", EPERM},
60 {"No such file or directory", ENOENT},
Eric Van Hensbergencb2e87a2005-09-09 13:04:28 -070061 {"directory entry not found", ENOENT},
Eric Van Hensbergen1346f512005-09-09 13:04:25 -070062 {"file not found", ENOENT},
63 {"Interrupted system call", EINTR},
64 {"Input/output error", EIO},
65 {"No such device or address", ENXIO},
66 {"Argument list too long", E2BIG},
67 {"Bad file descriptor", EBADF},
68 {"Resource temporarily unavailable", EAGAIN},
69 {"Cannot allocate memory", ENOMEM},
70 {"Permission denied", EACCES},
71 {"Bad address", EFAULT},
72 {"Block device required", ENOTBLK},
73 {"Device or resource busy", EBUSY},
74 {"File exists", EEXIST},
75 {"Invalid cross-device link", EXDEV},
76 {"No such device", ENODEV},
77 {"Not a directory", ENOTDIR},
78 {"Is a directory", EISDIR},
79 {"Invalid argument", EINVAL},
80 {"Too many open files in system", ENFILE},
81 {"Too many open files", EMFILE},
82 {"Text file busy", ETXTBSY},
83 {"File too large", EFBIG},
84 {"No space left on device", ENOSPC},
85 {"Illegal seek", ESPIPE},
86 {"Read-only file system", EROFS},
87 {"Too many links", EMLINK},
88 {"Broken pipe", EPIPE},
89 {"Numerical argument out of domain", EDOM},
90 {"Numerical result out of range", ERANGE},
91 {"Resource deadlock avoided", EDEADLK},
92 {"File name too long", ENAMETOOLONG},
93 {"No locks available", ENOLCK},
94 {"Function not implemented", ENOSYS},
95 {"Directory not empty", ENOTEMPTY},
96 {"Too many levels of symbolic links", ELOOP},
97 {"No message of desired type", ENOMSG},
98 {"Identifier removed", EIDRM},
99 {"No data available", ENODATA},
100 {"Machine is not on the network", ENONET},
101 {"Package not installed", ENOPKG},
102 {"Object is remote", EREMOTE},
103 {"Link has been severed", ENOLINK},
104 {"Communication error on send", ECOMM},
105 {"Protocol error", EPROTO},
106 {"Bad message", EBADMSG},
107 {"File descriptor in bad state", EBADFD},
108 {"Streams pipe error", ESTRPIPE},
109 {"Too many users", EUSERS},
110 {"Socket operation on non-socket", ENOTSOCK},
111 {"Message too long", EMSGSIZE},
112 {"Protocol not available", ENOPROTOOPT},
113 {"Protocol not supported", EPROTONOSUPPORT},
114 {"Socket type not supported", ESOCKTNOSUPPORT},
115 {"Operation not supported", EOPNOTSUPP},
116 {"Protocol family not supported", EPFNOSUPPORT},
117 {"Network is down", ENETDOWN},
118 {"Network is unreachable", ENETUNREACH},
119 {"Network dropped connection on reset", ENETRESET},
120 {"Software caused connection abort", ECONNABORTED},
121 {"Connection reset by peer", ECONNRESET},
122 {"No buffer space available", ENOBUFS},
123 {"Transport endpoint is already connected", EISCONN},
124 {"Transport endpoint is not connected", ENOTCONN},
125 {"Cannot send after transport endpoint shutdown", ESHUTDOWN},
126 {"Connection timed out", ETIMEDOUT},
127 {"Connection refused", ECONNREFUSED},
128 {"Host is down", EHOSTDOWN},
129 {"No route to host", EHOSTUNREACH},
130 {"Operation already in progress", EALREADY},
131 {"Operation now in progress", EINPROGRESS},
132 {"Is a named type file", EISNAM},
133 {"Remote I/O error", EREMOTEIO},
134 {"Disk quota exceeded", EDQUOT},
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -0700135/* errors from fossil, vacfs, and u9fs */
136 {"fid unknown or out of range", EBADF},
137 {"permission denied", EACCES},
138 {"file does not exist", ENOENT},
139 {"authentication failed", ECONNREFUSED},
140 {"bad offset in directory read", ESPIPE},
141 {"bad use of fid", EBADF},
142 {"wstat can't convert between files and directories", EPERM},
143 {"directory is not empty", ENOTEMPTY},
144 {"file exists", EEXIST},
145 {"file already exists", EEXIST},
146 {"file or directory already exists", EEXIST},
147 {"fid already in use", EBADF},
148 {"file in use", ETXTBSY},
149 {"i/o error", EIO},
150 {"file already open for I/O", ETXTBSY},
151 {"illegal mode", EINVAL},
152 {"illegal name", ENAMETOOLONG},
153 {"not a directory", ENOTDIR},
Eric Van Hensbergen73c592b2005-09-09 13:04:26 -0700154 {"not a member of proposed group", EPERM},
Eric Van Hensbergen3ed84912005-09-09 13:04:24 -0700155 {"not owner", EACCES},
156 {"only owner can change group in wstat", EACCES},
157 {"read only file system", EROFS},
158 {"no access to special file", EPERM},
159 {"i/o count too large", EIO},
160 {"unknown group", EINVAL},
161 {"unknown user", EINVAL},
162 {"bogus wstat buffer", EPROTO},
163 {"exclusive use file already open", EAGAIN},
164 {"corrupted directory entry", EIO},
165 {"corrupted file entry", EIO},
166 {"corrupted block label", EIO},
167 {"corrupted meta data", EIO},
168 {"illegal offset", EINVAL},
169 {"illegal path element", ENOENT},
170 {"root of file system is corrupted", EIO},
171 {"corrupted super block", EIO},
172 {"protocol botch", EPROTO},
173 {"file system is full", ENOSPC},
174 {"file is in use", EAGAIN},
175 {"directory entry is not allocated", ENOENT},
176 {"file is read only", EROFS},
177 {"file has been removed", EIDRM},
178 {"only support truncation to zero length", EPERM},
179 {"cannot remove root", EPERM},
180 {"file too big", EFBIG},
181 {"venti i/o error", EIO},
182 /* these are not errors */
183 {"u9fs rhostsauth: no authentication required", 0},
184 {"u9fs authnone: no authentication required", 0},
185 {NULL, -1}
186};
187
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500188/**
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600189 * p9_error_init - preload mappings into hash list
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500190 *
191 */
192
193int p9_error_init(void)
194{
195 struct errormap *c;
196 int bucket;
197
198 /* initialize hash table */
199 for (bucket = 0; bucket < ERRHASHSZ; bucket++)
200 INIT_HLIST_HEAD(&hash_errmap[bucket]);
201
202 /* load initial error map into hash table */
203 for (c = errmap; c->name != NULL; c++) {
204 c->namelen = strlen(c->name);
205 bucket = jhash(c->name, c->namelen, 0) % ERRHASHSZ;
206 INIT_HLIST_NODE(&c->list);
207 hlist_add_head(&c->list, &hash_errmap[bucket]);
208 }
209
210 return 1;
211}
212EXPORT_SYMBOL(p9_error_init);
213
214/**
215 * errstr2errno - convert error string to error number
216 * @errstr: error string
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600217 * @len: length of error string
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500218 *
219 */
220
221int p9_errstr2errno(char *errstr, int len)
222{
223 int errno;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500224 struct errormap *c;
225 int bucket;
226
227 errno = 0;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500228 c = NULL;
229 bucket = jhash(errstr, len, 0) % ERRHASHSZ;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800230 hlist_for_each_entry(c, &hash_errmap[bucket], list) {
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500231 if (c->namelen == len && !memcmp(c->name, errstr, len)) {
232 errno = c->val;
233 break;
234 }
235 }
236
237 if (errno == 0) {
238 /* TODO: if error isn't found, add it dynamically */
239 errstr[len] = 0;
Joe Perches5d385152011-11-28 10:40:46 -0800240 pr_err("%s: server reported unknown error %s\n",
241 __func__, errstr);
Abhishek Kulkarni0aad37e2009-08-17 16:38:45 -0500242 errno = ESERVERFAULT;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500243 }
244
245 return -errno;
246}
247EXPORT_SYMBOL(p9_errstr2errno);