1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
8 #include <sys/statfs.h>
13 #include "missing_stat.h"
14 #include "siphash24.h"
16 int is_symlink(const char *path
);
17 int is_dir_full(int atfd
, const char *fname
, bool follow
);
18 static inline int is_dir(const char *path
, bool follow
) {
19 return is_dir_full(AT_FDCWD
, path
, follow
);
21 static inline int is_dir_fd(int fd
) {
22 return is_dir_full(fd
, NULL
, false);
24 int is_device_node(const char *path
);
26 int dir_is_empty_at(int dir_fd
, const char *path
, bool ignore_hidden_or_backup
);
27 static inline int dir_is_empty(const char *path
, bool ignore_hidden_or_backup
) {
28 return dir_is_empty_at(AT_FDCWD
, path
, ignore_hidden_or_backup
);
31 bool null_or_empty(struct stat
*st
) _pure_
;
32 int null_or_empty_path_with_root(const char *fn
, const char *root
);
34 static inline int null_or_empty_path(const char *fn
) {
35 return null_or_empty_path_with_root(fn
, NULL
);
38 int path_is_read_only_fs(const char *path
);
40 int inode_same_at(int fda
, const char *filea
, int fdb
, const char *fileb
, int flags
);
42 static inline int inode_same(const char *filea
, const char *fileb
, int flags
) {
43 return inode_same_at(AT_FDCWD
, filea
, AT_FDCWD
, fileb
, flags
);
46 /* The .f_type field of struct statfs is really weird defined on
47 * different archs. Let's give its type a name. */
48 typedef typeof(((struct statfs
*)NULL
)->f_type
) statfs_f_type_t
;
50 bool is_fs_type(const struct statfs
*s
, statfs_f_type_t magic_value
) _pure_
;
51 int is_fs_type_at(int dir_fd
, const char *path
, statfs_f_type_t magic_value
);
52 static inline int fd_is_fs_type(int fd
, statfs_f_type_t magic_value
) {
53 return is_fs_type_at(fd
, NULL
, magic_value
);
55 static inline int path_is_fs_type(const char *path
, statfs_f_type_t magic_value
) {
56 return is_fs_type_at(AT_FDCWD
, path
, magic_value
);
59 bool is_temporary_fs(const struct statfs
*s
) _pure_
;
60 bool is_network_fs(const struct statfs
*s
) _pure_
;
62 int fd_is_temporary_fs(int fd
);
63 int fd_is_network_fs(int fd
);
65 int path_is_temporary_fs(const char *path
);
66 int path_is_network_fs(const char *path
);
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.
72 #define F_TYPE_EQUAL(a, b) (a == (typeof(a)) b)
74 int stat_verify_regular(const struct stat
*st
);
75 int fd_verify_regular(int fd
);
76 int verify_regular_at(int dir_fd
, const char *path
, bool follow
);
78 int stat_verify_directory(const struct stat
*st
);
79 int fd_verify_directory(int fd
);
81 int proc_mounted(void);
83 bool stat_inode_same(const struct stat
*a
, const struct stat
*b
);
84 bool stat_inode_unmodified(const struct stat
*a
, const struct stat
*b
);
86 bool statx_inode_same(const struct statx
*a
, const struct statx
*b
);
87 bool statx_mount_same(const struct new_statx
*a
, const struct new_statx
*b
);
89 int statx_fallback(int dfd
, const char *path
, int flags
, unsigned mask
, struct statx
*sx
);
91 int xstatfsat(int dir_fd
, const char *path
, struct statfs
*ret
);
93 #if HAS_FEATURE_MEMORY_SANITIZER
94 # warning "Explicitly initializing struct statx, to work around msan limitation. Please remove as soon as msan has been updated to not require this."
95 # define STRUCT_STATX_DEFINE(var) \
97 # define STRUCT_NEW_STATX_DEFINE(var) \
100 struct new_statx nsx; \
103 # define STRUCT_STATX_DEFINE(var) \
105 # define STRUCT_NEW_STATX_DEFINE(var) \
108 struct new_statx nsx; \
112 void inode_hash_func(const struct stat
*q
, struct siphash
*state
);
113 int inode_compare_func(const struct stat
*a
, const struct stat
*b
);
114 extern const struct hash_ops inode_hash_ops
;
116 const char* inode_type_to_string(mode_t m
);
117 mode_t
inode_type_from_string(const char *s
);