]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/mount/stropts.c
text-based mount command: support AF_INET6 in rewrite_mount_options()
[nfs-utils.git] / utils / mount / stropts.c
1 /*
2  * stropts.c -- NFS mount using C string to pass options to kernel
3  *
4  * Copyright (C) 2007 Oracle.  All rights reserved.
5  * Copyright (C) 2007 Chuck Lever <chuck.lever@oracle.com>
6  *
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.
11  *
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.
16  *
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.
21  *
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <unistd.h>
29 #include <errno.h>
30 #include <netdb.h>
31 #include <time.h>
32
33 #include <sys/socket.h>
34 #include <sys/mount.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
37
38 #include "xcommon.h"
39 #include "mount.h"
40 #include "nls.h"
41 #include "mount_constants.h"
42 #include "stropts.h"
43 #include "error.h"
44 #include "network.h"
45 #include "parse_opt.h"
46 #include "version.h"
47 #include "parse_dev.h"
48
49 #ifndef NFS_PROGRAM
50 #define NFS_PROGRAM     (100003)
51 #endif
52
53 #ifndef NFS_PORT
54 #define NFS_PORT        (2049)
55 #endif
56
57 #ifndef NFS_MAXHOSTNAME
58 #define NFS_MAXHOSTNAME         (255)
59 #endif
60
61 #ifndef NFS_MAXPATHNAME
62 #define NFS_MAXPATHNAME         (1024)
63 #endif
64
65 #ifndef NFS_DEF_FG_TIMEOUT_MINUTES
66 #define NFS_DEF_FG_TIMEOUT_MINUTES      (2u)
67 #endif
68
69 #ifndef NFS_DEF_BG_TIMEOUT_MINUTES
70 #define NFS_DEF_BG_TIMEOUT_MINUTES      (10000u)
71 #endif
72
73 extern int nfs_mount_data_version;
74 extern char *progname;
75 extern int verbose;
76 extern int sloppy;
77
78 struct nfsmount_info {
79         const char              *spec,          /* server:/path */
80                                 *node,          /* mounted-on dir */
81                                 *type;          /* "nfs" or "nfs4" */
82         char                    *hostname;      /* server's hostname */
83
84         struct mount_options    *options;       /* parsed mount options */
85         char                    **extra_opts;   /* string for /etc/mtab */
86
87         int                     flags,          /* MS_ flags */
88                                 fake,           /* actually do the mount? */
89                                 child;          /* forked bg child? */
90
91         sa_family_t             family;         /* supported address family */
92 };
93
94 /*
95  * Obtain a retry timeout value based on the value of the "retry=" option.
96  *
97  * Returns a time_t timeout timestamp, in seconds.
98  */
99 static time_t nfs_parse_retry_option(struct mount_options *options,
100                                      unsigned int timeout_minutes)
101 {
102         long tmp;
103
104         switch (po_get_numeric(options, "retry", &tmp)) {
105         case PO_NOT_FOUND:
106                 break;
107         case PO_FOUND:
108                 if (tmp >= 0) {
109                         timeout_minutes = tmp;
110                         break;
111                 }
112         case PO_BAD_VALUE:
113                 if (verbose)
114                         nfs_error(_("%s: invalid retry timeout was specified; "
115                                         "using default timeout"), progname);
116                 break;
117         }
118
119         return time(NULL) + (time_t)(timeout_minutes * 60);
120 }
121
122 /*
123  * Convert the passed-in sockaddr-style address to presentation
124  * format, then append an option of the form "keyword=address".
125  *
126  * Returns 1 if the option was appended successfully; otherwise zero.
127  */
128 static int nfs_append_generic_address_option(const struct sockaddr *sap,
129                                              const socklen_t salen,
130                                              const char *keyword,
131                                              struct mount_options *options)
132 {
133         char address[NI_MAXHOST];
134         char new_option[512];
135
136         if (!nfs_present_sockaddr(sap, salen, address, sizeof(address)))
137                 goto out_err;
138
139         if (snprintf(new_option, sizeof(new_option), "%s=%s",
140                                         keyword, address) >= sizeof(new_option))
141                 goto out_err;
142
143         if (po_append(options, new_option) != PO_SUCCEEDED)
144                 goto out_err;
145
146         return 1;
147
148 out_err:
149         nfs_error(_("%s: failed to construct %s option"), progname, keyword);
150         return 0;
151 }
152
153 /*
154  * Append the 'addr=' option to the options string to pass a resolved
155  * server address to the kernel.  After a successful mount, this address
156  * is also added to /etc/mtab for use when unmounting.
157  *
158  * If 'addr=' is already present, we strip it out.  This prevents users
159  * from setting a bogus 'addr=' option themselves, and also allows bg
160  * retries to recompute the server's address, in case it has changed.
161  *
162  * Returns 1 if 'addr=' option appended successfully;
163  * otherwise zero.
164  */
165 static int nfs_append_addr_option(const struct sockaddr *sap,
166                                   socklen_t salen,
167                                   struct mount_options *options)
168 {
169         po_remove_all(options, "addr");
170         return nfs_append_generic_address_option(sap, salen, "addr", options);
171 }
172
173 /*
174  * Called to discover our address and append an appropriate 'clientaddr='
175  * option to the options string.
176  *
177  * Returns 1 if 'clientaddr=' option created successfully or if
178  * 'clientaddr=' option is already present; otherwise zero.
179  */
180 static int nfs_append_clientaddr_option(const struct sockaddr *sap,
181                                         socklen_t salen,
182                                         struct mount_options *options)
183 {
184         struct sockaddr_storage dummy;
185         struct sockaddr *my_addr = (struct sockaddr *)&dummy;
186         socklen_t my_len = sizeof(dummy);
187
188         if (po_contains(options, "clientaddr") == PO_FOUND)
189                 return 1;
190
191         nfs_callback_address(sap, salen, my_addr, &my_len);
192
193         return nfs_append_generic_address_option(my_addr, my_len,
194                                                         "clientaddr", options);
195 }
196
197 /*
198  * Resolve the 'mounthost=' hostname and append a new option using
199  * the resulting address.
200  */
201 static int nfs_fix_mounthost_option(const sa_family_t family,
202                                     struct mount_options *options)
203 {
204         struct sockaddr_storage dummy;
205         struct sockaddr *sap = (struct sockaddr *)&dummy;
206         socklen_t salen = sizeof(dummy);
207         char *mounthost;
208
209         mounthost = po_get(options, "mounthost");
210         if (!mounthost)
211                 return 1;
212
213         if (!nfs_name_to_address(mounthost, family, sap, &salen)) {
214                 nfs_error(_("%s: unable to determine mount server's address"),
215                                 progname);
216                 return 0;
217         }
218
219         return nfs_append_generic_address_option(sap, salen,
220                                                         "mountaddr", options);
221 }
222
223 /*
224  * Returns zero if the "lock" option is in effect, but statd
225  * can't be started.  Otherwise, returns 1.
226  */
227 static const char *nfs_lock_opttbl[] = {
228         "nolock",
229         "lock",
230         NULL,
231 };
232
233 static int nfs_verify_lock_option(struct mount_options *options)
234 {
235         if (po_rightmost(options, nfs_lock_opttbl) == 1)
236                 return 1;
237
238         if (!start_statd()) {
239                 nfs_error(_("%s: rpc.statd is not running but is "
240                             "required for remote locking."), progname);
241                 nfs_error(_("%s: Either use '-o nolock' to keep "
242                             "locks local, or start statd."), progname);
243                 return 0;
244         }
245
246         return 1;
247 }
248
249 static int nfs_append_sloppy_option(struct mount_options *options)
250 {
251         if (!sloppy || linux_version_code() < MAKE_VERSION(2, 6, 27))
252                 return 1;
253
254         if (po_append(options, "sloppy") == PO_FAILED)
255                 return 0;
256         return 1;
257 }
258
259 /*
260  * Set up mandatory NFS mount options.
261  *
262  * Returns 1 if successful; otherwise zero.
263  */
264 static int nfs_validate_options(struct nfsmount_info *mi)
265 {
266         struct sockaddr_storage dummy;
267         struct sockaddr *sap = (struct sockaddr *)&dummy;
268         socklen_t salen = sizeof(dummy);
269
270         if (!nfs_parse_devname(mi->spec, &mi->hostname, NULL))
271                 return 0;
272
273         if (!nfs_name_to_address(mi->hostname, mi->family, sap, &salen))
274                 return 0;
275
276         if (strncmp(mi->type, "nfs4", 4) == 0) {
277                 if (!nfs_append_clientaddr_option(sap, salen, mi->options))
278                         return 0;
279         } else {
280                 if (!nfs_fix_mounthost_option(mi->family, mi->options))
281                         return 0;
282                 if (!mi->fake && !nfs_verify_lock_option(mi->options))
283                         return 0;
284         }
285
286         if (!nfs_append_sloppy_option(mi->options))
287                 return 0;
288
289         return nfs_append_addr_option(sap, salen, mi->options);
290 }
291
292 /*
293  * Distinguish between permanent and temporary errors.
294  *
295  * Returns 0 if the passed-in error is temporary, thus the
296  * mount system call should be retried; returns one if the
297  * passed-in error is permanent, thus the mount system call
298  * should not be retried.
299  */
300 static int nfs_is_permanent_error(int error)
301 {
302         switch (error) {
303         case ESTALE:
304         case ETIMEDOUT:
305         case ECONNREFUSED:
306                 return 0;       /* temporary */
307         default:
308                 return 1;       /* permanent */
309         }
310 }
311
312 /*
313  * Get NFS/mnt server addresses from mount options
314  *
315  * Returns 1 and fills in @nfs_saddr, @nfs_salen, @mnt_saddr, and @mnt_salen
316  * if all goes well; otherwise zero.
317  */
318 static int nfs_extract_server_addresses(struct mount_options *options,
319                                         struct sockaddr *nfs_saddr,
320                                         socklen_t *nfs_salen,
321                                         struct sockaddr *mnt_saddr,
322                                         socklen_t *mnt_salen)
323 {
324         char *option;
325
326         option = po_get(options, "addr");
327         if (option == NULL)
328                 return 0;
329         if (!nfs_string_to_sockaddr(option, strlen(option),
330                                                 nfs_saddr, nfs_salen))
331                 return 0;
332
333         option = po_get(options, "mountaddr");
334         if (option == NULL)
335                 memcpy(mnt_saddr, nfs_saddr, *nfs_salen);
336         else if (!nfs_string_to_sockaddr(option, strlen(option),
337                                                 mnt_saddr, mnt_salen))
338                 return 0;
339
340         return 1;
341 }
342
343 static int nfs_construct_new_options(struct mount_options *options,
344                                      struct pmap *nfs_pmap,
345                                      struct pmap *mnt_pmap)
346 {
347         char new_option[64];
348
349         po_remove_all(options, "nfsprog");
350         po_remove_all(options, "mountprog");
351
352         po_remove_all(options, "v2");
353         po_remove_all(options, "v3");
354         po_remove_all(options, "vers");
355         po_remove_all(options, "nfsvers");
356         snprintf(new_option, sizeof(new_option) - 1,
357                  "vers=%lu", nfs_pmap->pm_vers);
358         if (po_append(options, new_option) == PO_FAILED)
359                 return 0;
360
361         po_remove_all(options, "proto");
362         po_remove_all(options, "udp");
363         po_remove_all(options, "tcp");
364         switch (nfs_pmap->pm_prot) {
365         case IPPROTO_TCP:
366                 snprintf(new_option, sizeof(new_option) - 1,
367                          "proto=tcp");
368                 if (po_append(options, new_option) == PO_FAILED)
369                         return 0;
370                 break;
371         case IPPROTO_UDP:
372                 snprintf(new_option, sizeof(new_option) - 1,
373                          "proto=udp");
374                 if (po_append(options, new_option) == PO_FAILED)
375                         return 0;
376                 break;
377         }
378
379         po_remove_all(options, "port");
380         if (nfs_pmap->pm_port != NFS_PORT) {
381                 snprintf(new_option, sizeof(new_option) - 1,
382                          "port=%lu", nfs_pmap->pm_port);
383                 if (po_append(options, new_option) == PO_FAILED)
384                         return 0;
385         }
386
387         po_remove_all(options, "mountvers");
388         snprintf(new_option, sizeof(new_option) - 1,
389                  "mountvers=%lu", mnt_pmap->pm_vers);
390         if (po_append(options, new_option) == PO_FAILED)
391                 return 0;
392
393         po_remove_all(options, "mountproto");
394         switch (mnt_pmap->pm_prot) {
395         case IPPROTO_TCP:
396                 snprintf(new_option, sizeof(new_option) - 1,
397                          "mountproto=tcp");
398                 if (po_append(options, new_option) == PO_FAILED)
399                         return 0;
400                 break;
401         case IPPROTO_UDP:
402                 snprintf(new_option, sizeof(new_option) - 1,
403                          "mountproto=udp");
404                 if (po_append(options, new_option) == PO_FAILED)
405                         return 0;
406                 break;
407         }
408
409         po_remove_all(options, "mountport");
410         snprintf(new_option, sizeof(new_option) - 1,
411                  "mountport=%lu", mnt_pmap->pm_port);
412         if (po_append(options, new_option) == PO_FAILED)
413                 return 0;
414
415         return 1;
416 }
417
418 /*
419  * Reconstruct the mount option string based on a portmapper probe
420  * of the server.  Returns one if the server's portmapper returned
421  * something we can use, otherwise zero.
422  *
423  * To handle version and transport protocol fallback properly, we
424  * need to parse some of the mount options in order to set up a
425  * portmap probe.  Mount options that nfs_rewrite_mount_options()
426  * doesn't recognize are left alone.
427  *
428  * Returns a new group of mount options if successful; otherwise
429  * NULL is returned if some failure occurred.
430  */
431 static struct mount_options *nfs_rewrite_mount_options(char *str)
432 {
433         struct mount_options *options;
434         struct sockaddr_storage nfs_address;
435         struct sockaddr *nfs_saddr = (struct sockaddr *)&nfs_address;
436         socklen_t nfs_salen;
437         struct pmap nfs_pmap;
438         struct sockaddr_storage mnt_address;
439         struct sockaddr *mnt_saddr = (struct sockaddr *)&mnt_address;
440         socklen_t mnt_salen;
441         struct pmap mnt_pmap;
442
443         options = po_split(str);
444         if (!options) {
445                 errno = EFAULT;
446                 return NULL;
447         }
448
449         if (!nfs_extract_server_addresses(options, nfs_saddr, &nfs_salen,
450                                                 mnt_saddr, &mnt_salen)) {
451                 errno = EINVAL;
452                 goto err;
453         }
454
455         nfs_options2pmap(options, &nfs_pmap, &mnt_pmap);
456
457         /* The kernel NFS client doesn't support changing the RPC program
458          * number for these services, so reset these fields before probing
459          * the server's ports.  */
460         nfs_pmap.pm_prog = NFS_PROGRAM;
461         mnt_pmap.pm_prog = MOUNTPROG;
462
463         if (!nfs_probe_bothports(mnt_saddr, mnt_salen, &mnt_pmap,
464                                  nfs_saddr, nfs_salen, &nfs_pmap)) {
465                 errno = ESPIPE;
466                 goto err;
467         }
468
469         if (!nfs_construct_new_options(options, &nfs_pmap, &mnt_pmap)) {
470                 errno = EINVAL;
471                 goto err;
472         }
473
474         errno = 0;
475         return options;
476
477 err:
478         po_destroy(options);
479         return NULL;
480 }
481
482 /*
483  * Do the mount(2) system call.
484  *
485  * Returns 1 if successful, otherwise zero.
486  * "errno" is set to reflect the individual error.
487  */
488 static int nfs_sys_mount(const struct nfsmount_info *mi, const char *type,
489                          const char *options)
490 {
491         int result;
492
493         result = mount(mi->spec, mi->node, type,
494                                 mi->flags & ~(MS_USER|MS_USERS), options);
495         if (verbose && result) {
496                 int save = errno;
497                 nfs_error(_("%s: mount(2): %s"), progname, strerror(save));
498                 errno = save;
499         }
500         return !result;
501 }
502
503 /*
504  * Retry an NFS mount that failed because the requested service isn't
505  * available on the server.
506  *
507  * Returns 1 if successful.  Otherwise, returns zero.
508  * "errno" is set to reflect the individual error.
509  *
510  * Side effect: If the retry is successful, both 'options' and
511  * 'extra_opts' are updated to reflect the mount options that worked.
512  * If the retry fails, 'options' and 'extra_opts' are left unchanged.
513  */
514 static int nfs_retry_nfs23mount(struct nfsmount_info *mi)
515 {
516         struct mount_options *retry_options;
517         char *retry_str = NULL;
518         char **extra_opts = mi->extra_opts;
519
520         retry_options = nfs_rewrite_mount_options(*extra_opts);
521         if (!retry_options)
522                 return 0;
523
524         if (po_join(retry_options, &retry_str) == PO_FAILED) {
525                 po_destroy(retry_options);
526                 errno = EIO;
527                 return 0;
528         }
529
530         if (verbose)
531                 printf(_("%s: text-based options (retry): '%s'\n"),
532                         progname, retry_str);
533
534         if (!nfs_sys_mount(mi, "nfs", retry_str)) {
535                 po_destroy(retry_options);
536                 free(retry_str);
537                 return 0;
538         }
539
540         free(*extra_opts);
541         *extra_opts = retry_str;
542         po_replace(mi->options, retry_options);
543         return 1;
544 }
545
546 /*
547  * Attempt an NFSv2/3 mount via a mount(2) system call.  If the kernel
548  * claims the requested service isn't supported on the server, probe
549  * the server to see what's supported, rewrite the mount options,
550  * and retry the request.
551  *
552  * Returns 1 if successful.  Otherwise, returns zero.
553  * "errno" is set to reflect the individual error.
554  *
555  * Side effect: If the retry is successful, both 'options' and
556  * 'extra_opts' are updated to reflect the mount options that worked.
557  * If the retry fails, 'options' and 'extra_opts' are left unchanged.
558  */
559 static int nfs_try_nfs23mount(struct nfsmount_info *mi)
560 {
561         char **extra_opts = mi->extra_opts;
562
563         if (po_join(mi->options, extra_opts) == PO_FAILED) {
564                 errno = EIO;
565                 return 0;
566         }
567
568         if (verbose)
569                 printf(_("%s: text-based options: '%s'\n"),
570                         progname, *extra_opts);
571
572         if (mi->fake)
573                 return 1;
574
575         if (nfs_sys_mount(mi, "nfs", *extra_opts))
576                 return 1;
577
578         /*
579          * The kernel returns EOPNOTSUPP if the RPC bind failed,
580          * and EPROTONOSUPPORT if the version isn't supported.
581          */
582         if (errno != EOPNOTSUPP && errno != EPROTONOSUPPORT)
583                 return 0;
584
585         return nfs_retry_nfs23mount(mi);
586 }
587
588 /*
589  * Attempt an NFS v4 mount via a mount(2) system call.
590  *
591  * Returns 1 if successful.  Otherwise, returns zero.
592  * "errno" is set to reflect the individual error.
593  */
594 static int nfs_try_nfs4mount(struct nfsmount_info *mi)
595 {
596         char **extra_opts = mi->extra_opts;
597
598         if (po_join(mi->options, extra_opts) == PO_FAILED) {
599                 errno = EIO;
600                 return 0;
601         }
602
603         if (verbose)
604                 printf(_("%s: text-based options: '%s'\n"),
605                         progname, *extra_opts);
606
607         if (mi->fake)
608                 return 1;
609
610         return nfs_sys_mount(mi, "nfs4", *extra_opts);
611 }
612
613 /*
614  * Perform either an NFSv2/3 mount, or an NFSv4 mount system call.
615  *
616  * Returns 1 if successful.  Otherwise, returns zero.
617  * "errno" is set to reflect the individual error.
618  */
619 static int nfs_try_mount(struct nfsmount_info *mi)
620 {
621         if (strncmp(mi->type, "nfs4", 4) == 0)
622                 return nfs_try_nfs4mount(mi);
623         else
624                 return nfs_try_nfs23mount(mi);
625 }
626
627 /*
628  * Handle "foreground" NFS mounts.
629  *
630  * Retry the mount request for as long as the 'retry=' option says.
631  *
632  * Returns a valid mount command exit code.
633  */
634 static int nfsmount_fg(struct nfsmount_info *mi)
635 {
636         unsigned int secs = 1;
637         time_t timeout;
638
639         timeout = nfs_parse_retry_option(mi->options,
640                                          NFS_DEF_FG_TIMEOUT_MINUTES);
641         if (verbose)
642                 printf(_("%s: timeout set for %s"),
643                         progname, ctime(&timeout));
644
645         for (;;) {
646                 if (nfs_try_mount(mi))
647                         return EX_SUCCESS;
648
649                 if (nfs_is_permanent_error(errno))
650                         break;
651
652                 if (time(NULL) > timeout) {
653                         errno = ETIMEDOUT;
654                         break;
655                 }
656
657                 if (errno != ETIMEDOUT) {
658                         if (sleep(secs))
659                                 break;
660                         secs <<= 1;
661                         if (secs > 10)
662                                 secs = 10;
663                 }
664         };
665
666         mount_error(mi->spec, mi->node, errno);
667         return EX_FAIL;
668 }
669
670 /*
671  * Handle "background" NFS mount [first try]
672  *
673  * Returns a valid mount command exit code.
674  *
675  * EX_BG should cause the caller to fork and invoke nfsmount_child.
676  */
677 static int nfsmount_parent(struct nfsmount_info *mi)
678 {
679         if (nfs_try_mount(mi))
680                 return EX_SUCCESS;
681
682         if (nfs_is_permanent_error(errno)) {
683                 mount_error(mi->spec, mi->node, errno);
684                 return EX_FAIL;
685         }
686
687         sys_mount_errors(mi->hostname, errno, 1, 1);
688         return EX_BG;
689 }
690
691 /*
692  * Handle "background" NFS mount [retry daemon]
693  *
694  * Returns a valid mount command exit code: EX_SUCCESS if successful,
695  * EX_FAIL if a failure occurred.  There's nothing to catch the
696  * error return, though, so we use sys_mount_errors to log the
697  * failure.
698  */
699 static int nfsmount_child(struct nfsmount_info *mi)
700 {
701         unsigned int secs = 1;
702         time_t timeout;
703
704         timeout = nfs_parse_retry_option(mi->options,
705                                          NFS_DEF_BG_TIMEOUT_MINUTES);
706
707         for (;;) {
708                 if (sleep(secs))
709                         break;
710                 secs <<= 1;
711                 if (secs > 120)
712                         secs = 120;
713
714                 if (nfs_try_mount(mi))
715                         return EX_SUCCESS;
716
717                 if (nfs_is_permanent_error(errno))
718                         break;
719
720                 if (time(NULL) > timeout)
721                         break;
722
723                 sys_mount_errors(mi->hostname, errno, 1, 1);
724         };
725
726         sys_mount_errors(mi->hostname, errno, 1, 0);
727         return EX_FAIL;
728 }
729
730 /*
731  * Handle "background" NFS mount
732  *
733  * Returns a valid mount command exit code.
734  */
735 static int nfsmount_bg(struct nfsmount_info *mi)
736 {
737         if (!mi->child)
738                 return nfsmount_parent(mi);
739         else
740                 return nfsmount_child(mi);
741 }
742
743 /*
744  * Process mount options and try a mount system call.
745  *
746  * Returns a valid mount command exit code.
747  */
748 static const char *nfs_background_opttbl[] = {
749         "bg",
750         "fg",
751         NULL,
752 };
753
754 static int nfsmount_start(struct nfsmount_info *mi)
755 {
756         if (!nfs_validate_options(mi))
757                 return EX_FAIL;
758
759         if (po_rightmost(mi->options, nfs_background_opttbl) == 1)
760                 return nfsmount_bg(mi);
761         else
762                 return nfsmount_fg(mi);
763 }
764
765 /**
766  * nfsmount_string - Mount an NFS file system using C string options
767  * @spec: C string specifying remote share to mount ("hostname:path")
768  * @node: C string pathname of local mounted-on directory
769  * @type: C string that represents file system type ("nfs" or "nfs4")
770  * @flags: MS_ style mount flags
771  * @extra_opts: pointer to C string containing fs-specific mount options
772  *              (input and output argument)
773  * @fake: flag indicating whether to carry out the whole operation
774  * @child: one if this is a mount daemon (bg)
775  */
776 int nfsmount_string(const char *spec, const char *node, const char *type,
777                     int flags, char **extra_opts, int fake, int child)
778 {
779         struct nfsmount_info mi = {
780                 .spec           = spec,
781                 .node           = node,
782                 .type           = type,
783                 .extra_opts     = extra_opts,
784                 .flags          = flags,
785                 .fake           = fake,
786                 .child          = child,
787 #ifdef IPV6_SUPPORTED
788                 .family         = AF_UNSPEC,    /* either IPv4 or v6 */
789 #else
790                 .family         = AF_INET,      /* only IPv4 */
791 #endif
792         };
793         int retval = EX_FAIL;
794
795         mi.options = po_split(*extra_opts);
796         if (mi.options) {
797                 retval = nfsmount_start(&mi);
798                 po_destroy(mi.options);
799         } else
800                 nfs_error(_("%s: internal option parsing error"), progname);
801
802         free(mi.hostname);
803         return retval;
804 }