]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/stat-util.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / basic / stat-util.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
8fcde012
LP
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>
11c3a366 24#include <stddef.h>
8fcde012 25#include <sys/stat.h>
11c3a366 26#include <sys/statfs.h>
4e036b7a 27#include <sys/types.h>
8fcde012
LP
28#include <sys/vfs.h>
29
30#include "macro.h"
31
32int is_symlink(const char *path);
33int is_dir(const char *path, bool follow);
34int is_device_node(const char *path);
35
36int dir_is_empty(const char *path);
37
38static 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
46bool null_or_empty(struct stat *st) _pure_;
47int null_or_empty_path(const char *fn);
48int null_or_empty_fd(int fd);
49
50int path_is_read_only_fs(const char *path);
51int path_is_os_tree(const char *path);
52
e3f791a2 53int files_same(const char *filea, const char *fileb, int flags);
8fcde012
LP
54
55/* The .f_type field of struct statfs is really weird defined on
d6cd0846
HG
56 * different archs. Let's give its type a name. */
57typedef typeof(((struct statfs*)NULL)->f_type) statfs_f_type_t;
8fcde012
LP
58
59bool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) _pure_;
60int fd_check_fstype(int fd, statfs_f_type_t magic_value);
61int path_check_fstype(const char *path, statfs_f_type_t magic_value);
62
63bool is_temporary_fs(const struct statfs *s) _pure_;
64int fd_is_temporary_fs(int fd);
ffeb8285 65int path_is_temporary_fs(const char *path);
872a590e
LP
66
67/* Because statfs.t_type can be int on some architectures, we have to cast
68 * the const magic to the type, otherwise the compiler warns about
69 * signed/unsigned comparison, because the magic can be 32 bit unsigned.
70 */
71#define F_TYPE_EQUAL(a, b) (a == (typeof(a)) b)