1 | #include <inttypes.h> |
---|
2 | #include <string.h> |
---|
3 | |
---|
4 | /** |
---|
5 | * ata_id_string - Convert IDENTIFY DEVICE page into string |
---|
6 | * @id: IDENTIFY DEVICE results we will examine |
---|
7 | * @s: string into which data is output |
---|
8 | * @ofs: offset into identify device page |
---|
9 | * @len: length of string to return. must be an even number. |
---|
10 | * |
---|
11 | * The strings in the IDENTIFY DEVICE page are broken up into |
---|
12 | * 16-bit chunks. Run through the string, and output each |
---|
13 | * 8-bit chunk linearly, regardless of platform. |
---|
14 | * |
---|
15 | * LOCKING: |
---|
16 | * caller. |
---|
17 | */ |
---|
18 | void ata_id_string(const uint16_t * id, unsigned char *s, |
---|
19 | unsigned int ofs, unsigned int len) |
---|
20 | { |
---|
21 | unsigned int c; |
---|
22 | |
---|
23 | while (len > 0) { |
---|
24 | c = id[ofs] >> 8; |
---|
25 | *s = c; |
---|
26 | s++; |
---|
27 | |
---|
28 | c = id[ofs] & 0xff; |
---|
29 | *s = c; |
---|
30 | s++; |
---|
31 | |
---|
32 | ofs++; |
---|
33 | len -= 2; |
---|
34 | } |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | * ata_id_c_string - Convert IDENTIFY DEVICE page into C string |
---|
39 | * @id: IDENTIFY DEVICE results we will examine |
---|
40 | * @s: string into which data is output |
---|
41 | * @ofs: offset into identify device page |
---|
42 | * @len: length of string to return. must be an odd number. |
---|
43 | * |
---|
44 | * This function is identical to ata_id_string except that it |
---|
45 | * trims trailing spaces and terminates the resulting string with |
---|
46 | * null. @len must be actual maximum length (even number) + 1. |
---|
47 | * |
---|
48 | * LOCKING: |
---|
49 | * caller. |
---|
50 | */ |
---|
51 | void ata_id_c_string(const uint16_t * id, unsigned char *s, |
---|
52 | unsigned int ofs, unsigned int len) |
---|
53 | { |
---|
54 | unsigned char *p; |
---|
55 | |
---|
56 | ata_id_string(id, s, ofs, len - 1); |
---|
57 | |
---|
58 | p = s + strnlen((const char *)s, len - 1); |
---|
59 | while (p > s && p[-1] == ' ') |
---|
60 | p--; |
---|
61 | *p = '\0'; |
---|
62 | } |
---|