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