4 * Error string handling
6 * Plan 9 uses error strings, Unix uses error numbers. These functions
7 * try to help manage that and provide for dynamically adding error
10 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
11 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2
15 * as published by the Free Software Foundation.
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.
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
30 #include <linux/module.h>
31 #include <linux/list.h>
32 #include <linux/jhash.h>
33 #include <linux/errno.h>
34 #include <net/9p/9p.h>
37 * struct errormap - map string errors from Plan 9 to Linux numeric ids
38 * @name: string sent over 9P
39 * @val: numeric id most closely representing @name
40 * @namelen: length of string
41 * @list: hash-table list for string lookup
48 struct hlist_node list
;
52 static struct hlist_head hash_errmap
[ERRHASHSZ
];
54 static struct errormap errmap
[] = {
55 {"Operation not permitted", EPERM
},
56 {"wstat prohibited", EPERM
},
57 {"No such file or directory", ENOENT
},
58 {"directory entry not found", ENOENT
},
59 {"file not found", ENOENT
},
60 {"Interrupted system call", EINTR
},
61 {"Input/output error", EIO
},
62 {"No such device or address", ENXIO
},
63 {"Argument list too long", E2BIG
},
64 {"Bad file descriptor", EBADF
},
65 {"Resource temporarily unavailable", EAGAIN
},
66 {"Cannot allocate memory", ENOMEM
},
67 {"Permission denied", EACCES
},
68 {"Bad address", EFAULT
},
69 {"Block device required", ENOTBLK
},
70 {"Device or resource busy", EBUSY
},
71 {"File exists", EEXIST
},
72 {"Invalid cross-device link", EXDEV
},
73 {"No such device", ENODEV
},
74 {"Not a directory", ENOTDIR
},
75 {"Is a directory", EISDIR
},
76 {"Invalid argument", EINVAL
},
77 {"Too many open files in system", ENFILE
},
78 {"Too many open files", EMFILE
},
79 {"Text file busy", ETXTBSY
},
80 {"File too large", EFBIG
},
81 {"No space left on device", ENOSPC
},
82 {"Illegal seek", ESPIPE
},
83 {"Read-only file system", EROFS
},
84 {"Too many links", EMLINK
},
85 {"Broken pipe", EPIPE
},
86 {"Numerical argument out of domain", EDOM
},
87 {"Numerical result out of range", ERANGE
},
88 {"Resource deadlock avoided", EDEADLK
},
89 {"File name too long", ENAMETOOLONG
},
90 {"No locks available", ENOLCK
},
91 {"Function not implemented", ENOSYS
},
92 {"Directory not empty", ENOTEMPTY
},
93 {"Too many levels of symbolic links", ELOOP
},
94 {"No message of desired type", ENOMSG
},
95 {"Identifier removed", EIDRM
},
96 {"No data available", ENODATA
},
97 {"Machine is not on the network", ENONET
},
98 {"Package not installed", ENOPKG
},
99 {"Object is remote", EREMOTE
},
100 {"Link has been severed", ENOLINK
},
101 {"Communication error on send", ECOMM
},
102 {"Protocol error", EPROTO
},
103 {"Bad message", EBADMSG
},
104 {"File descriptor in bad state", EBADFD
},
105 {"Streams pipe error", ESTRPIPE
},
106 {"Too many users", EUSERS
},
107 {"Socket operation on non-socket", ENOTSOCK
},
108 {"Message too long", EMSGSIZE
},
109 {"Protocol not available", ENOPROTOOPT
},
110 {"Protocol not supported", EPROTONOSUPPORT
},
111 {"Socket type not supported", ESOCKTNOSUPPORT
},
112 {"Operation not supported", EOPNOTSUPP
},
113 {"Protocol family not supported", EPFNOSUPPORT
},
114 {"Network is down", ENETDOWN
},
115 {"Network is unreachable", ENETUNREACH
},
116 {"Network dropped connection on reset", ENETRESET
},
117 {"Software caused connection abort", ECONNABORTED
},
118 {"Connection reset by peer", ECONNRESET
},
119 {"No buffer space available", ENOBUFS
},
120 {"Transport endpoint is already connected", EISCONN
},
121 {"Transport endpoint is not connected", ENOTCONN
},
122 {"Cannot send after transport endpoint shutdown", ESHUTDOWN
},
123 {"Connection timed out", ETIMEDOUT
},
124 {"Connection refused", ECONNREFUSED
},
125 {"Host is down", EHOSTDOWN
},
126 {"No route to host", EHOSTUNREACH
},
127 {"Operation already in progress", EALREADY
},
128 {"Operation now in progress", EINPROGRESS
},
129 {"Is a named type file", EISNAM
},
130 {"Remote I/O error", EREMOTEIO
},
131 {"Disk quota exceeded", EDQUOT
},
132 /* errors from fossil, vacfs, and u9fs */
133 {"fid unknown or out of range", EBADF
},
134 {"permission denied", EACCES
},
135 {"file does not exist", ENOENT
},
136 {"authentication failed", ECONNREFUSED
},
137 {"bad offset in directory read", ESPIPE
},
138 {"bad use of fid", EBADF
},
139 {"wstat can't convert between files and directories", EPERM
},
140 {"directory is not empty", ENOTEMPTY
},
141 {"file exists", EEXIST
},
142 {"file already exists", EEXIST
},
143 {"file or directory already exists", EEXIST
},
144 {"fid already in use", EBADF
},
145 {"file in use", ETXTBSY
},
147 {"file already open for I/O", ETXTBSY
},
148 {"illegal mode", EINVAL
},
149 {"illegal name", ENAMETOOLONG
},
150 {"not a directory", ENOTDIR
},
151 {"not a member of proposed group", EPERM
},
152 {"not owner", EACCES
},
153 {"only owner can change group in wstat", EACCES
},
154 {"read only file system", EROFS
},
155 {"no access to special file", EPERM
},
156 {"i/o count too large", EIO
},
157 {"unknown group", EINVAL
},
158 {"unknown user", EINVAL
},
159 {"bogus wstat buffer", EPROTO
},
160 {"exclusive use file already open", EAGAIN
},
161 {"corrupted directory entry", EIO
},
162 {"corrupted file entry", EIO
},
163 {"corrupted block label", EIO
},
164 {"corrupted meta data", EIO
},
165 {"illegal offset", EINVAL
},
166 {"illegal path element", ENOENT
},
167 {"root of file system is corrupted", EIO
},
168 {"corrupted super block", EIO
},
169 {"protocol botch", EPROTO
},
170 {"file system is full", ENOSPC
},
171 {"file is in use", EAGAIN
},
172 {"directory entry is not allocated", ENOENT
},
173 {"file is read only", EROFS
},
174 {"file has been removed", EIDRM
},
175 {"only support truncation to zero length", EPERM
},
176 {"cannot remove root", EPERM
},
177 {"file too big", EFBIG
},
178 {"venti i/o error", EIO
},
179 /* these are not errors */
180 {"u9fs rhostsauth: no authentication required", 0},
181 {"u9fs authnone: no authentication required", 0},
186 * p9_error_init - preload mappings into hash list
190 int p9_error_init(void)
195 /* initialize hash table */
196 for (bucket
= 0; bucket
< ERRHASHSZ
; bucket
++)
197 INIT_HLIST_HEAD(&hash_errmap
[bucket
]);
199 /* load initial error map into hash table */
200 for (c
= errmap
; c
->name
!= NULL
; c
++) {
201 c
->namelen
= strlen(c
->name
);
202 bucket
= jhash(c
->name
, c
->namelen
, 0) % ERRHASHSZ
;
203 INIT_HLIST_NODE(&c
->list
);
204 hlist_add_head(&c
->list
, &hash_errmap
[bucket
]);
209 EXPORT_SYMBOL(p9_error_init
);
212 * errstr2errno - convert error string to error number
213 * @errstr: error string
214 * @len: length of error string
218 int p9_errstr2errno(char *errstr
, int len
)
221 struct hlist_node
*p
;
228 bucket
= jhash(errstr
, len
, 0) % ERRHASHSZ
;
229 hlist_for_each_entry(c
, p
, &hash_errmap
[bucket
], list
) {
230 if (c
->namelen
== len
&& !memcmp(c
->name
, errstr
, len
)) {
237 /* TODO: if error isn't found, add it dynamically */
239 printk(KERN_ERR
"%s: server reported unknown error %s\n",
241 errno
= ESERVERFAULT
;
246 EXPORT_SYMBOL(p9_errstr2errno
);