mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-29 11:26:48 -05:00
Use a thread-safe pread/pwrite implementation for Windows
This may be useful in future for concurrent calls to the same file.
This commit is contained in:
parent
b619b9bee1
commit
0849bfc261
1 changed files with 14 additions and 14 deletions
|
|
@ -1760,7 +1760,7 @@ off_t windows_lseek(int fd, off_t offset, int whence)
|
||||||
ssize_t windows_pread(int fd, void* buffer, size_t size, off_t offset)
|
ssize_t windows_pread(int fd, void* buffer, size_t size, off_t offset)
|
||||||
{
|
{
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
LARGE_INTEGER pos;
|
OVERLAPPED overlapped;
|
||||||
DWORD count;
|
DWORD count;
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
|
|
@ -1775,13 +1775,13 @@ ssize_t windows_pread(int fd, void* buffer, size_t size, off_t offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
pos.QuadPart = offset;
|
overlapped.Internal = 0;
|
||||||
if (!SetFilePointerEx(h, pos, 0, FILE_BEGIN)) {
|
overlapped.InternalHigh = 0;
|
||||||
windows_errno(GetLastError());
|
overlapped.Offset = offset & 0xFFFFFFFF;
|
||||||
return -1;
|
overlapped.OffsetHigh = offset >> 32;
|
||||||
}
|
overlapped.hEvent = 0;
|
||||||
|
|
||||||
if (!ReadFile(h, buffer, size, &count, 0)) {
|
if (!ReadFile(h, buffer, size, &count, &overlapped)) {
|
||||||
DWORD err = GetLastError();
|
DWORD err = GetLastError();
|
||||||
/*
|
/*
|
||||||
* If Windows is not able to allocate memory from the PagedPool for the disk cache
|
* If Windows is not able to allocate memory from the PagedPool for the disk cache
|
||||||
|
|
@ -1818,7 +1818,7 @@ retry:
|
||||||
ssize_t windows_pwrite(int fd, const void* buffer, size_t size, off_t offset)
|
ssize_t windows_pwrite(int fd, const void* buffer, size_t size, off_t offset)
|
||||||
{
|
{
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
LARGE_INTEGER pos;
|
OVERLAPPED overlapped;
|
||||||
DWORD count;
|
DWORD count;
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
|
|
@ -1833,13 +1833,13 @@ ssize_t windows_pwrite(int fd, const void* buffer, size_t size, off_t offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
pos.QuadPart = offset;
|
overlapped.Internal = 0;
|
||||||
if (!SetFilePointerEx(h, pos, 0, FILE_BEGIN)) {
|
overlapped.InternalHigh = 0;
|
||||||
windows_errno(GetLastError());
|
overlapped.Offset = offset & 0xFFFFFFFF;
|
||||||
return -1;
|
overlapped.OffsetHigh = offset >> 32;
|
||||||
}
|
overlapped.hEvent = 0;
|
||||||
|
|
||||||
if (!WriteFile(h, buffer, size, &count, 0)) {
|
if (!WriteFile(h, buffer, size, &count, &overlapped)) {
|
||||||
DWORD err = GetLastError();
|
DWORD err = GetLastError();
|
||||||
/* See windows_pread() for comments on this error management */
|
/* See windows_pread() for comments on this error management */
|
||||||
if (err == ERROR_NO_SYSTEM_RESOURCES) {
|
if (err == ERROR_NO_SYSTEM_RESOURCES) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue