sd-device: drop support of udev database version 0

The udev database versioning has been introduced in v247, which is
released on 2020-11-26.
Let's drop the support of old udev database.
This commit is contained in:
Yu Watanabe
2026-05-15 13:47:45 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent dca9ab5b92
commit 1fdcf3ee40
3 changed files with 4 additions and 23 deletions
+2 -1
View File
@@ -6,6 +6,7 @@
#include "sd-forward.h"
#include "iterator.h"
#define OLDEST_UDEV_DATABASE_VERSION 1
#define LATEST_UDEV_DATABASE_VERSION 1
struct sd_device {
@@ -51,7 +52,7 @@ struct sd_device {
/* The database version indicates the supported features by the udev database.
* This is saved and parsed in V field.
*
* 0: None of the following features are supported (systemd version <= 246).
* 0: None of the following features are supported (systemd version <= 246), unsupported since v261.
* 1: The current tags (Q) and the database version (V) features are implemented (>= 247).
*/
unsigned database_version;
+1 -1
View File
@@ -912,7 +912,7 @@ int device_update_db(sd_device *device) {
fprintf(f, "Q:%s\n", ct); /* Current tag */
/* Always write the latest database version here, instead of the value stored in
* device->database_version, as which may be 0. */
* device->database_version. */
fputs("V:" STRINGIFY(LATEST_UDEV_DATABASE_VERSION) "\n", f);
}
+1 -21
View File
@@ -47,6 +47,7 @@ int device_new_aux(sd_device **ret) {
.devuid = UID_INVALID,
.devgid = GID_INVALID,
.action = _SD_DEVICE_ACTION_INVALID,
.database_version = OLDEST_UDEV_DATABASE_VERSION,
};
*ret = device;
@@ -1966,26 +1967,11 @@ _public_ const char* sd_device_get_tag_next(sd_device *device) {
return v;
}
static bool device_database_supports_current_tags(sd_device *device) {
assert(device);
(void) device_read_db(device);
/* The current tags (saved in Q field) feature is implemented in database version 1.
* If the database version is 0, then the tags (NOT current tags, saved in G field) are not
* sticky. Thus, we can safely bypass the operations for the current tags (Q) to tags (G). */
return device->database_version >= 1;
}
_public_ const char* sd_device_get_current_tag_first(sd_device *device) {
void *v;
assert_return(device, NULL);
if (!device_database_supports_current_tags(device))
return sd_device_get_tag_first(device);
(void) device_read_db(device);
device->current_tags_iterator_generation = device->tags_generation;
@@ -2000,9 +1986,6 @@ _public_ const char* sd_device_get_current_tag_next(sd_device *device) {
assert_return(device, NULL);
if (!device_database_supports_current_tags(device))
return sd_device_get_tag_next(device);
(void) device_read_db(device);
if (device->current_tags_iterator_generation != device->tags_generation)
@@ -2273,9 +2256,6 @@ _public_ int sd_device_has_current_tag(sd_device *device, const char *tag) {
assert_return(device, -EINVAL);
assert_return(tag, -EINVAL);
if (!device_database_supports_current_tags(device))
return sd_device_has_tag(device, tag);
(void) device_read_db(device);
return set_contains(device->current_tags, tag);