4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-21 16:26:12 +08:00

* mount.cc (longopts): Add mount-commands to options list.

(usage): Add mount-commands option.
(mount_commands): New function.  Write commands to recreate current mounts.
This commit is contained in:
Christopher Faylor 2001-09-03 22:02:54 +00:00
parent 7170a41bc8
commit bee722a5e7
2 changed files with 81 additions and 2 deletions

View File

@ -1,3 +1,10 @@
2001-09-03 Michael A Chase <mchase@ix.netcom.com>
* mount.cc (longopts): Add mount-commands to options list.
(usage): Add mount-commands option.
(mount_commands): New function. Write commands to recreate current
mounts.
Sat Sep 1 15:58:11 2001 Christopher Faylor <cgf@cygnus.com> Sat Sep 1 15:58:11 2001 Christopher Faylor <cgf@cygnus.com>
* mount.cc (main): Eliminate excess arguments in printf. * mount.cc (main): Eliminate excess arguments in printf.

View File

@ -22,6 +22,7 @@ details. */
#endif #endif
#include <errno.h> #include <errno.h>
static void mount_commands (void);
static void show_mounts (void); static void show_mounts (void);
static void show_cygdrive_info (void); static void show_cygdrive_info (void);
static void change_cygdrive_prefix (const char *new_prefix, int flags); static void change_cygdrive_prefix (const char *new_prefix, int flags);
@ -98,10 +99,11 @@ struct option longopts[] =
{"cygwin-executable", no_argument, NULL, 'X'}, {"cygwin-executable", no_argument, NULL, 'X'},
{"show-cygdrive-prefix", no_argument, NULL, 'p'}, {"show-cygdrive-prefix", no_argument, NULL, 'p'},
{"import-old-mounts", no_argument, NULL, 'i'}, {"import-old-mounts", no_argument, NULL, 'i'},
{"mount-commands", no_argument, NULL, 'm'},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
char opts[] = "hbfstuxXpic"; char opts[] = "hbfstuxXpicm";
static void static void
usage (void) usage (void)
@ -121,6 +123,8 @@ usage (void)
-x, --executable treat all files under mount point as executables\n\ -x, --executable treat all files under mount point as executables\n\
-X, --cygwin-executable treat all files under mount point as cygwin\n\ -X, --cygwin-executable treat all files under mount point as cygwin\n\
executables\n\ executables\n\
-m, --mount-commands write mount commands to replace user and\n\
system mount points and cygdrive prefixes\n\
", progname); ", progname);
exit (1); exit (1);
} }
@ -135,7 +139,8 @@ main (int argc, char **argv)
nada, nada,
saw_change_cygdrive_prefix, saw_change_cygdrive_prefix,
saw_import_old_mounts, saw_import_old_mounts,
saw_show_cygdrive_prefix saw_show_cygdrive_prefix,
saw_mount_commands
} do_what = nada; } do_what = nada;
progname = argv[0]; progname = argv[0];
@ -188,6 +193,12 @@ main (int argc, char **argv)
case 'x': case 'x':
flags |= MOUNT_EXEC; flags |= MOUNT_EXEC;
break; break;
case 'm':
if (do_what == nada)
do_what = saw_mount_commands;
else
usage ();
break;
default: default:
usage (); usage ();
} }
@ -211,6 +222,11 @@ main (int argc, char **argv)
usage (); usage ();
show_cygdrive_info (); show_cygdrive_info ();
break; break;
case saw_mount_commands:
if (optind <= argc)
usage ();
mount_commands ();
break;
default: default:
if (optind != (argc - 1)) if (optind != (argc - 1))
{ {
@ -233,6 +249,62 @@ main (int argc, char **argv)
return 0; return 0;
} }
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
while ((p = getmntent (m)) != NULL) {
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");
while ((c = strchr (p->mnt_fsname, '\\')) != NULL)
*c = '/';
printf (format_mnt, opts, p->mnt_fsname, p->mnt_dir);
}
endmntent (m);
// write mount commands for cygdrive prefixes
cygwin_internal (CW_GET_CYGDRIVE_INFO, user, system, user_flags,
system_flags);
if (strlen (user) > 0) {
strcpy (opts, " ");
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);
}
exit(0);
}
static void static void
show_mounts (void) show_mounts (void)
{ {