#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "base/files/file.h"
#define _FILE_OFFSET_BITS …
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <sys/stat.h>
#include <unistd.h>
static_assert …;
#include <atomic>
#include <optional>
#include "base/check_op.h"
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "base/notimplemented.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/posix/eintr_wrapper.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/scoped_blocking_call.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/os_compat_android.h"
#endif
namespace base {
static_assert …;
namespace {
#if BUILDFLAG(IS_APPLE)
BASE_FEATURE(kMacEfficientFileFlush,
"MacEfficientFileFlush",
base::FEATURE_DISABLED_BY_DEFAULT);
const FeatureParam<bool> kMacEfficientFileFlushUseBarrier{
&kMacEfficientFileFlush, "MacEfficientFileFlushUseBarrier", true};
enum class MacFileFlushMechanism {
kFlush,
kFullFsync,
kBarrierFsync,
};
std::atomic<MacFileFlushMechanism> g_mac_file_flush_mechanism{
MacFileFlushMechanism::kFullFsync};
#endif
#if !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_AIX)
bool IsOpenAppend(PlatformFile file) { … }
int CallFtruncate(PlatformFile file, int64_t length) { … }
int CallFutimes(PlatformFile file, const struct timeval times[2]) { … }
#if !BUILDFLAG(IS_FUCHSIA)
short FcntlFlockType(std::optional<File::LockMode> mode) { … }
File::Error CallFcntlFlock(PlatformFile file,
std::optional<File::LockMode> mode) { … }
#endif
#else
bool IsOpenAppend(PlatformFile file) {
return false;
}
int CallFtruncate(PlatformFile file, int64_t length) {
NOTIMPLEMENTED();
return 0;
}
int CallFutimes(PlatformFile file, const struct timeval times[2]) {
NOTIMPLEMENTED();
return 0;
}
File::Error CallFcntlFlock(PlatformFile file,
std::optional<File::LockMode> mode) {
NOTIMPLEMENTED();
return File::FILE_ERROR_INVALID_OPERATION;
}
#endif
}
void File::Info::FromStat(const stat_wrapper_t& stat_info) { … }
bool File::IsValid() const { … }
PlatformFile File::GetPlatformFile() const { … }
PlatformFile File::TakePlatformFile() { … }
void File::Close() { … }
int64_t File::Seek(Whence whence, int64_t offset) { … }
int File::Read(int64_t offset, char* data, int size) { … }
int File::ReadAtCurrentPos(char* data, int size) { … }
int File::ReadNoBestEffort(int64_t offset, char* data, int size) { … }
int File::ReadAtCurrentPosNoBestEffort(char* data, int size) { … }
int File::Write(int64_t offset, const char* data, int size) { … }
int File::WriteAtCurrentPos(const char* data, int size) { … }
int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) { … }
int64_t File::GetLength() const { … }
bool File::SetLength(int64_t length) { … }
bool File::SetTimes(Time last_access_time, Time last_modified_time) { … }
bool File::GetInfo(Info* info) { … }
#if !BUILDFLAG(IS_FUCHSIA)
File::Error File::Lock(File::LockMode mode) { … }
File::Error File::Unlock() { … }
#endif
File File::Duplicate() const { … }
#if BUILDFLAG(IS_APPLE)
void File::InitializeFeatures() {
if (FeatureList::IsEnabled(kMacEfficientFileFlush)) {
if (kMacEfficientFileFlushUseBarrier.Get()) {
g_mac_file_flush_mechanism.store(MacFileFlushMechanism::kBarrierFsync,
std::memory_order_relaxed);
} else {
g_mac_file_flush_mechanism.store(MacFileFlushMechanism::kFlush,
std::memory_order_relaxed);
}
}
}
#endif
File::Error File::OSErrorToFileError(int saved_errno) { … }
#if !BUILDFLAG(IS_NACL)
void File::DoInitialize(const FilePath& path, uint32_t flags) { … }
#endif
bool File::Flush() { … }
void File::SetPlatformFile(PlatformFile file) { … }
File::Error File::GetLastFileError() { … }
int File::Stat(const FilePath& path, stat_wrapper_t* sb) { … }
int File::Fstat(int fd, stat_wrapper_t* sb) { … }
int File::Lstat(const FilePath& path, stat_wrapper_t* sb) { … }
}