From a5fe426282c0586415642baf7fb0c880f5f163de Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 11 Aug 2010 10:58:06 +0000 Subject: [PATCH] * mount.cc (struct opt): Add "bind" option. (mount_info::from_fstab_line): Handle "bind" option. (fillout_mntent): Add "bind" option to mnt_opts. (mount): Handle "bind" option. * include/sys/mount.h (MOUNT_BIND): New mount flag. --- winsup/cygwin/ChangeLog | 8 ++++++ winsup/cygwin/include/sys/mount.h | 3 ++- winsup/cygwin/mount.cc | 41 ++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 207f083fd..94e8f8c72 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,11 @@ +2010-08-11 Corinna Vinschen + + * mount.cc (struct opt): Add "bind" option. + (mount_info::from_fstab_line): Handle "bind" option. + (fillout_mntent): Add "bind" option to mnt_opts. + (mount): Handle "bind" option. + * include/sys/mount.h (MOUNT_BIND): New mount flag. + 2010-08-10 Christopher Faylor * sigproc.cc (init_sig_pipe): Add retry loop. diff --git a/winsup/cygwin/include/sys/mount.h b/winsup/cygwin/include/sys/mount.h index 0fe5e3c74..0680e4562 100644 --- a/winsup/cygwin/include/sys/mount.h +++ b/winsup/cygwin/include/sys/mount.h @@ -39,7 +39,8 @@ enum MOUNT_AUTOMATIC = 0x20000, /* Mount point was added automatically */ MOUNT_DOS = 0x40000, /* convert leading spaces and trailing dots and spaces to private use area */ - MOUNT_IHASH = 0x80000 /* Enforce hash values for inode numbers */ + MOUNT_IHASH = 0x80000, /* Enforce hash values for inode numbers */ + MOUNT_BIND = 0x100000 /* Allows bind syntax in fstab file. */ }; int mount (const char *, const char *, unsigned __flags); diff --git a/winsup/cygwin/mount.cc b/winsup/cygwin/mount.cc index 315125967..5f5e2e03c 100644 --- a/winsup/cygwin/mount.cc +++ b/winsup/cygwin/mount.cc @@ -931,6 +931,7 @@ struct opt {"acl", MOUNT_NOACL, 1}, {"auto", 0, 0}, {"binary", MOUNT_BINARY, 0}, + {"bind", MOUNT_BIND, 0}, {"cygexec", MOUNT_CYGWIN_EXEC, 0}, {"dos", MOUNT_DOS, 0}, {"exec", MOUNT_EXEC, 0}, @@ -1051,6 +1052,20 @@ mount_info::from_fstab_line (char *line, bool user) return true; if (user) mount_flags &= ~MOUNT_SYSTEM; + if (mount_flags & MOUNT_BIND) + { + /* Prepend root path to bound path. */ + char *bound_path = native_path; + device dev; + unsigned flags = 0; + native_path = (char *) alloca (PATH_MAX); + int error = conv_to_win32_path (bound_path, native_path, dev, &flags); + if (error || strlen (native_path) >= MAX_PATH) + return true; + if ((mount_flags & ~MOUNT_SYSTEM) == (MOUNT_BIND | MOUNT_BINARY)) + mount_flags = (MOUNT_BIND | flags) + & ~(MOUNT_IMMUTABLE | MOUNT_AUTOMATIC); + } if (!strcmp (fs_type, "cygdrive")) { cygdrive_flags = mount_flags | MOUNT_CYGDRIVE; @@ -1573,6 +1588,9 @@ fillout_mntent (const char *native_path, const char *posix_path, unsigned flags) if (flags & (MOUNT_AUTOMATIC | MOUNT_CYGDRIVE)) strcat (_my_tls.locals.mnt_opts, (char *) ",auto"); + if (flags & (MOUNT_BIND)) + strcat (_my_tls.locals.mnt_opts, (char *) ",bind"); + ret.mnt_opts = _my_tls.locals.mnt_opts; ret.mnt_freq = 1; @@ -1672,7 +1690,28 @@ mount (const char *win32_path, const char *posix_path, unsigned flags) else if (!*win32_path) set_errno (EINVAL); else - res = mount_table->add_item (win32_path, posix_path, flags); + { + char *w32_path = (char *) win32_path; + if (flags & MOUNT_BIND) + { + /* Prepend root path to bound path. */ + tmp_pathbuf tp; + device dev; + + unsigned conv_flags = 0; + const char *bound_path = w32_path; + + w32_path = tp.c_get (); + int error = mount_table->conv_to_win32_path (bound_path, w32_path, + dev, &conv_flags); + if (error || strlen (w32_path) >= MAX_PATH) + return true; + if ((flags & ~MOUNT_SYSTEM) == (MOUNT_BIND | MOUNT_BINARY)) + flags = (MOUNT_BIND | conv_flags) + & ~(MOUNT_IMMUTABLE | MOUNT_AUTOMATIC); + } + res = mount_table->add_item (w32_path, posix_path, flags); + } syscall_printf ("%d = mount (%s, %s, %p)", res, win32_path, posix_path, flags); return res;