Doesn't use the physical address in Wine.

This commit is contained in:
Andrea Mazzoleni 2013-07-10 18:31:48 +02:00
parent 275ef2ed3c
commit e8b2d359d6
2 changed files with 52 additions and 1 deletions

25
mingw.c
View file

@ -48,6 +48,7 @@ typedef struct _FILE_ATTRIBUTE_TAG_INFO {
#define WIN32_ES_AWAYMODE_REQUIRED 0x00000040L #define WIN32_ES_AWAYMODE_REQUIRED 0x00000040L
#define WIN32_ES_CONTINUOUS 0x80000000L #define WIN32_ES_CONTINUOUS 0x80000000L
#ifndef FSCTL_GET_RETRIEVAL_POINTERS
#define FSCTL_GET_RETRIEVAL_POINTERS 0x00090073 #define FSCTL_GET_RETRIEVAL_POINTERS 0x00090073
typedef struct RETRIEVAL_POINTERS_BUFFER { typedef struct RETRIEVAL_POINTERS_BUFFER {
@ -62,6 +63,7 @@ typedef struct RETRIEVAL_POINTERS_BUFFER {
typedef struct { typedef struct {
LARGE_INTEGER StartingVcn; LARGE_INTEGER StartingVcn;
} STARTING_VCN_INPUT_BUFFER; } STARTING_VCN_INPUT_BUFFER;
#endif
/** /**
* Portable implementation of GetFileInformationByHandleEx. * Portable implementation of GetFileInformationByHandleEx.
@ -86,14 +88,27 @@ static BOOLEAN (WINAPI* ptr_CreateSymbolicLinkW)(LPWSTR, LPWSTR, DWORD);
*/ */
static char* last_error; static char* last_error;
/**
* If we are running in Wine.
*/
static int is_wine;
void os_init(void) void os_init(void)
{ {
HMODULE kernel32 = GetModuleHandle("KERNEL32.DLL"); HMODULE kernel32, ntdll;
kernel32 = GetModuleHandle("KERNEL32.DLL");
if (!kernel32) { if (!kernel32) {
fprintf(stderr, "Error loading the KERNEL32 module.\n"); fprintf(stderr, "Error loading the KERNEL32 module.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
ntdll = GetModuleHandle("NTDLL.DLL");
if (!ntdll) {
fprintf(stderr, "Error loading the NTDLL module.\n");
exit(EXIT_FAILURE);
}
/* load functions not always available */ /* load functions not always available */
ptr_SetThreadExecutionState = (void*)GetProcAddress(kernel32, "SetThreadExecutionState"); ptr_SetThreadExecutionState = (void*)GetProcAddress(kernel32, "SetThreadExecutionState");
ptr_GetFileInformationByHandleEx = (void*)GetProcAddress(kernel32, "GetFileInformationByHandleEx"); ptr_GetFileInformationByHandleEx = (void*)GetProcAddress(kernel32, "GetFileInformationByHandleEx");
@ -108,6 +123,8 @@ void os_init(void)
} }
} }
is_wine = GetProcAddress(ntdll, "wine_get_version") != 0;
last_error = 0; last_error = 0;
} }
@ -1086,6 +1103,12 @@ int filephy(const char* file, struct stat* st, uint64_t* physical)
DWORD ret; DWORD ret;
DWORD n; DWORD n;
/* in Wine just uses the inode number as FSCTL_GET_RETRIVIAL_POINTERS is not supported */
if (is_wine) {
*physical = st->st_ino;
return 0;
}
/* open the handle of the file */ /* open the handle of the file */
h = CreateFileW(convert(file), 0, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); h = CreateFileW(convert(file), 0, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
if (h == INVALID_HANDLE_VALUE) { if (h == INVALID_HANDLE_VALUE) {

28
mingw.h
View file

@ -29,33 +29,52 @@
#define PATH_MAX 1024 #define PATH_MAX 1024
/* Remap functions and types */ /* Remap functions and types */
#undef fopen
#define fopen windows_fopen #define fopen windows_fopen
#undef open
#define open windows_open #define open windows_open
#define open_noatime windows_open #define open_noatime windows_open
#undef stat
#define stat windows_stat #define stat windows_stat
#undef lstat
#define lstat windows_lstat #define lstat windows_lstat
#undef off_t
#define off_t off64_t #define off_t off64_t
#undef fstat
#define fstat windows_fstat #define fstat windows_fstat
#define HAVE_FTRUNCATE 1 #define HAVE_FTRUNCATE 1
#undef ftruncate
#define ftruncate windows_ftruncate #define ftruncate windows_ftruncate
#define HAVE_FSYNC 1 #define HAVE_FSYNC 1
#undef fsync
#define fsync _commit #define fsync _commit
#undef rename
#define rename windows_rename #define rename windows_rename
#undef remove
#define remove windows_remove #define remove windows_remove
#undef mkdir
#define mkdir(a, b) windows_mkdir(a) #define mkdir(a, b) windows_mkdir(a)
#undef rmdir
#define rmdir windows_rmdir #define rmdir windows_rmdir
#undef dirent
#define dirent windows_dirent #define dirent windows_dirent
#undef DIR
#define DIR windows_dir #define DIR windows_dir
#undef opendir
#define opendir windows_opendir #define opendir windows_opendir
#undef readdir
#define readdir windows_readdir #define readdir windows_readdir
#undef closedir
#define closedir windows_closedir #define closedir windows_closedir
#define HAVE_FUTIMENS 1 #define HAVE_FUTIMENS 1
#undef futimens
#define futimens windows_futimens #define futimens windows_futimens
#define O_NOFOLLOW 0 #define O_NOFOLLOW 0
#define dirent_hidden windows_dirent_hidden #define dirent_hidden windows_dirent_hidden
#define HAVE_DIRENT_LSTAT 1 #define HAVE_DIRENT_LSTAT 1
#define dirent_lstat windows_dirent_lstat #define dirent_lstat windows_dirent_lstat
#define stat_desc windows_stat_desc #define stat_desc windows_stat_desc
#undef sleep
#define sleep windows_sleep #define sleep windows_sleep
/* 4==DIR, 5,6,7=free, 8==REG */ /* 4==DIR, 5,6,7=free, 8==REG */
#define S_IFLNK 0x5000 /* Symbolic link to file */ #define S_IFLNK 0x5000 /* Symbolic link to file */
@ -64,16 +83,25 @@
#define S_ISLNKDIR(m) (((m) & _S_IFMT) == S_IFLNKDIR) #define S_ISLNKDIR(m) (((m) & _S_IFMT) == S_IFLNKDIR)
#define S_IFJUN 0x7000 /* Junction */ #define S_IFJUN 0x7000 /* Junction */
#define S_ISJUN(m) (((m) & _S_IFMT) == S_IFJUN) #define S_ISJUN(m) (((m) & _S_IFMT) == S_IFJUN)
#undef readlink
#define readlink windows_readlink #define readlink windows_readlink
#undef symlink
#define symlink windows_symlink #define symlink windows_symlink
#undef link
#define link windows_link #define link windows_link
#undef strerror
#define strerror windows_strerror #define strerror windows_strerror
#undef read
#define read windows_read #define read windows_read
#undef write
#define write windows_write #define write windows_write
#undef lseek
#define lseek windows_lseek #define lseek windows_lseek
#define HAVE_PREAD 1 #define HAVE_PREAD 1
#define HAVE_PWRITE 1 #define HAVE_PWRITE 1
#undef pread
#define pread windows_pread #define pread windows_pread
#undef pwrite
#define pwrite windows_pwrite #define pwrite windows_pwrite
/* We have nano second support */ /* We have nano second support */