Merge pull request #27352 from poettering/devnum-more

devnum-util: port more things over
This commit is contained in:
Lennart Poettering 2023-04-21 16:45:51 +02:00 committed by GitHub
commit b676a94837
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 11 deletions

View file

@ -26,6 +26,7 @@
#include "chase.h"
#include "chattr-util.h"
#include "constants.h"
#include "devnum-util.h"
#include "dissect-image.h"
#include "fd-util.h"
#include "fileio.h"
@ -194,7 +195,7 @@ static int add_matches_for_device(sd_journal *j, const char *devpath) {
r = sd_device_new_from_stat_rdev(&device, &st);
if (r < 0)
return log_error_errno(r, "Failed to get device from devnum %u:%u: %m", major(st.st_rdev), minor(st.st_rdev));
return log_error_errno(r, "Failed to get device from devnum " DEVNUM_FORMAT_STR ": %m", DEVNUM_FORMAT_VAL(st.st_rdev));
for (d = device; d; ) {
_cleanup_free_ char *match = NULL;
@ -224,7 +225,7 @@ static int add_matches_for_device(sd_journal *j, const char *devpath) {
if (r < 0)
return log_error_errno(r, "Failed to stat() device node \"%s\": %m", devnode);
r = asprintf(&match1, "_KERNEL_DEVICE=%c%u:%u", S_ISBLK(st.st_mode) ? 'b' : 'c', major(st.st_rdev), minor(st.st_rdev));
r = asprintf(&match1, "_KERNEL_DEVICE=%c" DEVNUM_FORMAT_STR, S_ISBLK(st.st_mode) ? 'b' : 'c', DEVNUM_FORMAT_VAL(st.st_rdev));
if (r < 0)
return log_oom();

View file

@ -301,7 +301,7 @@ int device_new_from_mode_and_devnum(sd_device **ret, mode_t mode, dev_t devnum)
if (major(devnum) == 0)
return -ENODEV;
if (asprintf(&syspath, "/sys/dev/%s/%u:%u", t, major(devnum), minor(devnum)) < 0)
if (asprintf(&syspath, "/sys/dev/%s/" DEVNUM_FORMAT_STR, t, DEVNUM_FORMAT_VAL(devnum)) < 0)
return -ENOMEM;
r = sd_device_new_from_syspath(&dev, syspath);
@ -1654,9 +1654,9 @@ int device_get_device_id(sd_device *device, const char **ret) {
if (sd_device_get_devnum(device, &devnum) >= 0) {
/* use dev_t — b259:131072, c254:0 */
if (asprintf(&id, "%c%u:%u",
if (asprintf(&id, "%c" DEVNUM_FORMAT_STR,
streq(subsystem, "block") ? 'b' : 'c',
major(devnum), minor(devnum)) < 0)
DEVNUM_FORMAT_VAL(devnum)) < 0)
return -ENOMEM;
} else if (sd_device_get_ifindex(device, &ifindex) >= 0) {
/* use netdev ifindex — n3 */

View file

@ -197,7 +197,7 @@ static void session_save_devices(Session *s, FILE *f) {
if (!hashmap_isempty(s->devices)) {
fprintf(f, "DEVICES=");
HASHMAP_FOREACH(sd, s->devices)
fprintf(f, "%u:%u ", major(sd->dev), minor(sd->dev));
fprintf(f, DEVNUM_FORMAT_STR " ", DEVNUM_FORMAT_VAL(sd->dev));
fprintf(f, "\n");
}
}

View file

@ -26,6 +26,7 @@
#include "chase.h"
#include "constants.h"
#include "device-util.h"
#include "devnum-util.h"
#include "dirent-util.h"
#include "escape.h"
#include "fd-util.h"
@ -890,7 +891,7 @@ static int dm_points_list_detach(MountPoint **head, bool *changed, bool last_try
continue;
}
log_info("Detaching DM %s (%u:%u).", m->path, major(m->devnum), minor(m->devnum));
log_info("Detaching DM %s (" DEVNUM_FORMAT_STR ").", m->path, DEVNUM_FORMAT_VAL(m->devnum));
r = delete_dm(m);
if (r < 0) {
log_full_errno(last_try ? LOG_ERR : LOG_INFO, r, "Could not detach DM %s: %m", m->path);
@ -920,7 +921,7 @@ static int md_points_list_detach(MountPoint **head, bool *changed, bool last_try
continue;
}
log_info("Stopping MD %s (%u:%u).", m->path, major(m->devnum), minor(m->devnum));
log_info("Stopping MD %s (" DEVNUM_FORMAT_STR ").", m->path, DEVNUM_FORMAT_VAL(m->devnum));
r = delete_md(m);
if (r < 0) {
log_full_errno(last_try ? LOG_ERR : LOG_INFO, r, "Could not stop MD %s: %m", m->path);

View file

@ -23,6 +23,7 @@
#include "bus-locator.h"
#include "bus-util.h"
#include "constants.h"
#include "devnum-util.h"
#include "exec-util.h"
#include "fd-util.h"
#include "fileio.h"
@ -45,13 +46,14 @@ static SleepOperation arg_operation = _SLEEP_OPERATION_INVALID;
static int write_hibernate_location_info(const HibernateLocation *hibernate_location) {
char offset_str[DECIMAL_STR_MAX(uint64_t)];
char resume_str[DECIMAL_STR_MAX(unsigned) * 2 + STRLEN(":")];
const char *resume_str;
int r;
assert(hibernate_location);
assert(hibernate_location->swap);
xsprintf(resume_str, "%u:%u", major(hibernate_location->devno), minor(hibernate_location->devno));
resume_str = FORMAT_DEVNUM(hibernate_location->devno);
r = write_string_file("/sys/power/resume", resume_str, WRITE_STRING_FILE_DISABLE_BUFFER);
if (r < 0)
return log_debug_errno(r, "Failed to write partition device to /sys/power/resume for '%s': '%s': %m",

View file

@ -439,7 +439,7 @@ static int merge_hierarchy(
if (!f)
return log_oom();
r = write_string_filef(f, WRITE_STRING_FILE_CREATE, "%u:%u", major(st.st_dev), minor(st.st_dev));
r = write_string_file(f, FORMAT_DEVNUM(st.st_dev), WRITE_STRING_FILE_CREATE);
if (r < 0)
return log_error_errno(r, "Failed to write '%s': %m", f);