| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/platform_file.h" | 5 #include "base/files/file.h" |
| 6 | 6 |
| 7 #include <io.h> | 7 #include <io.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/sparse_histogram.h" | 11 #include "base/metrics/sparse_histogram.h" |
| 12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 PlatformFile CreatePlatformFileUnsafe(const FilePath& name, | 15 |
| 16 int flags, | 16 void File::CreateBaseFileUnsafe(const FilePath& name, uint32 flags) { |
| 17 bool* created, | |
| 18 PlatformFileError* error) { | |
| 19 base::ThreadRestrictions::AssertIOAllowed(); | 17 base::ThreadRestrictions::AssertIOAllowed(); |
| 18 DCHECK(!IsValid()); |
| 20 | 19 |
| 21 DWORD disposition = 0; | 20 DWORD disposition = 0; |
| 22 if (created) | |
| 23 *created = false; | |
| 24 | 21 |
| 25 if (flags & PLATFORM_FILE_OPEN) | 22 if (flags & FLAG_OPEN) |
| 26 disposition = OPEN_EXISTING; | 23 disposition = OPEN_EXISTING; |
| 27 | 24 |
| 28 if (flags & PLATFORM_FILE_CREATE) { | 25 if (flags & FLAG_CREATE) { |
| 29 DCHECK(!disposition); | 26 DCHECK(!disposition); |
| 30 disposition = CREATE_NEW; | 27 disposition = CREATE_NEW; |
| 31 } | 28 } |
| 32 | 29 |
| 33 if (flags & PLATFORM_FILE_OPEN_ALWAYS) { | 30 if (flags & FLAG_OPEN_ALWAYS) { |
| 34 DCHECK(!disposition); | 31 DCHECK(!disposition); |
| 35 disposition = OPEN_ALWAYS; | 32 disposition = OPEN_ALWAYS; |
| 36 } | 33 } |
| 37 | 34 |
| 38 if (flags & PLATFORM_FILE_CREATE_ALWAYS) { | 35 if (flags & FLAG_CREATE_ALWAYS) { |
| 39 DCHECK(!disposition); | 36 DCHECK(!disposition); |
| 40 disposition = CREATE_ALWAYS; | 37 disposition = CREATE_ALWAYS; |
| 41 } | 38 } |
| 42 | 39 |
| 43 if (flags & PLATFORM_FILE_OPEN_TRUNCATED) { | 40 if (flags & FLAG_OPEN_TRUNCATED) { |
| 44 DCHECK(!disposition); | 41 DCHECK(!disposition); |
| 45 DCHECK(flags & PLATFORM_FILE_WRITE); | 42 DCHECK(flags & FLAG_WRITE); |
| 46 disposition = TRUNCATE_EXISTING; | 43 disposition = TRUNCATE_EXISTING; |
| 47 } | 44 } |
| 48 | 45 |
| 49 if (!disposition) { | 46 if (!disposition) { |
| 50 NOTREACHED(); | 47 NOTREACHED(); |
| 51 return NULL; | 48 return; |
| 52 } | 49 } |
| 53 | 50 |
| 54 DWORD access = 0; | 51 DWORD access = 0; |
| 55 if (flags & PLATFORM_FILE_WRITE) | 52 if (flags & FLAG_WRITE) |
| 56 access = GENERIC_WRITE; | 53 access = GENERIC_WRITE; |
| 57 if (flags & PLATFORM_FILE_APPEND) { | 54 if (flags & FLAG_APPEND) { |
| 58 DCHECK(!access); | 55 DCHECK(!access); |
| 59 access = FILE_APPEND_DATA; | 56 access = FILE_APPEND_DATA; |
| 60 } | 57 } |
| 61 if (flags & PLATFORM_FILE_READ) | 58 if (flags & FLAG_READ) |
| 62 access |= GENERIC_READ; | 59 access |= GENERIC_READ; |
| 63 if (flags & PLATFORM_FILE_WRITE_ATTRIBUTES) | 60 if (flags & FLAG_WRITE_ATTRIBUTES) |
| 64 access |= FILE_WRITE_ATTRIBUTES; | 61 access |= FILE_WRITE_ATTRIBUTES; |
| 65 if (flags & PLATFORM_FILE_EXECUTE) | 62 if (flags & FLAG_EXECUTE) |
| 66 access |= GENERIC_EXECUTE; | 63 access |= GENERIC_EXECUTE; |
| 67 | 64 |
| 68 DWORD sharing = (flags & PLATFORM_FILE_EXCLUSIVE_READ) ? 0 : FILE_SHARE_READ; | 65 DWORD sharing = (flags & FLAG_EXCLUSIVE_READ) ? 0 : FILE_SHARE_READ; |
| 69 if (!(flags & PLATFORM_FILE_EXCLUSIVE_WRITE)) | 66 if (!(flags & FLAG_EXCLUSIVE_WRITE)) |
| 70 sharing |= FILE_SHARE_WRITE; | 67 sharing |= FILE_SHARE_WRITE; |
| 71 if (flags & PLATFORM_FILE_SHARE_DELETE) | 68 if (flags & FLAG_SHARE_DELETE) |
| 72 sharing |= FILE_SHARE_DELETE; | 69 sharing |= FILE_SHARE_DELETE; |
| 73 | 70 |
| 74 DWORD create_flags = 0; | 71 DWORD create_flags = 0; |
| 75 if (flags & PLATFORM_FILE_ASYNC) | 72 if (flags & FLAG_ASYNC) |
| 76 create_flags |= FILE_FLAG_OVERLAPPED; | 73 create_flags |= FILE_FLAG_OVERLAPPED; |
| 77 if (flags & PLATFORM_FILE_TEMPORARY) | 74 if (flags & FLAG_TEMPORARY) |
| 78 create_flags |= FILE_ATTRIBUTE_TEMPORARY; | 75 create_flags |= FILE_ATTRIBUTE_TEMPORARY; |
| 79 if (flags & PLATFORM_FILE_HIDDEN) | 76 if (flags & FLAG_HIDDEN) |
| 80 create_flags |= FILE_ATTRIBUTE_HIDDEN; | 77 create_flags |= FILE_ATTRIBUTE_HIDDEN; |
| 81 if (flags & PLATFORM_FILE_DELETE_ON_CLOSE) | 78 if (flags & FLAG_DELETE_ON_CLOSE) |
| 82 create_flags |= FILE_FLAG_DELETE_ON_CLOSE; | 79 create_flags |= FILE_FLAG_DELETE_ON_CLOSE; |
| 83 if (flags & PLATFORM_FILE_BACKUP_SEMANTICS) | 80 if (flags & FLAG_BACKUP_SEMANTICS) |
| 84 create_flags |= FILE_FLAG_BACKUP_SEMANTICS; | 81 create_flags |= FILE_FLAG_BACKUP_SEMANTICS; |
| 85 | 82 |
| 86 HANDLE file = CreateFile(name.value().c_str(), access, sharing, NULL, | 83 file_.Set(CreateFile(name.value().c_str(), access, sharing, NULL, |
| 87 disposition, create_flags, NULL); | 84 disposition, create_flags, NULL)); |
| 88 | 85 |
| 89 if (created && (INVALID_HANDLE_VALUE != file)) { | 86 if (file_.IsValid()) { |
| 90 if (flags & (PLATFORM_FILE_OPEN_ALWAYS)) | 87 error_ = FILE_OK; |
| 91 *created = (ERROR_ALREADY_EXISTS != GetLastError()); | 88 async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC); |
| 92 else if (flags & (PLATFORM_FILE_CREATE_ALWAYS | PLATFORM_FILE_CREATE)) | 89 |
| 93 *created = true; | 90 if (flags & (FLAG_OPEN_ALWAYS)) |
| 91 created_ = (ERROR_ALREADY_EXISTS != GetLastError()); |
| 92 else if (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE)) |
| 93 created_ = true; |
| 94 } else { |
| 95 error_ = OSErrorToFileError(GetLastError()); |
| 94 } | 96 } |
| 95 | |
| 96 if (error) { | |
| 97 if (file != kInvalidPlatformFileValue) | |
| 98 *error = PLATFORM_FILE_OK; | |
| 99 else | |
| 100 *error = LastErrorToPlatformFileError(GetLastError()); | |
| 101 } | |
| 102 | |
| 103 return file; | |
| 104 } | 97 } |
| 105 | 98 |
| 106 FILE* FdopenPlatformFile(PlatformFile file, const char* mode) { | 99 bool File::IsValid() const { |
| 107 if (file == kInvalidPlatformFileValue) | 100 return file_.IsValid(); |
| 108 return NULL; | 101 } |
| 109 int fd = _open_osfhandle(reinterpret_cast<intptr_t>(file), 0); | 102 PlatformFile File::TakePlatformFile() { |
| 110 if (fd < 0) | 103 return file_.Take(); |
| 111 return NULL; | |
| 112 return _fdopen(fd, mode); | |
| 113 } | 104 } |
| 114 | 105 |
| 115 bool ClosePlatformFile(PlatformFile file) { | 106 void File::Close() { |
| 116 base::ThreadRestrictions::AssertIOAllowed(); | 107 base::ThreadRestrictions::AssertIOAllowed(); |
| 117 return (CloseHandle(file) != 0); | 108 file_.Close(); |
| 118 } | 109 } |
| 119 | 110 |
| 120 int64 SeekPlatformFile(PlatformFile file, | 111 int64 File::Seek(Whence whence, int64 offset) { |
| 121 PlatformFileWhence whence, | |
| 122 int64 offset) { | |
| 123 base::ThreadRestrictions::AssertIOAllowed(); | 112 base::ThreadRestrictions::AssertIOAllowed(); |
| 124 if (file == kInvalidPlatformFileValue || offset < 0) | 113 DCHECK(IsValid()); |
| 114 if (offset < 0) |
| 125 return -1; | 115 return -1; |
| 126 | 116 |
| 127 LARGE_INTEGER distance, res; | 117 LARGE_INTEGER distance, res; |
| 128 distance.QuadPart = offset; | 118 distance.QuadPart = offset; |
| 129 DWORD move_method = static_cast<DWORD>(whence); | 119 DWORD move_method = static_cast<DWORD>(whence); |
| 130 if (!SetFilePointerEx(file, distance, &res, move_method)) | 120 if (!SetFilePointerEx(file_, distance, &res, move_method)) |
| 131 return -1; | 121 return -1; |
| 132 return res.QuadPart; | 122 return res.QuadPart; |
| 133 } | 123 } |
| 134 | 124 |
| 135 int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) { | 125 int File::Read(int64 offset, char* data, int size) { |
| 136 base::ThreadRestrictions::AssertIOAllowed(); | 126 base::ThreadRestrictions::AssertIOAllowed(); |
| 137 if (file == kInvalidPlatformFileValue || size < 0) | 127 DCHECK(IsValid()); |
| 128 DCHECK(!async_); |
| 129 if (size < 0) |
| 138 return -1; | 130 return -1; |
| 139 | 131 |
| 140 LARGE_INTEGER offset_li; | 132 LARGE_INTEGER offset_li; |
| 141 offset_li.QuadPart = offset; | 133 offset_li.QuadPart = offset; |
| 142 | 134 |
| 143 OVERLAPPED overlapped = {0}; | 135 OVERLAPPED overlapped = {0}; |
| 144 overlapped.Offset = offset_li.LowPart; | 136 overlapped.Offset = offset_li.LowPart; |
| 145 overlapped.OffsetHigh = offset_li.HighPart; | 137 overlapped.OffsetHigh = offset_li.HighPart; |
| 146 | 138 |
| 147 DWORD bytes_read; | 139 DWORD bytes_read; |
| 148 if (::ReadFile(file, data, size, &bytes_read, &overlapped) != 0) | 140 if (::ReadFile(file_, data, size, &bytes_read, &overlapped) != 0) |
| 149 return bytes_read; | 141 return bytes_read; |
| 150 if (ERROR_HANDLE_EOF == GetLastError()) | 142 if (ERROR_HANDLE_EOF == GetLastError()) |
| 151 return 0; | 143 return 0; |
| 152 | 144 |
| 153 return -1; | 145 return -1; |
| 154 } | 146 } |
| 155 | 147 |
| 156 int ReadPlatformFileAtCurrentPos(PlatformFile file, char* data, int size) { | 148 int File::ReadAtCurrentPos(char* data, int size) { |
| 157 base::ThreadRestrictions::AssertIOAllowed(); | 149 base::ThreadRestrictions::AssertIOAllowed(); |
| 158 if (file == kInvalidPlatformFileValue || size < 0) | 150 DCHECK(IsValid()); |
| 151 DCHECK(!async_); |
| 152 if (size < 0) |
| 159 return -1; | 153 return -1; |
| 160 | 154 |
| 161 DWORD bytes_read; | 155 DWORD bytes_read; |
| 162 if (::ReadFile(file, data, size, &bytes_read, NULL) != 0) | 156 if (::ReadFile(file_, data, size, &bytes_read, NULL) != 0) |
| 163 return bytes_read; | 157 return bytes_read; |
| 164 if (ERROR_HANDLE_EOF == GetLastError()) | 158 if (ERROR_HANDLE_EOF == GetLastError()) |
| 165 return 0; | 159 return 0; |
| 166 | 160 |
| 167 return -1; | 161 return -1; |
| 168 } | 162 } |
| 169 | 163 |
| 170 int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset, char* data, | 164 int File::ReadNoBestEffort(int64 offset, char* data, int size) { |
| 171 int size) { | 165 return Read(offset, data, size); |
| 172 return ReadPlatformFile(file, offset, data, size); | |
| 173 } | 166 } |
| 174 | 167 |
| 175 int ReadPlatformFileCurPosNoBestEffort(PlatformFile file, | 168 int File::ReadAtCurrentPosNoBestEffort(char* data, int size) { |
| 176 char* data, int size) { | 169 return ReadAtCurrentPos(data, size); |
| 177 return ReadPlatformFileAtCurrentPos(file, data, size); | |
| 178 } | 170 } |
| 179 | 171 |
| 180 int WritePlatformFile(PlatformFile file, int64 offset, | 172 int File::Write(int64 offset, const char* data, int size) { |
| 181 const char* data, int size) { | |
| 182 base::ThreadRestrictions::AssertIOAllowed(); | 173 base::ThreadRestrictions::AssertIOAllowed(); |
| 183 if (file == kInvalidPlatformFileValue) | 174 DCHECK(IsValid()); |
| 184 return -1; | 175 DCHECK(!async_); |
| 185 | 176 |
| 186 LARGE_INTEGER offset_li; | 177 LARGE_INTEGER offset_li; |
| 187 offset_li.QuadPart = offset; | 178 offset_li.QuadPart = offset; |
| 188 | 179 |
| 189 OVERLAPPED overlapped = {0}; | 180 OVERLAPPED overlapped = {0}; |
| 190 overlapped.Offset = offset_li.LowPart; | 181 overlapped.Offset = offset_li.LowPart; |
| 191 overlapped.OffsetHigh = offset_li.HighPart; | 182 overlapped.OffsetHigh = offset_li.HighPart; |
| 192 | 183 |
| 193 DWORD bytes_written; | 184 DWORD bytes_written; |
| 194 if (::WriteFile(file, data, size, &bytes_written, &overlapped) != 0) | 185 if (::WriteFile(file_, data, size, &bytes_written, &overlapped) != 0) |
| 195 return bytes_written; | 186 return bytes_written; |
| 196 | 187 |
| 197 return -1; | 188 return -1; |
| 198 } | 189 } |
| 199 | 190 |
| 200 int WritePlatformFileAtCurrentPos(PlatformFile file, const char* data, | 191 int File::WriteAtCurrentPos(const char* data, int size) { |
| 201 int size) { | 192 NOTREACHED(); |
| 202 return WritePlatformFile(file, 0, data, size); | 193 return -1; |
| 203 } | 194 } |
| 204 | 195 |
| 205 int WritePlatformFileCurPosNoBestEffort(PlatformFile file, | 196 int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) { |
| 206 const char* data, int size) { | 197 return WriteAtCurrentPos(data, size); |
| 207 return WritePlatformFile(file, 0, data, size); | |
| 208 } | 198 } |
| 209 | 199 |
| 210 bool TruncatePlatformFile(PlatformFile file, int64 length) { | 200 bool File::Truncate(int64 length) { |
| 211 base::ThreadRestrictions::AssertIOAllowed(); | 201 base::ThreadRestrictions::AssertIOAllowed(); |
| 212 if (file == kInvalidPlatformFileValue) | 202 DCHECK(IsValid()); |
| 213 return false; | |
| 214 | 203 |
| 215 // Get the current file pointer. | 204 // Get the current file pointer. |
| 216 LARGE_INTEGER file_pointer; | 205 LARGE_INTEGER file_pointer; |
| 217 LARGE_INTEGER zero; | 206 LARGE_INTEGER zero; |
| 218 zero.QuadPart = 0; | 207 zero.QuadPart = 0; |
| 219 if (::SetFilePointerEx(file, zero, &file_pointer, FILE_CURRENT) == 0) | 208 if (::SetFilePointerEx(file_, zero, &file_pointer, FILE_CURRENT) == 0) |
| 220 return false; | 209 return false; |
| 221 | 210 |
| 222 LARGE_INTEGER length_li; | 211 LARGE_INTEGER length_li; |
| 223 length_li.QuadPart = length; | 212 length_li.QuadPart = length; |
| 224 // If length > file size, SetFilePointerEx() should extend the file | 213 // If length > file size, SetFilePointerEx() should extend the file |
| 225 // with zeroes on all Windows standard file systems (NTFS, FATxx). | 214 // with zeroes on all Windows standard file systems (NTFS, FATxx). |
| 226 if (!::SetFilePointerEx(file, length_li, NULL, FILE_BEGIN)) | 215 if (!::SetFilePointerEx(file_, length_li, NULL, FILE_BEGIN)) |
| 227 return false; | 216 return false; |
| 228 | 217 |
| 229 // Set the new file length and move the file pointer to its old position. | 218 // Set the new file length and move the file pointer to its old position. |
| 230 // This is consistent with ftruncate()'s behavior, even when the file | 219 // This is consistent with ftruncate()'s behavior, even when the file |
| 231 // pointer points to a location beyond the end of the file. | 220 // pointer points to a location beyond the end of the file. |
| 232 return ((::SetEndOfFile(file) != 0) && | 221 return ((::SetEndOfFile(file_) != 0) && |
| 233 (::SetFilePointerEx(file, file_pointer, NULL, FILE_BEGIN) != 0)); | 222 (::SetFilePointerEx(file_, file_pointer, NULL, FILE_BEGIN) != 0)); |
| 234 } | 223 } |
| 235 | 224 |
| 236 bool FlushPlatformFile(PlatformFile file) { | 225 bool File::Flush() { |
| 237 base::ThreadRestrictions::AssertIOAllowed(); | 226 base::ThreadRestrictions::AssertIOAllowed(); |
| 238 return ((file != kInvalidPlatformFileValue) && ::FlushFileBuffers(file)); | 227 DCHECK(IsValid()); |
| 228 return ::FlushFileBuffers(file_) != FALSE; |
| 239 } | 229 } |
| 240 | 230 |
| 241 bool TouchPlatformFile(PlatformFile file, const base::Time& last_access_time, | 231 bool File::SetTime(Time last_access_time, Time last_modified_time) { |
| 242 const base::Time& last_modified_time) { | |
| 243 base::ThreadRestrictions::AssertIOAllowed(); | 232 base::ThreadRestrictions::AssertIOAllowed(); |
| 244 if (file == kInvalidPlatformFileValue) | 233 DCHECK(IsValid()); |
| 245 return false; | |
| 246 | 234 |
| 247 FILETIME last_access_filetime = last_access_time.ToFileTime(); | 235 FILETIME last_access_filetime = last_access_time.ToFileTime(); |
| 248 FILETIME last_modified_filetime = last_modified_time.ToFileTime(); | 236 FILETIME last_modified_filetime = last_modified_time.ToFileTime(); |
| 249 return (::SetFileTime(file, NULL, &last_access_filetime, | 237 return (::SetFileTime(file_, NULL, &last_access_filetime, |
| 250 &last_modified_filetime) != 0); | 238 &last_modified_filetime) != 0); |
| 251 } | 239 } |
| 252 | 240 |
| 253 bool GetPlatformFileInfo(PlatformFile file, PlatformFileInfo* info) { | 241 bool File::GetInfo(Info* info) { |
| 254 base::ThreadRestrictions::AssertIOAllowed(); | 242 base::ThreadRestrictions::AssertIOAllowed(); |
| 255 if (!info) | 243 DCHECK(IsValid()); |
| 256 return false; | |
| 257 | 244 |
| 258 BY_HANDLE_FILE_INFORMATION file_info; | 245 BY_HANDLE_FILE_INFORMATION file_info; |
| 259 if (GetFileInformationByHandle(file, &file_info) == 0) | 246 if (GetFileInformationByHandle(file_, &file_info) == 0) |
| 260 return false; | 247 return false; |
| 261 | 248 |
| 262 LARGE_INTEGER size; | 249 LARGE_INTEGER size; |
| 263 size.HighPart = file_info.nFileSizeHigh; | 250 size.HighPart = file_info.nFileSizeHigh; |
| 264 size.LowPart = file_info.nFileSizeLow; | 251 size.LowPart = file_info.nFileSizeLow; |
| 265 info->size = size.QuadPart; | 252 info->size = size.QuadPart; |
| 266 info->is_directory = | 253 info->is_directory = |
| 267 (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; | 254 (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; |
| 268 info->is_symbolic_link = false; // Windows doesn't have symbolic links. | 255 info->is_symbolic_link = false; // Windows doesn't have symbolic links. |
| 269 info->last_modified = base::Time::FromFileTime(file_info.ftLastWriteTime); | 256 info->last_modified = base::Time::FromFileTime(file_info.ftLastWriteTime); |
| 270 info->last_accessed = base::Time::FromFileTime(file_info.ftLastAccessTime); | 257 info->last_accessed = base::Time::FromFileTime(file_info.ftLastAccessTime); |
| 271 info->creation_time = base::Time::FromFileTime(file_info.ftCreationTime); | 258 info->creation_time = base::Time::FromFileTime(file_info.ftCreationTime); |
| 272 return true; | 259 return true; |
| 273 } | 260 } |
| 274 | 261 |
| 275 PlatformFileError LockPlatformFile(PlatformFile file) { | 262 File::Error base::File::Lock() { |
| 276 BOOL result = LockFile(file, 0, 0, MAXDWORD, MAXDWORD); | 263 DCHECK(IsValid()); |
| 264 BOOL result = LockFile(file_, 0, 0, MAXDWORD, MAXDWORD); |
| 277 if (!result) | 265 if (!result) |
| 278 return LastErrorToPlatformFileError(GetLastError()); | 266 return OSErrorToFileError(GetLastError()); |
| 279 return PLATFORM_FILE_OK; | 267 return FILE_OK; |
| 280 } | 268 } |
| 281 | 269 |
| 282 PlatformFileError UnlockPlatformFile(PlatformFile file) { | 270 File::Error File::Unlock() { |
| 283 BOOL result = UnlockFile(file, 0, 0, MAXDWORD, MAXDWORD); | 271 DCHECK(IsValid()); |
| 272 BOOL result = UnlockFile(file_, 0, 0, MAXDWORD, MAXDWORD); |
| 284 if (!result) | 273 if (!result) |
| 285 return LastErrorToPlatformFileError(GetLastError()); | 274 return OSErrorToFileError(GetLastError()); |
| 286 return PLATFORM_FILE_OK; | 275 return FILE_OK; |
| 287 } | 276 } |
| 288 | 277 |
| 289 PlatformFileError LastErrorToPlatformFileError(DWORD last_error) { | 278 // Static. |
| 279 File::Error File::OSErrorToFileError(DWORD last_error) { |
| 290 switch (last_error) { | 280 switch (last_error) { |
| 291 case ERROR_SHARING_VIOLATION: | 281 case ERROR_SHARING_VIOLATION: |
| 292 return PLATFORM_FILE_ERROR_IN_USE; | 282 return FILE_ERROR_IN_USE; |
| 293 case ERROR_FILE_EXISTS: | 283 case ERROR_FILE_EXISTS: |
| 294 return PLATFORM_FILE_ERROR_EXISTS; | 284 return FILE_ERROR_EXISTS; |
| 295 case ERROR_FILE_NOT_FOUND: | 285 case ERROR_FILE_NOT_FOUND: |
| 296 case ERROR_PATH_NOT_FOUND: | 286 case ERROR_PATH_NOT_FOUND: |
| 297 return PLATFORM_FILE_ERROR_NOT_FOUND; | 287 return FILE_ERROR_NOT_FOUND; |
| 298 case ERROR_ACCESS_DENIED: | 288 case ERROR_ACCESS_DENIED: |
| 299 return PLATFORM_FILE_ERROR_ACCESS_DENIED; | 289 return FILE_ERROR_ACCESS_DENIED; |
| 300 case ERROR_TOO_MANY_OPEN_FILES: | 290 case ERROR_TOO_MANY_OPEN_FILES: |
| 301 return PLATFORM_FILE_ERROR_TOO_MANY_OPENED; | 291 return FILE_ERROR_TOO_MANY_OPENED; |
| 302 case ERROR_OUTOFMEMORY: | 292 case ERROR_OUTOFMEMORY: |
| 303 case ERROR_NOT_ENOUGH_MEMORY: | 293 case ERROR_NOT_ENOUGH_MEMORY: |
| 304 return PLATFORM_FILE_ERROR_NO_MEMORY; | 294 return FILE_ERROR_NO_MEMORY; |
| 305 case ERROR_HANDLE_DISK_FULL: | 295 case ERROR_HANDLE_DISK_FULL: |
| 306 case ERROR_DISK_FULL: | 296 case ERROR_DISK_FULL: |
| 307 case ERROR_DISK_RESOURCES_EXHAUSTED: | 297 case ERROR_DISK_RESOURCES_EXHAUSTED: |
| 308 return PLATFORM_FILE_ERROR_NO_SPACE; | 298 return FILE_ERROR_NO_SPACE; |
| 309 case ERROR_USER_MAPPED_FILE: | 299 case ERROR_USER_MAPPED_FILE: |
| 310 return PLATFORM_FILE_ERROR_INVALID_OPERATION; | 300 return FILE_ERROR_INVALID_OPERATION; |
| 311 case ERROR_NOT_READY: | 301 case ERROR_NOT_READY: |
| 312 case ERROR_SECTOR_NOT_FOUND: | 302 case ERROR_SECTOR_NOT_FOUND: |
| 313 case ERROR_DEV_NOT_EXIST: | 303 case ERROR_DEV_NOT_EXIST: |
| 314 case ERROR_IO_DEVICE: | 304 case ERROR_IO_DEVICE: |
| 315 case ERROR_FILE_CORRUPT: | 305 case ERROR_FILE_CORRUPT: |
| 316 case ERROR_DISK_CORRUPT: | 306 case ERROR_DISK_CORRUPT: |
| 317 return PLATFORM_FILE_ERROR_IO; | 307 return FILE_ERROR_IO; |
| 318 default: | 308 default: |
| 319 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Windows", | 309 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Windows", |
| 320 last_error); | 310 last_error); |
| 321 return PLATFORM_FILE_ERROR_FAILED; | 311 return FILE_ERROR_FAILED; |
| 322 } | 312 } |
| 323 } | 313 } |
| 324 | 314 |
| 315 void File::SetPlatformFile(PlatformFile file) { |
| 316 file_.Set(file); |
| 317 } |
| 318 |
| 325 } // namespace base | 319 } // namespace base |
| OLD | NEW |