* mount.cc (NT_MAX_PATH): Define.

(longopts): Rename mount-commands option to mount-entries.
	(opts): Remove removed options.
	(struct opt): Move up in file to allow using it in usage.
	(usage): Change text for --mount-entries option.  Remove
	-X option.  Add valid options output.
	(main): Remove handling -b option.
	(convert_spaces): New static function to convert spaces to "\040"
	string.
	(mount_entries): Renamed from mount_commands.  Rewrite to emit
	/etc/fstab compatible output.
	(show_cygdrive_info): Print "nouser" rather than "system".
	* umount.cc (longopts): Remove remove-all-mounts,
	remove-cygdrive-prefix, remove-system-mounts, system and user options.
	(opts): Remove A, c, s, S, u options.
	(usage): Remove text for all removed options.
	(main): Remove handling for all removed options.
	(remove_all_mounts): Remove.
	(remove_all_system_mounts): Remove.
	(remove_cygdrive_prefix): Remove.
	* utils.sgml: Fix mount and umount documentation.  Move description
	of (cyg,not)exec options to mount table section.
This commit is contained in:
Corinna Vinschen 2008-08-13 16:35:04 +00:00
parent 04a6c4efd7
commit 56d8179570
4 changed files with 166 additions and 278 deletions

View File

@ -1,3 +1,28 @@
2008-08-13 Corinna Vinschen <corinna@vinschen.de>
* mount.cc (NT_MAX_PATH): Define.
(longopts): Rename mount-commands option to mount-entries.
(opts): Remove removed options.
(struct opt): Move up in file to allow using it in usage.
(usage): Change text for --mount-entries option. Remove
-X option. Add valid options output.
(main): Remove handling -b option.
(convert_spaces): New static function to convert spaces to "\040"
string.
(mount_entries): Renamed from mount_commands. Rewrite to emit
/etc/fstab compatible output.
(show_cygdrive_info): Print "nouser" rather than "system".
* umount.cc (longopts): Remove remove-all-mounts,
remove-cygdrive-prefix, remove-system-mounts, system and user options.
(opts): Remove A, c, s, S, u options.
(usage): Remove text for all removed options.
(main): Remove handling for all removed options.
(remove_all_mounts): Remove.
(remove_all_system_mounts): Remove.
(remove_cygdrive_prefix): Remove.
* utils.sgml: Fix mount and umount documentation. Move description
of (cyg,not)exec options to mount table section.
2008-08-04 Christopher Faylor <me+cygwin@cgf.cx>
* cygcheck.cc (load_cygwin): Duplicate argv list since it disappears

View File

@ -24,9 +24,11 @@ details. */
#endif
#include <errno.h>
#define NT_MAX_PATH 32768
#define EXEC_FLAGS (MOUNT_EXEC | MOUNT_NOTEXEC | MOUNT_CYGWIN_EXEC)
static void mount_commands (void);
static void mount_entries (void);
static void show_mounts (void);
static void show_cygdrive_info (void);
static void change_cygdrive_prefix (const char *new_prefix, int flags);
@ -114,14 +116,33 @@ static struct option longopts[] =
{"change-cygdrive-prefix", no_argument, NULL, 'c'},
{"force", no_argument, NULL, 'f'},
{"help", no_argument, NULL, 'h' },
{"mount-commands", no_argument, NULL, 'm'},
{"mount-entries", no_argument, NULL, 'm'},
{"options", required_argument, NULL, 'o'},
{"show-cygdrive-prefix", no_argument, NULL, 'p'},
{"version", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0}
};
static char opts[] = "bcfhmpstuvxEXo:";
static char opts[] = "cfhmpvo:";
struct opt
{
const char *name;
unsigned val;
bool clear;
} oopts[] =
{
{"binary", MOUNT_BINARY, false},
{"text", MOUNT_BINARY, true},
{"exec", MOUNT_EXEC, false},
{"notexec", MOUNT_NOTEXEC, false},
{"cygexec", MOUNT_CYGWIN_EXEC, false},
{"nosuid", 0, 0},
{"acl", MOUNT_NOACL, true},
{"noacl", MOUNT_NOACL, false},
{"posix=1", MOUNT_NOPOSIX, true},
{"posix=0", MOUNT_NOPOSIX, false},
};
static void
usage (FILE *where = stderr)
@ -133,34 +154,19 @@ Display information about mounted filesystems, or mount a filesystem\n\
-f, --force force mount, don't warn about missing mount\n\
point directories\n\
-h, --help output usage information and exit\n\
-m, --mount-commands write mount commands to replicate user and\n\
system mount points and cygdrive prefixes\n\
-m, --mount-entries write fstab entries to replicate mount points\n\
and cygdrive prefixes\n\
-o, --options X[,X...] specify mount options\n\
-p, --show-cygdrive-prefix show user and/or system cygdrive path prefix\n\
-v, --version output version information and exit\n\
-X, --cygwin-executable treat all files under mount point as cygwin\n\
executables\n\
", progname);
\n\
Valid options are:\n\n ", progname);
for (opt *o = oopts; o < (oopts + (sizeof (oopts) / sizeof (oopts[0]))); o++)
fprintf (where, "%s%s", o == oopts ? "" : ",", o->name);
fputs ("\n\n", where);
exit (where == stderr ? 1 : 0);
}
struct opt
{
const char *name;
unsigned val;
bool clear;
} oopts[] =
{
{"user", MOUNT_SYSTEM, true},
{"system", MOUNT_SYSTEM, false},
{"binary", MOUNT_BINARY, false},
{"text", MOUNT_BINARY, true},
{"exec", MOUNT_EXEC, false},
{"notexec", MOUNT_NOTEXEC, false},
{"cygexec", MOUNT_CYGWIN_EXEC, false},
{"nosuid", 0, 0}
};
static void
print_version ()
{
@ -223,9 +229,6 @@ main (int argc, char **argv)
while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
switch (i)
{
case 'b':
flags |= MOUNT_BINARY;
break;
case 'c':
if (do_what == nada)
do_what = saw_change_cygdrive_prefix;
@ -312,7 +315,7 @@ main (int argc, char **argv)
case saw_mount_commands:
if (optind <= argc)
usage ();
mount_commands ();
mount_entries ();
break;
default:
if (optind != (argc - 1))
@ -336,66 +339,63 @@ main (int argc, char **argv)
return 0;
}
static char *
convert_spaces (char *tgt, const char *src)
{
char *tp, *spacep;
const char *sp;
tp = tgt;
for (sp = src; (spacep = strchr (sp, ' ')); sp = spacep + 1)
{
tp = stpncpy (tp, sp, spacep - sp);
tp = stpcpy (tp, "\\040");
}
stpcpy (tp, sp);
return tgt;
}
static void
mount_commands (void)
mount_entries (void)
{
FILE *m = setmntent ("/-not-used-", "r");
struct mntent *p;
char *c;
const char *format_mnt = "mount%s \"%s\" \"%s\"\n";
const char *format_cyg = "mount%s --change-cygdrive-prefix \"%s\"\n";
char opts[MAX_PATH];
char user[MAX_PATH];
char system[MAX_PATH];
char user_flags[MAX_PATH];
char system_flags[MAX_PATH];
const char *format_mnt = "%s %s %s %s 0 0\n";
const char *format_cyg = "none %s cygdrive %s 0 0\n";
// write mount commands for user and system mount points
// write fstab entries for normal mount points
while ((p = getmntent (m)) != NULL)
// Only list non-cygdrives
if (!strstr (p->mnt_opts, ",noumount"))
{
strcpy(opts, " -f");
if (p->mnt_opts[0] == 'b')
strcat (opts, " -b");
else if (p->mnt_opts[0] == 't')
strcat (opts, " -t");
if (strstr (p->mnt_opts, ",exec"))
strcat (opts, " -x");
if (strstr (p->mnt_opts, ",noexec"))
strcat (opts, " -E");
if (strstr (p->mnt_opts, ",cygexec"))
strcat (opts, " -X");
while ((c = strchr (p->mnt_fsname, '\\')) != NULL)
*c = '/';
printf (format_mnt, opts, p->mnt_fsname, p->mnt_dir);
char fsname[NT_MAX_PATH], dirname[NT_MAX_PATH];
printf (format_mnt, convert_spaces (fsname, p->mnt_fsname),
convert_spaces (dirname, p->mnt_dir),
p->mnt_type, p->mnt_opts);
}
endmntent (m);
// write mount commands for cygdrive prefixes
cygwin_internal (CW_GET_CYGDRIVE_INFO, user, system, user_flags,
system_flags);
if (strlen (user) > 0)
// write fstab entry for cygdrive prefix
m = setmntent ("/-not-used-", "r");
while ((p = getmntent (m)) != NULL)
{
strcpy (opts, " -u");
if (user_flags[0] == 'b')
strcat (opts, " -b");
else if (user_flags[0] == 't')
strcat (opts, " -t");
printf (format_cyg, opts, user);
}
char *noumount;
if ((noumount = strstr (p->mnt_opts, ",noumount")))
{
char dirname[NT_MAX_PATH];
char opts[strlen (p->mnt_opts) + 1];
if (strlen (system) > 0)
{
strcpy (opts, " -s");
if (system_flags[0] == 'b')
strcat (opts, " -b");
else if (system_flags[0] == 't')
strcat (opts, " -t");
printf (format_cyg, opts, system);
convert_spaces (dirname, p->mnt_dir);
char *ls = strrchr (dirname, '/');
if (ls && ls > dirname)
*ls = '\0';
*stpncpy (opts, p->mnt_opts, noumount - p->mnt_opts) = '\0';
printf (format_cyg, dirname, opts);
break;
}
}
endmntent (m);
exit(0);
}
@ -493,7 +493,7 @@ show_cygdrive_info ()
if (strlen (user) > 0)
printf (format, user, "user", user_flags);
if (strlen (system) > 0)
printf (format, system, "system", system_flags);
printf (format, system, "nouser", system_flags);
exit (0);
}

View File

@ -1,6 +1,6 @@
/* umount.cc
Copyright 1996, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2008 Red Hat, Inc.
This file is part of Cygwin.
@ -16,10 +16,7 @@ details. */
#include <errno.h>
#include <getopt.h>
static void remove_all_mounts ();
static void remove_all_user_mounts ();
static void remove_all_system_mounts ();
static void remove_cygdrive_prefix (int flags);
static const char version[] = "$Revision$";
static const char *progname;
@ -27,17 +24,12 @@ static const char *progname;
struct option longopts[] =
{
{"help", no_argument, NULL, 'h' },
{"remove-all-mounts", no_argument, NULL, 'A'},
{"remove-cygdrive-prefix", no_argument, NULL, 'c'},
{"remove-system-mounts", no_argument, NULL, 'S'},
{"remove-user-mounts", no_argument, NULL, 'U'},
{"system", no_argument, NULL, 's'},
{"user", no_argument, NULL, 'u'},
{"version", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0}
};
char opts[] = "AchsSuUv";
char opts[] = "hUv";
static void
usage (FILE *where = stderr)
@ -46,12 +38,7 @@ usage (FILE *where = stderr)
Usage: %s [OPTION] [<posixpath>]\n\
Unmount filesystems\n\
\n\
-A, --remove-all-mounts remove all mounts\n\
-c, --remove-cygdrive-prefix remove cygdrive prefix\n\
-h, --help output usage information and exit\n\
-s, --system remove system mount (default)\n\
-S, --remove-system-mounts remove all system mounts\n\
-u, --user remove user mount\n\
-U, --remove-user-mounts remove all user mounts\n\
-v, --version output version information and exit\n\
", progname);
@ -97,9 +84,6 @@ main (int argc, char **argv)
enum do_what
{
nada,
saw_remove_all_mounts,
saw_remove_cygdrive_prefix,
saw_remove_all_system_mounts,
saw_remove_all_user_mounts
} do_what = nada;
@ -117,30 +101,8 @@ main (int argc, char **argv)
while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
switch (i)
{
case 'A':
if (do_what != nada)
usage ();
do_what = saw_remove_all_mounts;
break;
case 'c':
if (do_what != nada)
usage ();
do_what = saw_remove_cygdrive_prefix;
break;
case 'h':
usage (stdout);
case 's':
flags |= MOUNT_SYSTEM;
break;
case 'S':
if (do_what != nada)
usage ();
do_what = saw_remove_all_system_mounts;
break;
case 'u':
flags &= ~MOUNT_SYSTEM;
default_flag = 0;
break;
case 'U':
if (do_what != nada)
usage ();
@ -155,21 +117,6 @@ main (int argc, char **argv)
switch (do_what)
{
case saw_remove_all_mounts:
if (optind != argc)
usage ();
remove_all_mounts ();
break;
case saw_remove_cygdrive_prefix:
if (optind != argc)
usage ();
remove_cygdrive_prefix (flags | default_flag);
break;
case saw_remove_all_system_mounts:
if (optind != argc)
usage ();
remove_all_system_mounts ();
break;
case saw_remove_all_user_mounts:
if (optind != argc)
usage ();
@ -185,14 +132,6 @@ main (int argc, char **argv)
return 0;
}
/* remove_all_mounts: Unmount all mounts. */
static void
remove_all_mounts ()
{
remove_all_user_mounts ();
remove_all_system_mounts ();
}
/* remove_all_user_mounts: Unmount all user mounts. */
static void
remove_all_user_mounts ()
@ -217,38 +156,3 @@ remove_all_user_mounts ()
endmntent (m);
}
/* remove_all_system_mounts: Unmount all system mounts. */
static void
remove_all_system_mounts ()
{
FILE *m = setmntent ("/-not-used-", "r");
struct mntent *p;
while ((p = getmntent (m)) != NULL)
{
/* Remove the mount if it's a system mount. */
if (strncmp (p->mnt_type, "system", 6) == 0 &&
strstr (p->mnt_opts, "noumount") == NULL)
{
if (cygwin_umount (p->mnt_dir, MOUNT_SYSTEM))
error (p->mnt_dir);
/* We've modified the table so we need to start over. */
endmntent (m);
m = setmntent ("/-not-used-", "r");
}
}
endmntent (m);
}
/* remove_cygdrive_prefix: Remove cygdrive user or system path prefix. */
static void
remove_cygdrive_prefix (int flags)
{
int res = cygwin_umount (NULL, flags | MOUNT_CYGDRIVE);
if (res)
error ("remove_cygdrive_prefix");
exit (0);
}

View File

@ -702,33 +702,26 @@ up as file owners in <command>ls -l</command> output.
Usage: mount [OPTION] [&lt;win32path&gt; &lt;posixpath&gt;]
Display information about mounted filesystems, or mount a filesystem
-b, --binary (default) text files are equivalent to binary files
(newline = \n)
-c, --change-cygdrive-prefix change the cygdrive path prefix to &lt;posixpath&gt;
-f, --force force mount, don't warn about missing mount
point directories
-h, --help output usage information and exit
-m, --mount-commands write mount commands to replicate user and
system mount points and cygdrive prefixes
-m, --mount-entries write fstab entries to replicate mount points
and cygdrive prefixes
-o, --options X[,X...] specify mount options
-p, --show-cygdrive-prefix show user and/or system cygdrive path prefix
-s, --system (default) add system-wide mount point
-t, --text text files get \r\n line endings
-u, --user add user-only mount point
-v, --version output version information and exit
-x, --executable treat all files under mount point as executables
-E, --no-executable treat all files under mount point as
non-executables
-X, --cygwin-executable treat all files under mount point as cygwin
executables
</screen>
<para>The <command>mount</command> program is used to map your drives
and shares onto Cygwin's simulated POSIX directory tree, much like as is
done by mount commands on typical UNIX systems. Please see
<xref linkend="mount-table"></xref> for more information on the concepts
behind the Cygwin POSIX file system and strategies for using
mounts. To remove mounts, use <command>umount</command></para>
done by mount commands on typical UNIX systems. However, in contrast to
mount points given in <filename>/etc/fstab</filename>, mount points
created or changed with <command>mount</command> are not persistent. They
disappear immediately after the last process of the current user exited.
Please see <xref linkend="mount-table"></xref> for more information on the
concepts behind the Cygwin POSIX file system and strategies for using
mounts. To remove mounts temporarily, use <command>umount</command></para>
<sect3 id="utils-mount"><title>Using mount</title>
@ -739,11 +732,11 @@ will display the current mount table for you.</para>
<title>Displaying the current set of mount points</title>
<screen>
<prompt>c:\cygwin\&gt;</prompt> <userinput>mount</userinput>
c:\cygwin\bin on /usr/bin type system (binmode)
c:\cygwin\lib on /usr/lib type system (binmode)
c:\cygwin on / type system (binmode)
c: on /c type user (binmode,noumount)
d: on /d type user (binmode,noumount)
c:\cygwin\bin on /usr/bin type ntfs (binary)
c:\cygwin\lib on /usr/lib type ntfs (binary)
c:\cygwin on / type ntfs (binary)
c: on /c type ntfs (binary,user,noumount)
d: on /d type fat (binary,user,noumount)
</screen>
</example>
@ -756,7 +749,8 @@ to the current user.</para>
<para>The <command>mount</command> utility is also the mechanism for
adding new mounts to the mount table. The following example
demonstrates how to mount the directory
<filename>\\pollux\home\joe\data</filename> to <filename>/data</filename>.
<filename>\\pollux\home\joe\data</filename> to <filename>/data</filename>
for the duration of the current session.
</para>
<example id="utils-mount-add-ex">
@ -764,65 +758,25 @@ demonstrates how to mount the directory
<screen>
<prompt>c:\cygwin\&gt;</prompt> <userinput>ls /data</userinput>
ls: /data: No such file or directory
<prompt>c:\cygwin\&gt;</prompt> <userinput>mount \\pollux\home\joe\data /data</userinput>
<prompt>c:\cygwin\&gt;</prompt> <userinput>mount //pollux/home/joe/data /data</userinput>
mount: warning - /data does not exist!
<prompt>c:\cygwin\&gt;</prompt> <userinput>mount</userinput>
\\pollux\home\joe\data on /data type sytem (binmode)
c:\cygwin\bin on /usr/bin type system (binmode)
c:\cygwin\lib on /usr/lib type system (binmode)
c:\cygwin on / type system (binmode)
c: on /c type user (binmode,noumount)
d: on /d type user (binmode,noumount)
\\pollux\home\joe\data on /data type smbfs (binary)
c:\cygwin\bin on /usr/bin type ntfs (binary)
c:\cygwin\lib on /usr/lib type ntfs (binary)
c:\cygwin on / type ntfs (binary)
c: on /c type ntfs (binary,user,noumount)
d: on /d type fat (binary,user,noumount)
</screen>
</example>
<para>Note that <command>mount</command> was invoked from the Windows
command shell in the previous example. In many Unix shells, including
bash, it is legal and convenient to use the forward "/" in Win32
pathnames since the "\" is the shell's escape character. </para>
<para>The <literal>-s</literal> flag to <command>mount</command> is used to add a mount
in the system-wide mount table used by all Cygwin users on the system,
instead of the user-specific one. System-wide mounts are displayed
by <command>mount</command> as being of the "system" type, as is the
case for the <filename>/</filename> partition in the last example.
Under Windows NT, only those users with Administrator priviledges are
permitted to modify the system-wide mount table.</para>
<para>Note that a given POSIX path may only exist once in the user
table and once in the global, system-wide table. Attempts to replace
the mount will fail with a busy error. The <literal>-f</literal> (force) flag causes
the old mount to be silently replaced with the new one. It will also
silence warnings about the non-existence of directories at the Win32
path location.</para>
<para>The <literal>-b</literal> flag is used to instruct Cygwin to treat binary and
text files in the same manner by default. Binary mode mounts are
marked as "binmode" in the Flags column of <command>mount</command>
output. By default, mounts are in text mode ("textmode" in the Flags
column).</para>
<para>Normally, files ending in certain extensions (.exe, .com, .bat, .cmd)
are assumed to be executable. Files whose first two characters begin with
'#!' are also considered to be executable.
The <literal>-x</literal> flag is used to instruct Cygwin that the
mounted file is "executable". If the <literal>-x</literal> flag is used
with a directory then all files in the directory are executable.
This option allows other files to be marked as executable and avoids the
overhead of opening each file to check for a '#!'. The <literal>-X</literal>
option is very similar to <literal>-x</literal>, but also prevents Cygwin
from setting up commands and environment variables for a normal Windows
program, adding another small performance gain. The opposite of these
flags is the <literal>-E</literal> flag, which means that no files should be
marked as executable. </para>
<para>
The <literal>-m</literal> option causes the <command>mount</command> utility
to output a series of commands that could recreate both user and system mount
points. You can save this output as a backup when experimenting with the
mount table. It also makes moving your settings to a different machine
much easier.
</para>
<para>A given POSIX path may only exist once in the mount table. Attempts to
replace the mount will fail with a busy error. The <literal>-f</literal>
(force) option causes the old mount to be silently replaced with the new one,
provided the old mount point was a user mount point. It's not valid to
replace system-wide mount points. Additionally, the <literal>-f</literal>
option will silence warnings about the non-existence of directories at the
Win32 path location.</para>
<para>
The <literal>-o</literal> option is the method via which various options about
@ -830,17 +784,35 @@ the mount point may be recorded. The following options are available (note that
most of the options are duplicates of other mount flags):</para>
<screen>
user - mount lives user-specific mount
system - mount lives in system table (default)
binary - files default to binary mode (default)
text - files default to CRLF text mode line endings
exec - files below mount point are all executable
notexec - files below mount point are not executable
cygexec - files below mount point are all cygwin executables
nosuid - no suid files are allowed (currently unimplemented)
managed - directory is managed by cygwin. Mixed case and special
characters in filenames are allowed.
acl - Use the filesystem's access control lists (ACLs) to
implement real POSIX permissions (default).
noacl - Ignore ACLs and fake POSIX permissions.
binary - Files default to binary mode (default).
text - Files default to CRLF text mode line endings.
exec - Treat all files below mount point as executable.
notexec - Treat all files below mount point as not executable.
cygexec - Treat all files below mount point as cygwin executables.
nosuid - No suid files are allowed (currently unimplemented)
posix=0 - Switch off case sensitivity for paths under this mount point.
posix=1 - Switch on case sensitivity for paths under this mount point
(default).
</screen>
<para>For a more complete description of the mount options and the
<filename>/etc/fstab</filename> file, see
<xref linkend="mount-table"></xref>.</para>
<para>Note that all mount points added with <command>mount</command> are
user mount points. System mount points can only be specified in
the <filename>/etc/fstab</filename> file.</para>
<para>
The <literal>-m</literal> option causes the <command>mount</command> utility
to output the current mount table in a series of fstab entries. This allows
You can save this output as a backup when experimenting with the mount table.
Copy the output to <filename>/etc/fstab</filename> to restore the old state.
It also makes moving your settings to a different machine much easier.</para>
</sect3>
<sect3 id="utils-cygdrive"><title>Cygdrive mount points</title>
@ -1645,32 +1617,19 @@ This program is mainly useful for debugging the Cygwin DLL itself.</para>
Usage: umount.exe [OPTION] [&lt;posixpath&gt;]
Unmount filesystems
-A, --remove-all-mounts remove all mounts
-c, --remove-cygdrive-prefix remove cygdrive prefix
-h, --help output usage information and exit
-s, --system remove system mount (default)
-S, --remove-system-mounts remove all system mounts
-u, --user remove user mount
-U, --remove-user-mounts remove all user mounts
-v, --version output version information and exit
</screen>
<para>The <command>umount</command> program removes mounts from the
mount table. If you specify a POSIX path that corresponds to a
current mount point, <command>umount</command> will remove it from the
system registry area. (Administrator priviledges are required).
The <literal>-u</literal> flag may be used to specify removing the mount
from the user-specific registry area instead.</para>
mount table in the current session. If you specify a POSIX path that
corresponds to a current mount point, <command>umount</command> will
remove it from the current mount table. Note that you can only remove
user mount points. The <literal>-U</literal> flag may be used to
specify removing all user mount points from the current user session.</para>
<para>The <command>umount</command> utility may also be used to remove
all mounts of a particular type. With the extended options it is
possible to remove all mounts (<literal>-A</literal>), all
cygdrive automatically-mounted mounts (<literal>-c</literal>), all
mounts in the current user's registry area (<literal>-U</literal>),
or all mounts in the system-wide registry area (<literal>-S</literal>)
(with Administrator privileges).</para>
<para>See <xref linkend="mount"></xref> for more information on the mount
<para>See <xref linkend="mount-table"></xref> for more information on the mount
table.</para>
</sect2>