basic: add make_mount_point_inode helper
Creates a file or a directory depending on the source path, useful for creating mount points.
This commit is contained in:
committed by
Lennart Poettering
parent
9df1e11e31
commit
8bab802910
@@ -8,14 +8,17 @@
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "fs-util.h"
|
||||
#include "label.h"
|
||||
#include "missing_stat.h"
|
||||
#include "missing_syscall.h"
|
||||
#include "mkdir.h"
|
||||
#include "mountpoint-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
#include "stat-util.h"
|
||||
#include "stdio-util.h"
|
||||
#include "strv.h"
|
||||
#include "user-util.h"
|
||||
|
||||
/* This is the original MAX_HANDLE_SZ definition from the kernel, when the API was introduced. We use that in place of
|
||||
* any more currently defined value to future-proof things: if the size is increased in the API headers, and our code
|
||||
@@ -509,3 +512,25 @@ int mount_propagation_flags_from_string(const char *name, unsigned long *ret) {
|
||||
return -EINVAL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int make_mount_point_inode_from_stat(const struct stat *st, const char *dest, mode_t mode) {
|
||||
assert(st);
|
||||
assert(dest);
|
||||
|
||||
if (S_ISDIR(st->st_mode))
|
||||
return mkdir_label(dest, mode);
|
||||
else
|
||||
return mknod(dest, S_IFREG|(mode & ~0111), 0);
|
||||
}
|
||||
|
||||
int make_mount_point_inode_from_path(const char *source, const char *dest, mode_t mode) {
|
||||
struct stat st;
|
||||
|
||||
assert(source);
|
||||
assert(dest);
|
||||
|
||||
if (stat(source, &st) < 0)
|
||||
return -errno;
|
||||
|
||||
return make_mount_point_inode_from_stat(&st, dest, mode);
|
||||
}
|
||||
|
||||
@@ -23,3 +23,7 @@ int dev_is_devtmpfs(void);
|
||||
|
||||
const char *mount_propagation_flags_to_string(unsigned long flags);
|
||||
int mount_propagation_flags_from_string(const char *name, unsigned long *ret);
|
||||
|
||||
/* Creates a mount point (not parents) based on the source path or stat - ie, a file or a directory */
|
||||
int make_mount_point_inode_from_stat(const struct stat *st, const char *dest, mode_t mode);
|
||||
int make_mount_point_inode_from_path(const char *source, const char *dest, mode_t mode);
|
||||
|
||||
Reference in New Issue
Block a user