2 * error.c -- Common error handling functions
4 * Copyright (C) 2007 Oracle. All rights reserved.
5 * Copyright (C) 2007 Chuck Lever <chuck.lever@oracle.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public
18 * License along with this program; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 021110-1307, USA.
23 * + Proper support for internationalization
28 #include <sys/types.h>
35 #include <rpc/pmap_prot.h>
36 #include <rpc/pmap_clnt.h>
43 #ifdef HAVE_RPCSVC_NFS_PROT_H
44 #include <rpcsvc/nfs_prot.h>
46 #include <linux/nfs.h>
47 #define nfsstat nfs_stat
50 extern char *progname;
52 static char errbuf[BUFSIZ];
53 static char *erreob = &errbuf[BUFSIZ];
55 /* Convert RPC errors into strings */
56 static int rpc_strerror(int spos)
58 int cf_stat = rpc_createerr.cf_stat;
59 int pos = 0, cf_errno = rpc_createerr.cf_error.re_errno;
60 char *ptr, *estr = clnt_sperrno(cf_stat);
64 if ((ptr = index(estr, ':')))
68 if (cf_stat == RPC_SYSTEMERROR)
69 pos = snprintf(tmp, (erreob - tmp),
70 _("System Error: %s"),
73 pos = snprintf(tmp, (erreob - tmp),
74 _("RPC Error:%s"), estr);
79 void mount_errors(char *server, int will_retry, int bg)
83 static int onlyonce = 0;
87 pos = snprintf(tmp, (erreob - tmp),
88 _("mount to NFS server '%s' failed: "),
91 pos = snprintf(tmp, (erreob - tmp),
92 _("%s: mount to NFS server '%s' failed: "),
96 if (rpc_createerr.cf_stat == RPC_TIMEDOUT) {
98 pos = snprintf(tmp, (erreob - tmp),
99 _("timed out, retrying"));
101 pos = snprintf(tmp, (erreob - tmp),
102 _("timed out, giving up"));
104 pos += rpc_strerror(pos);
108 pos = snprintf(tmp, (erreob - tmp),
111 pos = snprintf(tmp, (erreob - tmp),
118 openlog("mount", LOG_CONS|LOG_PID, LOG_AUTH);
119 syslog(LOG_ERR, "%s", errbuf);
121 fprintf(stderr, "%s\n", errbuf);
124 void mount_error(const char *spec, const char *mount_point, int error)
128 nfs_error(_("%s: mount point %s is not a directory"),
129 progname, mount_point);
132 nfs_error(_("%s: %s is already mounted or busy"),
133 progname, mount_point);
137 nfs_error(_("%s: mounting %s failed, "
138 "reason given by server:\n %s"),
139 progname, spec, strerror(error));
141 nfs_error(_("%s: mount point %s does not exist"),
142 progname, mount_point);
145 nfs_error(_("%s: %s"),
146 progname, strerror(error));
151 * Report a failed umount
153 void umount_error(int err, const char *dev)
157 nfs_error(_("%s: %s: invalid block device"),
161 nfs_error(_("%s: %s: not mounted"),
165 nfs_error(_("%s: %s: can't write superblock"),
169 nfs_error(_("%s: %s: device is busy"),
173 nfs_error(_("%s: %s: not found"),
177 nfs_error(_("%s: %s: must be superuser to umount"),
181 nfs_error(_("%s: %s: block devices not permitted on fs"),
185 nfs_error(_("%s: %s: %s"),
186 progname, dev, strerror(err));
192 * We need to translate between nfs status return values and
193 * the local errno values which may not be the same.
195 * Andreas Schwab <schwab@LS5.informatik.uni-dortmund.de>: change errno:
196 * "after #include <errno.h> the symbol errno is reserved for any use,
197 * it cannot even be used as a struct tag or field name".
201 #define EDQUOT ENOSPC
209 { NFSERR_PERM, EPERM },
210 { NFSERR_NOENT, ENOENT },
212 { NFSERR_NXIO, ENXIO },
213 { NFSERR_ACCES, EACCES },
214 { NFSERR_EXIST, EEXIST },
215 { NFSERR_NODEV, ENODEV },
216 { NFSERR_NOTDIR, ENOTDIR },
217 { NFSERR_ISDIR, EISDIR },
219 { NFSERR_INVAL, EINVAL }, /* that Sun forgot */
221 { NFSERR_FBIG, EFBIG },
222 { NFSERR_NOSPC, ENOSPC },
223 { NFSERR_ROFS, EROFS },
224 { NFSERR_NAMETOOLONG, ENAMETOOLONG },
225 { NFSERR_NOTEMPTY, ENOTEMPTY },
226 { NFSERR_DQUOT, EDQUOT },
227 { NFSERR_STALE, ESTALE },
229 { NFSERR_WFLUSH, EWFLUSH },
231 /* Throw in some NFSv3 values for even more fun (HP returns these) */
237 char *nfs_strerror(int stat)
240 static char buf[256];
242 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
243 if (nfs_errtbl[i].stat == stat)
244 return strerror(nfs_errtbl[i].errnum);
246 sprintf(buf, _("unknown nfs status return value: %d"), stat);