diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index ca3befb30..6a3daab30 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -35,6 +35,7 @@ static int write_hibernate_location_info(void) { _cleanup_free_ struct fiemap *fiemap = NULL; char offset_str[DECIMAL_STR_MAX(uint64_t)]; char device_str[DECIMAL_STR_MAX(uint64_t)]; + char device_num_str [DECIMAL_STR_MAX(uint)*2+1]; _cleanup_close_ int fd = -1; struct stat stb; uint64_t offset; @@ -44,10 +45,15 @@ static int write_hibernate_location_info(void) { if (r < 0) return log_debug_errno(r, "Unable to find hibernation location: %m"); - /* if it's a swap partition, we just write the disk to /sys/power/resume */ - if (streq(type, "partition")) - return write_string_file("/sys/power/resume", device, 0); - else if (!streq(type, "file")) + /* if it's a swap partition, we just write the corresponding major:minor numbers to /sys/power/resume */ + if (streq(type, "partition")) { + r = stat( device, &stb); + if (r == -1) { + return log_debug_errno(errno, "Error while trying to get stats for %s: %m", device); + } + sprintf(device_num_str, "%u:%u",major(stb.st_rdev) , minor(stb.st_rdev) ); + return write_string_file("/sys/power/resume", device_num_str, 0); + }else if (!streq(type, "file")) return log_debug_errno(EINVAL, "Invalid hibernate type %s: %m", type);