* autoload.cc (FindFirstVolumeA): Remove.

(FindNextVolumeA): Remove.
	(FindVolumeClose): Remove.
	(GetVolumeNameForVolumeMountPointA): Remove.
	* ntdll.h (NtFlushBuffersFile): Declare.
	* syscalls.cc (sync_worker): Rewrite using native NT functions.
	(sync): Ditto.
This commit is contained in:
Corinna Vinschen 2011-04-02 11:43:43 +00:00
parent 8a5e2a62da
commit 0d6f2b0117
4 changed files with 55 additions and 66 deletions

View File

@ -1,3 +1,13 @@
2011-04-02 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (FindFirstVolumeA): Remove.
(FindNextVolumeA): Remove.
(FindVolumeClose): Remove.
(GetVolumeNameForVolumeMountPointA): Remove.
* ntdll.h (NtFlushBuffersFile): Declare.
* syscalls.cc (sync_worker): Rewrite using native NT functions.
(sync): Ditto.
2011-04-02 Corinna Vinschen <corinna@vinschen.de> 2011-04-02 Corinna Vinschen <corinna@vinschen.de>
* fhandler_proc.cc (format_proc_partitions): Express length in WCHAR * fhandler_proc.cc (format_proc_partitions): Express length in WCHAR

View File

@ -395,13 +395,9 @@ LoadDLLfunc (GetNetworkParams, 8, iphlpapi)
LoadDLLfunc (GetUdpTable, 12, iphlpapi) LoadDLLfunc (GetUdpTable, 12, iphlpapi)
LoadDLLfuncEx (AttachConsole, 4, kernel32, 1) LoadDLLfuncEx (AttachConsole, 4, kernel32, 1)
LoadDLLfunc (FindFirstVolumeA, 8, kernel32)
LoadDLLfunc (FindNextVolumeA, 12, kernel32)
LoadDLLfunc (FindVolumeClose, 4, kernel32)
LoadDLLfunc (GetConsoleWindow, 0, kernel32) LoadDLLfunc (GetConsoleWindow, 0, kernel32)
LoadDLLfuncEx (GetNamedPipeClientProcessId, 8, kernel32, 1) LoadDLLfuncEx (GetNamedPipeClientProcessId, 8, kernel32, 1)
LoadDLLfuncEx (GetSystemWindowsDirectoryW, 8, kernel32, 1) LoadDLLfuncEx (GetSystemWindowsDirectoryW, 8, kernel32, 1)
LoadDLLfunc (GetVolumeNameForVolumeMountPointA, 12, kernel32)
LoadDLLfunc (LocaleNameToLCID, 8, kernel32) LoadDLLfunc (LocaleNameToLCID, 8, kernel32)
LoadDLLfunc (WNetCloseEnum, 4, mpr) LoadDLLfunc (WNetCloseEnum, 4, mpr)

View File

@ -1003,6 +1003,7 @@ extern "C"
NTSTATUS NTAPI NtFsControlFile (HANDLE, HANDLE, PIO_APC_ROUTINE, PVOID, NTSTATUS NTAPI NtFsControlFile (HANDLE, HANDLE, PIO_APC_ROUTINE, PVOID,
PIO_STATUS_BLOCK, ULONG, PVOID, ULONG, PIO_STATUS_BLOCK, ULONG, PVOID, ULONG,
PVOID, ULONG); PVOID, ULONG);
NTSTATUS NTAPI NtFlushBuffersFile (HANDLE, PIO_STATUS_BLOCK);
NTSTATUS NTAPI NtLoadKey (POBJECT_ATTRIBUTES, POBJECT_ATTRIBUTES); NTSTATUS NTAPI NtLoadKey (POBJECT_ATTRIBUTES, POBJECT_ATTRIBUTES);
NTSTATUS NTAPI NtLockVirtualMemory (HANDLE, PVOID *, ULONG *, ULONG); NTSTATUS NTAPI NtLockVirtualMemory (HANDLE, PVOID *, ULONG *, ULONG);
NTSTATUS NTAPI NtMapViewOfSection (HANDLE, HANDLE, PVOID *, ULONG, ULONG, NTSTATUS NTAPI NtMapViewOfSection (HANDLE, HANDLE, PVOID *, ULONG, ULONG,

View File

@ -36,9 +36,9 @@ details. */
#include <utmpx.h> #include <utmpx.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <ctype.h> #include <ctype.h>
#include <wctype.h>
#include <unistd.h> #include <unistd.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <rpc.h>
#include "ntdll.h" #include "ntdll.h"
#undef fstat #undef fstat
@ -1492,80 +1492,62 @@ fsync (int fd)
EXPORT_ALIAS (fsync, fdatasync) EXPORT_ALIAS (fsync, fdatasync)
static void static void
sync_worker (const char *vol) sync_worker (HANDLE dir, USHORT len, LPCWSTR vol)
{ {
HANDLE fh = CreateFileA (vol, GENERIC_WRITE, FILE_SHARE_VALID_FLAGS, NTSTATUS status;
&sec_none_nih, OPEN_EXISTING, 0, NULL); HANDLE fh;
if (fh != INVALID_HANDLE_VALUE) IO_STATUS_BLOCK io;
{ OBJECT_ATTRIBUTES attr;
FlushFileBuffers (fh); UNICODE_STRING uvol = { len, len, (WCHAR *) vol };
CloseHandle (fh);
} InitializeObjectAttributes (&attr, &uvol, OBJ_CASE_INSENSITIVE, dir, NULL);
status = NtOpenFile (&fh, GENERIC_WRITE, &attr, &io,
FILE_SHARE_VALID_FLAGS, 0);
if (!NT_SUCCESS (status))
debug_printf ("NtOpenFile (%S), status %p", &uvol, status);
else else
debug_printf ("Open failed with %E"); {
status = NtFlushBuffersFile (fh, &io);
if (!NT_SUCCESS (status))
debug_printf ("NtFlushBuffersFile (%S), status %p", &uvol, status);
NtClose (fh);
}
} }
/* sync: SUSv3 */ /* sync: SUSv3 */
extern "C" void extern "C" void
sync () sync ()
{ {
/* Per MSDN, 50 bytes should be enough here. */ OBJECT_ATTRIBUTES attr;
char vol[MAX_PATH]; NTSTATUS status;
HANDLE devhdl;
UNICODE_STRING device;
if (wincap.has_guid_volumes ()) /* Win2k and newer */ /* Open \Device object directory. */
RtlInitUnicodeString (&device, L"\\Device");
InitializeObjectAttributes (&attr, &device, OBJ_CASE_INSENSITIVE, NULL, NULL);
status = NtOpenDirectoryObject (&devhdl, DIRECTORY_QUERY, &attr);
if (!NT_SUCCESS (status))
{ {
char a_drive[MAX_PATH] = {0}; debug_printf ("NtOpenDirectoryObject, status %p", status);
char b_drive[MAX_PATH] = {0}; return;
if (is_floppy ("A:"))
GetVolumeNameForVolumeMountPointA ("A:\\", a_drive, MAX_PATH);
if (is_floppy ("B:"))
GetVolumeNameForVolumeMountPointA ("B:\\", b_drive, MAX_PATH);
HANDLE sh = FindFirstVolumeA (vol, MAX_PATH);
if (sh != INVALID_HANDLE_VALUE)
{
do
{
debug_printf ("Try volume %s", vol);
/* Check vol for being a floppy on A: or B:. Skip them. */
if (strcasematch (vol, a_drive) || strcasematch (vol, b_drive))
{
debug_printf ("Is floppy, don't sync");
continue;
}
/* Eliminate trailing backslash. */
vol[strlen (vol) - 1] = '\0';
sync_worker (vol);
}
while (FindNextVolumeA (sh, vol, MAX_PATH));
FindVolumeClose (sh);
}
} }
else /* Traverse \Device directory ... */
PDIRECTORY_BASIC_INFORMATION dbi = (PDIRECTORY_BASIC_INFORMATION)
alloca (640);
BOOLEAN restart = TRUE;
ULONG context = 0;
while (NT_SUCCESS (NtQueryDirectoryObject (devhdl, dbi, 640, TRUE, restart,
&context, NULL)))
{ {
DWORD drives = GetLogicalDrives (); restart = FALSE;
DWORD mask = 1; /* ... and call sync_worker for each HarddiskVolumeX entry. */
/* Skip floppies on A: and B: as in setmntent. */ if (dbi->ObjectName.Length >= 15 * sizeof (WCHAR)
if ((drives & 1) && is_floppy ("A:")) && !wcsncasecmp (dbi->ObjectName.Buffer, L"HarddiskVolume", 14)
drives &= ~1; && iswdigit (dbi->ObjectName.Buffer[14]))
if ((drives & 2) && is_floppy ("B:")) sync_worker (devhdl, dbi->ObjectName.Length, dbi->ObjectName.Buffer);
drives &= ~2;
strcpy (vol, "\\\\.\\A:");
do
{
/* Geeh. Try to sync only non-floppy drives. */
if (drives & mask)
{
debug_printf ("Try volume %s", vol);
sync_worker (vol);
}
vol[4]++;
}
while ((mask <<= 1) <= 1 << 25);
} }
NtClose (devhdl);
} }
/* Cygwin internal */ /* Cygwin internal */