aboutsummaryrefslogtreecommitdiffstats
path: root/com32/gpllib/disk/ata.c
blob: 78f669ec2d3903fdbf7eece7012946e5c5e9dfe6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <inttypes.h>
#include <string.h>

/**
 *      ata_id_string - Convert IDENTIFY DEVICE page into string
 *      @id: IDENTIFY DEVICE results we will examine
 *      @s: string into which data is output
 *      @ofs: offset into identify device page
 *      @len: length of string to return. must be an even number.
 *
 *      The strings in the IDENTIFY DEVICE page are broken up into
 *      16-bit chunks.  Run through the string, and output each
 *      8-bit chunk linearly, regardless of platform.
 *
 *      LOCKING:
 *      caller.
 */
void ata_id_string(const uint16_t * id, unsigned char *s,
		   unsigned int ofs, unsigned int len)
{
    unsigned int c;

    while (len > 0) {
	c = id[ofs] >> 8;
	*s = c;
	s++;

	c = id[ofs] & 0xff;
	*s = c;
	s++;

	ofs++;
	len -= 2;
    }
}

/**
 *      ata_id_c_string - Convert IDENTIFY DEVICE page into C string
 *      @id: IDENTIFY DEVICE results we will examine
 *      @s: string into which data is output
 *      @ofs: offset into identify device page
 *      @len: length of string to return. must be an odd number.
 *
 *      This function is identical to ata_id_string except that it
 *      trims trailing spaces and terminates the resulting string with
 *      null.  @len must be actual maximum length (even number) + 1.
 *
 *      LOCKING:
 *      caller.
 */
void ata_id_c_string(const uint16_t * id, unsigned char *s,
		     unsigned int ofs, unsigned int len)
{
    unsigned char *p;

    ata_id_string(id, s, ofs, len - 1);

    p = s + strnlen((const char *)s, len - 1);
    while (p > s && p[-1] == ' ')
	p--;
    *p = '\0';
}