f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering#pragma once
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering/***
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering This file is part of systemd.
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering Copyright 2010 Lennart Poettering
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering systemd is free software; you can redistribute it and/or modify it
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering under the terms of the GNU Lesser General Public License as published by
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering (at your option) any later version.
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering systemd is distributed in the hope that it will be useful, but
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering Lesser General Public License for more details.
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering You should have received a copy of the GNU Lesser General Public License
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering***/
cf0fbc49e67b55f8d346fc94de28c90113505297Thomas Hindoe Paaboel Andersen
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering#include <fcntl.h>
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering#include <limits.h>
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering#include <stdbool.h>
1e5413f74faa378172d556e5dec35ab55de16bbfZbigniew Jędrzejewski-Szmek#include <stdint.h>
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering#include <sys/inotify.h>
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering#include <sys/types.h>
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering#include <unistd.h>
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering#include "time-util.h"
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poetteringint unlink_noerrno(const char *path);
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poetteringint rmdir_parents(const char *path, const char *stop);
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poetteringint rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
095b30cbf976b6c82a10c16bef76fa5b4c03f658Zbigniew Jędrzejewski-Szmek
095b30cbf976b6c82a10c16bef76fa5b4c03f658Zbigniew Jędrzejewski-Szmekint readlinkat_malloc(int fd, const char *p, char **ret);
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poetteringint readlink_malloc(const char *p, char **r);
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poetteringint readlink_value(const char *p, char **ret);
ebc05a09ad6d1672cf4f426ee4252cf495daa139Harald Hoyerint readlink_and_make_absolute(const char *p, char **r);
ebc05a09ad6d1672cf4f426ee4252cf495daa139Harald Hoyerint readlink_and_canonicalize(const char *p, char **r);
768100efd57ffbbefe9beaa33d1dd5ecc7f69173Lennart Poetteringint readlink_and_make_absolute_root(const char *root, const char *path, char **ret);
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering
768100efd57ffbbefe9beaa33d1dd5ecc7f69173Lennart Poetteringint chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poetteringint fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid);
2d5bdf5bc0e4714d42e5999a4e37553a6bf83575Lennart Poettering
d514feaa872820d5cb4e9321ad32673c09fbb3f4Thomas Hindoe Paaboel Andersenint fchmod_umask(int fd, mode_t mode);
d514feaa872820d5cb4e9321ad32673c09fbb3f4Thomas Hindoe Paaboel Andersen
095b30cbf976b6c82a10c16bef76fa5b4c03f658Zbigniew Jędrzejewski-Szmekint fd_warn_permissions(const char *path, int fd);
2d5bdf5bc0e4714d42e5999a4e37553a6bf83575Lennart Poettering
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering#define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW)
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poetteringint touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode);
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poetteringint touch(const char *path);
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poetteringint symlink_idempotent(const char *from, const char *to);
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poetteringint symlink_atomic(const char *from, const char *to);
98f59e59e0c31ffcb953d3a7dba0da5e6f2f55f7Harald Hoyerint mknod_atomic(const char *path, mode_t mode, dev_t dev);
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poetteringint mkfifo_atomic(const char *path, mode_t mode);
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering
98f59e59e0c31ffcb953d3a7dba0da5e6f2f55f7Harald Hoyerint get_files_in_directory(const char *path, char ***list);
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering#define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1)
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering#define FOREACH_INOTIFY_EVENT(e, buffer, sz) \
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering for ((e) = &buffer.ev; \
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering (uint8_t*) (e) < (uint8_t*) (buffer.raw) + (sz); \
98f59e59e0c31ffcb953d3a7dba0da5e6f2f55f7Harald Hoyer (e) = (struct inotify_event*) ((uint8_t*) (e) + sizeof(struct inotify_event) + (e)->len))
98f59e59e0c31ffcb953d3a7dba0da5e6f2f55f7Harald Hoyer
ebc05a09ad6d1672cf4f426ee4252cf495daa139Harald Hoyerunion inotify_event_buffer {
ebc05a09ad6d1672cf4f426ee4252cf495daa139Harald Hoyer struct inotify_event ev;
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering uint8_t raw[INOTIFY_EVENT_MAX];
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering};
f73141d7657b3f60b8669bc8386413d8a8a372c6Lennart Poettering