diff options
author | Pierre-Alexandre Meyer <pierre@mouraf.org> | 2009-04-19 08:13:00 -0700 |
---|---|---|
committer | Pierre-Alexandre Meyer <pierre@mouraf.org> | 2009-04-19 08:13:00 -0700 |
commit | a47eec26c8e5b269852fde63b9e3767ed76c1f47 (patch) | |
tree | d80eed5d325c6f181036ba485ad94d6d9590eba2 /com32/gpllib/disk/ata.c | |
parent | 796ac719ba031943201c5fc3cf740dea50315414 (diff) | |
download | syslinux-a47eec26c8e5b269852fde63b9e3767ed76c1f47.tar.gz |
gpllib: Add disk library
This library features read and write operations, as well as geometry detection.
It will prevent duplicating code between several modules (e.g. hdt and chain.c32).
Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Diffstat (limited to 'com32/gpllib/disk/ata.c')
-rw-r--r-- | com32/gpllib/disk/ata.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/com32/gpllib/disk/ata.c b/com32/gpllib/disk/ata.c new file mode 100644 index 00000000..f1716ffa --- /dev/null +++ b/com32/gpllib/disk/ata.c @@ -0,0 +1,59 @@ +/** + * 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(s, len - 1); + while (p > s && p[-1] == ' ') + p--; + *p = '\0'; +} |