stat-util.h revision 4e036b7a96b7a72461bdb68ded304041e892b8eb
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering#pragma once
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering/***
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering This file is part of systemd.
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering Copyright 2010-2012 Lennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering systemd is free software; you can redistribute it and/or modify it
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering under the terms of the GNU Lesser General Public License as published by
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering (at your option) any later version.
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering systemd is distributed in the hope that it will be useful, but
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering Lesser General Public License for more details.
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering You should have received a copy of the GNU Lesser General Public License
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering***/
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering#include <stdbool.h>
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering#include <sys/stat.h>
4871690d9e32608bbd9b18505b5326c2079c9690Allin Cottrell#include <sys/types.h>
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering#include <sys/vfs.h>
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering#include "macro.h"
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmekint is_symlink(const char *path);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint is_dir(const char *path, bool follow);
35e2e347d38cc2f8bd7c38a0d8a5129f5fbb0ab9Lennart Poetteringint is_device_node(const char *path);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint dir_is_empty(const char *path);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringstatic inline int dir_is_populated(const char *path) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering int r;
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering r = dir_is_empty(path);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering if (r < 0)
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering return r;
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering return !r;
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering}
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringbool null_or_empty(struct stat *st) _pure_;
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint null_or_empty_path(const char *fn);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint null_or_empty_fd(int fd);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint path_is_read_only_fs(const char *path);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint path_is_os_tree(const char *path);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint files_same(const char *filea, const char *fileb);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering/* The .f_type field of struct statfs is really weird defined on
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering * different archs. Let's use our own type we know is sufficiently
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering * larger to store the possible values. */
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringtypedef long statfs_f_type_t;
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringbool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) _pure_;
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint fd_check_fstype(int fd, statfs_f_type_t magic_value);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint path_check_fstype(const char *path, statfs_f_type_t magic_value);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringbool is_temporary_fs(const struct statfs *s) _pure_;
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint fd_is_temporary_fs(int fd);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering/* Because statfs.t_type can be int on some architectures, we have to cast
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering * the const magic to the type, otherwise the compiler warns about
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering * signed/unsigned comparison, because the magic can be 32 bit unsigned.
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering */
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering#define F_TYPE_EQUAL(a, b) (a == (typeof(a)) b)
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering