error.c 7.1 KB

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