~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/lib/errname.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <linux/build_bug.h>
  3 #include <linux/errno.h>
  4 #include <linux/errname.h>
  5 #include <linux/kernel.h>
  6 #include <linux/math.h>
  7 
  8 /*
  9  * Ensure these tables do not accidentally become gigantic if some
 10  * huge errno makes it in. On most architectures, the first table will
 11  * only have about 140 entries, but mips and parisc have more sparsely
 12  * allocated errnos (with EHWPOISON = 257 on parisc, and EDQUOT = 1133
 13  * on mips), so this wastes a bit of space on those - though we
 14  * special case the EDQUOT case.
 15  */
 16 #define E(err) [err + BUILD_BUG_ON_ZERO(err <= 0 || err > 300)] = "-" #err
 17 static const char *names_0[] = {
 18         E(E2BIG),
 19         E(EACCES),
 20         E(EADDRINUSE),
 21         E(EADDRNOTAVAIL),
 22         E(EADV),
 23         E(EAFNOSUPPORT),
 24         E(EAGAIN), /* EWOULDBLOCK */
 25         E(EALREADY),
 26         E(EBADE),
 27         E(EBADF),
 28         E(EBADFD),
 29         E(EBADMSG),
 30         E(EBADR),
 31         E(EBADRQC),
 32         E(EBADSLT),
 33         E(EBFONT),
 34         E(EBUSY),
 35         E(ECANCELED), /* ECANCELLED */
 36         E(ECHILD),
 37         E(ECHRNG),
 38         E(ECOMM),
 39         E(ECONNABORTED),
 40         E(ECONNREFUSED), /* EREFUSED */
 41         E(ECONNRESET),
 42         E(EDEADLK), /* EDEADLOCK */
 43 #if EDEADLK != EDEADLOCK /* mips, sparc, powerpc */
 44         E(EDEADLOCK),
 45 #endif
 46         E(EDESTADDRREQ),
 47         E(EDOM),
 48         E(EDOTDOT),
 49 #ifndef CONFIG_MIPS
 50         E(EDQUOT),
 51 #endif
 52         E(EEXIST),
 53         E(EFAULT),
 54         E(EFBIG),
 55         E(EHOSTDOWN),
 56         E(EHOSTUNREACH),
 57         E(EHWPOISON),
 58         E(EIDRM),
 59         E(EILSEQ),
 60 #ifdef EINIT
 61         E(EINIT),
 62 #endif
 63         E(EINPROGRESS),
 64         E(EINTR),
 65         E(EINVAL),
 66         E(EIO),
 67         E(EISCONN),
 68         E(EISDIR),
 69         E(EISNAM),
 70         E(EKEYEXPIRED),
 71         E(EKEYREJECTED),
 72         E(EKEYREVOKED),
 73         E(EL2HLT),
 74         E(EL2NSYNC),
 75         E(EL3HLT),
 76         E(EL3RST),
 77         E(ELIBACC),
 78         E(ELIBBAD),
 79         E(ELIBEXEC),
 80         E(ELIBMAX),
 81         E(ELIBSCN),
 82         E(ELNRNG),
 83         E(ELOOP),
 84         E(EMEDIUMTYPE),
 85         E(EMFILE),
 86         E(EMLINK),
 87         E(EMSGSIZE),
 88         E(EMULTIHOP),
 89         E(ENAMETOOLONG),
 90         E(ENAVAIL),
 91         E(ENETDOWN),
 92         E(ENETRESET),
 93         E(ENETUNREACH),
 94         E(ENFILE),
 95         E(ENOANO),
 96         E(ENOBUFS),
 97         E(ENOCSI),
 98         E(ENODATA),
 99         E(ENODEV),
100         E(ENOENT),
101         E(ENOEXEC),
102         E(ENOKEY),
103         E(ENOLCK),
104         E(ENOLINK),
105         E(ENOMEDIUM),
106         E(ENOMEM),
107         E(ENOMSG),
108         E(ENONET),
109         E(ENOPKG),
110         E(ENOPROTOOPT),
111         E(ENOSPC),
112         E(ENOSR),
113         E(ENOSTR),
114         E(ENOSYS),
115         E(ENOTBLK),
116         E(ENOTCONN),
117         E(ENOTDIR),
118         E(ENOTEMPTY),
119         E(ENOTNAM),
120         E(ENOTRECOVERABLE),
121         E(ENOTSOCK),
122         E(ENOTTY),
123         E(ENOTUNIQ),
124         E(ENXIO),
125         E(EOPNOTSUPP),
126         E(EOVERFLOW),
127         E(EOWNERDEAD),
128         E(EPERM),
129         E(EPFNOSUPPORT),
130         E(EPIPE),
131 #ifdef EPROCLIM
132         E(EPROCLIM),
133 #endif
134         E(EPROTO),
135         E(EPROTONOSUPPORT),
136         E(EPROTOTYPE),
137         E(ERANGE),
138         E(EREMCHG),
139 #ifdef EREMDEV
140         E(EREMDEV),
141 #endif
142         E(EREMOTE),
143         E(EREMOTEIO),
144         E(ERESTART),
145         E(ERFKILL),
146         E(EROFS),
147 #ifdef ERREMOTE
148         E(ERREMOTE),
149 #endif
150         E(ESHUTDOWN),
151         E(ESOCKTNOSUPPORT),
152         E(ESPIPE),
153         E(ESRCH),
154         E(ESRMNT),
155         E(ESTALE),
156         E(ESTRPIPE),
157         E(ETIME),
158         E(ETIMEDOUT),
159         E(ETOOMANYREFS),
160         E(ETXTBSY),
161         E(EUCLEAN),
162         E(EUNATCH),
163         E(EUSERS),
164         E(EXDEV),
165         E(EXFULL),
166 };
167 #undef E
168 
169 #ifdef EREFUSED /* parisc */
170 static_assert(EREFUSED == ECONNREFUSED);
171 #endif
172 #ifdef ECANCELLED /* parisc */
173 static_assert(ECANCELLED == ECANCELED);
174 #endif
175 static_assert(EAGAIN == EWOULDBLOCK); /* everywhere */
176 
177 #define E(err) [err - 512 + BUILD_BUG_ON_ZERO(err < 512 || err > 550)] = "-" #err
178 static const char *names_512[] = {
179         E(ERESTARTSYS),
180         E(ERESTARTNOINTR),
181         E(ERESTARTNOHAND),
182         E(ENOIOCTLCMD),
183         E(ERESTART_RESTARTBLOCK),
184         E(EPROBE_DEFER),
185         E(EOPENSTALE),
186         E(ENOPARAM),
187 
188         E(EBADHANDLE),
189         E(ENOTSYNC),
190         E(EBADCOOKIE),
191         E(ENOTSUPP),
192         E(ETOOSMALL),
193         E(ESERVERFAULT),
194         E(EBADTYPE),
195         E(EJUKEBOX),
196         E(EIOCBQUEUED),
197         E(ERECALLCONFLICT),
198 };
199 #undef E
200 
201 static const char *__errname(unsigned err)
202 {
203         if (err < ARRAY_SIZE(names_0))
204                 return names_0[err];
205         if (err >= 512 && err - 512 < ARRAY_SIZE(names_512))
206                 return names_512[err - 512];
207         /* But why? */
208         if (IS_ENABLED(CONFIG_MIPS) && err == EDQUOT) /* 1133 */
209                 return "-EDQUOT";
210         return NULL;
211 }
212 
213 /*
214  * errname(EIO) -> "EIO"
215  * errname(-EIO) -> "-EIO"
216  */
217 const char *errname(int err)
218 {
219         const char *name = __errname(abs(err));
220         if (!name)
221                 return NULL;
222 
223         return err > 0 ? name + 1 : name;
224 }
225 EXPORT_SYMBOL(errname);
226 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php