]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/stat-util.h
nspawn: introduce an option for specifying network namespace path
[thirdparty/systemd.git] / src / basic / stat-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2010-2012 Lennart Poettering
8
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 #include <stdbool.h>
24 #include <stddef.h>
25 #include <sys/stat.h>
26 #include <sys/statfs.h>
27 #include <sys/types.h>
28 #include <sys/vfs.h>
29
30 #include "macro.h"
31
32 int is_symlink(const char *path);
33 int is_dir(const char *path, bool follow);
34 int is_device_node(const char *path);
35
36 int dir_is_empty(const char *path);
37
38 static inline int dir_is_populated(const char *path) {
39 int r;
40 r = dir_is_empty(path);
41 if (r < 0)
42 return r;
43 return !r;
44 }
45
46 bool null_or_empty(struct stat *st) _pure_;
47 int null_or_empty_path(const char *fn);
48 int null_or_empty_fd(int fd);
49
50 int path_is_read_only_fs(const char *path);
51 int path_is_os_tree(const char *path);
52
53 int files_same(const char *filea, const char *fileb, int flags);
54
55 /* The .f_type field of struct statfs is really weird defined on
56 * different archs. Let's give its type a name. */
57 typedef typeof(((struct statfs*)NULL)->f_type) statfs_f_type_t;
58
59 bool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) _pure_;
60 int fd_is_fs_type(int fd, statfs_f_type_t magic_value);
61 int path_is_fs_type(const char *path, statfs_f_type_t magic_value);
62
63 bool is_temporary_fs(const struct statfs *s) _pure_;
64 int fd_is_temporary_fs(int fd);
65 int fd_is_network_ns(int fd);
66 int path_is_temporary_fs(const char *path);
67
68 /* Because statfs.t_type can be int on some architectures, we have to cast
69 * the const magic to the type, otherwise the compiler warns about
70 * signed/unsigned comparison, because the magic can be 32 bit unsigned.
71 */
72 #define F_TYPE_EQUAL(a, b) (a == (typeof(a)) b)