|
|
1.1 root 1: #include <errno.h>
2: #include <string.h>
3: #include <stdio.h>
4: #include <ipxe/errortab.h>
5:
6: /** @file
7: *
8: * Error descriptions.
9: *
10: * The error numbers used by Etherboot are a superset of those defined
11: * by the PXE specification version 2.1. See errno.h for a listing of
12: * the error values.
13: *
14: * To save space in ROM images, error string tables are optional. Use
15: * the ERRORMSG_XXX options in config.h to select which error string
16: * tables you want to include. If an error string table is omitted,
17: * strerror() will simply return the text "Error 0x<errno>".
18: *
19: */
20:
21: FILE_LICENCE ( GPL2_OR_LATER );
22:
23: /**
24: * Find error description
25: *
26: * @v errno Error number
27: * @ret errortab Error description, or NULL
28: */
29: static struct errortab * find_error ( int errno ) {
30: struct errortab *errortab;
31:
32: for_each_table_entry ( errortab, ERRORTAB ) {
33: if ( errortab->errno == errno )
34: return errortab;
35: }
36:
37: return NULL;
38: }
39:
40: /**
41: * Find closest error description
42: *
43: * @v errno Error number
44: * @ret errortab Error description, or NULL
45: *
46: *
47: */
48: static struct errortab * find_closest_error ( int errno ) {
49: struct errortab *errortab;
50:
51: /* First, look for an exact match */
52: if ( ( errortab = find_error ( errno ) ) != NULL )
53: return errortab;
54:
55: /* Second, try masking off the iPXE-specific bit and seeing if
56: * we have an entry for the generic POSIX error message.
57: */
58: if ( ( errortab = find_error ( errno & 0x7f0000ff ) ) != NULL )
59: return errortab;
60:
61: return NULL;
62: }
63:
64: /**
65: * Retrieve string representation of error number.
66: *
67: * @v errno/rc Error number or return status code
68: * @ret strerror Pointer to error text
69: *
70: * If the error is not found in the linked-in error tables, generates
71: * a generic "Error 0x<errno>" message.
72: *
73: * The pointer returned by strerror() is valid only until the next
74: * call to strerror().
75: *
76: */
77: const char * strerror ( int errno ) {
78: static char errbuf[64];
79: struct errortab *errortab;
80:
81: /* Allow for strerror(rc) as well as strerror(errno) */
82: if ( errno < 0 )
83: errno = -errno;
84:
85: /* Find the error description, if one exists */
86: errortab = find_closest_error ( errno );
87:
88: /* Construct the error message */
89: if ( errortab ) {
90: snprintf ( errbuf, sizeof ( errbuf ),
91: "%s (http://ipxe.org/%08x)",
92: errortab->text, errno );
93: } else {
94: snprintf ( errbuf, sizeof ( errbuf ),
95: "Error %#08x (http://ipxe.org/%08x)",
96: errno, errno );
97: }
98:
99: return errbuf;
100: }
101:
102: /* Do not include ERRFILE portion in the numbers in the error table */
103: #undef ERRFILE
104: #define ERRFILE 0
105:
106: /** The most common errors */
107: struct errortab common_errors[] __errortab = {
108: __einfo_errortab ( EINFO_ENOERR ),
109: __einfo_errortab ( EINFO_EACCES ),
110: __einfo_errortab ( EINFO_ECANCELED ),
111: __einfo_errortab ( EINFO_ECONNRESET ),
112: __einfo_errortab ( EINFO_EINVAL ),
113: __einfo_errortab ( EINFO_EIO ),
114: __einfo_errortab ( EINFO_ENETUNREACH ),
115: __einfo_errortab ( EINFO_ENODEV ),
116: __einfo_errortab ( EINFO_ENOENT ),
117: __einfo_errortab ( EINFO_ENOEXEC ),
118: __einfo_errortab ( EINFO_ENOMEM ),
119: __einfo_errortab ( EINFO_ENOSPC ),
120: __einfo_errortab ( EINFO_ENOTCONN ),
121: __einfo_errortab ( EINFO_ENOTSUP ),
122: __einfo_errortab ( EINFO_EPERM ),
123: __einfo_errortab ( EINFO_ERANGE ),
124: __einfo_errortab ( EINFO_ETIMEDOUT ),
125: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.