mount: Add more helpers
This commit is contained in:
+6
-30
@@ -22,21 +22,13 @@ static int property_get_what(
|
||||
|
||||
_cleanup_free_ char *escaped = NULL;
|
||||
Mount *m = ASSERT_PTR(userdata);
|
||||
const char *s = NULL;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
|
||||
if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
|
||||
s = m->parameters_proc_self_mountinfo.what;
|
||||
else if (m->from_fragment && m->parameters_fragment.what)
|
||||
s = m->parameters_fragment.what;
|
||||
|
||||
if (s) {
|
||||
escaped = utf8_escape_invalid(s);
|
||||
if (!escaped)
|
||||
return -ENOMEM;
|
||||
}
|
||||
escaped = mount_get_what_escaped(m);
|
||||
if (!escaped)
|
||||
return -ENOMEM;
|
||||
|
||||
return sd_bus_message_append_basic(reply, 's', escaped);
|
||||
}
|
||||
@@ -52,33 +44,17 @@ static int property_get_options(
|
||||
|
||||
_cleanup_free_ char *escaped = NULL;
|
||||
Mount *m = ASSERT_PTR(userdata);
|
||||
const char *s = NULL;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
|
||||
if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options)
|
||||
s = m->parameters_proc_self_mountinfo.options;
|
||||
else if (m->from_fragment && m->parameters_fragment.options)
|
||||
s = m->parameters_fragment.options;
|
||||
|
||||
if (s) {
|
||||
escaped = utf8_escape_invalid(s);
|
||||
if (!escaped)
|
||||
return -ENOMEM;
|
||||
}
|
||||
escaped = mount_get_options_escaped(m);
|
||||
if (!escaped)
|
||||
return -ENOMEM;
|
||||
|
||||
return sd_bus_message_append_basic(reply, 's', escaped);
|
||||
}
|
||||
|
||||
static const char *mount_get_fstype(const Mount *m) {
|
||||
if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
|
||||
return m->parameters_proc_self_mountinfo.fstype;
|
||||
else if (m->from_fragment && m->parameters_fragment.fstype)
|
||||
return m->parameters_fragment.fstype;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static BUS_DEFINE_PROPERTY_GET(property_get_type, "s", Mount, mount_get_fstype);
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, mount_result, MountResult);
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "strv.h"
|
||||
#include "unit-name.h"
|
||||
#include "unit.h"
|
||||
#include "utf8.h"
|
||||
|
||||
#define RETRY_UMOUNT_MAX 32
|
||||
|
||||
@@ -2345,6 +2346,58 @@ static int mount_subsystem_ratelimited(Manager *m) {
|
||||
return sd_event_source_is_ratelimited(m->mount_event_source);
|
||||
}
|
||||
|
||||
char* mount_get_what_escaped(const Mount *m) {
|
||||
_cleanup_free_ char *escaped = NULL;
|
||||
const char *s = NULL;
|
||||
|
||||
assert(m);
|
||||
|
||||
if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
|
||||
s = m->parameters_proc_self_mountinfo.what;
|
||||
else if (m->from_fragment && m->parameters_fragment.what)
|
||||
s = m->parameters_fragment.what;
|
||||
|
||||
if (s) {
|
||||
escaped = utf8_escape_invalid(s);
|
||||
if (!escaped)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return escaped ? TAKE_PTR(escaped) : strdup("");
|
||||
}
|
||||
|
||||
char* mount_get_options_escaped(const Mount *m) {
|
||||
_cleanup_free_ char *escaped = NULL;
|
||||
const char *s = NULL;
|
||||
|
||||
assert(m);
|
||||
|
||||
if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options)
|
||||
s = m->parameters_proc_self_mountinfo.options;
|
||||
else if (m->from_fragment && m->parameters_fragment.options)
|
||||
s = m->parameters_fragment.options;
|
||||
|
||||
if (s) {
|
||||
escaped = utf8_escape_invalid(s);
|
||||
if (!escaped)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return escaped ? TAKE_PTR(escaped) : strdup("");
|
||||
}
|
||||
|
||||
const char* mount_get_fstype(const Mount *m) {
|
||||
assert(m);
|
||||
|
||||
if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
|
||||
return m->parameters_proc_self_mountinfo.fstype;
|
||||
|
||||
if (m->from_fragment && m->parameters_fragment.fstype)
|
||||
return m->parameters_fragment.fstype;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char* const mount_exec_command_table[_MOUNT_EXEC_COMMAND_MAX] = {
|
||||
[MOUNT_EXEC_MOUNT] = "ExecMount",
|
||||
[MOUNT_EXEC_UNMOUNT] = "ExecUnmount",
|
||||
|
||||
@@ -97,6 +97,10 @@ void mount_fd_event(Manager *m, int events);
|
||||
|
||||
int mount_invalidate_state_by_path(Manager *manager, const char *path);
|
||||
|
||||
char* mount_get_what_escaped(const Mount *m);
|
||||
char* mount_get_options_escaped(const Mount *m);
|
||||
const char* mount_get_fstype(const Mount *m);
|
||||
|
||||
const char* mount_exec_command_to_string(MountExecCommand i) _const_;
|
||||
MountExecCommand mount_exec_command_from_string(const char *s) _pure_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user