* autoload.cc (FindFirstVolumeA): Add.

(FindNextVolumeA): Add.
	(FindVolumeClose): Add.
	(GetVolumePathNamesForVolumeNameA): Add.
	* fhandler.h (class fhandler_base): Declare new method fsync.
	* fhandler.cc (fhandler_base::fsync): New method.
	* syscalls.cc (fsync): Move functionality into fhandler method fsync.
	Just call this method from here.
	(sync_worker): New static function.
	(sync): Fill with life for NT systems.
	* wincap.h (wincaps::has_guid_volumes): New element.
	* wincap.cc: Implement above element throughout.
This commit is contained in:
Corinna Vinschen 2005-02-20 13:28:23 +00:00
parent 2b09be25a3
commit 4944ca2f09
7 changed files with 110 additions and 16 deletions

View File

@ -1,3 +1,18 @@
2005-02-20 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (FindFirstVolumeA): Add.
(FindNextVolumeA): Add.
(FindVolumeClose): Add.
(GetVolumePathNamesForVolumeNameA): Add.
* fhandler.h (class fhandler_base): Declare new method fsync.
* fhandler.cc (fhandler_base::fsync): New method.
* syscalls.cc (fsync): Move functionality into fhandler method fsync.
Just call this method from here.
(sync_worker): New static function.
(sync): Fill with life for NT systems.
* wincap.h (wincaps::has_guid_volumes): New element.
* wincap.cc: Implement above element throughout.
2005-02-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (enum query_state): Add query_write_attributes state.

View File

@ -500,11 +500,15 @@ LoadDLLfunc (CoTaskMemFree, 4, ole32)
LoadDLLfuncEx (CancelIo, 4, kernel32, 1)
LoadDLLfuncEx (CreateHardLinkA, 12, kernel32, 1)
LoadDLLfuncEx (CreateToolhelp32Snapshot, 8, kernel32, 1)
LoadDLLfuncEx (FindFirstVolumeA, 8, kernel32, 1)
LoadDLLfuncEx (FindNextVolumeA, 12, kernel32, 1)
LoadDLLfuncEx (FindVolumeClose, 4, kernel32, 1)
LoadDLLfuncEx2 (GetCompressedFileSizeA, 8, kernel32, 1, 0xffffffff)
LoadDLLfuncEx (GetConsoleWindow, 0, kernel32, 1)
LoadDLLfuncEx (GetDiskFreeSpaceEx, 16, kernel32, 1)
LoadDLLfuncEx (GetNativeSystemInfo, 4, kernel32, 1)
LoadDLLfuncEx (GetSystemTimes, 12, kernel32, 1)
LoadDLLfuncEx (GetVolumePathNamesForVolumeNameA, 16, kernel32, 1)
LoadDLLfuncEx2 (IsDebuggerPresent, 0, kernel32, 1, 1)
LoadDLLfunc (IsProcessorFeaturePresent, 4, kernel32);
LoadDLLfuncEx (IsWow64Process, 8, kernel32, 1);

View File

@ -1623,3 +1623,14 @@ fhandler_base::utimes (const struct timeval *tvp)
set_errno (EINVAL);
return -1;
}
int
fhandler_base::fsync ()
{
if (pc.isdir ()) /* Just succeed. */
return 0;
if (FlushFileBuffers (get_handle ()))
return 0;
__seterrno ();
return -1;
}

View File

@ -267,6 +267,7 @@ class fhandler_base
virtual int __stdcall ftruncate (_off64_t) __attribute__ ((regparm (2)));
virtual int __stdcall link (const char *) __attribute__ ((regparm (2)));
virtual int __stdcall utimes (const struct timeval *) __attribute__ ((regparm (2)));
virtual int __stdcall fsync (void) __attribute__ ((regparm (1)));
virtual int ioctl (unsigned int cmd, void *);
virtual int fcntl (int cmd, void *);
virtual char const *ttyname () { return get_name (); }

View File

@ -915,19 +915,68 @@ fsync (int fd)
syscall_printf ("-1 = fsync (%d)", fd);
return -1;
}
return cfd->fsync ();
}
if (FlushFileBuffers (cfd->get_handle ()) == 0)
static void
sync_worker (const char *vol)
{
HANDLE fh = CreateFileA (vol, GENERIC_WRITE, wincap.shared (),
&sec_none_nih, OPEN_EXISTING, 0, NULL);
if (fh != INVALID_HANDLE_VALUE)
{
__seterrno ();
return -1;
FlushFileBuffers (fh);
CloseHandle (fh);
}
return 0;
else
debug_printf ("Open failed with %E");
}
/* sync: SUSv3 */
extern "C" void
sync ()
{
char vol[CYG_MAX_PATH];
if (wincap.has_guid_volumes ()) /* Win2k and newer */
{
HANDLE sh = FindFirstVolumeA (vol, CYG_MAX_PATH);
if (sh != INVALID_HANDLE_VALUE)
{
do
{
char pvol[CYG_MAX_PATH];
DWORD len;
if (GetVolumePathNamesForVolumeNameA (vol, pvol, CYG_MAX_PATH,
&len))
debug_printf ("Try volume %s (GUID: %s)", pvol, vol);
else
debug_printf ("Try volume %s", vol);
/* Eliminate trailing backslash. */
vol[strlen (vol) - 1] = '\0';
sync_worker (vol);
}
while (FindNextVolumeA (sh, vol, CYG_MAX_PATH));
FindVolumeClose (sh);
}
}
else if (wincap.is_winnt ()) /* 9x has no concept for opening volumes */
{
DWORD drives = GetLogicalDrives ();
DWORD mask = 1;
strcpy (vol, "\\\\.\\A:");
do
{
if (drives & mask)
{
debug_printf ("Try volume %s", vol);
sync_worker (vol);
}
vol[4]++;
}
while ((mask <<= 1) <= 1 << 25);
}
}
/* Cygwin internal */

View File

@ -55,7 +55,8 @@ static NO_COPY wincaps wincap_unknown = {
cant_debug_dll_entry:false,
has_ioctl_storage_get_media_types_ex:false,
start_proc_suspended:true,
has_extended_priority_class:false
has_extended_priority_class:false,
has_guid_volumes:false
};
static NO_COPY wincaps wincap_95 = {
@ -102,7 +103,8 @@ static NO_COPY wincaps wincap_95 = {
cant_debug_dll_entry:true,
has_ioctl_storage_get_media_types_ex:false,
start_proc_suspended:true,
has_extended_priority_class:false
has_extended_priority_class:false,
has_guid_volumes:false
};
static NO_COPY wincaps wincap_95osr2 = {
@ -149,7 +151,8 @@ static NO_COPY wincaps wincap_95osr2 = {
cant_debug_dll_entry:true,
has_ioctl_storage_get_media_types_ex:false,
start_proc_suspended:true,
has_extended_priority_class:false
has_extended_priority_class:false,
has_guid_volumes:false
};
static NO_COPY wincaps wincap_98 = {
@ -196,7 +199,8 @@ static NO_COPY wincaps wincap_98 = {
cant_debug_dll_entry:true,
has_ioctl_storage_get_media_types_ex:false,
start_proc_suspended:true,
has_extended_priority_class:false
has_extended_priority_class:false,
has_guid_volumes:false
};
static NO_COPY wincaps wincap_98se = {
@ -243,7 +247,8 @@ static NO_COPY wincaps wincap_98se = {
cant_debug_dll_entry:true,
has_ioctl_storage_get_media_types_ex:false,
start_proc_suspended:true,
has_extended_priority_class:false
has_extended_priority_class:false,
has_guid_volumes:false
};
static NO_COPY wincaps wincap_me = {
@ -290,7 +295,8 @@ static NO_COPY wincaps wincap_me = {
cant_debug_dll_entry:true,
has_ioctl_storage_get_media_types_ex:false,
start_proc_suspended:true,
has_extended_priority_class:false
has_extended_priority_class:false,
has_guid_volumes:false
};
static NO_COPY wincaps wincap_nt3 = {
@ -337,7 +343,8 @@ static NO_COPY wincaps wincap_nt3 = {
cant_debug_dll_entry:false,
has_ioctl_storage_get_media_types_ex:false,
start_proc_suspended:false,
has_extended_priority_class:false
has_extended_priority_class:false,
has_guid_volumes:false
};
static NO_COPY wincaps wincap_nt4 = {
@ -384,7 +391,8 @@ static NO_COPY wincaps wincap_nt4 = {
cant_debug_dll_entry:false,
has_ioctl_storage_get_media_types_ex:false,
start_proc_suspended:false,
has_extended_priority_class:false
has_extended_priority_class:false,
has_guid_volumes:false
};
static NO_COPY wincaps wincap_nt4sp4 = {
@ -431,7 +439,8 @@ static NO_COPY wincaps wincap_nt4sp4 = {
cant_debug_dll_entry:false,
has_ioctl_storage_get_media_types_ex:false,
start_proc_suspended:false,
has_extended_priority_class:false
has_extended_priority_class:false,
has_guid_volumes:false
};
static NO_COPY wincaps wincap_2000 = {
@ -478,7 +487,8 @@ static NO_COPY wincaps wincap_2000 = {
cant_debug_dll_entry:false,
has_ioctl_storage_get_media_types_ex:false,
start_proc_suspended:false,
has_extended_priority_class:true
has_extended_priority_class:true,
has_guid_volumes:true
};
static NO_COPY wincaps wincap_xp = {
@ -525,7 +535,8 @@ static NO_COPY wincaps wincap_xp = {
cant_debug_dll_entry:false,
has_ioctl_storage_get_media_types_ex:true,
start_proc_suspended:false,
has_extended_priority_class:true
has_extended_priority_class:true,
has_guid_volumes:true
};
static NO_COPY wincaps wincap_2003 = {
@ -572,7 +583,8 @@ static NO_COPY wincaps wincap_2003 = {
cant_debug_dll_entry:false,
has_ioctl_storage_get_media_types_ex:true,
start_proc_suspended:false,
has_extended_priority_class:true
has_extended_priority_class:true,
has_guid_volumes:true
};
wincapc wincap;

View File

@ -57,6 +57,7 @@ struct wincaps
unsigned has_ioctl_storage_get_media_types_ex : 1;
unsigned start_proc_suspended : 1;
unsigned has_extended_priority_class : 1;
unsigned has_guid_volumes : 1;
};
class wincapc
@ -118,6 +119,7 @@ public:
bool IMPLEMENT (has_ioctl_storage_get_media_types_ex)
bool IMPLEMENT (start_proc_suspended)
bool IMPLEMENT (has_extended_priority_class)
bool IMPLEMENT (has_guid_volumes)
#undef IMPLEMENT
};