9#ifndef SQUID_SRC_BASE_FILE_H
10#define SQUID_SRC_BASE_FILE_H
42#if _SQUID_WINDOWS_ || _SQUID_MINGW_
43 DWORD desiredAccess = 0;
45 DWORD creationDisposition = OPEN_EXISTING;
53#if _SQUID_WINDOWS_ || _SQUID_MINGW_
56 int lockType = F_UNLCK;
95#if _SQUID_WINDOWS_ || _SQUID_MINGW_
116#if _SQUID_WINDOWS_ || _SQUID_MINGW_
void error(char *format,...)
How should a file be opened/created? Should it be locked?
const unsigned int retryGapUsec
pause before each lock retry
static FileOpeningConfig ReadWrite()
unsigned int lockAttempts
how many times to try locking
mode_t openMode
access mode; 3rd open(2) parameter
int openFlags
opening flags; 2nd open(2) parameter
static FileOpeningConfig ReadOnly()
int flockMode
2nd flock(2) parameter
mode_t creationMask
umask() parameter; the default is S_IWGRP|S_IWOTH
FileOpeningConfig & locked(unsigned int attempts=5)
protect concurrent accesses by attempting to obtain an appropriate lock
FileOpeningConfig & createdIfMissing()
when opening a file for writing, create it if it does not exist
FileOpeningConfig & openedByRoot()
enter_suid() to open the file; leaves suid ASAP after that
a portable locking-aware exception-friendly file (with RAII API)
const SBuf & name() const
File(const File &)=delete
Handle fd_
OS-specific file handle.
void lock(const FileOpeningConfig &cfg)
calls lockOnce() as many times as necessary (including zero)
void writeAll(const SBuf &data)
write(2) with a "wrote everything" check
FileOpeningConfig Be
convenient shorthand for File() callers
void open(const FileOpeningConfig &cfg)
opens (or creates) the file
static File * Optional(const SBuf &aName, const FileOpeningConfig &cfg)
File & operator=(const File &)=delete
void lockOnce(const FileOpeningConfig &cfg)
locks, blocking or returning immediately depending on the lock waiting mode
SBuf sysCallError(const char *callName, const int savedErrno) const
SBuf sysCallFailure(const char *callName, const SBuf &error) const
static const Handle InvalidHandle
void truncate()
makes the file size (and the current I/O offset) zero
void synchronize()
fsync(2)
SBuf readSmall(SBuf::size_type minBytes, SBuf::size_type maxBytes)
read(2) for small files
SBuf name_
location on disk
MemBlob::size_type size_type