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
, 0x0000ffff ) ) != NULL
)
66 /* Lastly, try masking off the POSIX bits and seeing if we
67 * have a match just based on the PXENV component. This
68 * allows us to report errors from underlying PXE stacks.
70 if ( ( errortab
= find_error ( ( errno
& 0x000000ff ),
71 0xffff00ff ) ) != NULL
)
78 * Retrieve string representation of error number.
80 * @v errno/rc Error number or return status code
81 * @ret strerror Pointer to error text
83 * If the error is not found in the linked-in error tables, generates
84 * a generic "Error 0x<errno>" message.
86 * The pointer returned by strerror() is valid only until the next
90 const char * strerror ( int errno
) {
91 static char errbuf
[64];
92 struct errortab
*errortab
;
94 /* Allow for strerror(rc) as well as strerror(errno) */
98 /* Find the error description, if one exists */
99 errortab
= find_closest_error ( errno
);
101 /* Construct the error message */
103 snprintf ( errbuf
, sizeof ( errbuf
), "%s (%#08x)",
104 errortab
->text
, errno
);
106 snprintf ( errbuf
, sizeof ( errbuf
), "Error %#08x", errno
);
112 /** The most common errors */
113 struct errortab common_errors
[] __errortab
= {
115 { ENOMEM
, "Out of memory" },
116 { EINVAL
, "Invalid argument" },
117 { ENOSPC
, "No space left on device" },
118 { EIO
, "Input/output error" },
119 { EACCES
, "Permission denied" },
120 { ENOENT
, "File not found" },
121 { ENETUNREACH
, "Network unreachable" },
122 { ETIMEDOUT
, "Connection timed out" },
123 { EPIPE
, "Broken pipe" },