From 8a86e15f07dd7030bfc31fb4944c24fb9a481fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=91=E8=B6=85=E5=8E=89=E5=AE=B3?= <524413304@qq.com> Date: Tue, 16 Jan 2024 13:57:07 +0800 Subject: [PATCH] udev: even if a device is a zac device, scsi-$ID_SERIAL will be reserved for it (#30459) Co-authored-by: wangyuhang --- rules.d/60-persistent-storage.rules.in | 2 ++ src/udev/ata_id/ata_id.c | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/rules.d/60-persistent-storage.rules.in b/rules.d/60-persistent-storage.rules.in index 96b888fdff..390c6e0034 100644 --- a/rules.d/60-persistent-storage.rules.in +++ b/rules.d/60-persistent-storage.rules.in @@ -59,6 +59,8 @@ KERNEL=="vd*", ATTRS{serial}=="?*", ENV{ID_SERIAL}="$attr{serial}", SYMLINK+="di # ATA KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", IMPORT{program}="ata_id --export $devnode" +KERNEL=="sd*[!0-9]|sr*", ENV{ID_BUS}=="ata", ENV{ID_ATA_PERIPHERAL_DEVICE_TYPE}=="20", PROGRAM="scsi_id -u -g $devnode", \ + SYMLINK+="disk/by-id/scsi-$result$env{.PART_SUFFIX}" # ATAPI devices (SPC-3 or later) KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="scsi", ATTRS{type}=="5", ATTRS{scsi_level}=="[6-9]*", IMPORT{program}="ata_id --export $devnode" diff --git a/src/udev/ata_id/ata_id.c b/src/udev/ata_id/ata_id.c index 0b1f0b7157..4dd7e54973 100644 --- a/src/udev/ata_id/ata_id.c +++ b/src/udev/ata_id/ata_id.c @@ -298,7 +298,8 @@ static void disk_identify_fixup_uint16(uint8_t identify[512], unsigned offset_wo * non-zero with errno set. */ static int disk_identify(int fd, - uint8_t out_identify[512]) { + uint8_t out_identify[512], + int *ret_peripheral_device_type) { uint8_t inquiry_buf[36]; int peripheral_device_type, r; @@ -358,6 +359,9 @@ static int disk_identify(int fd, if (all_nul_bytes) return log_debug_errno(SYNTHETIC_ERRNO(EIO), "IDENTIFY data is all zeroes."); + if (ret_peripheral_device_type) + *ret_peripheral_device_type = peripheral_device_type; + return 0; } @@ -407,7 +411,7 @@ static int run(int argc, char *argv[]) { char model[41], model_enc[256], serial[21], revision[9]; _cleanup_close_ int fd = -EBADF; uint16_t word; - int r; + int r, peripheral_device_type = -1; log_set_target(LOG_TARGET_AUTO); udev_parse_config(); @@ -422,7 +426,7 @@ static int run(int argc, char *argv[]) { if (fd < 0) return log_error_errno(errno, "Cannot open %s: %m", arg_device); - if (disk_identify(fd, identify.byte) >= 0) { + if (disk_identify(fd, identify.byte, &peripheral_device_type) >= 0) { /* * fix up only the fields from the IDENTIFY data that we are going to * use and copy it into the hd_driveid struct for convenience @@ -615,6 +619,9 @@ static int run(int argc, char *argv[]) { if (IN_SET(identify.wyde[0], 0x848a, 0x844a) || (identify.wyde[83] & 0xc004) == 0x4004) printf("ID_ATA_CFA=1\n"); + + if (peripheral_device_type >= 0) + printf("ID_ATA_PERIPHERAL_DEVICE_TYPE=%d\n", peripheral_device_type); } else { if (serial[0] != '\0') printf("%s_%s\n", model, serial);