LLVM 22.0.0git
OnDiskCommon.h
Go to the documentation of this file.
1//===- OnDiskCommon.h -------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIB_CAS_ONDISKCOMMON_H
10#define LLVM_LIB_CAS_ONDISKCOMMON_H
11
12#include "llvm/Support/Error.h"
14#include <chrono>
15
17
18/// Thread-safe alternative to \c sys::fs::lockFile. This does not support all
19/// the platforms that \c sys::fs::lockFile does, so keep it in the CAS library
20/// for now.
21std::error_code lockFileThreadSafe(int FD, llvm::sys::fs::LockKind Kind);
22
23/// Thread-safe alternative to \c sys::fs::unlockFile. This does not support all
24/// the platforms that \c sys::fs::lockFile does, so keep it in the CAS library
25/// for now.
26std::error_code unlockFileThreadSafe(int FD);
27
28/// Thread-safe alternative to \c sys::fs::tryLockFile. This does not support
29/// all the platforms that \c sys::fs::lockFile does, so keep it in the CAS
30/// library for now.
31std::error_code tryLockFileThreadSafe(
32 int FD, std::chrono::milliseconds Timeout = std::chrono::milliseconds(0),
34
35/// Allocate space for the file \p FD on disk, if the filesystem supports it.
36///
37/// On filesystems that support this operation, this ensures errors such as
38/// \c std::errc::no_space_on_device are detected before we write data.
39///
40/// \returns the new size of the file, or an \c Error.
41Expected<size_t> preallocateFileTail(int FD, size_t CurrentSize,
42 size_t NewSize);
43
44} // namespace llvm::cas::ondisk
45
46#endif // LLVM_LIB_CAS_ONDISKCOMMON_H
Tagged union holding either a T or a Error.
Definition Error.h:485
std::error_code lockFileThreadSafe(int FD, llvm::sys::fs::LockKind Kind)
Thread-safe alternative to sys::fs::lockFile.
std::error_code unlockFileThreadSafe(int FD)
Thread-safe alternative to sys::fs::unlockFile.
std::error_code tryLockFileThreadSafe(int FD, std::chrono::milliseconds Timeout=std::chrono::milliseconds(0), llvm::sys::fs::LockKind Kind=llvm::sys::fs::LockKind::Exclusive)
Thread-safe alternative to sys::fs::tryLockFile.
Expected< size_t > preallocateFileTail(int FD, size_t CurrentSize, size_t NewSize)
Allocate space for the file FD on disk, if the filesystem supports it.
LockKind
An enumeration for the lock kind.
@ Timeout
Reached timeout while waiting for the owner to release the lock.