mirror of
https://github.com/ErnyTech/Open-USB-Extreme
synced 2025-01-15 13:07:33 +01:00
Remove some cast for improve error detection
Signed-off-by: Ernesto Castellotti <erny.castell@gmail.com>
This commit is contained in:
parent
4caee1c98f
commit
89d98a759a
@ -22,7 +22,7 @@ align (1) struct UsbExtremeV0
|
|||||||
char[USBEXTREME_NAME_LENGTH] name;
|
char[USBEXTREME_NAME_LENGTH] name;
|
||||||
char[USBEXTREME_ID_LENGTH] id;
|
char[USBEXTREME_ID_LENGTH] id;
|
||||||
uint8_t n_parts;
|
uint8_t n_parts;
|
||||||
uint8_t type;
|
SCECdvdMediaType type;
|
||||||
uint8_t[4] empty;
|
uint8_t[4] empty;
|
||||||
uint8_t magic;
|
uint8_t magic;
|
||||||
uint8_t[USBEXTREME_NAME_EXT_LENGTH] empty2;
|
uint8_t[USBEXTREME_NAME_EXT_LENGTH] empty2;
|
||||||
@ -35,10 +35,10 @@ align (1) struct UsbExtremeV1
|
|||||||
char[USBEXTREME_NAME_LENGTH] name;
|
char[USBEXTREME_NAME_LENGTH] name;
|
||||||
char[USBEXTREME_ID_LENGTH] id;
|
char[USBEXTREME_ID_LENGTH] id;
|
||||||
uint8_t n_parts;
|
uint8_t n_parts;
|
||||||
uint8_t type;
|
SCECdvdMediaType type;
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
uint8_t videoMode;
|
uint8_t videoMode;
|
||||||
uint8_t usbExtremeVersion;
|
UsbExtremeVersion usbExtremeVersion;
|
||||||
uint8_t magic;
|
uint8_t magic;
|
||||||
char[USBEXTREME_NAME_EXT_LENGTH] nameExt;
|
char[USBEXTREME_NAME_EXT_LENGTH] nameExt;
|
||||||
}
|
}
|
||||||
@ -47,28 +47,27 @@ struct UsbExtremeHeaders
|
|||||||
{
|
{
|
||||||
const(void)* firstHeader;
|
const(void)* firstHeader;
|
||||||
const(UsbExtremeBase)[] headers;
|
const(UsbExtremeBase)[] headers;
|
||||||
int numHeaders;
|
size_t numHeaders;
|
||||||
size_t headersLen;
|
size_t headersLen;
|
||||||
UsbExtremeVersion oueVersion;
|
UsbExtremeVersion oueVersion;
|
||||||
}
|
}
|
||||||
struct UsbExtremeFilestat
|
struct UsbExtremeFilestat
|
||||||
{
|
{
|
||||||
int offset;
|
size_t offset;
|
||||||
char[USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH] name;
|
char[USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH] name;
|
||||||
SCECdvdMediaType type;
|
SCECdvdMediaType type;
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
uint8_t videoMode;
|
uint8_t videoMode;
|
||||||
UsbExtremeVersion usbExtremeVersion;
|
UsbExtremeVersion usbExtremeVersion;
|
||||||
}
|
}
|
||||||
enum UsbExtremeVersion
|
enum UsbExtremeVersion : uint8_t
|
||||||
{
|
{
|
||||||
V0 = 0,
|
V0 = 0,
|
||||||
V1,
|
V1,
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
enum SCECdvdMediaType
|
enum SCECdvdMediaType : uint8_t
|
||||||
{
|
{
|
||||||
SCECdGDTFUNCFAIL = -1,
|
|
||||||
SCECdNODISC = 0,
|
SCECdNODISC = 0,
|
||||||
SCECdDETCT,
|
SCECdDETCT,
|
||||||
SCECdDETCTCD,
|
SCECdDETCTCD,
|
||||||
@ -85,9 +84,9 @@ enum SCECdvdMediaType
|
|||||||
SCECdIllegalMediaoffset,
|
SCECdIllegalMediaoffset,
|
||||||
}
|
}
|
||||||
extern (D) bool isOue(const(void)[] headers);
|
extern (D) bool isOue(const(void)[] headers);
|
||||||
extern (D) UsbExtremeVersion getVersion(uint8_t usbExtremeVersion);
|
extern (D) UsbExtremeVersion getVersion(UsbExtremeVersion usbExtremeVersion);
|
||||||
extern (D) int oueNumHeaders(const(void)[] headers);
|
extern (D) size_t oueNumHeaders(const(void)[] headers);
|
||||||
extern (D) int ouePointHeaders(ref const(UsbExtremeBase)[] headers, const(void)[] rawHeaders);
|
extern (D) size_t ouePointHeaders(ref const(UsbExtremeBase)[] headers, const(void)[] rawHeaders);
|
||||||
extern (D) UsbExtremeVersion oueHeadersVersion(const(void)[] headers);
|
extern (D) UsbExtremeVersion oueHeadersVersion(const(void)[] headers);
|
||||||
extern (D) int oueReadHeaders(ref UsbExtremeHeaders headers, const(void)[] rawHeaders);
|
extern (D) int oueReadHeaders(ref UsbExtremeHeaders headers, const(void)[] rawHeaders);
|
||||||
extern (D) UsbExtremeFilestat[] oueRead(UsbExtremeFilestat[] filestats, const(UsbExtremeHeaders) headers);
|
extern (D) UsbExtremeFilestat[] oueRead(UsbExtremeFilestat[] filestats, const(UsbExtremeHeaders) headers);
|
||||||
|
@ -71,7 +71,7 @@ typedef struct __attribute__((__packed__)) {
|
|||||||
} usb_extreme_v1;
|
} usb_extreme_v1;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int offset;
|
size_t offset;
|
||||||
char name[USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH];
|
char name[USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH];
|
||||||
SCECdvdMediaType type;
|
SCECdvdMediaType type;
|
||||||
u16 size;
|
u16 size;
|
||||||
@ -82,7 +82,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
void *first_header;
|
void *first_header;
|
||||||
usb_extreme_base *headers;
|
usb_extreme_base *headers;
|
||||||
int num_headers;
|
size_t num_headers;
|
||||||
size_t headerslen;
|
size_t headerslen;
|
||||||
usb_extreme_versions version;
|
usb_extreme_versions version;
|
||||||
} usb_extreme_headers;
|
} usb_extreme_headers;
|
||||||
@ -92,13 +92,13 @@ typedef struct {
|
|||||||
/* Global headers functions */
|
/* Global headers functions */
|
||||||
int is_oue(const void *headers, const size_t headerslen);
|
int is_oue(const void *headers, const size_t headerslen);
|
||||||
usb_extreme_versions get_version(u8 version);
|
usb_extreme_versions get_version(u8 version);
|
||||||
int oue_point_headers(usb_extreme_base **headers, void *raw_headers, size_t headerslen);
|
size_t oue_point_headers(usb_extreme_base **headers, void *raw_headers, size_t headerslen);
|
||||||
int oue_num_headers(int *num_headers, const void *headers, size_t headerslen);
|
size_t oue_num_headers(size_t *num_headers, const void *headers, size_t headerslen);
|
||||||
int oue_version(usb_extreme_versions *version, const void *headers, size_t headerslen);
|
int oue_version(usb_extreme_versions *version, const void *headers, size_t headerslen);
|
||||||
int oue_read_headers(usb_extreme_headers *headers, void *raw_headers, const size_t headerslen);
|
int oue_read_headers(usb_extreme_headers *headers, void *raw_headers, const size_t headerslen);
|
||||||
|
|
||||||
/* Read functions */
|
/* Read functions */
|
||||||
int oue_read(usb_extreme_filestat *filestats, const usb_extreme_headers headers, const int filestats_nlen);
|
size_t oue_read(usb_extreme_filestat *filestats, const usb_extreme_headers headers, const int filestats_nlen);
|
||||||
|
|
||||||
/* implementation in development
|
/* implementation in development
|
||||||
*
|
*
|
||||||
|
10
lib/cabi.d
10
lib/cabi.d
@ -7,16 +7,16 @@ extern(C) int is_oue(const(void)* headers, size_t headersLen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern(C) UsbExtremeVersion get_version(uint8_t usbExtremeVersion) {
|
extern(C) UsbExtremeVersion get_version(uint8_t usbExtremeVersion) {
|
||||||
return getVersion(usbExtremeVersion);
|
return getVersion(cast(UsbExtremeVersion) usbExtremeVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(C) int oue_num_headers(int *numHeaders, const(void) *headers, size_t headersLen) {
|
extern(C) size_t oue_num_headers(size_t *numHeaders, const(void) *headers, size_t headersLen) {
|
||||||
auto result = oueNumHeaders(headers[0..headersLen]);
|
auto result = oueNumHeaders(headers[0..headersLen]);
|
||||||
*numHeaders = result;
|
*numHeaders = result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(C) int oue_point_headers(const(UsbExtremeBase)** headers, const(void)* rawHeaders, size_t headersLen) {
|
extern(C) size_t oue_point_headers(const(UsbExtremeBase)** headers, const(void)* rawHeaders, size_t headersLen) {
|
||||||
auto len = headersLen / UsbExtremeBase.sizeof;
|
auto len = headersLen / UsbExtremeBase.sizeof;
|
||||||
const(UsbExtremeBase)[] headersArr = (*headers)[0..len];
|
const(UsbExtremeBase)[] headersArr = (*headers)[0..len];
|
||||||
return ouePointHeaders(headersArr, rawHeaders[0..headersLen]);
|
return ouePointHeaders(headersArr, rawHeaders[0..headersLen]);
|
||||||
@ -37,7 +37,7 @@ extern(C) int oue_read_headers(UsbExtremeHeaders* headers, const(void)* rawHeade
|
|||||||
return oueReadHeaders(*headers, rawHeaders[0..headersLen]);
|
return oueReadHeaders(*headers, rawHeaders[0..headersLen]);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(C) int oue_read(UsbExtremeFilestat* filestat, const(UsbExtremeHeaders) headers, int filestatsLen) {
|
extern(C) size_t oue_read(UsbExtremeFilestat* filestat, const(UsbExtremeHeaders) headers, int filestatsLen) {
|
||||||
auto result = oueRead(filestat[0..filestatsLen], headers);
|
auto result = oueRead(filestat[0..filestatsLen], headers);
|
||||||
return cast(int) result.length;
|
return result.length;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ align(1) struct UsbExtremeV0 {
|
|||||||
char[USBEXTREME_NAME_LENGTH] name;
|
char[USBEXTREME_NAME_LENGTH] name;
|
||||||
char[USBEXTREME_ID_LENGTH] id;
|
char[USBEXTREME_ID_LENGTH] id;
|
||||||
uint8_t n_parts;
|
uint8_t n_parts;
|
||||||
uint8_t type;
|
SCECdvdMediaType type;
|
||||||
uint8_t[4] empty;
|
uint8_t[4] empty;
|
||||||
uint8_t magic;
|
uint8_t magic;
|
||||||
uint8_t[USBEXTREME_NAME_EXT_LENGTH] empty2;
|
uint8_t[USBEXTREME_NAME_EXT_LENGTH] empty2;
|
||||||
@ -30,10 +30,10 @@ align(1) struct UsbExtremeV1 {
|
|||||||
char[USBEXTREME_NAME_LENGTH] name;
|
char[USBEXTREME_NAME_LENGTH] name;
|
||||||
char[USBEXTREME_ID_LENGTH] id;
|
char[USBEXTREME_ID_LENGTH] id;
|
||||||
uint8_t n_parts;
|
uint8_t n_parts;
|
||||||
uint8_t type;
|
SCECdvdMediaType type;
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
uint8_t videoMode;
|
uint8_t videoMode;
|
||||||
uint8_t usbExtremeVersion;
|
UsbExtremeVersion usbExtremeVersion;
|
||||||
uint8_t magic;
|
uint8_t magic;
|
||||||
char[USBEXTREME_NAME_EXT_LENGTH] nameExt;
|
char[USBEXTREME_NAME_EXT_LENGTH] nameExt;
|
||||||
}
|
}
|
||||||
@ -41,13 +41,13 @@ align(1) struct UsbExtremeV1 {
|
|||||||
struct UsbExtremeHeaders {
|
struct UsbExtremeHeaders {
|
||||||
const(void)* firstHeader;
|
const(void)* firstHeader;
|
||||||
const(UsbExtremeBase)[] headers;
|
const(UsbExtremeBase)[] headers;
|
||||||
int numHeaders;
|
size_t numHeaders;
|
||||||
size_t headersLen;
|
size_t headersLen;
|
||||||
UsbExtremeVersion oueVersion;
|
UsbExtremeVersion oueVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UsbExtremeFilestat {
|
struct UsbExtremeFilestat {
|
||||||
int offset;
|
size_t offset;
|
||||||
char[USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH] name;
|
char[USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH] name;
|
||||||
SCECdvdMediaType type;
|
SCECdvdMediaType type;
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
@ -55,14 +55,13 @@ struct UsbExtremeFilestat {
|
|||||||
UsbExtremeVersion usbExtremeVersion;
|
UsbExtremeVersion usbExtremeVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum UsbExtremeVersion {
|
enum UsbExtremeVersion : uint8_t {
|
||||||
V0 = 0x00,
|
V0 = 0x00,
|
||||||
V1,
|
V1,
|
||||||
Unknown
|
Unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SCECdvdMediaType {
|
enum SCECdvdMediaType : uint8_t {
|
||||||
SCECdGDTFUNCFAIL = -1,
|
|
||||||
SCECdNODISC = 0x00,
|
SCECdNODISC = 0x00,
|
||||||
SCECdDETCT,
|
SCECdDETCT,
|
||||||
SCECdDETCTCD,
|
SCECdDETCTCD,
|
||||||
@ -93,24 +92,24 @@ extern(D) bool isOue(const(void)[] headers) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(D) UsbExtremeVersion getVersion(uint8_t usbExtremeVersion) {
|
extern(D) UsbExtremeVersion getVersion(UsbExtremeVersion usbExtremeVersion) {
|
||||||
switch (usbExtremeVersion) {
|
switch (usbExtremeVersion) {
|
||||||
case 0: {
|
case UsbExtremeVersion.V0: {
|
||||||
return UsbExtremeVersion.V0;
|
return UsbExtremeVersion.V0;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1: {
|
case UsbExtremeVersion.V1: {
|
||||||
return UsbExtremeVersion.V1;
|
return UsbExtremeVersion.V1;
|
||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
return UsbExtremeVersion.V1;
|
return UsbExtremeVersion.V0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(D) int oueNumHeaders(const(void)[] headers) {
|
extern(D) size_t oueNumHeaders(const(void)[] headers) {
|
||||||
auto headersLen = cast(int) (castArray!(UsbExtremeBase)(headers).length);
|
auto headersLen = castArray!(UsbExtremeBase)(headers).length;
|
||||||
|
|
||||||
if (!isOue(headers)) {
|
if (!isOue(headers)) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -119,7 +118,7 @@ extern(D) int oueNumHeaders(const(void)[] headers) {
|
|||||||
return headersLen;
|
return headersLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(D) int ouePointHeaders(ref const(UsbExtremeBase)[] headers, const(void)[] rawHeaders) {
|
extern(D) size_t ouePointHeaders(ref const(UsbExtremeBase)[] headers, const(void)[] rawHeaders) {
|
||||||
auto headersLen = oueNumHeaders(rawHeaders);
|
auto headersLen = oueNumHeaders(rawHeaders);
|
||||||
|
|
||||||
if (headersLen <= 0) {
|
if (headersLen <= 0) {
|
||||||
@ -195,8 +194,8 @@ extern(D) UsbExtremeFilestat[] oueRead(UsbExtremeFilestat[] filestats, const(Usb
|
|||||||
}
|
}
|
||||||
|
|
||||||
filestat.size = size;
|
filestat.size = size;
|
||||||
filestat.type = cast(SCECdvdMediaType) header.type;
|
filestat.type = header.type;
|
||||||
filestat.offset = cast(int) i;
|
filestat.offset = i;
|
||||||
filestat.videoMode = videoMode;
|
filestat.videoMode = videoMode;
|
||||||
filestat.usbExtremeVersion = headerVersion;
|
filestat.usbExtremeVersion = headerVersion;
|
||||||
headersLength -= 1;
|
headersLength -= 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user