2 * Copyright (C) 2010 Karel Zak <kzak@redhat.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 021110-1307, USA.
29 #include <sys/types.h>
33 #include "nfs_mount.h"
41 #include "parse_dev.h"
44 extern char *progname;
47 * Choose the version of the nfs_mount_data structure that is appropriate
48 * for the kernel that is doing the mount.
50 * NFS_MOUNT_VERSION: maximum version supported by these sources
51 * nfs_mount_data_version: maximum version supported by the running kernel
53 int discover_nfs_mount_data_version(int *string_ver)
55 unsigned int kernel_version = linux_version_code();
61 if (kernel_version < MAKE_VERSION(2, 1, 32))
63 else if (kernel_version < MAKE_VERSION(2, 2, 18))
65 else if (kernel_version < MAKE_VERSION(2, 3, 0))
67 else if (kernel_version < MAKE_VERSION(2, 3, 99))
69 else if (kernel_version < MAKE_VERSION(2, 6, 3))
74 if (ver > NFS_MOUNT_VERSION)
75 ver = NFS_MOUNT_VERSION;
77 if (kernel_version > MAKE_VERSION(2, 6, 22))
83 void print_one(char *spec, char *node, char *type, char *opts)
89 printf(_("%s on %s type %s (%s)\n"), spec, node, type, opts);
91 printf(_("%s on %s type %s\n"), spec, node, type);
94 void mount_usage(void)
96 printf(_("usage: %s remotetarget dir [-rvVwfnsih] [-o nfsoptions]\n"),
98 printf(_("options:\n"));
99 printf(_("\t-r\t\tMount file system readonly\n"));
100 printf(_("\t-v\t\tVerbose\n"));
101 printf(_("\t-V\t\tPrint version\n"));
102 printf(_("\t-w\t\tMount file system read-write\n"));
103 printf(_("\t-f\t\tFake mount, do not actually mount\n"));
104 printf(_("\t-n\t\tDo not update /etc/mtab\n"));
105 printf(_("\t-s\t\tTolerate sloppy mount options rather than fail\n"));
106 printf(_("\t-h\t\tPrint this help\n"));
107 printf(_("\tnfsoptions\tRefer to mount.nfs(8) or nfs(5)\n\n"));
110 void umount_usage(void)
112 printf(_("usage: %s dir [-fvnrlh]\n"), progname);
113 printf(_("options:\n\t-f\t\tforce unmount\n"));
114 printf(_("\t-v\tverbose\n"));
115 printf(_("\t-n\tDo not update /etc/mtab\n"));
116 printf(_("\t-r\tremount\n"));
117 printf(_("\t-l\tlazy unmount\n"));
118 printf(_("\t-h\tprint this help\n\n"));
121 int chk_mountpoint(const char *mount_point)
125 if (stat(mount_point, &sb) < 0){
126 mount_error(NULL, mount_point, errno);
129 if (S_ISDIR(sb.st_mode) == 0){
130 mount_error(NULL, mount_point, ENOTDIR);
133 if (access(mount_point, X_OK) < 0) {
134 mount_error(NULL, mount_point, errno);
142 * Pick up certain mount options used during the original mount
143 * from /etc/mtab. The basics include the server's IP address and
144 * the server pathname of the share to unregister.
146 * These options might also describe the mount port, mount protocol
147 * version, and transport protocol used to punch through a firewall.
148 * We will need this information to get through the firewall again
151 * Note that option parsing failures won't necessarily cause the
152 * umount request to fail. Those values will be left zero in the
153 * pmap tuple. If the GETPORT call later fails to disambiguate them,
156 int nfs_umount23(const char *devname, char *string)
158 char *hostname = NULL, *dirname = NULL;
159 struct mount_options *options;
160 int result = EX_FAIL;
162 if (!nfs_parse_devname(devname, &hostname, &dirname))
165 options = po_split(string);
167 result = nfs_umount_do_umnt(options, &hostname, &dirname);
170 nfs_error(_("%s: option parsing error"), progname);