Chromium Code Reviews| 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/platform_file.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 | 22 |
| 23 namespace base { | 23 namespace base { |
| 24 | 24 |
| 25 // Make sure our Whence mappings match the system headers. | 25 // Make sure our Whence mappings match the system headers. |
| 26 COMPILE_ASSERT(PLATFORM_FILE_FROM_BEGIN == SEEK_SET && | 26 COMPILE_ASSERT(PLATFORM_FILE_FROM_BEGIN == SEEK_SET && |
| 27 PLATFORM_FILE_FROM_CURRENT == SEEK_CUR && | 27 PLATFORM_FILE_FROM_CURRENT == SEEK_CUR && |
| 28 PLATFORM_FILE_FROM_END == SEEK_END, whence_matches_system); | 28 PLATFORM_FILE_FROM_END == SEEK_END, whence_matches_system); |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 #if defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL) | 32 #if defined(OS_BSD) || defined(OS_MACOSX) |
|
pasko
2013/08/21 14:40:58
nacl has largefile with so this should be OK, than
| |
| 33 typedef struct stat stat_wrapper_t; | 33 typedef struct stat stat_wrapper_t; |
| 34 static int CallFstat(int fd, stat_wrapper_t *sb) { | 34 static int CallFstat(int fd, stat_wrapper_t *sb) { |
| 35 base::ThreadRestrictions::AssertIOAllowed(); | 35 base::ThreadRestrictions::AssertIOAllowed(); |
| 36 return fstat(fd, sb); | 36 return fstat(fd, sb); |
| 37 } | 37 } |
| 38 #else | 38 #else |
| 39 typedef struct stat64 stat_wrapper_t; | 39 typedef struct stat64 stat_wrapper_t; |
| 40 static int CallFstat(int fd, stat_wrapper_t *sb) { | 40 static int CallFstat(int fd, stat_wrapper_t *sb) { |
| 41 base::ThreadRestrictions::AssertIOAllowed(); | 41 base::ThreadRestrictions::AssertIOAllowed(); |
| 42 return fstat64(fd, sb); | 42 return fstat64(fd, sb); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 return false; | 373 return false; |
| 374 | 374 |
| 375 stat_wrapper_t file_info; | 375 stat_wrapper_t file_info; |
| 376 if (CallFstat(file, &file_info)) | 376 if (CallFstat(file, &file_info)) |
| 377 return false; | 377 return false; |
| 378 | 378 |
| 379 info->is_directory = S_ISDIR(file_info.st_mode); | 379 info->is_directory = S_ISDIR(file_info.st_mode); |
| 380 info->is_symbolic_link = S_ISLNK(file_info.st_mode); | 380 info->is_symbolic_link = S_ISLNK(file_info.st_mode); |
| 381 info->size = file_info.st_size; | 381 info->size = file_info.st_size; |
| 382 | 382 |
| 383 #if defined(OS_LINUX) | 383 #if defined(OS_MACOSX) |
| 384 const time_t last_modified_sec = file_info.st_mtim.tv_sec; | 384 info->last_modified = base::Time::FromTimeSpec(file_info.st_mtimespec); |
| 385 const int64 last_modified_nsec = file_info.st_mtim.tv_nsec; | 385 info->last_accessed = base::Time::FromTimeSpec(file_info.st_atimespec); |
| 386 const time_t last_accessed_sec = file_info.st_atim.tv_sec; | 386 info->creation_time = base::Time::FromTimeSpec(file_info.st_ctimespec); |
| 387 const int64 last_accessed_nsec = file_info.st_atim.tv_nsec; | |
| 388 const time_t creation_time_sec = file_info.st_ctim.tv_sec; | |
| 389 const int64 creation_time_nsec = file_info.st_ctim.tv_nsec; | |
| 390 #elif defined(OS_ANDROID) | 387 #elif defined(OS_ANDROID) |
| 391 const time_t last_modified_sec = file_info.st_mtime; | 388 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); |
| 392 const int64 last_modified_nsec = file_info.st_mtime_nsec; | 389 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); |
| 393 const time_t last_accessed_sec = file_info.st_atime; | 390 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); |
| 394 const int64 last_accessed_nsec = file_info.st_atime_nsec; | |
| 395 const time_t creation_time_sec = file_info.st_ctime; | |
| 396 const int64 creation_time_nsec = file_info.st_ctime_nsec; | |
| 397 #elif defined(OS_MACOSX) || defined(OS_IOS) || defined(OS_BSD) | |
| 398 const time_t last_modified_sec = file_info.st_mtimespec.tv_sec; | |
| 399 const int64 last_modified_nsec = file_info.st_mtimespec.tv_nsec; | |
| 400 const time_t last_accessed_sec = file_info.st_atimespec.tv_sec; | |
| 401 const int64 last_accessed_nsec = file_info.st_atimespec.tv_nsec; | |
| 402 const time_t creation_time_sec = file_info.st_ctimespec.tv_sec; | |
| 403 const int64 creation_time_nsec = file_info.st_ctimespec.tv_nsec; | |
| 404 #else | 391 #else |
| 405 // TODO(gavinp): Investigate a good high resolution option for OS_NACL. | 392 info->last_modified = base::Time::FromTimeSpec(file_info.st_mtim); |
| 406 const time_t last_modified_sec = file_info.st_mtime; | 393 info->last_accessed = base::Time::FromTimeSpec(file_info.st_atim); |
| 407 const int64 last_modified_nsec = 0; | 394 info->creation_time = base::Time::FromTimeSpec(file_info.st_ctim); |
| 408 const time_t last_accessed_sec = file_info.st_atime; | |
| 409 const int64 last_accessed_nsec = 0; | |
| 410 const time_t creation_time_sec = file_info.st_ctime; | |
| 411 const int64 creation_time_nsec = 0; | |
| 412 #endif | 395 #endif |
| 413 | |
| 414 info->last_modified = | |
| 415 base::Time::FromTimeT(last_modified_sec) + | |
| 416 base::TimeDelta::FromMicroseconds(last_modified_nsec / | |
| 417 base::Time::kNanosecondsPerMicrosecond); | |
| 418 info->last_accessed = | |
| 419 base::Time::FromTimeT(last_accessed_sec) + | |
| 420 base::TimeDelta::FromMicroseconds(last_accessed_nsec / | |
| 421 base::Time::kNanosecondsPerMicrosecond); | |
| 422 info->creation_time = | |
| 423 base::Time::FromTimeT(creation_time_sec) + | |
| 424 base::TimeDelta::FromMicroseconds(creation_time_nsec / | |
| 425 base::Time::kNanosecondsPerMicrosecond); | |
| 426 return true; | 396 return true; |
| 427 } | 397 } |
| 428 | 398 |
| 429 PlatformFileError ErrnoToPlatformFileError(int saved_errno) { | 399 PlatformFileError ErrnoToPlatformFileError(int saved_errno) { |
| 430 switch (saved_errno) { | 400 switch (saved_errno) { |
| 431 case EACCES: | 401 case EACCES: |
| 432 case EISDIR: | 402 case EISDIR: |
| 433 case EROFS: | 403 case EROFS: |
| 434 case EPERM: | 404 case EPERM: |
| 435 return PLATFORM_FILE_ERROR_ACCESS_DENIED; | 405 return PLATFORM_FILE_ERROR_ACCESS_DENIED; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 452 default: | 422 default: |
| 453 #if !defined(OS_NACL) // NaCl build has no metrics code. | 423 #if !defined(OS_NACL) // NaCl build has no metrics code. |
| 454 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Posix", | 424 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Posix", |
| 455 saved_errno); | 425 saved_errno); |
| 456 #endif | 426 #endif |
| 457 return PLATFORM_FILE_ERROR_FAILED; | 427 return PLATFORM_FILE_ERROR_FAILED; |
| 458 } | 428 } |
| 459 } | 429 } |
| 460 | 430 |
| 461 } // namespace base | 431 } // namespace base |
| OLD | NEW |