mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-21 00:07:36 +08:00
Throughout avoid having to initialize constant UNICODE_STRINGs.
* globals.cc: Define constant UNICODE_STRINGs and store in .rdata section. * fhandler_disk_file.cc: Throughout, use readonly UNICODE_STRINGs rather then initializing local UNICODE_STRING variable where applicable. * fhandler_mem.cc (fhandler_dev_mem::open): Ditto. * flock.cc (inode_t::inode_t): Ditto. * mmap.cc: Ditto. * syscalls.cc: Ditto. * mount.cc (fs_info::update): Ditto. * path.cc: Ditto. * ntdll.h (RtlEqualUnicodePathPrefix): Redefine to take prefix as UNICODE_STRING. (RtlEqualUnicodePathSuffix): Redefine to take suffix as UNICODE_STRING. * fhandler_disk_file.cc: Accommodate throughout. * mount.cc (fs_info::update): Ditto. * path.cc (cwdstuff::set): Ditto. * syscalls.cc: Ditto.
This commit is contained in:
parent
472345a06c
commit
8deb411836
@ -1,3 +1,26 @@
|
|||||||
|
2009-07-14 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
Throughout avoid having to initialize constant UNICODE_STRINGs.
|
||||||
|
* globals.cc: Define constant UNICODE_STRINGs and store in .rdata
|
||||||
|
section.
|
||||||
|
* fhandler_disk_file.cc: Throughout, use readonly UNICODE_STRINGs
|
||||||
|
rather then initializing local UNICODE_STRING variable where
|
||||||
|
applicable.
|
||||||
|
* fhandler_mem.cc (fhandler_dev_mem::open): Ditto.
|
||||||
|
* flock.cc (inode_t::inode_t): Ditto.
|
||||||
|
* mmap.cc: Ditto.
|
||||||
|
* syscalls.cc: Ditto.
|
||||||
|
* mount.cc (fs_info::update): Ditto.
|
||||||
|
* path.cc: Ditto.
|
||||||
|
|
||||||
|
* ntdll.h (RtlEqualUnicodePathPrefix): Redefine to take prefix as
|
||||||
|
UNICODE_STRING.
|
||||||
|
(RtlEqualUnicodePathSuffix): Redefine to take suffix as UNICODE_STRING.
|
||||||
|
* fhandler_disk_file.cc: Accommodate throughout.
|
||||||
|
* mount.cc (fs_info::update): Ditto.
|
||||||
|
* path.cc (cwdstuff::set): Ditto.
|
||||||
|
* syscalls.cc: Ditto.
|
||||||
|
|
||||||
2009-07-14 Corinna Vinschen <corinna@vinschen.de>
|
2009-07-14 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* globals.cc (active_codepage): Remove.
|
* globals.cc (active_codepage): Remove.
|
||||||
|
@ -79,10 +79,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (parent_dir_len == 1) /* root dir */
|
if (parent_dir_len == 1) /* root dir */
|
||||||
{
|
{
|
||||||
UNICODE_STRING proc;
|
if (RtlEqualUnicodeString (fname, &ro_u_proc, FALSE))
|
||||||
|
|
||||||
RtlInitUnicodeString (&proc, L"proc");
|
|
||||||
if (RtlEqualUnicodeString (fname, &proc, FALSE))
|
|
||||||
{
|
{
|
||||||
found[__DIR_PROC] = true;
|
found[__DIR_PROC] = true;
|
||||||
return 2;
|
return 2;
|
||||||
@ -636,22 +633,21 @@ fhandler_base::fstat_helper (struct __stat64 *buf,
|
|||||||
{
|
{
|
||||||
PUNICODE_STRING path = pc.get_nt_native_path ();
|
PUNICODE_STRING path = pc.get_nt_native_path ();
|
||||||
|
|
||||||
if (RtlEqualUnicodePathSuffix (path, L".exe", TRUE)
|
if (RtlEqualUnicodePathSuffix (path, &ro_u_exe, TRUE)
|
||||||
|| RtlEqualUnicodePathSuffix (path, L".bat", TRUE)
|
|| RtlEqualUnicodePathSuffix (path, &ro_u_lnk, TRUE)
|
||||||
|| RtlEqualUnicodePathSuffix (path, L".com", TRUE))
|
|| RtlEqualUnicodePathSuffix (path, &ro_u_com, TRUE))
|
||||||
pc.set_exec ();
|
pc.set_exec ();
|
||||||
}
|
}
|
||||||
/* No known sufix, check file header. This catches binaries and
|
/* No known sufix, check file header. This catches binaries and
|
||||||
shebang scripts. */
|
shebang scripts. */
|
||||||
if (pc.exec_state () == dont_know_if_executable)
|
if (pc.exec_state () == dont_know_if_executable)
|
||||||
{
|
{
|
||||||
UNICODE_STRING same;
|
|
||||||
OBJECT_ATTRIBUTES attr;
|
OBJECT_ATTRIBUTES attr;
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
IO_STATUS_BLOCK io;
|
IO_STATUS_BLOCK io;
|
||||||
|
|
||||||
RtlInitUnicodeString (&same, L"");
|
InitializeObjectAttributes (&attr, &ro_u_empty, 0, get_handle (),
|
||||||
InitializeObjectAttributes (&attr, &same, 0, get_handle (), NULL);
|
NULL);
|
||||||
if (NT_SUCCESS (NtOpenFile (&h, FILE_READ_DATA, &attr, &io,
|
if (NT_SUCCESS (NtOpenFile (&h, FILE_READ_DATA, &attr, &io,
|
||||||
FILE_SHARE_VALID_FLAGS, 0)))
|
FILE_SHARE_VALID_FLAGS, 0)))
|
||||||
{
|
{
|
||||||
@ -1199,9 +1195,9 @@ fhandler_disk_file::link (const char *newpath)
|
|||||||
else if (!pc.isdir ()
|
else if (!pc.isdir ()
|
||||||
&& pc.is_binary ()
|
&& pc.is_binary ()
|
||||||
&& RtlEqualUnicodePathSuffix (pc.get_nt_native_path (),
|
&& RtlEqualUnicodePathSuffix (pc.get_nt_native_path (),
|
||||||
L".exe", TRUE)
|
&ro_u_exe, TRUE)
|
||||||
&& !RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
|
&& !RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
|
||||||
L".exe", TRUE))
|
&ro_u_exe, TRUE))
|
||||||
{
|
{
|
||||||
/* Executable hack. */
|
/* Executable hack. */
|
||||||
stpcpy (stpcpy (new_buf, newpath), ".exe");
|
stpcpy (stpcpy (new_buf, newpath), ".exe");
|
||||||
@ -1766,14 +1762,12 @@ fhandler_disk_file::readdir_helper (DIR *dir, dirent *de, DWORD w32_err,
|
|||||||
if ((attr & FILE_ATTRIBUTE_READONLY) && fname->Length > 4 * sizeof (WCHAR))
|
if ((attr & FILE_ATTRIBUTE_READONLY) && fname->Length > 4 * sizeof (WCHAR))
|
||||||
{
|
{
|
||||||
UNICODE_STRING uname;
|
UNICODE_STRING uname;
|
||||||
UNICODE_STRING lname;
|
|
||||||
|
|
||||||
RtlInitCountedUnicodeString (&uname,
|
RtlInitCountedUnicodeString (&uname,
|
||||||
fname->Buffer
|
fname->Buffer
|
||||||
+ fname->Length / sizeof (WCHAR) - 4,
|
+ fname->Length / sizeof (WCHAR) - 4,
|
||||||
4 * sizeof (WCHAR));
|
4 * sizeof (WCHAR));
|
||||||
RtlInitUnicodeString (&lname, (PWCHAR) L".lnk");
|
if (RtlEqualUnicodeString (&uname, &ro_u_lnk, TRUE))
|
||||||
if (RtlEqualUnicodeString (&uname, &lname, TRUE))
|
|
||||||
{
|
{
|
||||||
tmp_pathbuf tp;
|
tmp_pathbuf tp;
|
||||||
UNICODE_STRING fbuf;
|
UNICODE_STRING fbuf;
|
||||||
@ -2018,14 +2012,12 @@ fhandler_disk_file::rewinddir (DIR *dir)
|
|||||||
to NtQueryDirectoryFile on remote shares is ignored, thus
|
to NtQueryDirectoryFile on remote shares is ignored, thus
|
||||||
resulting in not being able to rewind on remote shares. By
|
resulting in not being able to rewind on remote shares. By
|
||||||
reopening the directory, we get a fresh new directory pointer. */
|
reopening the directory, we get a fresh new directory pointer. */
|
||||||
UNICODE_STRING fname;
|
|
||||||
OBJECT_ATTRIBUTES attr;
|
OBJECT_ATTRIBUTES attr;
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
IO_STATUS_BLOCK io;
|
IO_STATUS_BLOCK io;
|
||||||
HANDLE new_dir;
|
HANDLE new_dir;
|
||||||
|
|
||||||
RtlInitUnicodeString (&fname, L"");
|
InitializeObjectAttributes (&attr, &ro_u_empty, pc.objcaseinsensitive (),
|
||||||
InitializeObjectAttributes (&attr, &fname, pc.objcaseinsensitive (),
|
|
||||||
get_handle (), NULL);
|
get_handle (), NULL);
|
||||||
status = NtOpenFile (&new_dir, SYNCHRONIZE | FILE_LIST_DIRECTORY,
|
status = NtOpenFile (&new_dir, SYNCHRONIZE | FILE_LIST_DIRECTORY,
|
||||||
&attr, &io, FILE_SHARE_VALID_FLAGS,
|
&attr, &io, FILE_SHARE_VALID_FLAGS,
|
||||||
|
@ -77,11 +77,8 @@ fhandler_dev_mem::open (int flags, mode_t)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
UNICODE_STRING memstr;
|
|
||||||
RtlInitUnicodeString (&memstr, L"\\device\\physicalmemory");
|
|
||||||
|
|
||||||
OBJECT_ATTRIBUTES attr;
|
OBJECT_ATTRIBUTES attr;
|
||||||
InitializeObjectAttributes (&attr, &memstr,
|
InitializeObjectAttributes (&attr, &ro_u_pmem,
|
||||||
OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
|
OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
|
||||||
|
@ -453,8 +453,7 @@ inode_t::inode_t (__dev32_t dev, __ino64_t ino)
|
|||||||
api_fatal ("NtCreateDirectoryObject(inode): %p", status);
|
api_fatal ("NtCreateDirectoryObject(inode): %p", status);
|
||||||
/* Create a mutex object in the file specific dir, which is used for
|
/* Create a mutex object in the file specific dir, which is used for
|
||||||
access synchronization on the dir and its objects. */
|
access synchronization on the dir and its objects. */
|
||||||
RtlInitUnicodeString (&uname, L"mtx");
|
InitializeObjectAttributes (&attr, &ro_u_mtx, OBJ_INHERIT | OBJ_OPENIF, i_dir,
|
||||||
InitializeObjectAttributes (&attr, &uname, OBJ_INHERIT | OBJ_OPENIF, i_dir,
|
|
||||||
everyone_sd (CYG_MUTANT_ACCESS));
|
everyone_sd (CYG_MUTANT_ACCESS));
|
||||||
status = NtCreateMutant (&i_mtx, CYG_MUTANT_ACCESS, &attr, FALSE);
|
status = NtCreateMutant (&i_mtx, CYG_MUTANT_ACCESS, &attr, FALSE);
|
||||||
if (!NT_SUCCESS (status))
|
if (!NT_SUCCESS (status))
|
||||||
|
@ -72,6 +72,31 @@ char NO_COPY almost_null[1];
|
|||||||
|
|
||||||
char *old_title;
|
char *old_title;
|
||||||
|
|
||||||
|
/* Heavily-used const UNICODE_STRINGs are defined here once. */
|
||||||
|
#define _ROU(_s) \
|
||||||
|
{ Length: sizeof (_s) - sizeof (WCHAR), \
|
||||||
|
MaximumLength: sizeof (_s), \
|
||||||
|
Buffer: (PWSTR) (_s) }
|
||||||
|
#define _RDATA __attribute__ ((section(".rdata")))
|
||||||
|
UNICODE_STRING _RDATA ro_u_empty = _ROU (L"");
|
||||||
|
UNICODE_STRING _RDATA ro_u_lnk = _ROU (L".lnk");
|
||||||
|
UNICODE_STRING _RDATA ro_u_exe = _ROU (L".exe");
|
||||||
|
UNICODE_STRING _RDATA ro_u_com = _ROU (L".com");
|
||||||
|
UNICODE_STRING _RDATA ro_u_proc = _ROU (L"proc");
|
||||||
|
UNICODE_STRING _RDATA ro_u_pmem = _ROU (L"\\device\\physicalmemory");
|
||||||
|
UNICODE_STRING _RDATA ro_u_mtx = _ROU (L"mtx");
|
||||||
|
UNICODE_STRING _RDATA ro_u_fat = _ROU (L"FAT");
|
||||||
|
UNICODE_STRING _RDATA ro_u_csc = _ROU (L"CSC-CACHE");
|
||||||
|
UNICODE_STRING _RDATA ro_u_ntfs = _ROU (L"NTFS");
|
||||||
|
UNICODE_STRING _RDATA ro_u_nfs = _ROU (L"NFS");
|
||||||
|
UNICODE_STRING _RDATA ro_u_unixfs = _ROU (L"UNIXFS");
|
||||||
|
UNICODE_STRING _RDATA ro_u_sunwnfs = _ROU (L"SUNWNFS");
|
||||||
|
UNICODE_STRING _RDATA ro_u_udf = _ROU (L"UDF");
|
||||||
|
UNICODE_STRING _RDATA ro_u_natp = _ROU (L"\\??\\");
|
||||||
|
UNICODE_STRING _RDATA ro_u_uncp = _ROU (L"\\??\\UNC\\");
|
||||||
|
#undef _RDATA
|
||||||
|
#undef _ROU
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
/* This is an exported copy of environ which can be used by DLLs
|
/* This is an exported copy of environ which can be used by DLLs
|
||||||
|
@ -835,14 +835,12 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off)
|
|||||||
|
|
||||||
/* You can't create mappings with PAGE_EXECUTE protection if
|
/* You can't create mappings with PAGE_EXECUTE protection if
|
||||||
the file isn't explicitely opened with EXECUTE access. */
|
the file isn't explicitely opened with EXECUTE access. */
|
||||||
UNICODE_STRING fname;
|
|
||||||
OBJECT_ATTRIBUTES attr;
|
OBJECT_ATTRIBUTES attr;
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
IO_STATUS_BLOCK io;
|
IO_STATUS_BLOCK io;
|
||||||
|
|
||||||
RtlInitUnicodeString (&fname, L"");
|
InitializeObjectAttributes (&attr, &ro_u_empty, fh->pc.objcaseinsensitive (),
|
||||||
InitializeObjectAttributes (&attr, &fname, fh->pc.objcaseinsensitive (),
|
|
||||||
fh->get_handle (), NULL);
|
fh->get_handle (), NULL);
|
||||||
status = NtOpenFile (&h,
|
status = NtOpenFile (&h,
|
||||||
fh->get_access () | GENERIC_EXECUTE | SYNCHRONIZE,
|
fh->get_access () | GENERIC_EXECUTE | SYNCHRONIZE,
|
||||||
@ -1622,11 +1620,8 @@ fhandler_dev_mem::mmap (caddr_t *addr, size_t len, int prot,
|
|||||||
return INVALID_HANDLE_VALUE;
|
return INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
UNICODE_STRING memstr;
|
|
||||||
RtlInitUnicodeString (&memstr, L"\\device\\physicalmemory");
|
|
||||||
|
|
||||||
OBJECT_ATTRIBUTES attr;
|
OBJECT_ATTRIBUTES attr;
|
||||||
InitializeObjectAttributes (&attr, &memstr,
|
InitializeObjectAttributes (&attr, &ro_u_pmem,
|
||||||
OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
|
OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ fs_info::update (PUNICODE_STRING upath, HANDLE in_vol)
|
|||||||
FILE_FS_VOLUME_INFORMATION ffvi;
|
FILE_FS_VOLUME_INFORMATION ffvi;
|
||||||
WCHAR buf[NAME_MAX + 1];
|
WCHAR buf[NAME_MAX + 1];
|
||||||
} ffvi_buf;
|
} ffvi_buf;
|
||||||
UNICODE_STRING fsname, testname;
|
UNICODE_STRING fsname;
|
||||||
|
|
||||||
clear ();
|
clear ();
|
||||||
if (in_vol)
|
if (in_vol)
|
||||||
@ -173,7 +173,7 @@ fs_info::update (PUNICODE_STRING upath, HANDLE in_vol)
|
|||||||
|
|
||||||
if (ffdi.Characteristics & FILE_REMOTE_DEVICE
|
if (ffdi.Characteristics & FILE_REMOTE_DEVICE
|
||||||
|| (!ffdi.DeviceType
|
|| (!ffdi.DeviceType
|
||||||
&& RtlEqualUnicodePathPrefix (attr.ObjectName, L"\\??\\UNC\\", TRUE)))
|
&& RtlEqualUnicodePathPrefix (attr.ObjectName, &ro_u_uncp, TRUE)))
|
||||||
is_remote_drive (true);
|
is_remote_drive (true);
|
||||||
else
|
else
|
||||||
is_remote_drive (false);
|
is_remote_drive (false);
|
||||||
@ -217,10 +217,8 @@ fs_info::update (PUNICODE_STRING upath, HANDLE in_vol)
|
|||||||
| FILE_NAMED_STREAMS)
|
| FILE_NAMED_STREAMS)
|
||||||
RtlInitCountedUnicodeString (&fsname, ffai_buf.ffai.FileSystemName,
|
RtlInitCountedUnicodeString (&fsname, ffai_buf.ffai.FileSystemName,
|
||||||
ffai_buf.ffai.FileSystemNameLength);
|
ffai_buf.ffai.FileSystemNameLength);
|
||||||
is_fat (RtlEqualUnicodePathPrefix (&fsname, L"FAT", TRUE));
|
is_fat (RtlEqualUnicodePathPrefix (&fsname, &ro_u_fat, TRUE));
|
||||||
RtlInitUnicodeString (&testname, L"CSC-CACHE");
|
is_csc_cache (RtlEqualUnicodeString (&fsname, &ro_u_csc, FALSE));
|
||||||
is_csc_cache (RtlEqualUnicodeString (&fsname, &testname, FALSE));
|
|
||||||
RtlInitUnicodeString (&testname, L"NTFS");
|
|
||||||
if (is_remote_drive ())
|
if (is_remote_drive ())
|
||||||
{
|
{
|
||||||
/* This always fails on NT4. */
|
/* This always fails on NT4. */
|
||||||
@ -239,35 +237,32 @@ fs_info::update (PUNICODE_STRING upath, HANDLE in_vol)
|
|||||||
/* Test for Samba on NT4 or for older Samba releases not supporting
|
/* Test for Samba on NT4 or for older Samba releases not supporting
|
||||||
extended info. */
|
extended info. */
|
||||||
if (!is_samba ())
|
if (!is_samba ())
|
||||||
is_samba (RtlEqualUnicodeString (&fsname, &testname, FALSE)
|
is_samba (RtlEqualUnicodeString (&fsname, &ro_u_ntfs, FALSE)
|
||||||
&& FS_IS_SAMBA);
|
&& FS_IS_SAMBA);
|
||||||
|
|
||||||
if (!is_samba ())
|
if (!is_samba ())
|
||||||
{
|
{
|
||||||
is_netapp (RtlEqualUnicodeString (&fsname, &testname, FALSE)
|
is_netapp (RtlEqualUnicodeString (&fsname, &ro_u_ntfs, FALSE)
|
||||||
&& FS_IS_NETAPP_DATAONTAP);
|
&& FS_IS_NETAPP_DATAONTAP);
|
||||||
|
|
||||||
RtlInitUnicodeString (&testname, L"NFS");
|
is_nfs (RtlEqualUnicodeString (&fsname, &ro_u_nfs, FALSE));
|
||||||
is_nfs (RtlEqualUnicodeString (&fsname, &testname, FALSE));
|
|
||||||
|
|
||||||
if (!is_nfs ())
|
if (!is_nfs ())
|
||||||
{
|
{
|
||||||
/* Known remote file systems which can't handle calls to
|
/* Known remote file systems which can't handle calls to
|
||||||
NtQueryDirectoryFile(FileIdBothDirectoryInformation) */
|
NtQueryDirectoryFile(FileIdBothDirectoryInformation) */
|
||||||
RtlInitUnicodeString (&testname, L"UNIXFS");
|
|
||||||
has_buggy_fileid_dirinfo (RtlEqualUnicodeString (&fsname,
|
has_buggy_fileid_dirinfo (RtlEqualUnicodeString (&fsname,
|
||||||
&testname,
|
&ro_u_unixfs,
|
||||||
FALSE));
|
FALSE));
|
||||||
|
|
||||||
/* Known remote file systems with buggy open calls. Further
|
/* Known remote file systems with buggy open calls. Further
|
||||||
explanation in fhandler.cc (fhandler_disk_file::open). */
|
explanation in fhandler.cc (fhandler_disk_file::open). */
|
||||||
RtlInitUnicodeString (&testname, L"SUNWNFS");
|
has_buggy_open (RtlEqualUnicodeString (&fsname, &ro_u_sunwnfs,
|
||||||
has_buggy_open (RtlEqualUnicodeString (&fsname, &testname,
|
|
||||||
FALSE));
|
FALSE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is_ntfs (RtlEqualUnicodeString (&fsname, &testname, FALSE)
|
is_ntfs (RtlEqualUnicodeString (&fsname, &ro_u_ntfs, FALSE)
|
||||||
&& !is_samba () && !is_netapp ());
|
&& !is_samba () && !is_netapp ());
|
||||||
|
|
||||||
has_acls (flags () & FS_PERSISTENT_ACLS);
|
has_acls (flags () & FS_PERSISTENT_ACLS);
|
||||||
@ -283,8 +278,7 @@ fs_info::update (PUNICODE_STRING upath, HANDLE in_vol)
|
|||||||
is_cdrom (ffdi.DeviceType == FILE_DEVICE_CD_ROM);
|
is_cdrom (ffdi.DeviceType == FILE_DEVICE_CD_ROM);
|
||||||
if (is_cdrom ())
|
if (is_cdrom ())
|
||||||
{
|
{
|
||||||
RtlInitUnicodeString (&testname, L"UDF");
|
is_udf (RtlEqualUnicodeString (&fsname, &ro_u_udf, FALSE));
|
||||||
is_udf (RtlEqualUnicodeString (&fsname, &testname, FALSE));
|
|
||||||
/* UDF on NT 5.x is broken (at least) in terms of case sensitivity. The
|
/* UDF on NT 5.x is broken (at least) in terms of case sensitivity. The
|
||||||
UDF driver reports the FILE_CASE_SENSITIVE_SEARCH capability but:
|
UDF driver reports the FILE_CASE_SENSITIVE_SEARCH capability but:
|
||||||
- Opening the root directory for query seems to work at first, but the
|
- Opening the root directory for query seems to work at first, but the
|
||||||
|
@ -1040,32 +1040,32 @@ extern "C"
|
|||||||
}
|
}
|
||||||
/* Check if prefix is a prefix of path. */
|
/* Check if prefix is a prefix of path. */
|
||||||
inline
|
inline
|
||||||
BOOLEAN NTAPI RtlEqualUnicodePathPrefix (PUNICODE_STRING path, PCWSTR prefix,
|
BOOLEAN NTAPI RtlEqualUnicodePathPrefix (PUNICODE_STRING path,
|
||||||
|
PUNICODE_STRING prefix,
|
||||||
BOOLEAN caseinsensitive)
|
BOOLEAN caseinsensitive)
|
||||||
{
|
{
|
||||||
UNICODE_STRING p, pref;
|
UNICODE_STRING p;
|
||||||
|
|
||||||
RtlInitUnicodeString (&pref, prefix);
|
|
||||||
RtlInitCountedUnicodeString (&p, path->Buffer,
|
RtlInitCountedUnicodeString (&p, path->Buffer,
|
||||||
pref.Length < path->Length
|
prefix->Length < path->Length
|
||||||
? pref.Length : path->Length);
|
? prefix->Length : path->Length);
|
||||||
return RtlEqualUnicodeString (&p, &pref, caseinsensitive);
|
return RtlEqualUnicodeString (&p, prefix, caseinsensitive);
|
||||||
}
|
}
|
||||||
/* Check if sufffix is a sufffix of path. */
|
/* Check if sufffix is a sufffix of path. */
|
||||||
inline
|
inline
|
||||||
BOOL NTAPI RtlEqualUnicodePathSuffix (PUNICODE_STRING path, PCWSTR suffix,
|
BOOL NTAPI RtlEqualUnicodePathSuffix (PUNICODE_STRING path,
|
||||||
|
PUNICODE_STRING suffix,
|
||||||
BOOLEAN caseinsensitive)
|
BOOLEAN caseinsensitive)
|
||||||
{
|
{
|
||||||
UNICODE_STRING p, suf;
|
UNICODE_STRING p;
|
||||||
|
|
||||||
RtlInitUnicodeString (&suf, suffix);
|
if (suffix->Length < path->Length)
|
||||||
if (suf.Length < path->Length)
|
|
||||||
RtlInitCountedUnicodeString (&p, (PWCHAR) ((PBYTE) path->Buffer
|
RtlInitCountedUnicodeString (&p, (PWCHAR) ((PBYTE) path->Buffer
|
||||||
+ path->Length - suf.Length),
|
+ path->Length - suffix->Length),
|
||||||
suf.Length);
|
suffix->Length);
|
||||||
else
|
else
|
||||||
RtlInitCountedUnicodeString (&p, path->Buffer, path->Length);
|
RtlInitCountedUnicodeString (&p, path->Buffer, path->Length);
|
||||||
return RtlEqualUnicodeString (&p, &suf, caseinsensitive);
|
return RtlEqualUnicodeString (&p, suffix, caseinsensitive);
|
||||||
}
|
}
|
||||||
/* Implemented in strfuncs.cc. Create a Hex UNICODE_STRING from a given
|
/* Implemented in strfuncs.cc. Create a Hex UNICODE_STRING from a given
|
||||||
64 bit integer value. If append is TRUE, append the hex string,
|
64 bit integer value. If append is TRUE, append the hex string,
|
||||||
|
@ -448,7 +448,7 @@ get_nt_native_path (const char *path, UNICODE_STRING& upath)
|
|||||||
{
|
{
|
||||||
if (path[1] == ':') /* X:\... */
|
if (path[1] == ':') /* X:\... */
|
||||||
{
|
{
|
||||||
RtlAppendUnicodeToString (&upath, L"\\??\\");
|
RtlAppendUnicodeStringToString (&upath, &ro_u_natp);
|
||||||
str2uni_cat (upath, path);
|
str2uni_cat (upath, path);
|
||||||
/* The drive letter must be upper case. */
|
/* The drive letter must be upper case. */
|
||||||
upath.Buffer[4] = towupper (upath.Buffer[4]);
|
upath.Buffer[4] = towupper (upath.Buffer[4]);
|
||||||
@ -462,13 +462,13 @@ get_nt_native_path (const char *path, UNICODE_STRING& upath)
|
|||||||
else if ((path[2] != '.' && path[2] != '?')
|
else if ((path[2] != '.' && path[2] != '?')
|
||||||
|| path[3] != '\\') /* \\server\share\... */
|
|| path[3] != '\\') /* \\server\share\... */
|
||||||
{
|
{
|
||||||
RtlAppendUnicodeToString (&upath, L"\\??\\UNC\\");
|
RtlAppendUnicodeStringToString (&upath, &ro_u_uncp);
|
||||||
str2uni_cat (upath, path + 2);
|
str2uni_cat (upath, path + 2);
|
||||||
transform_chars (&upath, 8);
|
transform_chars (&upath, 8);
|
||||||
}
|
}
|
||||||
else /* \\.\device or \\?\foo */
|
else /* \\.\device or \\?\foo */
|
||||||
{
|
{
|
||||||
RtlAppendUnicodeToString (&upath, L"\\??\\");
|
RtlAppendUnicodeStringToString (&upath, &ro_u_natp);
|
||||||
str2uni_cat (upath, path + 4);
|
str2uni_cat (upath, path + 4);
|
||||||
}
|
}
|
||||||
return &upath;
|
return &upath;
|
||||||
@ -3079,7 +3079,7 @@ cwdstuff::set (PUNICODE_STRING nat_cwd, const char *posix_cwd, bool doit)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
len = upath.Length / sizeof (WCHAR) - 4;
|
len = upath.Length / sizeof (WCHAR) - 4;
|
||||||
if (RtlEqualUnicodePathPrefix (&upath, L"\\??\\UNC\\", TRUE))
|
if (RtlEqualUnicodePathPrefix (&upath, &ro_u_uncp, TRUE))
|
||||||
len -= 2;
|
len -= 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ try_to_bin (path_conv &pc, HANDLE &fh, ACCESS_MASK access)
|
|||||||
goto out;
|
goto out;
|
||||||
/* Is the file a subdir of the recycler? */
|
/* Is the file a subdir of the recycler? */
|
||||||
RtlInitCountedUnicodeString(&fname, pfni->FileName, pfni->FileNameLength);
|
RtlInitCountedUnicodeString(&fname, pfni->FileName, pfni->FileNameLength);
|
||||||
if (RtlEqualUnicodePathPrefix (&fname, recycler.Buffer, TRUE))
|
if (RtlEqualUnicodePathPrefix (&fname, &recycler, TRUE))
|
||||||
goto out;
|
goto out;
|
||||||
/* Is fname the recycler? Temporarily hide trailing backslash. */
|
/* Is fname the recycler? Temporarily hide trailing backslash. */
|
||||||
recycler.Length -= sizeof (WCHAR);
|
recycler.Length -= sizeof (WCHAR);
|
||||||
@ -558,12 +558,10 @@ unlink_nt (path_conv &pc)
|
|||||||
if (status == STATUS_CANNOT_DELETE && !pc.isremote ())
|
if (status == STATUS_CANNOT_DELETE && !pc.isremote ())
|
||||||
{
|
{
|
||||||
HANDLE fh2;
|
HANDLE fh2;
|
||||||
UNICODE_STRING fname;
|
|
||||||
|
|
||||||
/* Re-open from handle so we open the correct file no matter if it
|
/* Re-open from handle so we open the correct file no matter if it
|
||||||
has been moved to the bin or not. */
|
has been moved to the bin or not. */
|
||||||
RtlInitUnicodeString (&fname, L"");
|
InitializeObjectAttributes (&attr, &ro_u_empty, 0, fh, NULL);
|
||||||
InitializeObjectAttributes (&attr, &fname, 0, fh, NULL);
|
|
||||||
status = NtOpenFile (&fh2, DELETE, &attr, &io,
|
status = NtOpenFile (&fh2, DELETE, &attr, &io,
|
||||||
bin_stat == move_to_bin ? FILE_SHARE_VALID_FLAGS
|
bin_stat == move_to_bin ? FILE_SHARE_VALID_FLAGS
|
||||||
: FILE_SHARE_DELETE,
|
: FILE_SHARE_DELETE,
|
||||||
@ -1750,11 +1748,11 @@ rename (const char *oldpath, const char *newpath)
|
|||||||
}
|
}
|
||||||
else if (oldpc.is_lnk_symlink ()
|
else if (oldpc.is_lnk_symlink ()
|
||||||
&& !RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
|
&& !RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
|
||||||
L".lnk", TRUE))
|
&ro_u_lnk, TRUE))
|
||||||
rename_append_suffix (newpc, newpath, nlen, ".lnk");
|
rename_append_suffix (newpc, newpath, nlen, ".lnk");
|
||||||
else if (oldpc.is_binary () && !old_explicit_suffix
|
else if (oldpc.is_binary () && !old_explicit_suffix
|
||||||
&& !RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
|
&& !RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
|
||||||
L".exe", TRUE))
|
&ro_u_exe, TRUE))
|
||||||
/* To rename an executable foo.exe to bar-without-exe-suffix, the
|
/* To rename an executable foo.exe to bar-without-exe-suffix, the
|
||||||
.exe suffix must be given explicitly in oldpath. */
|
.exe suffix must be given explicitly in oldpath. */
|
||||||
rename_append_suffix (newpc, newpath, nlen, ".exe");
|
rename_append_suffix (newpc, newpath, nlen, ".exe");
|
||||||
@ -1781,7 +1779,7 @@ rename (const char *oldpath, const char *newpath)
|
|||||||
{
|
{
|
||||||
if (!newpc.is_lnk_symlink ()
|
if (!newpc.is_lnk_symlink ()
|
||||||
&& !RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
|
&& !RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
|
||||||
L".lnk", TRUE))
|
&ro_u_lnk, TRUE))
|
||||||
{
|
{
|
||||||
rename_append_suffix (new2pc, newpath, nlen, ".lnk");
|
rename_append_suffix (new2pc, newpath, nlen, ".lnk");
|
||||||
removepc = &newpc;
|
removepc = &newpc;
|
||||||
@ -1790,7 +1788,7 @@ rename (const char *oldpath, const char *newpath)
|
|||||||
else if (oldpc.is_binary ())
|
else if (oldpc.is_binary ())
|
||||||
{
|
{
|
||||||
if (!RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
|
if (!RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
|
||||||
L".exe", TRUE))
|
&ro_u_exe, TRUE))
|
||||||
{
|
{
|
||||||
rename_append_suffix (new2pc, newpath, nlen, ".exe");
|
rename_append_suffix (new2pc, newpath, nlen, ".exe");
|
||||||
removepc = &newpc;
|
removepc = &newpc;
|
||||||
@ -1799,9 +1797,9 @@ rename (const char *oldpath, const char *newpath)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
|
if ((RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
|
||||||
L".lnk", TRUE)
|
&ro_u_lnk, TRUE)
|
||||||
|| RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
|
|| RtlEqualUnicodePathSuffix (newpc.get_nt_native_path (),
|
||||||
L".exe", TRUE))
|
&ro_u_exe, TRUE))
|
||||||
&& !new_explicit_suffix)
|
&& !new_explicit_suffix)
|
||||||
{
|
{
|
||||||
new2pc.check (newpath, PC_SYM_NOFOLLOW, stat_suffixes);
|
new2pc.check (newpath, PC_SYM_NOFOLLOW, stat_suffixes);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user