2000-02-18 03:38:33 +08:00
|
|
|
/* mount.cc
|
|
|
|
|
2008-04-23 19:37:58 +08:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005,
|
2011-10-10 22:57:48 +08:00
|
|
|
2008, 2009, 2010, 2011 Red Hat, Inc.
|
2000-02-18 03:38:33 +08: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>
|
2011-10-10 22:57:48 +08:00
|
|
|
#include <cygwin/version.h>
|
2000-06-06 02:43:54 +08:00
|
|
|
#include <stdlib.h>
|
2009-07-22 18:20:26 +08:00
|
|
|
#include <unistd.h>
|
2001-04-03 10:41:54 +08:00
|
|
|
#include <getopt.h>
|
2003-07-26 13:38:51 +08:00
|
|
|
#include <dirent.h>
|
2009-07-22 18:20:26 +08:00
|
|
|
#include "path.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
#ifdef errno
|
|
|
|
#undef errno
|
|
|
|
#endif
|
|
|
|
#include <errno.h>
|
|
|
|
|
2008-08-14 00:35:04 +08:00
|
|
|
#define NT_MAX_PATH 32768
|
|
|
|
|
2002-05-12 12:29:54 +08:00
|
|
|
#define EXEC_FLAGS (MOUNT_EXEC | MOUNT_NOTEXEC | MOUNT_CYGWIN_EXEC)
|
|
|
|
|
2008-08-14 00:35:04 +08:00
|
|
|
static void mount_entries (void);
|
2000-02-18 03:38:33 +08:00
|
|
|
static void show_mounts (void);
|
2000-11-09 04:39:45 +08:00
|
|
|
static void show_cygdrive_info (void);
|
2000-02-18 03:38:33 +08: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;
|
2009-07-22 18:20:26 +08:00
|
|
|
static bool force = false;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
static const char *progname;
|
|
|
|
|
2000-06-08 20:54:12 +08: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-18 03:38:33 +08: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-11 05:50:06 +08:00
|
|
|
statres = stat (where, &statbuf);
|
2000-02-18 03:38:33 +08: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 12:29:54 +08:00
|
|
|
if (!force)
|
2000-02-18 03:38:33 +08:00
|
|
|
fprintf (stderr, "%s: warning - %s does not exist.\n", progname, where);
|
|
|
|
}
|
|
|
|
else if (!(statbuf.st_mode & S_IFDIR))
|
|
|
|
{
|
2002-05-12 12:29:54 +08:00
|
|
|
if (!force)
|
2011-10-10 22:57:48 +08:00
|
|
|
fprintf (stderr, "%s: warning: %s is not a directory.\n",
|
|
|
|
progname, where);
|
2000-10-28 13:00:00 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2010-08-11 19:01:14 +08:00
|
|
|
if (!force && !(flags & (EXEC_FLAGS | MOUNT_BIND)) && strlen (dev))
|
2002-05-12 12:29:54 +08:00
|
|
|
{
|
|
|
|
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 23:49:36 +08:00
|
|
|
on non-directory paths. */
|
2002-05-12 12:29:54 +08:00
|
|
|
for (const char *p = dev; (p = strpbrk (p, "/\\")); p++)
|
|
|
|
strcat (devtmp, "\\..");
|
|
|
|
strcat (devtmp, "\\");
|
|
|
|
if (GetDriveType (devtmp) == DRIVE_REMOTE)
|
|
|
|
{
|
2011-10-10 22:57:48 +08:00
|
|
|
fprintf (stderr,
|
|
|
|
"%s: defaulting to 'notexec' mount option for speed since native path\n"
|
|
|
|
"%*creferences a remote share. Use '-f' option to override.\n",
|
|
|
|
progname, strlen(progname) + 2, ' ');
|
2002-05-12 12:29:54 +08:00
|
|
|
flags |= MOUNT_NOTEXEC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mount (dev, where, flags))
|
|
|
|
error (where);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2009-07-22 18:20:26 +08:00
|
|
|
static void
|
|
|
|
from_fstab (bool user)
|
|
|
|
{
|
|
|
|
char path[PATH_MAX];
|
|
|
|
char buf[65536];
|
|
|
|
mnt_t *m = mount_table + max_mount_entry;
|
|
|
|
|
|
|
|
strcpy (path, "/etc/fstab");
|
|
|
|
if (user)
|
|
|
|
{
|
|
|
|
strcat (path, ".d/");
|
|
|
|
strcat (path, getlogin ());
|
|
|
|
}
|
|
|
|
FILE *fh = fopen (path, "rt");
|
|
|
|
if (!fh)
|
|
|
|
return;
|
|
|
|
while (fgets (buf, 65536, fh))
|
|
|
|
{
|
|
|
|
char *c = strrchr (buf, '\n');
|
2010-08-14 03:10:22 +08:00
|
|
|
if (c)
|
2009-07-22 18:20:26 +08:00
|
|
|
*c = '\0';
|
|
|
|
if (from_fstab_line (m, buf, user))
|
|
|
|
++m;
|
|
|
|
}
|
|
|
|
max_mount_entry = m - mount_table;
|
|
|
|
fclose (fh);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_mount_from_fstab (const char *where)
|
|
|
|
{
|
|
|
|
force = true;
|
|
|
|
/* Read fstab entries. */
|
|
|
|
from_fstab (false);
|
|
|
|
from_fstab (true);
|
|
|
|
/* Loop through fstab entries and see if it matches `where'. If `where'
|
|
|
|
is NULL, all entries match. */
|
|
|
|
bool exists = false;
|
|
|
|
for (mnt_t *m = mount_table; m - mount_table < max_mount_entry; ++m)
|
2010-01-11 20:13:55 +08:00
|
|
|
if (!where || !strcmp (where, m->posix))
|
2009-07-22 18:20:26 +08:00
|
|
|
{
|
2010-01-11 20:13:55 +08:00
|
|
|
if (m->flags & MOUNT_CYGDRIVE)
|
|
|
|
{
|
|
|
|
/* Get the cygdrive info */
|
|
|
|
char user[MAX_PATH];
|
|
|
|
char system[MAX_PATH];
|
|
|
|
char user_flags[MAX_PATH];
|
|
|
|
char system_flags[MAX_PATH];
|
|
|
|
|
|
|
|
exists = true;
|
|
|
|
cygwin_internal (CW_GET_CYGDRIVE_INFO, user, system, user_flags,
|
|
|
|
system_flags);
|
|
|
|
if ((*user && strcmp (user, m->posix) != 0)
|
|
|
|
|| (*system && strcmp (system, m->posix) != 0))
|
|
|
|
if (mount (NULL, m->posix, m->flags))
|
|
|
|
error (m->posix);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
exists = true;
|
|
|
|
/* Compare with existing mount table. If the entry doesn't exist,
|
|
|
|
mount it. */
|
|
|
|
FILE *mt = setmntent ("/-not-used-", "r");
|
|
|
|
struct mntent *p;
|
|
|
|
|
|
|
|
while ((p = getmntent (mt)) != NULL)
|
|
|
|
if (!strcmp (m->posix, p->mnt_dir))
|
|
|
|
break;
|
|
|
|
if (!p)
|
|
|
|
do_mount (m->native, m->posix, m->flags);
|
|
|
|
endmntent (mt);
|
|
|
|
if (where)
|
|
|
|
break;
|
|
|
|
}
|
2009-07-22 18:20:26 +08:00
|
|
|
}
|
|
|
|
if (!exists && where)
|
|
|
|
fprintf (stderr,
|
|
|
|
"%s: can't find %s in /etc/fstab or in /etc/fstab.d/$USER\n",
|
|
|
|
progname, where);
|
|
|
|
}
|
|
|
|
|
2002-05-13 13:13:58 +08:00
|
|
|
static struct option longopts[] =
|
2001-04-03 10:41:54 +08:00
|
|
|
{
|
2009-07-22 18:20:26 +08:00
|
|
|
{"all", no_argument, NULL, 'a'},
|
2001-04-03 10:41:54 +08:00
|
|
|
{"change-cygdrive-prefix", no_argument, NULL, 'c'},
|
2002-05-23 12:19:07 +08:00
|
|
|
{"force", no_argument, NULL, 'f'},
|
|
|
|
{"help", no_argument, NULL, 'h' },
|
2008-08-14 00:35:04 +08:00
|
|
|
{"mount-entries", no_argument, NULL, 'm'},
|
2005-08-03 17:23:39 +08:00
|
|
|
{"options", required_argument, NULL, 'o'},
|
2002-05-23 12:19:07 +08:00
|
|
|
{"show-cygdrive-prefix", no_argument, NULL, 'p'},
|
2011-10-10 22:57:48 +08:00
|
|
|
{"version", no_argument, NULL, 'V'},
|
2001-04-03 10:41:54 +08:00
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
2011-10-10 22:57:48 +08:00
|
|
|
static char opts[] = "acfhmpVo:";
|
2008-08-14 00:35:04 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
static void
|
2002-05-23 12:19:07 +08:00
|
|
|
usage (FILE *where = stderr)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2010-04-29 16:50:23 +08:00
|
|
|
char *options;
|
|
|
|
|
2011-10-10 22:57:48 +08:00
|
|
|
fprintf (where, "Usage: %1$s [OPTION] [<win32path> <posixpath>]\n\
|
|
|
|
%1$s -a\n\
|
|
|
|
%1$s <posixpath>\n\
|
|
|
|
\n\
|
2003-04-27 05:52:03 +08:00
|
|
|
Display information about mounted filesystems, or mount a filesystem\n\
|
|
|
|
\n\
|
2009-07-22 18:20:26 +08:00
|
|
|
-a, --all mount all filesystems mentioned in fstab\n\
|
2001-04-03 10:41:54 +08:00
|
|
|
-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 10:51:03 +08:00
|
|
|
point directories\n\
|
2002-05-23 12:19:07 +08:00
|
|
|
-h, --help output usage information and exit\n\
|
2008-08-14 00:35:04 +08:00
|
|
|
-m, --mount-entries write fstab entries to replicate mount points\n\
|
|
|
|
and cygdrive prefixes\n\
|
2003-07-04 11:11:18 +08:00
|
|
|
-o, --options X[,X...] specify mount options\n\
|
2001-04-03 10:41:54 +08:00
|
|
|
-p, --show-cygdrive-prefix show user and/or system cygdrive path prefix\n\
|
2011-10-10 22:57:48 +08:00
|
|
|
-V, --version output version information and exit\n\n",
|
|
|
|
progname);
|
2010-04-29 16:50:23 +08:00
|
|
|
if (!cygwin_internal (CW_LST_MNT_OPTS, &options))
|
|
|
|
fprintf (where, "Valid options are: %s\n\n", options);
|
2002-05-23 12:19:07 +08:00
|
|
|
exit (where == stderr ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_version ()
|
|
|
|
{
|
2011-10-10 22:57:48 +08:00
|
|
|
printf ("mount (cygwin) %d.%d.%d\n"
|
|
|
|
"Mount filesystem utility\n"
|
|
|
|
"Copyright (C) 1996 - %s Red Hat, Inc.\n"
|
|
|
|
"This is free software; see the source for copying conditions. There is NO\n"
|
|
|
|
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
|
|
|
|
CYGWIN_VERSION_DLL_MAJOR / 1000,
|
|
|
|
CYGWIN_VERSION_DLL_MAJOR % 1000,
|
|
|
|
CYGWIN_VERSION_DLL_MINOR,
|
|
|
|
strrchr (__DATE__, ' ') + 1);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-07-04 11:11:18 +08: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-18 03:38:33 +08:00
|
|
|
int
|
2001-04-03 10:41:54 +08:00
|
|
|
main (int argc, char **argv)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int i;
|
2002-05-30 11:42:19 +08:00
|
|
|
int flags = MOUNT_BINARY;
|
2003-07-04 11:11:18 +08:00
|
|
|
char *options = strdup ("");
|
2001-04-03 10:41:54 +08:00
|
|
|
enum do_what
|
|
|
|
{
|
|
|
|
nada,
|
|
|
|
saw_change_cygdrive_prefix,
|
2001-09-04 06:02:54 +08:00
|
|
|
saw_show_cygdrive_prefix,
|
2009-07-22 18:20:26 +08:00
|
|
|
saw_mount_commands,
|
|
|
|
saw_mount_all,
|
2001-04-03 10:41:54 +08:00
|
|
|
} do_what = nada;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-10-10 22:57:48 +08:00
|
|
|
progname = program_invocation_short_name;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (argc == 1)
|
|
|
|
{
|
|
|
|
show_mounts ();
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
2001-04-03 10:41:54 +08:00
|
|
|
while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
|
|
|
|
switch (i)
|
|
|
|
{
|
2009-07-22 18:20:26 +08:00
|
|
|
case 'a':
|
|
|
|
if (do_what == nada)
|
|
|
|
do_what = saw_mount_all;
|
|
|
|
else
|
|
|
|
usage ();
|
|
|
|
break;
|
2001-04-16 10:51:03 +08:00
|
|
|
case 'c':
|
2001-04-03 10:41:54 +08:00
|
|
|
if (do_what == nada)
|
|
|
|
do_what = saw_change_cygdrive_prefix;
|
|
|
|
else
|
|
|
|
usage ();
|
|
|
|
break;
|
|
|
|
case 'f':
|
2009-07-22 18:20:26 +08:00
|
|
|
force = true;
|
2001-04-03 10:41:54 +08:00
|
|
|
break;
|
2002-05-23 12:19:07 +08:00
|
|
|
case 'h':
|
|
|
|
usage (stdout);
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
if (do_what == nada)
|
|
|
|
do_what = saw_mount_commands;
|
|
|
|
else
|
|
|
|
usage ();
|
|
|
|
break;
|
2003-07-04 11:11:18 +08:00
|
|
|
case 'o':
|
2009-07-22 18:20:26 +08:00
|
|
|
if (do_what == saw_mount_all)
|
|
|
|
usage ();
|
|
|
|
else if (*options)
|
2003-07-04 11:11:18 +08:00
|
|
|
options = concat3 (options, ",", optarg);
|
|
|
|
else
|
|
|
|
options = strdup (optarg);
|
|
|
|
break;
|
2001-04-03 10:41:54 +08:00
|
|
|
case 'p':
|
|
|
|
if (do_what == nada)
|
|
|
|
do_what = saw_show_cygdrive_prefix;
|
|
|
|
else
|
|
|
|
usage ();
|
|
|
|
break;
|
2011-10-10 22:57:48 +08:00
|
|
|
case 'V':
|
2002-05-23 12:19:07 +08:00
|
|
|
print_version ();
|
|
|
|
return 0;
|
2001-04-03 10:41:54 +08:00
|
|
|
break;
|
|
|
|
default:
|
2011-10-10 22:57:48 +08:00
|
|
|
fprintf (stderr, "Try `%s --help' for more information.\n", progname);
|
|
|
|
return 1;
|
2001-04-03 10:41:54 +08:00
|
|
|
}
|
2000-10-28 13:00:00 +08:00
|
|
|
|
2010-04-29 16:50:23 +08:00
|
|
|
if (cygwin_internal (CW_CVT_MNT_OPTS, &options, &flags))
|
2003-07-04 11:11:18 +08:00
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: invalid option - '%s'\n", progname, options);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2002-05-12 12:29:54 +08:00
|
|
|
if (flags & MOUNT_NOTEXEC && flags & (MOUNT_EXEC | MOUNT_CYGWIN_EXEC))
|
|
|
|
{
|
2011-10-10 22:57:48 +08:00
|
|
|
fprintf (stderr, "%s: invalid combination of executable options\n",
|
|
|
|
progname);
|
2002-05-12 12:29:54 +08:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2007-03-30 21:36:06 +08:00
|
|
|
cygwin_internal (CW_SET_DOS_FILE_WARNING, false);
|
|
|
|
|
2001-04-03 10:41:54 +08:00
|
|
|
argc--;
|
|
|
|
switch (do_what)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-03 10:41:54 +08:00
|
|
|
case saw_change_cygdrive_prefix:
|
|
|
|
if (optind != argc)
|
|
|
|
usage ();
|
2008-04-23 19:37:58 +08:00
|
|
|
change_cygdrive_prefix (argv[optind], flags);
|
2001-04-03 10:41:54 +08:00
|
|
|
break;
|
|
|
|
case saw_show_cygdrive_prefix:
|
|
|
|
if (optind <= argc)
|
|
|
|
usage ();
|
|
|
|
show_cygdrive_info ();
|
|
|
|
break;
|
2001-09-04 06:02:54 +08:00
|
|
|
case saw_mount_commands:
|
|
|
|
if (optind <= argc)
|
|
|
|
usage ();
|
2008-08-14 00:35:04 +08:00
|
|
|
mount_entries ();
|
2001-09-04 06:02:54 +08:00
|
|
|
break;
|
2009-07-22 18:20:26 +08:00
|
|
|
case saw_mount_all:
|
|
|
|
if (optind <= argc)
|
|
|
|
usage ();
|
|
|
|
do_mount_from_fstab (NULL);
|
|
|
|
break;
|
2001-04-03 10:41:54 +08:00
|
|
|
default:
|
2009-07-22 18:20:26 +08:00
|
|
|
if (optind == argc)
|
|
|
|
do_mount_from_fstab (argv[optind]);
|
|
|
|
else if (optind != (argc - 1))
|
2001-04-03 10:41:54 +08:00
|
|
|
{
|
2009-07-22 18:20:26 +08:00
|
|
|
fprintf (stderr, "%s: too many arguments\n", progname);
|
2001-04-03 10:41:54 +08:00
|
|
|
usage ();
|
|
|
|
}
|
2009-07-22 18:20:26 +08:00
|
|
|
else if (force || !mount_already_exists (argv[optind + 1], flags))
|
2008-04-23 19:37:58 +08:00
|
|
|
do_mount (argv[optind], argv[optind + 1], flags);
|
2001-04-03 10:41:54 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
errno = EBUSY;
|
|
|
|
error (argv[optind + 1]);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTREACHED */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-14 00:35:04 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-09-04 06:02:54 +08:00
|
|
|
static void
|
2008-08-14 00:35:04 +08:00
|
|
|
mount_entries (void)
|
2001-09-04 06:02:54 +08:00
|
|
|
{
|
|
|
|
FILE *m = setmntent ("/-not-used-", "r");
|
|
|
|
struct mntent *p;
|
2008-08-14 00:35:04 +08:00
|
|
|
const char *format_mnt = "%s %s %s %s 0 0\n";
|
|
|
|
const char *format_cyg = "none %s cygdrive %s 0 0\n";
|
2001-09-04 06:02:54 +08:00
|
|
|
|
2008-08-14 00:35:04 +08:00
|
|
|
// write fstab entries for normal mount points
|
2003-09-04 09:04:57 +08:00
|
|
|
while ((p = getmntent (m)) != NULL)
|
2010-08-11 19:01:14 +08:00
|
|
|
// Only list non-cygdrives and non-automounts
|
2009-05-14 11:25:45 +08:00
|
|
|
if (!strstr (p->mnt_opts, ",noumount") && !strstr (p->mnt_opts, ",auto"))
|
2003-09-04 09:04:57 +08:00
|
|
|
{
|
2008-08-14 00:35:04 +08:00
|
|
|
char fsname[NT_MAX_PATH], dirname[NT_MAX_PATH];
|
2010-08-11 19:01:14 +08:00
|
|
|
/* Drop the "bind" option since it can't be reverted. */
|
|
|
|
char *c = strstr (p->mnt_opts, ",bind");
|
|
|
|
if (c)
|
|
|
|
memmove (c, c + 5, strlen (c + 5) + 1);
|
2008-08-14 00:35:04 +08:00
|
|
|
printf (format_mnt, convert_spaces (fsname, p->mnt_fsname),
|
|
|
|
convert_spaces (dirname, p->mnt_dir),
|
|
|
|
p->mnt_type, p->mnt_opts);
|
2003-09-04 09:04:57 +08:00
|
|
|
}
|
2001-09-04 06:02:54 +08:00
|
|
|
endmntent (m);
|
|
|
|
|
2008-08-14 00:35:04 +08:00
|
|
|
// write fstab entry for cygdrive prefix
|
|
|
|
m = setmntent ("/-not-used-", "r");
|
|
|
|
while ((p = getmntent (m)) != NULL)
|
2003-09-04 09:04:57 +08:00
|
|
|
{
|
2008-08-14 00:35:04 +08:00
|
|
|
char *noumount;
|
|
|
|
if ((noumount = strstr (p->mnt_opts, ",noumount")))
|
|
|
|
{
|
|
|
|
char dirname[NT_MAX_PATH];
|
|
|
|
char opts[strlen (p->mnt_opts) + 1];
|
|
|
|
|
|
|
|
convert_spaces (dirname, p->mnt_dir);
|
2009-03-02 18:47:04 +08:00
|
|
|
// remove trailing slash
|
2008-08-14 00:35:04 +08:00
|
|
|
char *ls = strrchr (dirname, '/');
|
2009-03-02 18:47:04 +08:00
|
|
|
if (ls)
|
|
|
|
{
|
|
|
|
// last slash == leading slash? cygdrive prefix == "/"
|
|
|
|
if (ls == dirname)
|
|
|
|
++ls;
|
|
|
|
*ls = '\0';
|
|
|
|
}
|
2008-08-14 00:35:04 +08:00
|
|
|
*stpncpy (opts, p->mnt_opts, noumount - p->mnt_opts) = '\0';
|
|
|
|
printf (format_cyg, dirname, opts);
|
|
|
|
break;
|
|
|
|
}
|
2003-09-04 09:04:57 +08:00
|
|
|
}
|
2008-08-14 00:35:04 +08:00
|
|
|
endmntent (m);
|
|
|
|
|
2001-09-04 06:02:54 +08:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
static void
|
|
|
|
show_mounts (void)
|
|
|
|
{
|
|
|
|
FILE *m = setmntent ("/-not-used-", "r");
|
|
|
|
struct mntent *p;
|
2001-04-02 22:58:47 +08:00
|
|
|
const char *format = "%s on %s type %s (%s)\n";
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-04-02 22:58:47 +08:00
|
|
|
// printf (format, "Device", "Directory", "Type", "Flags");
|
2000-02-18 03:38:33 +08:00
|
|
|
while ((p = getmntent (m)) != NULL)
|
2001-04-02 22:58:47 +08:00
|
|
|
printf (format, p->mnt_fsname, p->mnt_dir, p->mnt_type, p->mnt_opts);
|
2000-02-18 03:38:33 +08: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-14 05:49:36 +08:00
|
|
|
if (p->mnt_type[0] == 'u')
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-16 10:51:03 +08: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-18 03:38:33 +08:00
|
|
|
break;
|
2001-04-16 10:51:03 +08:00
|
|
|
}
|
2000-07-14 05:49:36 +08:00
|
|
|
else if (p->mnt_type[0] == 's')
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-16 10:51:03 +08:00
|
|
|
if (flags & MOUNT_SYSTEM) /* both system */
|
|
|
|
found_matching = 1;
|
|
|
|
else
|
|
|
|
fprintf (stderr,
|
|
|
|
"%s: warning: user mount point of '%s' "
|
2011-10-10 22:57:48 +08:00
|
|
|
"masks system mount.\n", progname, posix_path);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-10 22:57:48 +08:00
|
|
|
fprintf (stderr, "%s: warning: couldn't determine mount type.\n",
|
|
|
|
progname);
|
2000-02-18 03:38:33 +08: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 12:54:32 +08:00
|
|
|
flags |= MOUNT_CYGDRIVE;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (mount (NULL, new_prefix, flags))
|
2000-06-08 20:54:12 +08:00
|
|
|
error (new_prefix);
|
2000-10-28 13:00:00 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
exit (0);
|
|
|
|
}
|
2000-07-29 06:34:24 +08:00
|
|
|
|
2001-04-03 10:41:54 +08:00
|
|
|
/* show_cygdrive_info: Show the user and/or cygdrive info, i.e., prefix and
|
2000-11-09 04:39:45 +08:00
|
|
|
flags.*/
|
2000-07-29 06:34:24 +08:00
|
|
|
static void
|
2000-11-09 04:39:45 +08:00
|
|
|
show_cygdrive_info ()
|
2000-07-29 06:34:24 +08:00
|
|
|
{
|
2000-11-09 04:39:45 +08:00
|
|
|
/* Get the cygdrive info */
|
2000-07-29 06:34:24 +08:00
|
|
|
char user[MAX_PATH];
|
|
|
|
char system[MAX_PATH];
|
2000-11-09 04:39:45 +08: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 06:34:24 +08:00
|
|
|
|
2001-04-03 10:41:54 +08:00
|
|
|
/* Display the user and system cygdrive path prefix, if necessary
|
2000-07-29 06:34:24 +08:00
|
|
|
(ie, not empty) */
|
2000-11-09 04:39:45 +08:00
|
|
|
const char *format = "%-18s %-11s %s\n";
|
|
|
|
printf (format, "Prefix", "Type", "Flags");
|
2000-07-29 06:34:24 +08:00
|
|
|
if (strlen (user) > 0)
|
2000-11-09 04:39:45 +08:00
|
|
|
printf (format, user, "user", user_flags);
|
2000-07-29 06:34:24 +08:00
|
|
|
if (strlen (system) > 0)
|
2008-08-14 00:35:04 +08:00
|
|
|
printf (format, system, "nouser", system_flags);
|
2000-07-29 06:34:24 +08:00
|
|
|
|
|
|
|
exit (0);
|
|
|
|
}
|