]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/file_utils.h
conf: make use of stashed container mountpoint fd in mount_autodev()
[mirror_lxc.git] / src / lxc / file_utils.h
CommitLineData
cc73685d 1/* SPDX-License-Identifier: LGPL-2.1+ */
37ef15bb
CB
2
3#ifndef __LXC_FILE_UTILS_H
4#define __LXC_FILE_UTILS_H
5
37ef15bb
CB
6#include <fcntl.h>
7#include <stdbool.h>
8#include <stdio.h>
9#include <sys/stat.h>
10#include <sys/types.h>
99d03dec 11#include <sys/uio.h>
37ef15bb
CB
12#include <sys/vfs.h>
13#include <unistd.h>
14
674c9692
CB
15#include "compiler.h"
16
37ef15bb 17/* read and write whole files */
4a9ee78a
CB
18__hidden extern int lxc_write_to_file(const char *filename, const void *buf, size_t count,
19 bool add_newline, mode_t mode) __access_r(2, 3);
674c9692 20
4a9ee78a
CB
21__hidden extern int lxc_readat(int dirfd, const char *filename, void *buf, size_t count)
22 __access_w(3, 4);
674c9692 23
4a9ee78a
CB
24__hidden extern int lxc_writeat(int dirfd, const char *filename, const void *buf, size_t count)
25 __access_r(3, 4);
674c9692 26
4a9ee78a
CB
27__hidden extern int lxc_write_openat(const char *dir, const char *filename, const void *buf,
28 size_t count) __access_r(3, 4);
674c9692 29
4a9ee78a
CB
30__hidden extern int lxc_read_from_file(const char *filename, void *buf, size_t count)
31 __access_w(2, 3);
37ef15bb
CB
32
33/* send and receive buffers completely */
4a9ee78a 34__hidden extern ssize_t lxc_write_nointr(int fd, const void *buf, size_t count) __access_r(2, 3);
674c9692 35
4a9ee78a
CB
36__hidden extern ssize_t lxc_pwrite_nointr(int fd, const void *buf, size_t count, off_t offset)
37 __access_r(2, 3);
674c9692 38
4a9ee78a
CB
39__hidden extern ssize_t lxc_send_nointr(int sockfd, void *buf, size_t len, int flags)
40 __access_r(2, 3);
674c9692 41
4a9ee78a 42__hidden extern ssize_t lxc_read_nointr(int fd, void *buf, size_t count) __access_w(2, 3);
674c9692 43
4a9ee78a
CB
44__hidden extern ssize_t lxc_read_nointr_expect(int fd, void *buf, size_t count,
45 const void *expected_buf) __access_w(2, 3);
674c9692 46
4a9ee78a
CB
47__hidden extern ssize_t lxc_read_file_expect(const char *path, void *buf, size_t count,
48 const void *expected_buf) __access_w(2, 3);
674c9692 49
4a9ee78a
CB
50__hidden extern ssize_t lxc_recv_nointr(int sockfd, void *buf, size_t len, int flags)
51 __access_w(2, 3);
674c9692 52
4a9ee78a
CB
53__hidden extern ssize_t lxc_recvmsg_nointr_iov(int sockfd, struct iovec *iov, size_t iovlen,
54 int flags);
de69edd1 55
4a9ee78a
CB
56__hidden extern bool file_exists(const char *f);
57__hidden extern int print_to_file(const char *file, const char *content);
58__hidden extern int is_dir(const char *path);
59__hidden extern int lxc_count_file_lines(const char *fn);
60__hidden extern int lxc_make_tmpfile(char *template, bool rm);
37ef15bb
CB
61
62/* __typeof__ should be safe to use with all compilers. */
63typedef __typeof__(((struct statfs *)NULL)->f_type) fs_type_magic;
4a9ee78a
CB
64__hidden extern bool has_fs_type(const char *path, fs_type_magic magic_val);
65__hidden extern bool fhas_fs_type(int fd, fs_type_magic magic_val);
66__hidden extern bool is_fs_type(const struct statfs *fs, fs_type_magic magic_val);
67__hidden extern FILE *fopen_cloexec(const char *path, const char *mode);
68__hidden extern ssize_t lxc_sendfile_nointr(int out_fd, int in_fd, off_t *offset, size_t count);
69__hidden extern char *file_to_buf(const char *path, size_t *length);
70__hidden extern int fd_to_buf(int fd, char **buf, size_t *length);
71__hidden extern int fd_to_fd(int from, int to);
72__hidden extern int lxc_open_dirfd(const char *dir);
73__hidden extern FILE *fdopen_cached(int fd, const char *mode, void **caller_freed_buffer);
74__hidden extern FILE *fopen_cached(const char *path, const char *mode, void **caller_freed_buffer);
75__hidden extern int timens_offset_write(clockid_t clk_id, int64_t s_offset, int64_t ns_offset);
37ef15bb
CB
76
77#endif /* __LXC_FILE_UTILS_H */