The existing ioctl(SG_GET_SCSI_ID) fills a object of type struct sg_scsi_id whose last field is int unused[2]. Add an anonymous union with u8 scsi_lun[8] sharing those last 8 bytes. This patch will place the current device's full LUN in the scsi_lun array using T10's preferred LUN format (i.e. an array of 8 bytes) when ioctl(SG_GET_SCSI_ID) is called. Note that structure already contains a 'lun' field but that is a 32 bit integer. Users of this upgrade should choose the scsi_lun array field henceforth but existing code can remain as it is and will get the same 'lun' value with the version 3 or version 4 driver. Signed-off-by: Douglas Gilbert <dgilbert@xxxxxxxxxxxx> --- drivers/scsi/sg.c | 5 +++-- include/uapi/scsi/sg.h | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 694a2f50063b..fb7eeafff801 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -1684,6 +1684,7 @@ static int sg_ctl_scsi_id(struct scsi_device *sdev, struct sg_fd *sfp, void __user *p) { struct sg_scsi_id __user *sg_idp = p; + struct scsi_lun lun8b; SG_LOG(3, sfp, "%s: SG_GET_SCSI_ID\n", __func__); if (!access_ok(p, sizeof(struct sg_scsi_id))) @@ -1701,8 +1702,8 @@ sg_ctl_scsi_id(struct scsi_device *sdev, struct sg_fd *sfp, void __user *p) &sg_idp->h_cmd_per_lun); __put_user((short)sdev->queue_depth, &sg_idp->d_queue_depth); - __put_user(0, &sg_idp->unused[0]); - __put_user(0, &sg_idp->unused[1]); + int_to_scsilun(sdev->lun, &lun8b); + __copy_to_user(sg_idp->scsi_lun, lun8b.scsi_lun, 8); return 0; } diff --git a/include/uapi/scsi/sg.h b/include/uapi/scsi/sg.h index 47eefe731a84..0d6fbf976e5c 100644 --- a/include/uapi/scsi/sg.h +++ b/include/uapi/scsi/sg.h @@ -135,7 +135,10 @@ typedef struct sg_scsi_id { int scsi_type; /* TYPE_... defined in scsi/scsi.h */ short h_cmd_per_lun;/* host (adapter) maximum commands per lun */ short d_queue_depth;/* device (or adapter) maximum queue length */ - int unused[2]; + union { + int unused[2]; /* as per version 3 driver */ + __u8 scsi_lun[8]; /* full 8 byte SCSI LUN [in v4 driver] */ + }; } sg_scsi_id_t; /* For backward compatibility v4 driver yields at most SG_MAX_QUEUE of these */ -- 2.22.0