]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/file_utils.h
cgfsng: rework cgroup2 attach
[mirror_lxc.git] / src / lxc / file_utils.h
1 /* liblxcapi
2 *
3 * Copyright © 2018 Christian Brauner <christian.brauner@ubuntu.com>.
4 * Copyright © 2018 Canonical Ltd.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef __LXC_FILE_UTILS_H
22 #define __LXC_FILE_UTILS_H
23
24 #include <fcntl.h>
25 #include <stdbool.h>
26 #include <stdio.h>
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 #include <sys/uio.h>
30 #include <sys/vfs.h>
31 #include <unistd.h>
32
33 /* read and write whole files */
34 extern int lxc_write_to_file(const char *filename, const void *buf,
35 size_t count, bool add_newline, mode_t mode);
36 extern int lxc_writeat(int dirfd, const char *filename, const void *buf,
37 size_t count);
38 extern int lxc_read_from_file(const char *filename, void *buf, size_t count);
39
40 /* send and receive buffers completely */
41 extern ssize_t lxc_write_nointr(int fd, const void *buf, size_t count);
42 extern ssize_t lxc_send_nointr(int sockfd, void *buf, size_t len, int flags);
43 extern ssize_t lxc_read_nointr(int fd, void *buf, size_t count);
44 extern ssize_t lxc_read_nointr_expect(int fd, void *buf, size_t count,
45 const void *expected_buf);
46 extern ssize_t lxc_read_file_expect(const char *path, void *buf, size_t count,
47 const void *expected_buf);
48 extern ssize_t lxc_recv_nointr(int sockfd, void *buf, size_t len, int flags);
49 ssize_t lxc_recvmsg_nointr_iov(int sockfd, struct iovec *iov, size_t iovlen,
50 int flags);
51
52 extern bool file_exists(const char *f);
53 extern int print_to_file(const char *file, const char *content);
54 extern int is_dir(const char *path);
55 extern int lxc_count_file_lines(const char *fn);
56 extern int lxc_make_tmpfile(char *template, bool rm);
57
58 /* __typeof__ should be safe to use with all compilers. */
59 typedef __typeof__(((struct statfs *)NULL)->f_type) fs_type_magic;
60 extern bool has_fs_type(const char *path, fs_type_magic magic_val);
61 extern bool fhas_fs_type(int fd, fs_type_magic magic_val);
62 extern bool is_fs_type(const struct statfs *fs, fs_type_magic magic_val);
63 extern FILE *fopen_cloexec(const char *path, const char *mode);
64 extern ssize_t lxc_sendfile_nointr(int out_fd, int in_fd, off_t *offset,
65 size_t count);
66 extern char *file_to_buf(char *path, size_t *length);
67 extern int fd_to_fd(int from, int to);
68
69 #endif /* __LXC_FILE_UTILS_H */