2000-02-17 20:38:33 +01:00
|
|
|
/* mount.cc
|
|
|
|
|
2005-08-03 11:23:39 +02:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005 Red Hat, Inc.
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <mntent.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <sys/cygwin.h>
|
2000-06-05 20:43:54 +02:00
|
|
|
#include <stdlib.h>
|
2001-04-03 04:41:54 +02:00
|
|
|
#include <getopt.h>
|
2003-07-26 07:38:51 +02:00
|
|
|
#include <dirent.h>
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
#ifdef errno
|
|
|
|
#undef errno
|
|
|
|
#endif
|
|
|
|
#include <errno.h>
|
|
|
|
|
2002-05-12 06:29:54 +02:00
|
|
|
#define EXEC_FLAGS (MOUNT_EXEC | MOUNT_NOTEXEC | MOUNT_CYGWIN_EXEC)
|
|
|
|
|
2001-09-04 00:02:54 +02:00
|
|
|
static void mount_commands (void);
|
2000-02-17 20:38:33 +01:00
|
|
|
static void show_mounts (void);
|
2000-11-08 21:39:45 +01:00
|
|
|
static void show_cygdrive_info (void);
|
2000-02-17 20:38:33 +01:00
|
|
|
static void change_cygdrive_prefix (const char *new_prefix, int flags);
|
|
|
|
static int mount_already_exists (const char *posix_path, int flags);
|
|
|
|
|
|
|
|
// static short create_missing_dirs = FALSE;
|
|
|
|
static short force = FALSE;
|
|
|
|
|
2002-05-23 06:19:07 +02:00
|
|
|
static const char version[] = "$Revision$";
|
2000-02-17 20:38:33 +01:00
|
|
|
static const char *progname;
|
|
|
|
|
2000-06-08 14:54:12 +02:00
|
|
|
static void
|
|
|
|
error (const char *path)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: %s: %s\n", progname, path,
|
|
|
|
(errno == EMFILE) ? "Too many mount entries" : strerror (errno));
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* FIXME: do_mount should also print a warning message if the dev arg
|
|
|
|
is a non-existent Win32 path. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_mount (const char *dev, const char *where, int flags)
|
|
|
|
{
|
|
|
|
struct stat statbuf;
|
|
|
|
int statres;
|
|
|
|
|
2006-12-10 22:50:06 +01:00
|
|
|
statres = stat (where, &statbuf);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (statres == -1)
|
|
|
|
{
|
|
|
|
/* FIXME: this'll fail if mount dir is missing any parent dirs */
|
|
|
|
if (create_missing_dirs == TRUE)
|
|
|
|
{
|
|
|
|
if (mkdir (where, 0755) == -1)
|
|
|
|
fprintf (stderr, "Warning: unable to create %s!\n", where);
|
|
|
|
else
|
|
|
|
statres = 0; /* Pretend stat succeeded if we could mkdir. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (statres == -1)
|
|
|
|
{
|
2002-05-12 06:29:54 +02:00
|
|
|
if (!force)
|
2000-02-17 20:38:33 +01:00
|
|
|
fprintf (stderr, "%s: warning - %s does not exist.\n", progname, where);
|
|
|
|
}
|
|
|
|
else if (!(statbuf.st_mode & S_IFDIR))
|
|
|
|
{
|
2002-05-12 06:29:54 +02:00
|
|
|
if (!force)
|
2000-07-13 23:49:36 +02:00
|
|
|
fprintf (stderr, "%s: warning: %s is not a directory.\n", progname, where);
|
2000-10-28 07:00:00 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-05-12 06:29:54 +02:00
|
|
|
if (!force && !(flags & EXEC_FLAGS) && strlen (dev))
|
|
|
|
{
|
|
|
|
char devtmp[1 + 2 * strlen (dev)];
|
|
|
|
strcpy (devtmp, dev);
|
|
|
|
char c = strchr (devtmp, '\0')[-1];
|
|
|
|
if (c == '/' || c == '\\')
|
|
|
|
strcat (devtmp, ".");
|
|
|
|
/* Use a curious property of Windows which allows the use of \.. even
|
2004-10-25 17:49:36 +02:00
|
|
|
on non-directory paths. */
|
2002-05-12 06:29:54 +02:00
|
|
|
for (const char *p = dev; (p = strpbrk (p, "/\\")); p++)
|
|
|
|
strcat (devtmp, "\\..");
|
|
|
|
strcat (devtmp, "\\");
|
|
|
|
if (GetDriveType (devtmp) == DRIVE_REMOTE)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: defaulting to '--no-executable' flag for speed since native path\n"
|
|
|
|
"%*creferences a remote share. Use '-f' option to override.\n", progname,
|
|
|
|
strlen(progname) + 2, ' ');
|
|
|
|
flags |= MOUNT_NOTEXEC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-26 07:38:51 +02:00
|
|
|
if (!force && flags & MOUNT_ENC)
|
|
|
|
{
|
|
|
|
DIR *dd = opendir (dev);
|
|
|
|
if (dd)
|
|
|
|
{
|
|
|
|
struct dirent *d;
|
|
|
|
while ((d = readdir (dd)))
|
|
|
|
{
|
|
|
|
if (d->d_name[0] != '.')
|
|
|
|
/* fall through */;
|
|
|
|
else if (d->d_name[1] == '\0'
|
|
|
|
|| (d->d_name[1] == '.' && d->d_name[2] == '\0'))
|
|
|
|
continue;
|
|
|
|
fprintf (stderr, "%s: error: don't use \"-o managed\" on non-empty directories\n", progname);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-12 06:29:54 +02:00
|
|
|
if (mount (dev, where, flags))
|
|
|
|
error (where);
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
2002-05-13 07:13:58 +02:00
|
|
|
static struct option longopts[] =
|
2001-04-03 04:41:54 +02:00
|
|
|
{
|
|
|
|
{"binary", no_argument, NULL, 'b'},
|
|
|
|
{"change-cygdrive-prefix", no_argument, NULL, 'c'},
|
|
|
|
{"cygwin-executable", no_argument, NULL, 'X'},
|
2002-05-23 06:19:07 +02:00
|
|
|
{"executable", no_argument, NULL, 'x'},
|
|
|
|
{"force", no_argument, NULL, 'f'},
|
|
|
|
{"help", no_argument, NULL, 'h' },
|
2001-09-04 00:02:54 +02:00
|
|
|
{"mount-commands", no_argument, NULL, 'm'},
|
2002-05-23 06:19:07 +02:00
|
|
|
{"no-executable", no_argument, NULL, 'E'},
|
2005-08-03 11:23:39 +02:00
|
|
|
{"options", required_argument, NULL, 'o'},
|
2002-05-23 06:19:07 +02:00
|
|
|
{"show-cygdrive-prefix", no_argument, NULL, 'p'},
|
|
|
|
{"system", no_argument, NULL, 's'},
|
|
|
|
{"text", no_argument, NULL, 't'},
|
|
|
|
{"user", no_argument, NULL, 'u'},
|
|
|
|
{"version", no_argument, NULL, 'v'},
|
2001-04-03 04:41:54 +02:00
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
2003-07-04 05:11:18 +02:00
|
|
|
static char opts[] = "bcfhmpstuvxEXo:";
|
2001-04-03 04:41:54 +02:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
static void
|
2002-05-23 06:19:07 +02:00
|
|
|
usage (FILE *where = stderr)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-05-23 06:19:07 +02:00
|
|
|
fprintf (where, "Usage: %s [OPTION] [<win32path> <posixpath>]\n\
|
2003-04-26 23:52:03 +02:00
|
|
|
Display information about mounted filesystems, or mount a filesystem\n\
|
|
|
|
\n\
|
2002-10-19 13:41:31 +02:00
|
|
|
-b, --binary (default) text files are equivalent to binary files\n\
|
2001-04-03 04:41:54 +02:00
|
|
|
(newline = \\n)\n\
|
|
|
|
-c, --change-cygdrive-prefix change the cygdrive path prefix to <posixpath>\n\
|
|
|
|
-f, --force force mount, don't warn about missing mount\n\
|
2001-04-16 04:51:03 +02:00
|
|
|
point directories\n\
|
2002-05-23 06:19:07 +02:00
|
|
|
-h, --help output usage information and exit\n\
|
2005-05-01 17:50:02 +02:00
|
|
|
-m, --mount-commands write mount commands to replicate user and\n\
|
2002-05-23 06:19:07 +02:00
|
|
|
system mount points and cygdrive prefixes\n\
|
2003-07-04 05:11:18 +02:00
|
|
|
-o, --options X[,X...] specify mount options\n\
|
2001-04-03 04:41:54 +02:00
|
|
|
-p, --show-cygdrive-prefix show user and/or system cygdrive path prefix\n\
|
2002-05-12 06:29:54 +02:00
|
|
|
-s, --system (default) add system-wide mount point\n\
|
2002-10-19 13:41:31 +02:00
|
|
|
-t, --text text files get \\r\\n line endings\n\
|
2002-05-12 06:29:54 +02:00
|
|
|
-u, --user add user-only mount point\n\
|
2002-05-23 06:19:07 +02:00
|
|
|
-v, --version output version information and exit\n\
|
2001-04-03 04:41:54 +02:00
|
|
|
-x, --executable treat all files under mount point as executables\n\
|
2002-05-23 06:19:07 +02:00
|
|
|
-E, --no-executable treat all files under mount point as \n\
|
|
|
|
non-executables\n\
|
2001-04-03 04:41:54 +02:00
|
|
|
-X, --cygwin-executable treat all files under mount point as cygwin\n\
|
|
|
|
executables\n\
|
2000-02-17 20:38:33 +01:00
|
|
|
", progname);
|
2002-05-23 06:19:07 +02:00
|
|
|
exit (where == stderr ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2003-07-04 05:11:18 +02:00
|
|
|
struct opt
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
unsigned val;
|
|
|
|
bool clear;
|
|
|
|
} oopts[] =
|
|
|
|
{
|
|
|
|
{"user", MOUNT_SYSTEM, 1},
|
|
|
|
{"system", MOUNT_SYSTEM, 0},
|
|
|
|
{"binary", MOUNT_BINARY, 0},
|
|
|
|
{"text", MOUNT_BINARY, 1},
|
|
|
|
{"exec", MOUNT_EXEC, 0},
|
|
|
|
{"notexec", MOUNT_NOTEXEC, 0},
|
|
|
|
{"cygexec", MOUNT_CYGWIN_EXEC, 0},
|
2003-07-04 05:20:22 +02:00
|
|
|
{"nosuid", 0, 0},
|
2003-07-04 05:11:18 +02:00
|
|
|
{"managed", MOUNT_ENC, 0}
|
|
|
|
};
|
|
|
|
|
2002-05-23 06:19:07 +02:00
|
|
|
static void
|
|
|
|
print_version ()
|
|
|
|
{
|
|
|
|
const char *v = strchr (version, ':');
|
|
|
|
int len;
|
|
|
|
if (!v)
|
|
|
|
{
|
|
|
|
v = "?";
|
|
|
|
len = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
v += 2;
|
|
|
|
len = strchr (v, ' ') - v;
|
|
|
|
}
|
|
|
|
printf ("\
|
|
|
|
%s (cygwin) %.*s\n\
|
|
|
|
Filesystem Utility\n\
|
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.\n\
|
2002-09-15 21:24:37 +02:00
|
|
|
Compiled on %s\n\
|
|
|
|
", progname, len, v, __DATE__);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2003-07-04 05:11:18 +02:00
|
|
|
static char *
|
|
|
|
concat3 (char *a, const char *b, const char *c)
|
|
|
|
{
|
|
|
|
size_t totlen = strlen (a) + strlen (b) + strlen (c) + 1;
|
|
|
|
a = (char *) realloc (a, totlen);
|
|
|
|
return strcat (strcat (a, b), c);
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
int
|
2001-04-03 04:41:54 +02:00
|
|
|
main (int argc, char **argv)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
int i;
|
2002-05-30 05:42:19 +02:00
|
|
|
int flags = MOUNT_BINARY;
|
2002-05-12 06:29:54 +02:00
|
|
|
int default_flag = MOUNT_SYSTEM;
|
2003-07-04 05:11:18 +02:00
|
|
|
char *options = strdup ("");
|
2001-04-03 04:41:54 +02:00
|
|
|
enum do_what
|
|
|
|
{
|
|
|
|
nada,
|
|
|
|
saw_change_cygdrive_prefix,
|
2001-09-04 00:02:54 +02:00
|
|
|
saw_show_cygdrive_prefix,
|
|
|
|
saw_mount_commands
|
2001-04-03 04:41:54 +02:00
|
|
|
} do_what = nada;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-05-23 06:19:07 +02:00
|
|
|
progname = strrchr (argv[0], '/');
|
|
|
|
if (progname == NULL)
|
|
|
|
progname = strrchr (argv[0], '\\');
|
|
|
|
if (progname == NULL)
|
|
|
|
progname = argv[0];
|
|
|
|
else
|
|
|
|
progname++;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (argc == 1)
|
|
|
|
{
|
|
|
|
show_mounts ();
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
2001-04-03 04:41:54 +02:00
|
|
|
while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 'b':
|
2000-04-27 05:44:23 +02:00
|
|
|
flags |= MOUNT_BINARY;
|
2001-04-03 04:41:54 +02:00
|
|
|
break;
|
2001-04-16 04:51:03 +02:00
|
|
|
case 'c':
|
2001-04-03 04:41:54 +02:00
|
|
|
if (do_what == nada)
|
|
|
|
do_what = saw_change_cygdrive_prefix;
|
|
|
|
else
|
|
|
|
usage ();
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
force = TRUE;
|
|
|
|
break;
|
2002-05-23 06:19:07 +02:00
|
|
|
case 'h':
|
|
|
|
usage (stdout);
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
if (do_what == nada)
|
|
|
|
do_what = saw_mount_commands;
|
|
|
|
else
|
|
|
|
usage ();
|
|
|
|
break;
|
2003-07-04 05:11:18 +02:00
|
|
|
case 'o':
|
|
|
|
if (*options)
|
|
|
|
options = concat3 (options, ",", optarg);
|
|
|
|
else
|
|
|
|
options = strdup (optarg);
|
|
|
|
break;
|
2001-04-03 04:41:54 +02:00
|
|
|
case 'p':
|
|
|
|
if (do_what == nada)
|
|
|
|
do_what = saw_show_cygdrive_prefix;
|
|
|
|
else
|
|
|
|
usage ();
|
|
|
|
break;
|
|
|
|
case 's':
|
2000-04-27 05:44:23 +02:00
|
|
|
flags |= MOUNT_SYSTEM;
|
2001-04-03 04:41:54 +02:00
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
flags &= ~MOUNT_BINARY;
|
|
|
|
break;
|
|
|
|
case 'u':
|
2000-04-27 05:44:23 +02:00
|
|
|
flags &= ~MOUNT_SYSTEM;
|
2002-05-12 06:29:54 +02:00
|
|
|
default_flag = 0;
|
2001-04-03 04:41:54 +02:00
|
|
|
break;
|
2002-05-23 06:19:07 +02:00
|
|
|
case 'v':
|
|
|
|
print_version ();
|
|
|
|
return 0;
|
2001-04-03 04:41:54 +02:00
|
|
|
break;
|
|
|
|
case 'x':
|
2000-04-27 05:44:23 +02:00
|
|
|
flags |= MOUNT_EXEC;
|
2001-04-03 04:41:54 +02:00
|
|
|
break;
|
2002-05-12 06:29:54 +02:00
|
|
|
case 'E':
|
|
|
|
flags |= MOUNT_NOTEXEC;
|
|
|
|
break;
|
2002-05-23 06:19:07 +02:00
|
|
|
case 'X':
|
|
|
|
flags |= MOUNT_CYGWIN_EXEC;
|
2001-09-04 00:02:54 +02:00
|
|
|
break;
|
2001-04-03 04:41:54 +02:00
|
|
|
default:
|
2000-04-27 05:44:23 +02:00
|
|
|
usage ();
|
2001-04-03 04:41:54 +02:00
|
|
|
}
|
2000-10-28 07:00:00 +02:00
|
|
|
|
2003-07-04 05:11:18 +02:00
|
|
|
while (*options)
|
|
|
|
{
|
|
|
|
char *p = strchr (options, ',');
|
|
|
|
if (p)
|
|
|
|
*p++ = '\0';
|
|
|
|
else
|
|
|
|
p = strchr (options, '\0');
|
|
|
|
|
|
|
|
for (opt *o = oopts; o < (oopts + (sizeof (oopts) / sizeof (oopts[0]))); o++)
|
|
|
|
if (strcmp (options, o->name) == 0)
|
|
|
|
{
|
|
|
|
if (o->clear)
|
|
|
|
flags &= ~o->val;
|
|
|
|
else
|
|
|
|
flags |= o->val;
|
|
|
|
goto gotit;
|
|
|
|
}
|
|
|
|
fprintf (stderr, "%s: invalid option - '%s'\n", progname, options);
|
|
|
|
exit (1);
|
|
|
|
|
|
|
|
gotit:
|
|
|
|
options = p;
|
|
|
|
}
|
|
|
|
|
2002-05-12 06:29:54 +02:00
|
|
|
if (flags & MOUNT_NOTEXEC && flags & (MOUNT_EXEC | MOUNT_CYGWIN_EXEC))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: invalid combination of executable options\n", progname);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2007-03-30 15:36:06 +02:00
|
|
|
cygwin_internal (CW_SET_DOS_FILE_WARNING, false);
|
|
|
|
|
2001-04-03 04:41:54 +02:00
|
|
|
argc--;
|
|
|
|
switch (do_what)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-04-03 04:41:54 +02:00
|
|
|
case saw_change_cygdrive_prefix:
|
|
|
|
if (optind != argc)
|
|
|
|
usage ();
|
2002-06-09 06:54:32 +02:00
|
|
|
change_cygdrive_prefix (argv[optind], flags | default_flag);
|
2001-04-03 04:41:54 +02:00
|
|
|
break;
|
|
|
|
case saw_show_cygdrive_prefix:
|
|
|
|
if (optind <= argc)
|
|
|
|
usage ();
|
|
|
|
show_cygdrive_info ();
|
|
|
|
break;
|
2001-09-04 00:02:54 +02:00
|
|
|
case saw_mount_commands:
|
|
|
|
if (optind <= argc)
|
|
|
|
usage ();
|
|
|
|
mount_commands ();
|
|
|
|
break;
|
2001-04-03 04:41:54 +02:00
|
|
|
default:
|
|
|
|
if (optind != (argc - 1))
|
|
|
|
{
|
2001-08-28 20:48:38 +02:00
|
|
|
if (optind >= argc)
|
|
|
|
fprintf (stderr, "%s: not enough arguments\n", progname);
|
|
|
|
else
|
2001-09-01 21:58:40 +02:00
|
|
|
fprintf (stderr, "%s: too many arguments\n", progname);
|
2001-04-03 04:41:54 +02:00
|
|
|
usage ();
|
|
|
|
}
|
2002-07-01 22:54:35 +02:00
|
|
|
if (force || !mount_already_exists (argv[optind + 1], flags | default_flag))
|
2002-05-12 06:29:54 +02:00
|
|
|
do_mount (argv[optind], argv[optind + 1], flags | default_flag);
|
2001-04-03 04:41:54 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
errno = EBUSY;
|
|
|
|
error (argv[optind + 1]);
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTREACHED */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-09-04 00:02:54 +02:00
|
|
|
static void
|
|
|
|
mount_commands (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];
|
|
|
|
|
|
|
|
// write mount commands for user and system mount points
|
2003-09-04 03:04:57 +02:00
|
|
|
while ((p = getmntent (m)) != NULL)
|
2001-09-04 03:09:39 +02:00
|
|
|
// Only list non-cygdrives
|
2003-09-04 03:04:57 +02:00
|
|
|
if (!strstr (p->mnt_opts, ",noumount"))
|
|
|
|
{
|
|
|
|
strcpy(opts, " -f");
|
|
|
|
if (p->mnt_type[0] == 'u')
|
|
|
|
strcat (opts, " -u");
|
|
|
|
else if (p->mnt_type[0] == 's')
|
|
|
|
strcat (opts, " -s");
|
|
|
|
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");
|
2005-05-13 22:24:20 +02:00
|
|
|
if (strstr (p->mnt_opts, ",cygexec"))
|
|
|
|
strcat (opts, " -X");
|
2003-09-04 03:04:57 +02:00
|
|
|
if (strstr (p->mnt_opts, ",managed"))
|
|
|
|
strcat (opts, " -o managed");
|
|
|
|
while ((c = strchr (p->mnt_fsname, '\\')) != NULL)
|
|
|
|
*c = '/';
|
|
|
|
printf (format_mnt, opts, p->mnt_fsname, p->mnt_dir);
|
|
|
|
}
|
2001-09-04 00:02:54 +02:00
|
|
|
endmntent (m);
|
|
|
|
|
|
|
|
// write mount commands for cygdrive prefixes
|
|
|
|
cygwin_internal (CW_GET_CYGDRIVE_INFO, user, system, user_flags,
|
|
|
|
system_flags);
|
2003-09-04 03:04:57 +02:00
|
|
|
|
|
|
|
if (strlen (user) > 0)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2001-09-04 00:02:54 +02:00
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
static void
|
|
|
|
show_mounts (void)
|
|
|
|
{
|
|
|
|
FILE *m = setmntent ("/-not-used-", "r");
|
|
|
|
struct mntent *p;
|
2001-04-02 16:58:47 +02:00
|
|
|
const char *format = "%s on %s type %s (%s)\n";
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-04-02 16:58:47 +02:00
|
|
|
// printf (format, "Device", "Directory", "Type", "Flags");
|
2000-02-17 20:38:33 +01:00
|
|
|
while ((p = getmntent (m)) != NULL)
|
2001-04-02 16:58:47 +02:00
|
|
|
printf (format, p->mnt_fsname, p->mnt_dir, p->mnt_type, p->mnt_opts);
|
2000-02-17 20:38:33 +01:00
|
|
|
endmntent (m);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return 1 if mountpoint from the same registry area is already in
|
|
|
|
mount table. Otherwise return 0. */
|
|
|
|
static int
|
|
|
|
mount_already_exists (const char *posix_path, int flags)
|
|
|
|
{
|
|
|
|
int found_matching = 0;
|
|
|
|
|
|
|
|
FILE *m = setmntent ("/-not-used-", "r");
|
|
|
|
struct mntent *p;
|
|
|
|
|
|
|
|
while ((p = getmntent (m)) != NULL)
|
|
|
|
{
|
|
|
|
/* if the paths match, and they're both the same type of mount. */
|
|
|
|
if (strcmp (p->mnt_dir, posix_path) == 0)
|
|
|
|
{
|
2000-07-13 23:49:36 +02:00
|
|
|
if (p->mnt_type[0] == 'u')
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-04-16 04:51:03 +02:00
|
|
|
if (!(flags & MOUNT_SYSTEM)) /* both current_user */
|
|
|
|
found_matching = 1;
|
|
|
|
else
|
|
|
|
fprintf (stderr,
|
|
|
|
"%s: warning: system mount point of '%s' "
|
|
|
|
"will always be masked by user mount.\n",
|
|
|
|
progname, posix_path);
|
2000-02-17 20:38:33 +01:00
|
|
|
break;
|
2001-04-16 04:51:03 +02:00
|
|
|
}
|
2000-07-13 23:49:36 +02:00
|
|
|
else if (p->mnt_type[0] == 's')
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-04-16 04:51:03 +02:00
|
|
|
if (flags & MOUNT_SYSTEM) /* both system */
|
|
|
|
found_matching = 1;
|
|
|
|
else
|
|
|
|
fprintf (stderr,
|
|
|
|
"%s: warning: user mount point of '%s' "
|
|
|
|
"masks system mount.\n",
|
|
|
|
progname, posix_path);
|
2000-02-17 20:38:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-07-13 23:49:36 +02:00
|
|
|
fprintf (stderr, "%s: warning: couldn't determine mount type.\n", progname);
|
2000-02-17 20:38:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
endmntent (m);
|
|
|
|
|
|
|
|
return found_matching;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* change_cygdrive_prefix: Change the cygdrive prefix */
|
|
|
|
static void
|
|
|
|
change_cygdrive_prefix (const char *new_prefix, int flags)
|
|
|
|
{
|
2002-06-09 06:54:32 +02:00
|
|
|
flags |= MOUNT_CYGDRIVE;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (mount (NULL, new_prefix, flags))
|
2000-06-08 14:54:12 +02:00
|
|
|
error (new_prefix);
|
2000-10-28 07:00:00 +02:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
exit (0);
|
|
|
|
}
|
2000-07-29 00:34:24 +02:00
|
|
|
|
2001-04-03 04:41:54 +02:00
|
|
|
/* show_cygdrive_info: Show the user and/or cygdrive info, i.e., prefix and
|
2000-11-08 21:39:45 +01:00
|
|
|
flags.*/
|
2000-07-29 00:34:24 +02:00
|
|
|
static void
|
2000-11-08 21:39:45 +01:00
|
|
|
show_cygdrive_info ()
|
2000-07-29 00:34:24 +02:00
|
|
|
{
|
2000-11-08 21:39:45 +01:00
|
|
|
/* Get the cygdrive info */
|
2000-07-29 00:34:24 +02:00
|
|
|
char user[MAX_PATH];
|
|
|
|
char system[MAX_PATH];
|
2000-11-08 21:39:45 +01:00
|
|
|
char user_flags[MAX_PATH];
|
|
|
|
char system_flags[MAX_PATH];
|
|
|
|
cygwin_internal (CW_GET_CYGDRIVE_INFO, user, system, user_flags,
|
|
|
|
system_flags);
|
2000-07-29 00:34:24 +02:00
|
|
|
|
2001-04-03 04:41:54 +02:00
|
|
|
/* Display the user and system cygdrive path prefix, if necessary
|
2000-07-29 00:34:24 +02:00
|
|
|
(ie, not empty) */
|
2000-11-08 21:39:45 +01:00
|
|
|
const char *format = "%-18s %-11s %s\n";
|
|
|
|
printf (format, "Prefix", "Type", "Flags");
|
2000-07-29 00:34:24 +02:00
|
|
|
if (strlen (user) > 0)
|
2000-11-08 21:39:45 +01:00
|
|
|
printf (format, user, "user", user_flags);
|
2000-07-29 00:34:24 +02:00
|
|
|
if (strlen (system) > 0)
|
2000-11-08 21:39:45 +01:00
|
|
|
printf (format, system, "system", system_flags);
|
2000-07-29 00:34:24 +02:00
|
|
|
|
|
|
|
exit (0);
|
|
|
|
}
|