Blame view

net/9p/error.c 7.41 KB
3ed8491c8   Eric Van Hensbergen   [PATCH] v9fs: deb...
1
  /*
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
2
   * linux/fs/9p/error.c
3ed8491c8   Eric Van Hensbergen   [PATCH] v9fs: deb...
3
   *
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
4
   * Error string handling
3ed8491c8   Eric Van Hensbergen   [PATCH] v9fs: deb...
5
   *
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
6
7
8
   * Plan 9 uses error strings, Unix uses error numbers.  These functions
   * try to help manage that and provide for dynamically adding error
   * mappings.
3ed8491c8   Eric Van Hensbergen   [PATCH] v9fs: deb...
9
10
11
12
13
   *
   *  Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
   *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
   *
   *  This program is free software; you can redistribute it and/or modify
42e8c509c   Eric Van Hensbergen   [PATCH] v9fs: upd...
14
15
   *  it under the terms of the GNU General Public License version 2
   *  as published by the Free Software Foundation.
3ed8491c8   Eric Van Hensbergen   [PATCH] v9fs: deb...
16
17
18
19
20
21
22
23
24
25
26
27
28
   *
   *  This program is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
   *
   *  You should have received a copy of the GNU General Public License
   *  along with this program; if not, write to:
   *  Free Software Foundation
   *  51 Franklin Street, Fifth Floor
   *  Boston, MA  02111-1301  USA
   *
   */
5d3851530   Joe Perches   9p: Reduce object...
29
  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
30
31
32
  #include <linux/module.h>
  #include <linux/list.h>
  #include <linux/jhash.h>
3ed8491c8   Eric Van Hensbergen   [PATCH] v9fs: deb...
33
  #include <linux/errno.h>
bd238fb43   Latchesar Ionkov   9p: Reorganizatio...
34
  #include <net/9p/9p.h>
3ed8491c8   Eric Van Hensbergen   [PATCH] v9fs: deb...
35

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