Skip to content

Commit

Permalink
Parse qword in ATA, use for extended addressable num blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
baruch committed Jan 10, 2016
1 parent 13c7948 commit 7206989
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/ata.h
Expand Up @@ -23,6 +23,7 @@

typedef uint16_t ata_word_t;
typedef uint32_t ata_longword_t;
typedef uint64_t ata_qword_t;

typedef enum passthrough_protocol_e {
PT_PROTO_HARDWARE_RESET = 0,
Expand Down Expand Up @@ -108,6 +109,14 @@ static inline ata_longword_t ata_get_longword(const unsigned char *buf, int star
return longword;
}

static inline ata_qword_t ata_get_qword(const unsigned char *buf, int start_word)
{
ata_qword_t low = ata_get_longword(buf, start_word);
ata_qword_t high = ata_get_longword(buf, start_word+2);
ata_qword_t qword = high << 32 | low;
return qword;
}

bool ata_inquiry_checksum_verify(const char *buf, int buf_len);

static inline unsigned char ata_passthrough_flags_2(int offline, int ck_cond, int direction_in, int transfer_block, ata_passthrough_len_spec_e len_spec)
Expand Down
4 changes: 4 additions & 0 deletions include/ata_parse.h
Expand Up @@ -37,6 +37,10 @@ static inline bool ata_get_ata_identify_rzat_supported(const unsigned char *buf)
return val & (1 << 5);
}

static inline ata_qword_t ata_get_ata_identify_extended_num_user_addressable_sectors(const unsigned char *buf) {
return ata_get_qword(buf, 230);
}

static inline bool ata_get_ata_identify_wwn_64bit_supported(const unsigned char *buf) {
ata_word_t val = ata_get_word(buf, 84);
return val & (1 << 8);
Expand Down
4 changes: 4 additions & 0 deletions structs/ata_identify.yaml
Expand Up @@ -220,4 +220,8 @@ ata_identify:
string: [170, 173]
current_media_serial:
string: [176, 205]

extended_num_user_addressable_sectors:
qword: 230

# vim:set et ts=4 sw=4:
6 changes: 6 additions & 0 deletions structs/ata_struct_2_c_dump.py
Expand Up @@ -23,11 +23,16 @@ def emit_func_longword(name, field, params):
bit_params = dict(name=name, field=field, word_start=int(params))
print('printf("%%-40s: %%u\\n", "%(field)s", ata_get_%(name)s_%(field)s(buf));' % bit_params)

def emit_func_qword(name, field, params):
bit_params = dict(name=name, field=field, word_start=int(params))
print('printf("%%-40s: %%"PRIu64"\\n", "%(field)s", ata_get_%(name)s_%(field)s(buf));' % bit_params)

kinds = {
'bit': emit_func_bit,
'bits': emit_func_bits,
'string': emit_func_string,
'longword': emit_func_longword,
'qword': emit_func_qword,
}

def emit_header_single(name, struct):
Expand Down Expand Up @@ -55,6 +60,7 @@ def emit_prefix():
print('#include "ata_parse.h"')
print('#include "ata_identify_dump.h"')
print('#include <stdio.h>')
print('#include <inttypes.h>')

def emit_suffix():
print('')
Expand Down
8 changes: 8 additions & 0 deletions structs/ata_struct_2_h.py
Expand Up @@ -33,11 +33,19 @@ def emit_func_longword(name, field, params):
}
""" % bit_params)

def emit_func_qword(name, field, params):
bit_params = dict(name=name, field=field, word_start=int(params))
print("""static inline ata_qword_t ata_get_%(name)s_%(field)s(const unsigned char *buf) {
return ata_get_qword(buf, %(word_start)d);
}
""" % bit_params)

kinds = {
'bit': emit_func_bit,
'bits': emit_func_bits,
'string': emit_func_string,
'longword': emit_func_longword,
'qword': emit_func_qword,
}

def emit_header_single(name, struct):
Expand Down

0 comments on commit 7206989

Please sign in to comment.