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

Side by Side 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: . 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 case FileWriteMode::kReuseOrCreate: 95 case FileWriteMode::kReuseOrCreate:
96 disposition = OPEN_ALWAYS; 96 disposition = OPEN_ALWAYS;
97 break; 97 break;
98 case FileWriteMode::kTruncateOrCreate: 98 case FileWriteMode::kTruncateOrCreate:
99 disposition = CREATE_ALWAYS; 99 disposition = CREATE_ALWAYS;
100 break; 100 break;
101 case FileWriteMode::kCreateOrFail: 101 case FileWriteMode::kCreateOrFail:
102 disposition = CREATE_NEW; 102 disposition = CREATE_NEW;
103 break; 103 break;
104 } 104 }
105 HANDLE file = CreateFile(path.value().c_str(), GENERIC_WRITE, 0, nullptr, 105 HANDLE file = CreateFile(path.value().c_str(),
106 disposition, FILE_ATTRIBUTE_NORMAL, nullptr); 106 GENERIC_WRITE,
107 FILE_SHARE_READ | FILE_SHARE_WRITE,
108 nullptr,
109 disposition,
110 FILE_ATTRIBUTE_NORMAL,
111 nullptr);
107 PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) << "CreateFile " 112 PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) << "CreateFile "
108 << path.value().c_str(); 113 << path.value().c_str();
109 return file; 114 return file;
110 } 115 }
111 116
117 bool LoggingLockFile(FileHandle file, FileLocking locking) {
118 DWORD flags =
119 locking == FileLocking::kExclusive ? LOCKFILE_EXCLUSIVE_LOCK : 0;
Robert Sesek 2015/03/12 15:28:03 nit: () around condition
scottmg 2015/03/19 22:06:20 Done.
120
121 // Note that the `Offset` fields of overlapped indicate the start location for
122 // locking (beginning of file in this case), and `hEvent` must be also be set
123 // to 0.
124 OVERLAPPED overlapped = {0};
125 if (!LockFileEx(file, flags, 0, MAXDWORD, MAXDWORD, &overlapped)) {
126 PLOG(ERROR) << "LockFileEx";
127 return false;
128 }
129 return true;
130 }
131
132 bool LoggingUnlockFile(FileHandle file) {
133 // Note that the `Offset` fields of overlapped indicate the start location for
134 // locking (beginning of file in this case), and `hEvent` must be also be set
135 // to 0.
136 OVERLAPPED overlapped = {0};
137 if (!UnlockFileEx(file, 0, MAXDWORD, MAXDWORD, &overlapped)) {
138 PLOG(ERROR) << "LockFileEx";
139 return false;
140 }
141 return true;
142 }
143
112 FileOffset LoggingSeekFile(FileHandle file, FileOffset offset, int whence) { 144 FileOffset LoggingSeekFile(FileHandle file, FileOffset offset, int whence) {
113 DWORD method = 0; 145 DWORD method = 0;
114 switch (whence) { 146 switch (whence) {
115 case SEEK_SET: 147 case SEEK_SET:
116 method = FILE_BEGIN; 148 method = FILE_BEGIN;
117 break; 149 break;
118 case SEEK_CUR: 150 case SEEK_CUR:
119 method = FILE_CURRENT; 151 method = FILE_CURRENT;
120 break; 152 break;
121 case SEEK_END: 153 case SEEK_END:
(...skipping 15 matching lines...) Expand all
137 return new_offset.QuadPart; 169 return new_offset.QuadPart;
138 } 170 }
139 171
140 bool LoggingCloseFile(FileHandle file) { 172 bool LoggingCloseFile(FileHandle file) {
141 BOOL rv = CloseHandle(file); 173 BOOL rv = CloseHandle(file);
142 PLOG_IF(ERROR, !rv) << "CloseHandle"; 174 PLOG_IF(ERROR, !rv) << "CloseHandle";
143 return rv; 175 return rv;
144 } 176 }
145 177
146 } // namespace crashpad 178 } // namespace crashpad
OLDNEW
« util/file/file_io_test.cc ('K') | « util/file/file_io_test.cc ('k') | util/util.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698