]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/rm-rf.h
Merge pull request #8575 from keszybz/non-absolute-paths
[thirdparty/systemd.git] / src / basic / rm-rf.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2015 Lennart Poettering
8 ***/
9
10 #include <sys/stat.h>
11
12 #include "util.h"
13
14 typedef enum RemoveFlags {
15 REMOVE_ONLY_DIRECTORIES = 1 << 0,
16 REMOVE_ROOT = 1 << 1,
17 REMOVE_PHYSICAL = 1 << 2, /* if not set, only removes files on tmpfs, never physical file systems */
18 REMOVE_SUBVOLUME = 1 << 3,
19 } RemoveFlags;
20
21 int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev);
22 int rm_rf(const char *path, RemoveFlags flags);
23
24 /* Useful for usage with _cleanup_(), destroys a directory and frees the pointer */
25 static inline void rm_rf_physical_and_free(char *p) {
26 PROTECT_ERRNO;
27 (void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL);
28 free(p);
29 }
30 DEFINE_TRIVIAL_CLEANUP_FUNC(char*, rm_rf_physical_and_free);