]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
f4f15635 LP |
2 | #pragma once |
3 | ||
4 | /*** | |
5 | This file is part of systemd. | |
6 | ||
7 | Copyright 2010 Lennart Poettering | |
8 | ||
9 | systemd is free software; you can redistribute it and/or modify it | |
10 | under the terms of the GNU Lesser General Public License as published by | |
11 | the Free Software Foundation; either version 2.1 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | systemd is distributed in the hope that it will be useful, but | |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | Lesser General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU Lesser General Public License | |
20 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
21 | ***/ | |
22 | ||
f4f15635 | 23 | #include <fcntl.h> |
71d35b6b | 24 | #include <limits.h> |
11c3a366 TA |
25 | #include <stdbool.h> |
26 | #include <stdint.h> | |
77601719 LP |
27 | #include <sys/inotify.h> |
28 | #include <sys/types.h> | |
f4f15635 LP |
29 | #include <unistd.h> |
30 | ||
31 | #include "time-util.h" | |
32 | ||
33 | int unlink_noerrno(const char *path); | |
34 | ||
35 | int rmdir_parents(const char *path, const char *stop); | |
36 | ||
37 | int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); | |
38 | ||
39 | int readlinkat_malloc(int fd, const char *p, char **ret); | |
40 | int readlink_malloc(const char *p, char **r); | |
41 | int readlink_value(const char *p, char **ret); | |
42 | int readlink_and_make_absolute(const char *p, char **r); | |
e1873695 | 43 | int readlink_and_canonicalize(const char *p, const char *root, char **r); |
0ec0deaa | 44 | int readlink_and_make_absolute_root(const char *root, const char *path, char **ret); |
f4f15635 LP |
45 | |
46 | int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid); | |
f4f15635 LP |
47 | |
48 | int fchmod_umask(int fd, mode_t mode); | |
49 | ||
50 | int fd_warn_permissions(const char *path, int fd); | |
51 | ||
52 | #define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW) | |
53 | ||
54 | int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode); | |
55 | int touch(const char *path); | |
56 | ||
57 | int symlink_idempotent(const char *from, const char *to); | |
58 | ||
59 | int symlink_atomic(const char *from, const char *to); | |
60 | int mknod_atomic(const char *path, mode_t mode, dev_t dev); | |
61 | int mkfifo_atomic(const char *path, mode_t mode); | |
62 | ||
63 | int get_files_in_directory(const char *path, char ***list); | |
77601719 | 64 | |
992e8f22 LP |
65 | int tmp_dir(const char **ret); |
66 | int var_tmp_dir(const char **ret); | |
34a8f081 | 67 | |
77601719 LP |
68 | #define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1) |
69 | ||
70 | #define FOREACH_INOTIFY_EVENT(e, buffer, sz) \ | |
71 | for ((e) = &buffer.ev; \ | |
72 | (uint8_t*) (e) < (uint8_t*) (buffer.raw) + (sz); \ | |
73 | (e) = (struct inotify_event*) ((uint8_t*) (e) + sizeof(struct inotify_event) + (e)->len)) | |
74 | ||
75 | union inotify_event_buffer { | |
76 | struct inotify_event ev; | |
77 | uint8_t raw[INOTIFY_EVENT_MAX]; | |
78 | }; | |
430fbf8e LP |
79 | |
80 | int inotify_add_watch_fd(int fd, int what, uint32_t mask); | |
d944dc95 | 81 | |
c4f4fce7 LP |
82 | enum { |
83 | CHASE_PREFIX_ROOT = 1, /* If set, the specified path will be prefixed by the specified root before beginning the iteration */ | |
cb638b5e | 84 | CHASE_NONEXISTENT = 2, /* If set, it's OK if the path doesn't actually exist. */ |
655f2da0 | 85 | CHASE_NO_AUTOFS = 4, /* If set, return -EREMOTE if autofs mount point found */ |
c4f4fce7 LP |
86 | }; |
87 | ||
88 | int chase_symlinks(const char *path_with_prefix, const char *root, unsigned flags, char **ret); | |
676bcb0f LP |
89 | |
90 | /* Useful for usage with _cleanup_(), removes a directory and frees the pointer */ | |
91 | static inline void rmdir_and_free(char *p) { | |
92 | (void) rmdir(p); | |
93 | free(p); | |
94 | } | |
95 | DEFINE_TRIVIAL_CLEANUP_FUNC(char*, rmdir_and_free); | |
f5b84de2 LP |
96 | |
97 | static inline void unlink_and_free(char *p) { | |
98 | (void) unlink(p); | |
99 | free(p); | |
100 | } | |
101 | DEFINE_TRIVIAL_CLEANUP_FUNC(char*, unlink_and_free); | |
57a4359e LP |
102 | |
103 | int access_fd(int fd, int mode); |