folly/folly/FileUtil.cpp

/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <folly/FileUtil.h>

#include <cerrno>
#include <string>
#include <system_error>
#include <vector>

#include <folly/detail/FileUtilDetail.h>
#include <folly/detail/FileUtilVectorDetail.h>
#include <folly/net/NetOps.h>
#include <folly/portability/Fcntl.h>
#include <folly/portability/Sockets.h>
#include <folly/portability/Stdlib.h>
#include <folly/portability/SysFile.h>
#include <folly/portability/SysStat.h>

namespace folly {
namespace {
iovec getIOVecFor(ByteRange);
} // namespace

usingnamespacefileutil_detail;

int openNoInt(const char* name, int flags, mode_t mode) {}

static int filterCloseReturn(int r) {}

int closeNoInt(int fd) {}

int closeNoInt(NetworkSocket fd) {}

int fsyncNoInt(int fd) {}

int dupNoInt(int fd) {}

int dup2NoInt(int oldFd, int newFd) {}

int fdatasyncNoInt(int fd) {}

int ftruncateNoInt(int fd, off_t len) {}

int truncateNoInt(const char* path, off_t len) {}

int flockNoInt(int fd, int operation) {}

int shutdownNoInt(NetworkSocket fd, int how) {}

ssize_t readNoInt(int fd, void* buf, size_t count) {}

ssize_t preadNoInt(int fd, void* buf, size_t count, off_t offset) {}

ssize_t readvNoInt(int fd, const iovec* iov, int count) {}

ssize_t preadvNoInt(int fd, const iovec* iov, int count, off_t offset) {}

ssize_t writeNoInt(int fd, const void* buf, size_t count) {}

ssize_t pwriteNoInt(int fd, const void* buf, size_t count, off_t offset) {}

ssize_t writevNoInt(int fd, const iovec* iov, int count) {}

ssize_t pwritevNoInt(int fd, const iovec* iov, int count, off_t offset) {}

ssize_t readFull(int fd, void* buf, size_t count) {}

ssize_t preadFull(int fd, void* buf, size_t count, off_t offset) {}

ssize_t writeFull(int fd, const void* buf, size_t count) {}

ssize_t pwriteFull(int fd, const void* buf, size_t count, off_t offset) {}

#ifndef _WIN32
ssize_t readvFull(int fd, iovec* iov, int count) {}

ssize_t preadvFull(int fd, iovec* iov, int count, off_t offset) {}

ssize_t writevFull(int fd, iovec* iov, int count) {}

ssize_t pwritevFull(int fd, iovec* iov, int count, off_t offset) {}
#else // _WIN32

// On Windows, the *vFull() functions wrap the simple read/pread/write/pwrite
// functions.  While folly/portability/SysUio.cpp does define readv() and
// writev() implementations for Windows, these attempt to lock the file to
// provide atomicity.  The *vFull() functions do not provide any atomicity
// guarantees, so we can avoid the locking logic.

ssize_t readvFull(int fd, iovec* iov, int count) {
  return wrapvFull(read, fd, iov, count);
}

ssize_t preadvFull(int fd, iovec* iov, int count, off_t offset) {
  return wrapvFull(pread, fd, iov, count, offset);
}

ssize_t writevFull(int fd, iovec* iov, int count) {
  return wrapvFull(write, fd, iov, count);
}

ssize_t pwritevFull(int fd, iovec* iov, int count, off_t offset) {
  return wrapvFull(pwrite, fd, iov, count, offset);
}
#endif // _WIN32

WriteFileAtomicOptions& WriteFileAtomicOptions::setPermissions(
    mode_t _permissions) {}

WriteFileAtomicOptions& WriteFileAtomicOptions::setSyncType(
    SyncType _syncType) {}

WriteFileAtomicOptions& WriteFileAtomicOptions::setTemporaryDirectory(
    std::string _temporaryDirectory) {}

namespace {
void throwIfWriteFileAtomicFailed(
    StringPiece function, StringPiece filename, std::int64_t rc) {}

// We write the data to a temporary file name first, then atomically rename
// it into place.
//
// If SyncType::WITH_SYNC is used, this ensures that the file contents will
// always be valid, even if we crash or are killed partway through writing out
// data.
int writeFileAtomicNoThrowImpl(
    StringPiece filename,
    iovec* iov,
    int count,
    const WriteFileAtomicOptions& options) {}
} // namespace

int writeFileAtomicNoThrow(
    StringPiece filename,
    iovec* iov,
    int count,
    mode_t permissions,
    SyncType syncType) {}

int writeFileAtomicNoThrow(
    StringPiece filename,
    StringPiece data,
    const WriteFileAtomicOptions& options) {}

void writeFileAtomic(
    StringPiece filename,
    iovec* iov,
    int count,
    mode_t permissions,
    SyncType syncType) {}

void writeFileAtomic(
    StringPiece filename,
    ByteRange data,
    mode_t permissions,
    SyncType syncType) {}

void writeFileAtomic(
    StringPiece filename,
    StringPiece data,
    mode_t permissions,
    SyncType syncType) {}

void writeFileAtomic(
    StringPiece filename,
    StringPiece data,
    const WriteFileAtomicOptions& options) {}

namespace {
iovec getIOVecFor(ByteRange byteRange) {}
} // namespace
} // namespace folly