discover-image: introduce bus_property_get_image_is_read_only() with BUS_DEFINE_PROPERTY_GET() macro

This also makes image_is_read_only() return bool.

Follow-up for ee327e086e.
This commit is contained in:
Yu Watanabe
2025-10-31 20:33:34 +09:00
parent cbd8a12bce
commit 7829c9cc48
4 changed files with 7 additions and 31 deletions

View File

@@ -24,20 +24,6 @@
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, image_type, ImageType);
static int property_get_read_only(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
Image *image = ASSERT_PTR(userdata);
return sd_bus_message_append(ASSERT_PTR(reply), "b", image_is_read_only(image));
}
int bus_image_method_remove(
sd_bus_message *message,
void *userdata,
@@ -462,7 +448,7 @@ const sd_bus_vtable image_vtable[] = {
SD_BUS_PROPERTY("Name", "s", NULL, offsetof(Image, name), 0),
SD_BUS_PROPERTY("Path", "s", NULL, offsetof(Image, path), 0),
SD_BUS_PROPERTY("Type", "s", property_get_type, offsetof(Image, type), 0),
SD_BUS_PROPERTY("ReadOnly", "b", property_get_read_only, 0, 0),
SD_BUS_PROPERTY("ReadOnly", "b", bus_property_get_image_is_read_only, 0, 0),
SD_BUS_PROPERTY("CreationTimestamp", "t", NULL, offsetof(Image, crtime), 0),
SD_BUS_PROPERTY("ModificationTimestamp", "t", NULL, offsetof(Image, mtime), 0),
SD_BUS_PROPERTY("Usage", "t", NULL, offsetof(Image, usage), 0),

View File

@@ -30,20 +30,6 @@
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, image_type, ImageType);
static int property_get_read_only(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
Image *image = ASSERT_PTR(userdata);
return sd_bus_message_append(ASSERT_PTR(reply), "b", image_is_read_only(image));
}
int bus_image_common_get_os_release(
Manager *m,
sd_bus_message *message,
@@ -879,7 +865,7 @@ const sd_bus_vtable image_vtable[] = {
SD_BUS_PROPERTY("Name", "s", NULL, offsetof(Image, name), 0),
SD_BUS_PROPERTY("Path", "s", NULL, offsetof(Image, path), 0),
SD_BUS_PROPERTY("Type", "s", property_get_type, offsetof(Image, type), 0),
SD_BUS_PROPERTY("ReadOnly", "b", property_get_read_only, 0, 0),
SD_BUS_PROPERTY("ReadOnly", "b", bus_property_get_image_is_read_only, 0, 0),
SD_BUS_PROPERTY("CreationTimestamp", "t", NULL, offsetof(Image, crtime), 0),
SD_BUS_PROPERTY("ModificationTimestamp", "t", NULL, offsetof(Image, mtime), 0),
SD_BUS_PROPERTY("Usage", "t", NULL, offsetof(Image, usage), 0),

View File

@@ -16,6 +16,7 @@
#include "alloc-util.h"
#include "blockdev-util.h"
#include "btrfs-util.h"
#include "bus-get-properties.h"
#include "chase.h"
#include "chattr-util.h"
#include "copy.h"
@@ -2220,3 +2221,5 @@ int image_root_pick(
*ret = TAKE_PTR(s);
return 0;
}
BUS_DEFINE_PROPERTY_GET(bus_property_get_image_is_read_only, "b", Image, (int) image_is_read_only);

View File

@@ -91,7 +91,7 @@ static inline bool image_is_hidden(const Image *i) {
return i->name && i->name[0] == '.';
}
static inline int image_is_read_only(const Image *i) {
static inline bool image_is_read_only(const Image *i) {
assert(i);
/* We enforce the rule that hidden images are always read-only too. If people want to change hidden
@@ -102,6 +102,7 @@ static inline int image_is_read_only(const Image *i) {
return i->read_only;
}
int bus_property_get_image_is_read_only(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error);
bool image_is_vendor(const Image *i);
bool image_is_host(const Image *i);