sg3_utils
sg3_utils copied to clipboard
sg_logs: Fix parameter lengths in show_data_compression_page
For the parameters in show_data_compression_page the length pl is initialized from bp[3] and checked for 0 || > 8, but the value passed to sg_get_unaligned_be is off-by-four. So all values in this page were effectively truncated to 0.
Output from sg_logs /dev/sg0 -p 0x1b before
Data compression log page (ssc-4) [0x1b]
Read compression ratio x100: 0
Write compression ratio x100: 0
Megabytes transferred to server: 0
Bytes transferred to server: 0
Megabytes read from tape: 0
Bytes read from tape: 0
Megabytes transferred from server: 0
Bytes transferred from server: 0
Megabytes written to tape: 0
Bytes written to tape: 0
Data compression enabled: 0
unknown Parameter code = 0xabcd, contents in hex:
00 00 00 00
and after fix
Data compression log page (ssc-4) [0x1b]
Read compression ratio x100: 42
Write compression ratio x100: 84
Megabytes transferred to server: 1234
Bytes transferred to server: 4567
Megabytes read from tape: 0
Bytes read from tape: 0
Megabytes transferred from server: 0
Bytes transferred from server: 0
Megabytes written to tape: 0
Bytes written to tape: 0
Data compression enabled: 1
unknown Parameter code = 0xabcd, contents in hex:
00 00 00 00 ff 00 ff 00
I'm still playing around with emulation code and not an actual device, yes, so those are dummy values. The unknown parameter was injected for the 8 byte length, the values in the page covered 1/2/4 already. I think the data I'm generating is correct, but :)
(Similar-ish code in that file sometimes prefers pl + 4 but made for a more invasive change).