Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: util/file/file_io_win.cc

Issue 1001673002: Add Locking calls to file_io.h plus implementations and test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: release load Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « util/file/file_io_test.cc ('k') | util/test/errors.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/file/file_io_win.cc
diff --git a/util/file/file_io_win.cc b/util/file/file_io_win.cc
index adbe7a99efaa15498877220d67c38c40860f4170..33da8baa36bec4539f3c99a7e493f83d74fb04c7 100644
--- a/util/file/file_io_win.cc
+++ b/util/file/file_io_win.cc
@@ -80,8 +80,13 @@ ssize_t WriteFile(FileHandle file, const void* buffer, size_t size) {
}
FileHandle LoggingOpenFileForRead(const base::FilePath& path) {
- HANDLE file = CreateFile(path.value().c_str(), GENERIC_READ, FILE_SHARE_READ,
- nullptr, OPEN_EXISTING, 0, nullptr);
+ HANDLE file = CreateFile(path.value().c_str(),
+ GENERIC_READ,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ nullptr,
+ OPEN_EXISTING,
+ 0,
+ nullptr);
PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) << "CreateFile "
<< path.value().c_str();
return file;
@@ -102,13 +107,45 @@ FileHandle LoggingOpenFileForWrite(const base::FilePath& path,
disposition = CREATE_NEW;
break;
}
- HANDLE file = CreateFile(path.value().c_str(), GENERIC_WRITE, 0, nullptr,
- disposition, FILE_ATTRIBUTE_NORMAL, nullptr);
+ HANDLE file = CreateFile(path.value().c_str(),
+ GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ nullptr,
+ disposition,
+ FILE_ATTRIBUTE_NORMAL,
+ nullptr);
PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) << "CreateFile "
<< path.value().c_str();
return file;
}
+bool LoggingLockFile(FileHandle file, FileLocking locking) {
+ DWORD flags =
+ (locking == FileLocking::kExclusive) ? LOCKFILE_EXCLUSIVE_LOCK : 0;
+
+ // Note that the `Offset` fields of overlapped indicate the start location for
+ // locking (beginning of file in this case), and `hEvent` must be also be set
+ // to 0.
+ OVERLAPPED overlapped = {0};
+ if (!LockFileEx(file, flags, 0, MAXDWORD, MAXDWORD, &overlapped)) {
+ PLOG(ERROR) << "LockFileEx";
+ return false;
+ }
+ return true;
+}
+
+bool LoggingUnlockFile(FileHandle file) {
+ // Note that the `Offset` fields of overlapped indicate the start location for
+ // locking (beginning of file in this case), and `hEvent` must be also be set
+ // to 0.
+ OVERLAPPED overlapped = {0};
+ if (!UnlockFileEx(file, 0, MAXDWORD, MAXDWORD, &overlapped)) {
+ PLOG(ERROR) << "UnlockFileEx";
+ return false;
+ }
+ return true;
+}
+
FileOffset LoggingSeekFile(FileHandle file, FileOffset offset, int whence) {
DWORD method = 0;
switch (whence) {
« no previous file with comments | « util/file/file_io_test.cc ('k') | util/test/errors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698