Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2008-05-23 20:38:51 +0400
committerChristopher Faylor <me@cgf.cx>2008-05-23 20:38:51 +0400
commite765b3c0adf2d1a6133b52ce7cb2e71a74811756 (patch)
tree8e95621e464a8d24c2ccf9e81b170a6953610535
parent7cd454287369cf3918cb31ed3d8b284eb42e257a (diff)
* mount.cc (find_root_from_cygwin_dll): New function factored from from_fstab.
Avoid use of tls since it isn't necessarily initialized when cygwin1.dll is dynamically loaded. (mount_info::create_root_entry): Ditto. (mount_info::init): Calculate cygwin root once. Use create_root_entry to record it. Pass fstab location to from_fstab. (mount_info::from_fstab): Move root calculation stuff elsewhere, as per above. * shared_info.h (mount_info::from_fstab_line): Make private. (mount_info::fstab): Ditto. Accommodate new arguments.
-rw-r--r--winsup/cygwin/ChangeLog14
-rw-r--r--winsup/cygwin/mount.cc102
-rw-r--r--winsup/cygwin/shared_info.h8
3 files changed, 74 insertions, 50 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index bd426b210..b8519ded9 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,19 @@
2008-05-23 Christopher Faylor <me+cygwin@cgf.cx>
+ * mount.cc (find_root_from_cygwin_dll): New function factored from
+ from_fstab. Avoid use of tls since it isn't necessarily initialized
+ when cygwin1.dll is dynamically loaded.
+ (mount_info::create_root_entry): Ditto.
+ (mount_info::init): Calculate cygwin root once. Use create_root_entry
+ to record it. Pass fstab location to from_fstab.
+ (mount_info::from_fstab): Move root calculation stuff elsewhere, as per
+ above.
+
+ * shared_info.h (mount_info::from_fstab_line): Make private.
+ (mount_info::fstab): Ditto. Accommodate new arguments.
+
+2008-05-23 Christopher Faylor <me+cygwin@cgf.cx>
+
* mount.cc (mount_info::from_fstab): Use cygwin_hmodule rather than
trying to find handle based on cygwin1.dll.
diff --git a/winsup/cygwin/mount.cc b/winsup/cygwin/mount.cc
index 1d7d7cda7..eb10425d0 100644
--- a/winsup/cygwin/mount.cc
+++ b/winsup/cygwin/mount.cc
@@ -72,15 +72,62 @@ win32_device_name (const char *src_path, char *win32_path, device& dev)
return true;
}
+/* Use absolute path of cygwin1.dll to derive a "root".
+ Return false if GetModuleFileNameW fails or path is "funny".
+ Otherwise return true. */
+static inline PWCHAR
+find_root_from_cygwin_dll (WCHAR *path)
+{
+ if (!GetModuleFileNameW (cygwin_hmodule, path, NT_MAX_PATH))
+ {
+ debug_printf ("GetModuleFileNameW(%p, %p, %u), %E", cygwin_hmodule, path, NT_MAX_PATH);
+ return NULL;
+ }
+ PWCHAR w = wcsrchr (path, L'\\');
+ if (w)
+ {
+ *w = L'\0';
+ w = wcsrchr (path, L'\\');
+ }
+ if (!w)
+ {
+ debug_printf ("Invalid DLL path");
+ return NULL;
+ }
+ *w = L'\0';
+ return w;
+}
+
+inline void
+mount_info::create_root_entry (const PWCHAR root)
+{
+ /* Create a default root dir from the path the Cygwin DLL is in. */
+ char native_root[NT_MAX_PATH];
+ sys_wcstombs (native_root, NT_MAX_PATH, root);
+ mount_table->add_item (native_root, "/", MOUNT_SYSTEM | MOUNT_BINARY);
+ /* Create a default cygdrive entry. Note that this is a user entry.
+ This allows to override it with mount, unless the sysadmin created
+ a cygdrive entry in /etc/fstab. */
+ cygdrive_flags = MOUNT_BINARY | MOUNT_CYGDRIVE;
+ strcpy (cygdrive, CYGWIN_INFO_CYGDRIVE_DEFAULT_PREFIX "/");
+ cygdrive_len = strlen (cygdrive);
+}
+
/* init: Initialize the mount table. */
void
mount_info::init ()
{
nmounts = 0;
-
- if (from_fstab (false) | from_fstab (true)) /* The single | is correct! */
- return;
+ PWCHAR pathend;
+ WCHAR path[NT_MAX_PATH];
+ if ((pathend = find_root_from_cygwin_dll (path)))
+ {
+ create_root_entry (path);
+ pathend = wcpcpy (pathend, L"\\etc\\fstab");
+ if (from_fstab (false, path, pathend) | from_fstab (true, path, pathend)) /* The single | is correct! */
+ return;
+ }
/* FIXME: Remove warning message before releasing 1.7.0. */
small_printf ("Huh? No /etc/fstab file? Using default root and cygdrive prefix...\n");
@@ -870,58 +917,21 @@ mount_info::from_fstab_line (char *line, bool user)
}
bool
-mount_info::from_fstab (bool user)
+mount_info::from_fstab (bool user, WCHAR fstab[], PWCHAR fstab_end)
{
- tmp_pathbuf tp;
- PWCHAR path_buf = tp.w_get ();
- PWCHAR path = path_buf;
- PWCHAR w;
-
- if (!GetModuleFileNameW (cygwin_hmodule, path, NT_MAX_PATH))
- {
- debug_printf ("GetModuleFileNameW(%p, path, %u), %E", cygwin_hmodule, NT_MAX_PATH);
- return false;
- }
- w = wcsrchr (path, L'\\');
- if (w)
- {
- *w = L'\0';
- w = wcsrchr (path, L'\\');
- }
- if (!w)
- {
- debug_printf ("Invalid DLL path");
- return false;
- }
-
- if (!user)
- {
- /* Create a default root dir from the path the Cygwin DLL is in. */
- *w = L'\0';
- char *native_root = tp.c_get ();
- sys_wcstombs (native_root, NT_MAX_PATH, path);
- mount_table->add_item (native_root, "/", MOUNT_SYSTEM | MOUNT_BINARY);
- /* Create a default cygdrive entry. Note that this is a user entry.
- This allows to override it with mount, unless the sysadmin created
- a cygdrive entry in /etc/fstab. */
- cygdrive_flags = MOUNT_BINARY | MOUNT_CYGDRIVE;
- strcpy (cygdrive, CYGWIN_INFO_CYGDRIVE_DEFAULT_PREFIX "/");
- cygdrive_len = strlen (cygdrive);
- }
-
- PWCHAR u = wcpcpy (w, L"\\etc\\fstab");
if (user)
- sys_mbstowcs (wcpcpy (u, L".d\\"), NT_MAX_PATH - (u - path),
+ sys_mbstowcs (wcpcpy (fstab_end, L".d\\"),
+ NT_MAX_PATH - (fstab_end - fstab),
cygheap->user.name ());
- debug_printf ("Try to read mounts from %W", path);
- HANDLE h = CreateFileW (path, GENERIC_READ, FILE_SHARE_READ, &sec_none_nih,
+ debug_printf ("Try to read mounts from %W", fstab);
+ HANDLE h = CreateFileW (fstab, GENERIC_READ, FILE_SHARE_READ, &sec_none_nih,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE)
{
debug_printf ("CreateFileW, %E");
return false;
}
- char *const buf = reinterpret_cast<char *const> (path);
+ char *const buf = reinterpret_cast<char *const> (fstab);
char *got = buf;
DWORD len = 0;
/* Using NT_MAX_PATH-1 leaves space to append two \0. */
diff --git a/winsup/cygwin/shared_info.h b/winsup/cygwin/shared_info.h
index bd743d5df..197ef9529 100644
--- a/winsup/cygwin/shared_info.h
+++ b/winsup/cygwin/shared_info.h
@@ -75,9 +75,6 @@ class mount_info
int add_item (const char *dev, const char *path, unsigned flags);
int del_item (const char *path, unsigned flags);
- bool from_fstab_line (char *line, bool user);
- bool from_fstab (bool user);
-
unsigned set_flags_from_win32_path (const char *path);
int conv_to_win32_path (const char *src_path, char *dst, device&,
unsigned *flags = NULL);
@@ -96,9 +93,12 @@ class mount_info
PUNICODE_STRING cygd);
private:
-
void sort ();
void mount_slash ();
+ void mount_info::create_root_entry (const PWCHAR root);
+
+ bool from_fstab_line (char *line, bool user);
+ bool from_fstab (bool user, WCHAR [], PWCHAR);
int cygdrive_win32_path (const char *src, char *dst, int& unit);
};