summaryrefslogtreecommitdiffstats
path: root/src/hibernate-resume
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-04-03 03:42:59 +0200
committerMike Yuan <me@yhndnzj.com>2024-04-03 15:59:59 +0200
commit9fa0f584ec8590b22c3b8529b65e7368983fcd71 (patch)
treec2c0c90189e701c856b5f5e07a1678f340514141 /src/hibernate-resume
parenthibernate-resume: EINVAL -> ENOTBLK where appropriate (diff)
downloadsystemd-9fa0f584ec8590b22c3b8529b65e7368983fcd71.tar.xz
systemd-9fa0f584ec8590b22c3b8529b65e7368983fcd71.zip
hibernate-resume-config: expose get_efi_hibernate_location
Diffstat (limited to 'src/hibernate-resume')
-rw-r--r--src/hibernate-resume/hibernate-resume-config.c35
-rw-r--r--src/hibernate-resume/hibernate-resume-config.h31
2 files changed, 30 insertions, 36 deletions
diff --git a/src/hibernate-resume/hibernate-resume-config.c b/src/hibernate-resume/hibernate-resume-config.c
index c6db83a9d3..504d27a396 100644
--- a/src/hibernate-resume/hibernate-resume-config.c
+++ b/src/hibernate-resume/hibernate-resume-config.c
@@ -28,20 +28,7 @@ static KernelHibernateLocation* kernel_hibernate_location_free(KernelHibernateLo
DEFINE_TRIVIAL_CLEANUP_FUNC(KernelHibernateLocation*, kernel_hibernate_location_free);
-typedef struct EFIHibernateLocation {
- char *device;
-
- sd_id128_t uuid;
- uint64_t offset;
-
- char *kernel_version;
- char *id;
- char *image_id;
- char *version_id;
- char *image_version;
-} EFIHibernateLocation;
-
-static EFIHibernateLocation* efi_hibernate_location_free(EFIHibernateLocation *e) {
+EFIHibernateLocation* efi_hibernate_location_free(EFIHibernateLocation *e) {
if (!e)
return NULL;
@@ -55,8 +42,6 @@ static EFIHibernateLocation* efi_hibernate_location_free(EFIHibernateLocation *e
return mfree(e);
}
-DEFINE_TRIVIAL_CLEANUP_FUNC(EFIHibernateLocation*, efi_hibernate_location_free);
-
void hibernate_info_done(HibernateInfo *info) {
assert(info);
@@ -140,7 +125,7 @@ static bool validate_efi_hibernate_location(EFIHibernateLocation *e) {
if (!streq_ptr(id, e->id) ||
!streq_ptr(image_id, e->image_id)) {
- log_notice("HibernateLocation system identifier doesn't match currently running system, not resuming from it.");
+ log_notice("HibernateLocation system identifier doesn't match currently running system, would not resume from it.");
return false;
}
@@ -152,8 +137,9 @@ static bool validate_efi_hibernate_location(EFIHibernateLocation *e) {
return true;
}
+#endif
-static int get_efi_hibernate_location(EFIHibernateLocation **ret) {
+int get_efi_hibernate_location(EFIHibernateLocation **ret) {
static const JsonDispatch dispatch_table[] = {
{ "uuid", JSON_VARIANT_STRING, json_dispatch_id128, offsetof(EFIHibernateLocation, uuid), JSON_MANDATORY },
@@ -171,8 +157,6 @@ static int get_efi_hibernate_location(EFIHibernateLocation **ret) {
_cleanup_free_ char *location_str = NULL;
int r;
- assert(ret);
-
if (!is_efi_boot())
goto skip;
@@ -211,15 +195,18 @@ static int get_efi_hibernate_location(EFIHibernateLocation **ret) {
if (asprintf(&e->device, "/dev/disk/by-uuid/" SD_ID128_UUID_FORMAT_STR, SD_ID128_FORMAT_VAL(e->uuid)) < 0)
return log_oom();
- *ret = TAKE_PTR(e);
+ if (ret)
+ *ret = TAKE_PTR(e);
return 1;
skip:
- *ret = NULL;
+ if (ret)
+ *ret = NULL;
return 0;
}
void compare_hibernate_location_and_warn(const HibernateInfo *info) {
+#if ENABLE_EFI
int r;
assert(info);
@@ -243,8 +230,8 @@ void compare_hibernate_location_and_warn(const HibernateInfo *info) {
if (info->cmdline->offset != info->efi->offset)
log_warning("resume_offset=%" PRIu64 " doesn't match with EFI HibernateLocation offset %" PRIu64 ", proceeding anyway with resume_offset=.",
info->cmdline->offset, info->efi->offset);
-}
#endif
+}
int acquire_hibernate_info(HibernateInfo *ret) {
_cleanup_(hibernate_info_done) HibernateInfo i = {};
@@ -254,11 +241,9 @@ int acquire_hibernate_info(HibernateInfo *ret) {
if (r < 0)
return r;
-#if ENABLE_EFI
r = get_efi_hibernate_location(&i.efi);
if (r < 0)
return r;
-#endif
if (i.cmdline) {
i.device = i.cmdline->device;
diff --git a/src/hibernate-resume/hibernate-resume-config.h b/src/hibernate-resume/hibernate-resume-config.h
index c0aa9e00ad..68ef075355 100644
--- a/src/hibernate-resume/hibernate-resume-config.h
+++ b/src/hibernate-resume/hibernate-resume-config.h
@@ -5,8 +5,27 @@
#include "sd-id128.h"
+#include "macro.h"
+
typedef struct KernelHibernateLocation KernelHibernateLocation;
-typedef struct EFIHibernateLocation EFIHibernateLocation;
+
+typedef struct EFIHibernateLocation {
+ char *device;
+
+ sd_id128_t uuid;
+ uint64_t offset;
+
+ char *kernel_version;
+ char *id;
+ char *image_id;
+ char *version_id;
+ char *image_version;
+} EFIHibernateLocation;
+
+EFIHibernateLocation* efi_hibernate_location_free(EFIHibernateLocation *e);
+DEFINE_TRIVIAL_CLEANUP_FUNC(EFIHibernateLocation*, efi_hibernate_location_free);
+
+int get_efi_hibernate_location(EFIHibernateLocation **ret);
typedef struct HibernateInfo {
const char *device;
@@ -20,14 +39,4 @@ void hibernate_info_done(HibernateInfo *info);
int acquire_hibernate_info(HibernateInfo *ret);
-#if ENABLE_EFI
-
void compare_hibernate_location_and_warn(const HibernateInfo *info);
-
-#else
-
-static inline void compare_hibernate_location_and_warn(const HibernateInfo *info) {
- return;
-}
-
-#endif