Merge pull request #16676 from poettering/repart-mkfs

repart: add new settings Format=, CopyFiles=, Encrypt= and teach --size= a new value "auto"
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-08-25 12:19:46 +02:00
committed by GitHub
17 changed files with 1264 additions and 286 deletions
+52
View File
@@ -5,6 +5,7 @@
#include <string.h>
#include "alloc-util.h"
#include "fd-util.h"
#include "format-util.h"
#include "fs-util.h"
#include "macro.h"
@@ -187,3 +188,54 @@ int mkdir_p(const char *path, mode_t mode) {
int mkdir_p_safe(const char *prefix, const char *path, mode_t mode, uid_t uid, gid_t gid, MkdirFlags flags) {
return mkdir_p_internal(prefix, path, mode, uid, gid, flags, mkdir_errno_wrapper);
}
int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m) {
_cleanup_free_ char *pp = NULL;
_cleanup_close_ int dfd = -1;
const char *bn;
int r;
pp = dirname_malloc(p);
if (!pp)
return -ENOMEM;
/* Not top-level? */
if (!(path_equal(pp, "/") || isempty(pp) || path_equal(pp, "."))) {
/* Recurse up */
r = mkdir_p_root(root, pp, uid, gid, m);
if (r < 0)
return r;
}
bn = basename(p);
if (path_equal(bn, "/") || isempty(bn) || path_equal(bn, "."))
return 0;
if (!filename_is_valid(bn))
return -EINVAL;
dfd = chase_symlinks_and_open(pp, root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_DIRECTORY, NULL);
if (dfd < 0)
return dfd;
if (mkdirat(dfd, bn, m) < 0) {
if (errno == EEXIST)
return 0;
return -errno;
}
if (uid_is_valid(uid) || gid_is_valid(gid)) {
_cleanup_close_ int nfd = -1;
nfd = openat(dfd, bn, O_RDONLY|O_CLOEXEC|O_DIRECTORY);
if (nfd < 0)
return -errno;
if (fchown(nfd, uid, gid) < 0)
return -errno;
}
return 1;
}
+2
View File
@@ -26,3 +26,5 @@ typedef int (*mkdir_func_t)(const char *pathname, mode_t mode);
int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, MkdirFlags flags, mkdir_func_t _mkdir);
int mkdir_parents_internal(const char *prefix, const char *path, mode_t mode, uid_t uid, gid_t gid, MkdirFlags flags, mkdir_func_t _mkdir);
int mkdir_p_internal(const char *prefix, const char *path, mode_t mode, uid_t uid, gid_t gid, MkdirFlags flags, mkdir_func_t _mkdir);
int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m);
-12
View File
@@ -726,18 +726,6 @@ int fsck_exists(const char *fstype) {
return binary_is_good(checker);
}
int mkfs_exists(const char *fstype) {
const char *mkfs;
assert(fstype);
if (streq(fstype, "auto"))
return -EINVAL;
mkfs = strjoina("mkfs.", fstype);
return binary_is_good(mkfs);
}
int parse_path_argument_and_warn(const char *path, bool suppress_root, char **arg) {
char *p;
int r;
-1
View File
@@ -85,7 +85,6 @@ int find_binary(const char *name, char **filename);
bool paths_check_timestamp(const char* const* paths, usec_t *paths_ts_usec, bool update);
int fsck_exists(const char *fstype);
int mkfs_exists(const char *fstype);
/* Iterates through the path prefixes of the specified path, going up
* the tree, to root. Also returns "" (and not "/"!) for the root