master
h 47 lines 1.79 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #ifndef NETDATA_DIR_SIZE_H
4 #define NETDATA_DIR_SIZE_H
5
6 #include "libnetdata/libnetdata.h"
7 #include "libnetdata/simple_pattern/simple_pattern.h"
8
9 typedef struct {
10 uint64_t bytes; // Total size in bytes
11 size_t files; // Number of files
12 size_t directories; // Number of directories (including root directory)
13 size_t depth; // Maximum depth found
14 size_t errors; // Number of errors encountered during calculation
15 } DIR_SIZE;
16
17 #define DIR_SIZE_EMPTY (DIR_SIZE){ 0 }
18 #define DIR_SIZE_OK(ds) ((ds).bytes > 0 && (ds).errors == 0)
19
20 /**
21 * Calculate the total size of a directory and its contents
22 *
23 * @param path Path to the directory
24 * @param pattern Simple pattern to filter files (NULL to include all files)
25 * @param max_depth Maximum recursion depth (0 for unlimited)
26 * @return DIR_SIZE structure with the size information
27 *
28 * This function recursively traverses the directory structure starting from
29 * the given path and calculates the total size in bytes, counting files and
30 * directories. It safely handles symbolic links to avoid infinite loops.
31 */
32 DIR_SIZE dir_size(const char *path, SIMPLE_PATTERN *pattern, size_t max_depth);
33
34 /**
35 * Calculate multiple directory sizes in one pass
36 *
37 * @param paths Array of directory paths to calculate
38 * @param num_paths Number of paths in the array
39 * @param pattern Simple pattern to filter files (NULL to include all files)
40 * @param max_depth Maximum recursion depth (0 for unlimited)
41 * @return DIR_SIZE structure with the combined size information
42 *
43 * This function calculates sizes for multiple directories and returns their combined total.
44 */
45 DIR_SIZE dir_size_multiple(const char **paths, int num_paths, SIMPLE_PATTERN *pattern, size_t max_depth);
46
47 #endif //NETDATA_DIR_SIZE_H