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 static struct errortab errortab_start[0]
22 __table_start ( struct errortab, errortab );
23 static struct errortab errortab_end[0]
24 __table_end ( struct errortab, errortab );
27 * Find error description
29 * @v errno Error number
30 * @v mask Mask of bits that we care about
31 * @ret errortab Error description, or NULL
33 static struct errortab * find_error ( int errno, int mask ) {
34 struct errortab *errortab;
36 for ( errortab = errortab_start ; errortab < errortab_end ;
38 if ( ( ( errortab->errno ^ errno ) & mask ) == 0 )
46 * Find closest error description
48 * @v errno Error number
49 * @ret errortab Error description, or NULL
53 static struct errortab * find_closest_error ( int errno ) {
54 struct errortab *errortab;
56 /* First, look for an exact match */
57 if ( ( errortab = find_error ( errno, 0x7fffffff ) ) != NULL )
60 /* Second, try masking off the gPXE-specific bit and seeing if
61 * we have an entry for the generic POSIX error message.
63 if ( ( errortab = find_error ( errno, 0x4f0000ff ) ) != NULL )
70 * Retrieve string representation of error number.
72 * @v errno/rc Error number or return status code
73 * @ret strerror Pointer to error text
75 * If the error is not found in the linked-in error tables, generates
76 * a generic "Error 0x<errno>" message.
78 * The pointer returned by strerror() is valid only until the next
82 const char * strerror ( int errno ) {
83 static char errbuf[64];
84 struct errortab *errortab;
86 /* Allow for strerror(rc) as well as strerror(errno) */
90 /* Find the error description, if one exists */
91 errortab = find_closest_error ( errno );
93 /* Construct the error message */
95 snprintf ( errbuf, sizeof ( errbuf ), "%s (%#08x)",
96 errortab->text, errno );
98 snprintf ( errbuf, sizeof ( errbuf ), "Error %#08x", errno );
104 /* Do not include ERRFILE portion in the numbers in the error table */
108 /** The most common errors */
109 struct errortab common_errors[] __errortab = {
111 { ENOMEM, "Out of memory" },
112 { EINVAL, "Invalid argument" },
113 { ENOSPC, "No space left on device" },
114 { EIO, "Input/output error" },
115 { EACCES, "Permission denied" },
116 { ENOENT, "File not found" },
117 { ENETUNREACH, "Network unreachable" },
118 { ETIMEDOUT, "Connection timed out" },
119 { EPIPE, "Broken pipe" },
120 { ECANCELED, "Operation cancelled" },