8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering#pragma once
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering/***
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering This file is part of systemd.
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering Copyright 2010-2012 Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering systemd is free software; you can redistribute it and/or modify it
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering under the terms of the GNU Lesser General Public License as published by
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering (at your option) any later version.
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering systemd is distributed in the hope that it will be useful, but
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering Lesser General Public License for more details.
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering You should have received a copy of the GNU Lesser General Public License
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering***/
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering#include <stdbool.h>
11c3a36649e5e5e77db499c92f3cdcbd619efd3aThomas Hindoe Paaboel Andersen#include <stddef.h>
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering#include <sys/stat.h>
11c3a36649e5e5e77db499c92f3cdcbd619efd3aThomas Hindoe Paaboel Andersen#include <sys/statfs.h>
4e036b7a96b7a72461bdb68ded304041e892b8ebLennart Poettering#include <sys/types.h>
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering#include <sys/vfs.h>
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering#include "macro.h"
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringint is_symlink(const char *path);
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringint is_dir(const char *path, bool follow);
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringint is_device_node(const char *path);
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringint dir_is_empty(const char *path);
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringstatic inline int dir_is_populated(const char *path) {
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering int r;
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering r = dir_is_empty(path);
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering if (r < 0)
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering return r;
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering return !r;
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering}
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringbool null_or_empty(struct stat *st) _pure_;
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringint null_or_empty_path(const char *fn);
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringint null_or_empty_fd(int fd);
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringint path_is_read_only_fs(const char *path);
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringint path_is_os_tree(const char *path);
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringint files_same(const char *filea, const char *fileb);
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering/* The .f_type field of struct statfs is really weird defined on
d6cd08464d06660b6f1e40d3c53bea0509b09c26Helmut Grohne * different archs. Let's give its type a name. */
d6cd08464d06660b6f1e40d3c53bea0509b09c26Helmut Grohnetypedef typeof(((struct statfs*)NULL)->f_type) statfs_f_type_t;
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringbool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) _pure_;
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringint fd_check_fstype(int fd, statfs_f_type_t magic_value);
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringint path_check_fstype(const char *path, statfs_f_type_t magic_value);
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringbool is_temporary_fs(const struct statfs *s) _pure_;
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poetteringint fd_is_temporary_fs(int fd);
872a590ef83b23a65071242a8082d25d5efa6db6Lennart Poettering
872a590ef83b23a65071242a8082d25d5efa6db6Lennart Poettering/* Because statfs.t_type can be int on some architectures, we have to cast
872a590ef83b23a65071242a8082d25d5efa6db6Lennart Poettering * the const magic to the type, otherwise the compiler warns about
872a590ef83b23a65071242a8082d25d5efa6db6Lennart Poettering * signed/unsigned comparison, because the magic can be 32 bit unsigned.
872a590ef83b23a65071242a8082d25d5efa6db6Lennart Poettering */
872a590ef83b23a65071242a8082d25d5efa6db6Lennart Poettering#define F_TYPE_EQUAL(a, b) (a == (typeof(a)) b)