Miscellaneous: No Offset-Bending, Scatter-Gather IO, Truncating#
I/O without Offset Manipulation#
#include <unistd.h>
ssize_t pread(int fd, void *buf, size_t count, off_t offset);
ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
read()
andwrite()
have been made for sequential accessRandom access only together with
lseek()
Inefficient
Not atomic ⟶ race conditions!
Scatter/Gather I/O#
#include <sys/uio.h>
ssize_t readv(int fd, const struct iovec *iov, int iovcnt);
ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
Often data is not present in one contiguous block
E.g. layered protocols
⟶ Copy pieces together, or issue repeated small system calls
⟶ Scatter/Gather I/O
Scatter/Gather I/O, without Offset Manipulation#
#include <sys/uio.h>
ssize_t preadv(int fd, const struct iovec *iov, int iovcnt,
off_t offset);
ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt,
off_t offset);
Truncating Files#
#include <unistd.h>
int truncate(const char *path, off_t length);
int ftruncate(int fd, off_t length);
Truncating a file …
… or create a hole (⟶
lseek()
)