mirror of
https://github.com/systemd/systemd.git
synced 2026-11-06 13:27:45 +00:00
loop_write() writes one buffer at the file position. To write at an offset, callers call pwrite() or pwritev() directly and handle short writes themselves. Add pwritev_full(), which writes all iovecs at an offset, retries on EINTR and short writes, splits batches larger than IOV_MAX, and reports the number of bytes written, also on failure. Add pwrite_full(), which does the same for one buffer. (cherry picked from commit4d36be491a) (cherry picked from commit8b9fb1bbec)
53 lines
2.1 KiB
C
53 lines
2.1 KiB
C
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
#pragma once
|
|
|
|
#include "basic-forward.h"
|
|
|
|
/* On most architectures POLL* and EPOLL* share numeric values, but sparc allocates POLLRDHUP at
|
|
* 0x800 while EPOLLRDHUP is 0x2000 everywhere. Always go through these helpers when crossing
|
|
* between poll() and epoll() event masks. Bits outside the mapped set (EPOLLET, EPOLLONESHOT,
|
|
* POLLNVAL, …) are dropped. */
|
|
uint32_t poll_events_to_epoll(uint32_t events);
|
|
uint32_t epoll_events_to_poll(uint32_t events);
|
|
|
|
int flush_fd(int fd);
|
|
|
|
ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll);
|
|
int loop_read_exact(int fd, void *buf, size_t nbytes, bool do_poll);
|
|
|
|
int loop_write_full(int fd, const void *buf, size_t nbytes, usec_t timeout) _nonnull_if_nonzero_(2, 3);
|
|
static inline int loop_write(int fd, const void *buf, size_t nbytes) {
|
|
return loop_write_full(fd, buf, nbytes, 0);
|
|
}
|
|
|
|
int pwritev_full(int fd, struct iovec *iovec, size_t n, uint64_t offset, uint64_t *ret_written);
|
|
int pwrite_full(int fd, const void *buf, size_t nbytes, uint64_t offset) _nonnull_if_nonzero_(2, 3);
|
|
|
|
int pipe_eof(int fd);
|
|
|
|
int ppoll_usec_full(struct pollfd *fds, size_t n_fds, usec_t timeout, const sigset_t *ss) _nonnull_if_nonzero_(1, 2);
|
|
_nonnull_if_nonzero_(1, 2) static inline int ppoll_usec(struct pollfd *fds, size_t n_fds, usec_t timeout) {
|
|
return ppoll_usec_full(fds, n_fds, timeout, NULL);
|
|
}
|
|
|
|
int fd_wait_for_event(int fd, int event, usec_t timeout);
|
|
|
|
ssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length);
|
|
|
|
static inline bool FILE_SIZE_VALID(uint64_t l) {
|
|
/* ftruncate() and friends take an unsigned file size, but actually cannot deal with file sizes larger than
|
|
* 2^63 since the kernel internally handles it as signed value. This call allows checking for this early. */
|
|
|
|
return (l >> 63) == 0;
|
|
}
|
|
|
|
static inline bool FILE_SIZE_VALID_OR_INFINITY(uint64_t l) {
|
|
|
|
/* Same as above, but allows one extra value: -1 as indication for infinity. */
|
|
|
|
if (l == UINT64_MAX)
|
|
return true;
|
|
|
|
return FILE_SIZE_VALID(l);
|
|
}
|