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