+ if (fake)
+ return 1;
+
+ if (!mount(spec, node, "nfs",
+ flags & ~(MS_USER|MS_USERS), *extra_opts))
+ return 1;
+
+ /*
+ * The kernel returns EOPNOTSUPP if the RPC bind failed,
+ * and EPROTONOSUPPORT if the version isn't supported.
+ */
+ if (errno != EOPNOTSUPP && errno != EPROTONOSUPPORT)
+ return 0;
+
+ return retry_nfsmount(spec, node, flags, options, fake, extra_opts);
+}
+
+/*
+ * Attempt an NFS v4 mount via a mount(2) system call.
+ *
+ * Returns 1 if successful. Otherwise, returns zero.
+ * "errno" is set to reflect the individual error.
+ */
+static int try_nfs4mount(const char *spec, const char *node,
+ int flags, struct mount_options *options,
+ int fake, char **extra_opts)
+{
+ if (po_join(options, extra_opts) == PO_FAILED) {
+ errno = EIO;
+ return 0;
+ }
+
+ if (verbose)
+ printf(_("%s: text-based options: '%s'\n"),
+ progname, *extra_opts);
+
+ if (fake)
+ return 1;
+
+ if (!mount(spec, node, "nfs4",
+ flags & ~(MS_USER|MS_USERS), *extra_opts))
+ return 1;
+ return 0;
+}
+
+/*
+ * Try the mount(2) system call.
+ *
+ * Returns 1 if successful. Otherwise, returns zero.
+ * "errno" is set to reflect the individual error.
+ */
+static int try_mount(const char *spec, const char *node, const char *type,
+ int flags, struct mount_options *options, int fake,
+ char **extra_opts)
+{
+ if (strncmp(type, "nfs4", 4) == 0)
+ return try_nfs4mount(spec, node, flags,
+ options, fake, extra_opts);
+ else
+ return try_nfs23mount(spec, node, flags,
+ options, fake, extra_opts);
+}
+
+/*
+ * Handle "foreground" NFS mounts.
+ *
+ * Retry the mount request for as long as the 'retry=' option says.
+ *
+ * Returns a valid mount command exit code.
+ */
+static int nfsmount_fg(const char *spec, const char *node,
+ const char *type, int flags,
+ struct mount_options *options, int fake,
+ char **extra_opts)
+{
+ unsigned int secs = 1;
+ time_t timeout = time(NULL);
+ char *retry;
+
+ timeout += 60 * 2; /* default: 2 minutes */
+ retry = po_get(options, "retry");
+ if (retry)
+ timeout += 60 * atoi(retry);
+
+ if (verbose)
+ printf(_("%s: timeout set for %s"),
+ progname, ctime(&timeout));
+
+ for (;;) {
+ if (try_mount(spec, node, type, flags,
+ options, fake, extra_opts))
+ return EX_SUCCESS;
+
+ if (is_permanent_error(errno))
+ break;
+
+ if (time(NULL) > timeout) {
+ errno = ETIMEDOUT;
+ break;