]>
Commit | Line | Data |
---|---|---|
52ad194e | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
663996b3 MS |
2 | #pragma once |
3 | ||
e3bff60a | 4 | #include <sys/stat.h> |
e735f4d4 | 5 | |
1d42b86d MB |
6 | #include "util.h" |
7 | ||
e3bff60a | 8 | typedef enum RemoveFlags { |
98393f85 MB |
9 | REMOVE_ONLY_DIRECTORIES = 1 << 0, |
10 | REMOVE_ROOT = 1 << 1, | |
11 | REMOVE_PHYSICAL = 1 << 2, /* if not set, only removes files on tmpfs, never physical file systems */ | |
12 | REMOVE_SUBVOLUME = 1 << 3, | |
e3bff60a MP |
13 | } RemoveFlags; |
14 | ||
15 | int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev); | |
16 | int rm_rf(const char *path, RemoveFlags flags); | |
aa27b158 MP |
17 | |
18 | /* Useful for usage with _cleanup_(), destroys a directory and frees the pointer */ | |
19 | static inline void rm_rf_physical_and_free(char *p) { | |
1d42b86d | 20 | PROTECT_ERRNO; |
aa27b158 MP |
21 | (void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL); |
22 | free(p); | |
23 | } | |
24 | DEFINE_TRIVIAL_CLEANUP_FUNC(char*, rm_rf_physical_and_free); | |
6e866b33 MB |
25 | |
26 | /* Similar as above, but also has magic btrfs subvolume powers */ | |
27 | static inline void rm_rf_subvolume_and_free(char *p) { | |
28 | PROTECT_ERRNO; | |
29 | (void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME); | |
30 | free(p); | |
31 | } | |
32 | DEFINE_TRIVIAL_CLEANUP_FUNC(char*, rm_rf_subvolume_and_free); |