From f4f15635ec05293ffcc83a5b39f624bbabbd8fd0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 26 Oct 2015 21:16:26 +0100 Subject: util-lib: move a number of fs operations into fs-util.[ch] --- src/basic/fs-util.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/basic/fs-util.h (limited to 'src/basic/fs-util.h') diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h new file mode 100644 index 0000000000..0e1906ba3f --- /dev/null +++ b/src/basic/fs-util.h @@ -0,0 +1,60 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +#include +#include +#include + +#include "time-util.h" + +int unlink_noerrno(const char *path); + +int rmdir_parents(const char *path, const char *stop); + +int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); + +int readlinkat_malloc(int fd, const char *p, char **ret); +int readlink_malloc(const char *p, char **r); +int readlink_value(const char *p, char **ret); +int readlink_and_make_absolute(const char *p, char **r); +int readlink_and_canonicalize(const char *p, char **r); + +int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid); +int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid); + +int fchmod_umask(int fd, mode_t mode); + +int fd_warn_permissions(const char *path, int fd); + +#define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW) + +int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode); +int touch(const char *path); + +int symlink_idempotent(const char *from, const char *to); + +int symlink_atomic(const char *from, const char *to); +int mknod_atomic(const char *path, mode_t mode, dev_t dev); +int mkfifo_atomic(const char *path, mode_t mode); + +int get_files_in_directory(const char *path, char ***list); -- cgit v1.2.3-54-g00ecf From 7760171904ef007f19e8f46aa240a00e382d5b74 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 Oct 2015 14:58:05 +0100 Subject: util-lib: move inotify-related definitions to fs-util.[ch] --- src/basic/fs-util.h | 16 +++++++++++++++- src/basic/util.h | 12 ------------ src/core/cgroup.c | 1 + src/core/path.c | 1 + src/journal/sd-journal.c | 1 + src/libsystemd/sd-network/sd-network.c | 5 +++-- 6 files changed, 21 insertions(+), 15 deletions(-) (limited to 'src/basic/fs-util.h') diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h index 0e1906ba3f..b94873e65b 100644 --- a/src/basic/fs-util.h +++ b/src/basic/fs-util.h @@ -21,9 +21,11 @@ along with systemd; If not, see . ***/ -#include #include +#include +#include #include +#include #include "time-util.h" @@ -58,3 +60,15 @@ int mknod_atomic(const char *path, mode_t mode, dev_t dev); int mkfifo_atomic(const char *path, mode_t mode); int get_files_in_directory(const char *path, char ***list); + +#define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1) + +#define FOREACH_INOTIFY_EVENT(e, buffer, sz) \ + for ((e) = &buffer.ev; \ + (uint8_t*) (e) < (uint8_t*) (buffer.raw) + (sz); \ + (e) = (struct inotify_event*) ((uint8_t*) (e) + sizeof(struct inotify_event) + (e)->len)) + +union inotify_event_buffer { + struct inotify_event ev; + uint8_t raw[INOTIFY_EVENT_MAX]; +}; diff --git a/src/basic/util.h b/src/basic/util.h index 2c2cb36190..a8fba372d1 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -181,16 +181,4 @@ uint64_t physical_memory(void); int update_reboot_param_file(const char *param); -#define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1) - -#define FOREACH_INOTIFY_EVENT(e, buffer, sz) \ - for ((e) = &buffer.ev; \ - (uint8_t*) (e) < (uint8_t*) (buffer.raw) + (sz); \ - (e) = (struct inotify_event*) ((uint8_t*) (e) + sizeof(struct inotify_event) + (e)->len)) - -union inotify_event_buffer { - struct inotify_event ev; - uint8_t raw[INOTIFY_EVENT_MAX]; -}; - int version(void); diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 70f6d4af0f..bed01fde21 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -27,6 +27,7 @@ #include "cgroup.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" diff --git a/src/core/path.c b/src/core/path.c index 9c5309a58a..35e1753583 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -28,6 +28,7 @@ #include "bus-util.h" #include "dbus-path.h" #include "fd-util.h" +#include "fs-util.h" #include "glob-util.h" #include "macro.h" #include "mkdir.h" diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 6eda5162c7..043087485b 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -37,6 +37,7 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" #include "hashmap.h" #include "hostname-util.h" #include "io-util.h" diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c index 2eaa2626f7..efbceba83d 100644 --- a/src/libsystemd/sd-network/sd-network.c +++ b/src/libsystemd/sd-network/sd-network.c @@ -28,13 +28,14 @@ #include "sd-network.h" #include "alloc-util.h" +#include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "macro.h" +#include "parse-util.h" #include "string-util.h" #include "strv.h" #include "util.h" -#include "fd-util.h" -#include "parse-util.h" _public_ int sd_network_get_operational_state(char **state) { _cleanup_free_ char *s = NULL; -- cgit v1.2.3-54-g00ecf