4 #include <gpxe/errortab.h>
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
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>".
21 FILE_LICENCE ( GPL2_OR_LATER );
24 * Find error description
26 * @v errno Error number
27 * @ret errortab Error description, or NULL
29 static struct errortab * find_error ( int errno ) {
30 struct errortab *errortab;
32 for_each_table_entry ( errortab, ERRORTAB ) {
33 if ( errortab->errno == errno )
41 * Find closest error description
43 * @v errno Error number
44 * @ret errortab Error description, or NULL
48 static struct errortab * find_closest_error ( int errno ) {
49 struct errortab *errortab;
51 /* First, look for an exact match */
52 if ( ( errortab = find_error ( errno ) ) != NULL )
55 /* Second, try masking off the gPXE-specific bit and seeing if
56 * we have an entry for the generic POSIX error message.
58 if ( ( errortab = find_error ( errno & 0x7f0000ff ) ) != NULL )
65 * Retrieve string representation of error number.
67 * @v errno/rc Error number or return status code
68 * @ret strerror Pointer to error text
70 * If the error is not found in the linked-in error tables, generates
71 * a generic "Error 0x<errno>" message.
73 * The pointer returned by strerror() is valid only until the next
77 const char * strerror ( int errno ) {
78 static char errbuf[64];
79 struct errortab *errortab;
81 /* Allow for strerror(rc) as well as strerror(errno) */
85 /* Find the error description, if one exists */
86 errortab = find_closest_error ( errno );
88 /* Construct the error message */
90 snprintf ( errbuf, sizeof ( errbuf ), "%s (%#08x)",
91 errortab->text, errno );
93 snprintf ( errbuf, sizeof ( errbuf ), "Error %#08x", errno );
99 /* Do not include ERRFILE portion in the numbers in the error table */
103 /** The most common errors */
104 struct errortab common_errors[] __errortab = {
106 { EACCES, "Permission denied" },
107 { ECANCELED, "Operation cancelled" },
108 { ECONNRESET, "Connection reset" },
109 { EINVAL, "Invalid argument" },
110 { EIO, "Input/output error" },
111 { ENETUNREACH, "Network unreachable" },
112 { ENODEV, "No such device" },
113 { ENOENT, "File not found" },
114 { ENOEXEC, "Not an executable image" },
115 { ENOMEM, "Out of memory" },
116 { ENOSPC, "No space left on device" },
117 { ENOTCONN, "Not connected" },
118 { ENOTSUP, "Not supported" },
119 { EPERM, "Operation not permitted" },
120 { ERANGE, "Out of range" },
121 { ETIMEDOUT, "Connection timed out" },