]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/rm-rf.h
network: drop all checks of ipv6_disabled sysctl
[thirdparty/systemd.git] / src / basic / rm-rf.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
c6878637
LP
2#pragma once
3
c6878637
LP
4#include <sys/stat.h>
5
2b2fec7d 6#include "errno-util.h"
dfd14786 7
c6878637 8typedef enum RemoveFlags {
c0228b4f
LP
9 REMOVE_ONLY_DIRECTORIES = 1 << 0, /* Only remove empty directories, no files */
10 REMOVE_ROOT = 1 << 1, /* Remove the specified directory itself too, not just the contents of it */
11 REMOVE_PHYSICAL = 1 << 2, /* If not set, only removes files on tmpfs, never physical file systems */
12 REMOVE_SUBVOLUME = 1 << 3, /* Drop btrfs subvolumes in the tree too */
13 REMOVE_MISSING_OK = 1 << 4, /* If the top-level directory is missing, ignore the ENOENT for it */
c6878637
LP
14} RemoveFlags;
15
16int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev);
17int rm_rf(const char *path, RemoveFlags flags);
d2120590
LP
18
19/* Useful for usage with _cleanup_(), destroys a directory and frees the pointer */
f942504e 20static inline void rm_rf_physical_and_free(char *p) {
dfd14786 21 PROTECT_ERRNO;
f942504e 22 (void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL);
d2120590
LP
23 free(p);
24}
f942504e 25DEFINE_TRIVIAL_CLEANUP_FUNC(char*, rm_rf_physical_and_free);
1d7579c4
LP
26
27/* Similar as above, but also has magic btrfs subvolume powers */
28static inline void rm_rf_subvolume_and_free(char *p) {
29 PROTECT_ERRNO;
30 (void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
31 free(p);
32}
33DEFINE_TRIVIAL_CLEANUP_FUNC(char*, rm_rf_subvolume_and_free);