]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/stat-util.h
Merge pull request #7388 from keszybz/doc-tweak
[thirdparty/systemd.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 int is_symlink(const char *path);
32 int is_dir(const char *path, bool follow);
33 int is_device_node(const char *path);
34
35 int dir_is_empty(const char *path);
36
37 static inline int dir_is_populated(const char *path) {
38 int r;
39 r = dir_is_empty(path);
40 if (r < 0)
41 return r;
42 return !r;
43 }
44
45 bool null_or_empty(struct stat *st) _pure_;
46 int null_or_empty_path(const char *fn);
47 int null_or_empty_fd(int fd);
48
49 int path_is_read_only_fs(const char *path);
50 int path_is_os_tree(const char *path);
51
52 int files_same(const char *filea, const char *fileb, int flags);
53
54 /* The .f_type field of struct statfs is really weird defined on
55 * different archs. Let's give its type a name. */
56 typedef typeof(((struct statfs*)NULL)->f_type) statfs_f_type_t;
57
58 bool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) _pure_;
59 int fd_check_fstype(int fd, statfs_f_type_t magic_value);
60 int path_check_fstype(const char *path, statfs_f_type_t magic_value);
61
62 bool is_temporary_fs(const struct statfs *s) _pure_;
63 int fd_is_temporary_fs(int fd);
64 int path_is_temporary_fs(const char *path);
65
66 /* Because statfs.t_type can be int on some architectures, we have to cast
67 * the const magic to the type, otherwise the compiler warns about
68 * signed/unsigned comparison, because the magic can be 32 bit unsigned.
69 */
70 #define F_TYPE_EQUAL(a, b) (a == (typeof(a)) b)