From 91d2f6eebffcc8aa492b59c99f429aa41d09e82e Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Thu, 19 Jul 2007 11:41:17 +0000 Subject: [PATCH] * fhandler.cc (fhandler_base::open): Drop local wpath and upath variables. Call pc.get_object_attr to create object attributes. * fhandler_disk_file.cc (fhandler_disk_file::opendir): Ditto. * syscalls.cc (unlink_nt): Ditto. * path.cc (path_conv::set_normalized_path): Set wide_path to NULL. (path_conv::get_nt_native_path): Drop parameter. Create path in wide_path/uni_path members. (path_conv::get_object_attr): New method to create object attributes. (path_conv::get_wide_win32_path): New method to create Win32 wide path. (path_conv::check): Initialize wide_path to NULL. (path_conv::~path_conv): cfree wide_path. * path.h (class path_conv): New members wide_path and uni_path. Add declarations of get_object_attr and get_wide_win32_path. (path_conv::path_conv): Initialize wide_path to NULL. (path_conv::get_nt_native_path): Drop parameter. --- winsup/cygwin/ChangeLog | 18 ++++++++++++ winsup/cygwin/fhandler.cc | 7 +---- winsup/cygwin/fhandler_disk_file.cc | 9 ++---- winsup/cygwin/path.cc | 43 +++++++++++++++++++++++++++-- winsup/cygwin/path.h | 15 +++++++--- winsup/cygwin/syscalls.cc | 6 +--- 6 files changed, 74 insertions(+), 24 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index c5c012ca1..754892a1a 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,21 @@ +2007-07-19 Corinna Vinschen + + * fhandler.cc (fhandler_base::open): Drop local wpath and upath + variables. Call pc.get_object_attr to create object attributes. + * fhandler_disk_file.cc (fhandler_disk_file::opendir): Ditto. + * syscalls.cc (unlink_nt): Ditto. + * path.cc (path_conv::set_normalized_path): Set wide_path to NULL. + (path_conv::get_nt_native_path): Drop parameter. Create path in + wide_path/uni_path members. + (path_conv::get_object_attr): New method to create object attributes. + (path_conv::get_wide_win32_path): New method to create Win32 wide path. + (path_conv::check): Initialize wide_path to NULL. + (path_conv::~path_conv): cfree wide_path. + * path.h (class path_conv): New members wide_path and uni_path. + Add declarations of get_object_attr and get_wide_win32_path. + (path_conv::path_conv): Initialize wide_path to NULL. + (path_conv::get_nt_native_path): Drop parameter. + 2007-07-19 Corinna Vinschen * sec_helper.cc: Remove unused code. diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 1920dbec7..960b37549 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -457,10 +457,6 @@ done: int fhandler_base::open (int flags, mode_t mode) { - WCHAR wpath[CYG_MAX_PATH + 10]; - UNICODE_STRING upath = {0, sizeof (wpath), wpath}; - pc.get_nt_native_path (upath); - int res = 0; HANDLE x; ULONG file_attributes = 0; @@ -475,8 +471,7 @@ fhandler_base::open (int flags, mode_t mode) syscall_printf ("(%s, %p)", get_win32_name (), flags); - InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE | OBJ_INHERIT, - NULL, sa.lpSecurityDescriptor); + pc.get_object_attr (attr, sa); switch (query_open ()) { diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 17c93be9a..a2b2bf093 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -1575,16 +1575,11 @@ fhandler_disk_file::opendir (int fd) OBJECT_ATTRIBUTES attr; NTSTATUS status; IO_STATUS_BLOCK io; - WCHAR wpath[CYG_MAX_PATH + 10] = { 0 }; - UNICODE_STRING upath = {0, sizeof (wpath), wpath}; - SECURITY_ATTRIBUTES sa = sec_none; - pc.get_nt_native_path (upath); - InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE, - NULL, sa.lpSecurityDescriptor); status = NtOpenFile (&get_handle (), SYNCHRONIZE | FILE_LIST_DIRECTORY, - &attr, &io, FILE_SHARE_VALID_FLAGS, + pc.get_object_attr (attr, sec_none_nih), + &io, FILE_SHARE_VALID_FLAGS, FILE_SYNCHRONOUS_IO_NONALERT | FILE_OPEN_FOR_BACKUP_INTENT | FILE_DIRECTORY_FILE); diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index e2ac1bb9c..6e345588e 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -79,6 +79,7 @@ details. */ #include "environ.h" #include #include +#include bool dos_file_warning = true; static int normalize_win32_path (const char *, char *, char *&); @@ -539,6 +540,7 @@ path_conv::set_normalized_path (const char *path_copy, bool strip_tail) } memcpy (normalized_path, path_copy, n); + wide_path = NULL; } PUNICODE_STRING @@ -566,9 +568,40 @@ get_nt_native_path (const char *path, UNICODE_STRING &upath) } PUNICODE_STRING -path_conv::get_nt_native_path (UNICODE_STRING &upath) +path_conv::get_nt_native_path () { - return ::get_nt_native_path (path, upath); + if (!wide_path) + { + uni_path.Length = 0; + uni_path.MaximumLength = (strlen (path) + 10) * sizeof (WCHAR); + wide_path = (PWCHAR) cmalloc (HEAP_STR, uni_path.MaximumLength); + uni_path.Buffer = wide_path; + ::get_nt_native_path (path, uni_path); + } + return &uni_path; +} + +POBJECT_ATTRIBUTES +path_conv::get_object_attr (OBJECT_ATTRIBUTES &attr, SECURITY_ATTRIBUTES &sa) +{ + if (!get_nt_native_path ()) + return NULL; + InitializeObjectAttributes (&attr, &uni_path, + OBJ_CASE_INSENSITIVE + | (sa.bInheritHandle ? OBJ_INHERIT : 0), + NULL, sa.lpSecurityDescriptor); + return &attr; +} + +PWCHAR +path_conv::get_wide_win32_path (PWCHAR wc) +{ + get_nt_native_path (); + if (!wide_path || wide_path[1] != L'?') /* Native NT device path */ + return NULL; + wcscpy (wc, wide_path); + wc[1] = L'\\'; + return wc; } void @@ -640,6 +673,7 @@ path_conv::check (const char *src, unsigned opt, path_flags = 0; known_suffix = NULL; fileattr = INVALID_FILE_ATTRIBUTES; + wide_path = NULL; case_clash = false; memset (&dev, 0, sizeof (dev)); fs.clear (); @@ -1147,6 +1181,11 @@ path_conv::~path_conv () cfree (normalized_path); normalized_path = NULL; } + if (wide_path) + { + cfree (wide_path); + wide_path = NULL; + } } /* Return true if src_path is a valid, internally supported device name. diff --git a/winsup/cygwin/path.h b/winsup/cygwin/path.h index 272d397b2..6e553be6b 100644 --- a/winsup/cygwin/path.h +++ b/winsup/cygwin/path.h @@ -156,6 +156,8 @@ class path_conv { DWORD fileattr; fs_info fs; + PWCHAR wide_path; + UNICODE_STRING uni_path; void add_ext_from_sym (symlink_info&); public: @@ -236,7 +238,8 @@ class path_conv const suffix_info *suffixes = NULL) __attribute__ ((regparm(3))); path_conv (const device& in_dev): fileattr (INVALID_FILE_ATTRIBUTES), - path_flags (0), known_suffix (NULL), error (0), dev (in_dev) + wide_path (NULL), path_flags (0), known_suffix (NULL), error (0), + dev (in_dev) { strcpy (path, in_dev.native); } @@ -253,14 +256,18 @@ class path_conv check (src, opt | PC_NULLEMPTY, suffixes); } - path_conv (): fileattr (INVALID_FILE_ATTRIBUTES), path_flags (0), - known_suffix (NULL), error (0), normalized_path (NULL) + path_conv (): fileattr (INVALID_FILE_ATTRIBUTES), wide_path (NULL), + path_flags (0), known_suffix (NULL), error (0), + normalized_path (NULL) {path[0] = '\0';} ~path_conv (); void set_name (const char *win32, const char *posix); inline char *get_win32 () { return path; } - PUNICODE_STRING get_nt_native_path (UNICODE_STRING &upath); + PUNICODE_STRING get_nt_native_path (); + POBJECT_ATTRIBUTES get_object_attr (OBJECT_ATTRIBUTES &attr, + SECURITY_ATTRIBUTES &sa); + PWCHAR get_wide_win32_path (PWCHAR wc); operator char *() {return path;} operator const char *() {return path;} operator DWORD &() {return fileattr;} diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 3d9cba259..65aac3b64 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -234,8 +234,6 @@ try_to_bin (path_conv &win32_path, HANDLE h) DWORD unlink_nt (path_conv &win32_name, bool setattrs) { - WCHAR wpath[CYG_MAX_PATH + 10]; - UNICODE_STRING upath = {0, sizeof (wpath), wpath}; OBJECT_ATTRIBUTES attr; IO_STATUS_BLOCK io; NTSTATUS status; @@ -269,9 +267,7 @@ unlink_nt (path_conv &win32_name, bool setattrs) if (win32_name.is_rep_symlink ()) flags |= FILE_OPEN_REPARSE_POINT; - win32_name.get_nt_native_path (upath); - InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE | OBJ_INHERIT, - NULL, sec_none_nih.lpSecurityDescriptor); + win32_name.get_object_attr (attr, sec_none_nih); /* First try to open the file with sharing not allowed. If the file has an open handle on it, this will fail. That indicates that the file has to be moved to the recycle bin so that it actually disappears