Adding upstream version 4.00~pre61+dfsg.
[syslinux-debian/hramrach.git] / com32 / gpllib / disk / ata.c
blob78f669ec2d3903fdbf7eece7012946e5c5e9dfe6
1 #include <inttypes.h>
2 #include <string.h>
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.
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.
15 * LOCKING:
16 * caller.
18 void ata_id_string(const uint16_t * id, unsigned char *s,
19 unsigned int ofs, unsigned int len)
21 unsigned int c;
23 while (len > 0) {
24 c = id[ofs] >> 8;
25 *s = c;
26 s++;
28 c = id[ofs] & 0xff;
29 *s = c;
30 s++;
32 ofs++;
33 len -= 2;
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.
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.
48 * LOCKING:
49 * caller.
51 void ata_id_c_string(const uint16_t * id, unsigned char *s,
52 unsigned int ofs, unsigned int len)
54 unsigned char *p;
56 ata_id_string(id, s, ofs, len - 1);
58 p = s + strnlen((const char *)s, len - 1);
59 while (p > s && p[-1] == ' ')
60 p--;
61 *p = '\0';