Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/test/test_file_util.h" | 5 #include "base/test/test_file_util.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| 11 | 11 |
| 12 #if defined(OS_ANDROID) | |
| 13 #include <asm/unistd.h> | |
| 14 #include <errno.h> | |
| 15 #include <linux/fadvise.h> | |
| 16 #include <sys/syscall.h> | |
| 17 #endif | |
| 18 | |
| 12 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 13 #include "base/files/scoped_file.h" | 20 #include "base/files/scoped_file.h" |
| 14 | 21 |
| 15 namespace base { | 22 namespace base { |
| 16 | 23 |
| 24 // Inconveniently, the NDK doesn't provide for posix_fadvise | |
|
jbudorick
2017/05/30 15:48:02
Should this all just be in test_file_util_android.
Maks Orlovich
2017/05/30 16:49:17
I can bind "all" two different ways, and have diff
jbudorick
2017/05/30 16:52:05
This was what I meant. Your reasoning for keeping
| |
| 25 // until API level = 21, which we don't use yet, so provide a wrapper, at least | |
|
jbudorick
2017/05/30 15:48:02
nit: note that this is *native* api level 21.
Maks Orlovich
2017/05/30 16:49:17
Thanks for elaborating, I wasn't aware of this dis
| |
| 26 // on ARM32 | |
| 27 #if defined(OS_ANDROID) | |
|
jbudorick
2017/05/30 15:48:02
nit: Should this be
if defined(OS_ANDROID) && _
Maks Orlovich
2017/05/30 16:49:17
Done.
| |
| 28 | |
| 29 namespace { | |
| 30 int posix_fadvise(int fd, off_t offset, off_t len, int advice) { | |
| 31 #if defined(ARCH_CPU_ARMEL) | |
| 32 // Note that the syscall argument order on ARM is different from the C | |
| 33 // function; this is helpfully documented in the Linux posix_fadvise manpage. | |
| 34 return syscall(__NR_arm_fadvise64_64, fd, advice, | |
| 35 0, // Upper 32-bits for offset | |
| 36 offset, | |
| 37 0, // Upper 32-bits for length | |
| 38 len); | |
| 39 #endif | |
| 40 NOTIMPLEMENTED(); | |
| 41 return ENOSYS; | |
| 42 } | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 46 #endif // OS_ANDROID | |
| 47 | |
| 17 bool EvictFileFromSystemCache(const FilePath& file) { | 48 bool EvictFileFromSystemCache(const FilePath& file) { |
| 18 ScopedFD fd(open(file.value().c_str(), O_RDONLY)); | 49 ScopedFD fd(open(file.value().c_str(), O_RDONLY)); |
| 19 if (!fd.is_valid()) | 50 if (!fd.is_valid()) |
| 20 return false; | 51 return false; |
| 21 if (fdatasync(fd.get()) != 0) | 52 if (fdatasync(fd.get()) != 0) |
| 22 return false; | 53 return false; |
| 23 if (posix_fadvise(fd.get(), 0, 0, POSIX_FADV_DONTNEED) != 0) | 54 if (posix_fadvise(fd.get(), 0, 0, POSIX_FADV_DONTNEED) != 0) |
| 24 return false; | 55 return false; |
| 25 return true; | 56 return true; |
| 26 } | 57 } |
| 27 | 58 |
| 28 } // namespace base | 59 } // namespace base |
| OLD | NEW |