hdparm: fix ATA identification string output
No binary (build failed)
gcc -Wp,-MD,applets/.usage.d -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -Iinclude -Iinclude -o applets/usage applets/usage.c
(log yok)
| @@ -552,7 +552,7 @@ static void print_ascii(const char *p, int length) | |
| length *= 2; | |
| /* find first non-space & print it */ | |
| - | while (length && p[ofs] != ' ') { |
| + | while (length && p[ofs] == ' ') { |
| p++; | |
| LE_ONLY(ofs = -ofs;) | |
| length--; | |
| @@ -0,0 +1,51 @@ | |
| + | #!/bin/sh |
| + | # Copyright 2026 by Romain Guyard <[email protected]> |
| + | # Licensed under GPLv2, see file LICENSE in this source tree. |
| + | |
| + | . ./testing.sh |
| + | |
| + | # testing "test name" "commands" "expected result" "file input" "stdin" |
| + | |
| + | # With no device argument and a non-tty stdin, hdparm parses a hex IDENTIFY |
| + | # DEVICE block from stdin (identify_from_stdin) and prints it the way |
| + | # "hdparm -I" does. That makes the ASCII field decoding testable without |
| + | # a disk. |
| + | # |
| + | # The block below carries: |
| + | # words 10-19 serial number "SN0123456789ABCDEF" (no embedded space) |
| + | # words 23-26 firmware rev "FW1234" |
| + | # words 27-46 model number "EXAMPLE SSD 256GB" (has one) |
| + | # words 176-195 media serial " MEDIASN00001" (leading spaces) |
| + | # |
| + | # ATA strings are left-justified and space-padded. print_ascii() must skip |
| + | # leading *spaces* only. It used to skip the leading run of *non-space* |
| + | # characters instead, which emptied every field with no embedded space |
| + | # (serial number, firmware revision) and truncated the model number at its |
| + | # first space. |
| + | |
| + | testing "hdparm -I decodes ASCII fields" \ |
| + | "hdparm | grep -E 'Number:|Revision:|Serial Num:' | sed 's/[[:space:]]*\$//'" \ |
| + | "\ |
| + | \tModel Number: EXAMPLE SSD 256GB |
| + | \tSerial Number: SN0123456789ABCDEF |
| + | \tFirmware Revision: FW1234 |
| + | \tMedia Serial Num: MEDIASN00001 |
| + | " \ |
| + | "" \ |
| + | "\ |
| + | 0040000000000000000000000000000000000000534e3031323334353637383941424344454620200000000000004657\ |
| + | 3132333420204558414d504c452053534420323536474220202020202020202020202020202020202020202020200000\ |
| + | 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\ |
| + | 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\ |
| + | 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\ |
| + | 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\ |
| + | 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\ |
| + | 000000000000000000000000000000002020204d45444941534e30303030312020202020202020202020202020202020\ |
| + | 202020202020202000000000000000000000000000000000000000000000000000000000000000000000000000000000\ |
| + | 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\ |
| + | 00000000000000000000000000000000000000000000000000000000000000a500000000000000000000000000000000\ |
| + | 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\ |
| + | 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\ |
| + | 00000000000000000000000000000000" |
| + | |
| + | exit $FAILCOUNT |