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