mirror of
https://github.com/aaru-dps/aaruremote.git
synced 2025-12-16 19:24:37 +00:00
Genera refactor and cleanup.
This commit is contained in:
129
linux/ata.c
129
linux/ata.c
@@ -29,33 +29,29 @@ int32_t AtaProtocolToScsiDirection(uint8_t protocol)
|
||||
case AARUREMOTE_ATA_PROTOCOL_HARD_RESET:
|
||||
case AARUREMOTE_ATA_PROTOCOL_NO_DATA:
|
||||
case AARUREMOTE_ATA_PROTOCOL_SOFT_RESET:
|
||||
case AARUREMOTE_ATA_PROTOCOL_RETURN_RESPONSE: return AARUREMOTE_SCSI_DIRECTION_NONE;
|
||||
case AARUREMOTE_ATA_PROTOCOL_RETURN_RESPONSE:
|
||||
return AARUREMOTE_SCSI_DIRECTION_NONE;
|
||||
case AARUREMOTE_ATA_PROTOCOL_PIO_IN:
|
||||
case AARUREMOTE_ATA_PROTOCOL_UDMA_IN: return AARUREMOTE_SCSI_DIRECTION_IN;
|
||||
case AARUREMOTE_ATA_PROTOCOL_UDMA_IN:
|
||||
return AARUREMOTE_SCSI_DIRECTION_IN;
|
||||
case AARUREMOTE_ATA_PROTOCOL_PIO_OUT:
|
||||
case AARUREMOTE_ATA_PROTOCOL_UDMA_OUT: return AARUREMOTE_SCSI_DIRECTION_OUT;
|
||||
default: return AARUREMOTE_SCSI_DIRECTION_UNSPECIFIED;
|
||||
case AARUREMOTE_ATA_PROTOCOL_UDMA_OUT:
|
||||
return AARUREMOTE_SCSI_DIRECTION_OUT;
|
||||
default:
|
||||
return AARUREMOTE_SCSI_DIRECTION_UNSPECIFIED;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t SendAtaChsCommand(void* device_ctx,
|
||||
AtaRegistersChs registers,
|
||||
AtaErrorRegistersChs* error_registers,
|
||||
uint8_t protocol,
|
||||
uint8_t transfer_register,
|
||||
char* buffer,
|
||||
uint32_t timeout,
|
||||
uint8_t transfer_blocks,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len)
|
||||
int32_t SendAtaChsCommand(void *device_ctx, AtaRegistersChs registers, AtaErrorRegistersChs *error_registers,
|
||||
uint8_t protocol, uint8_t transfer_register, char *buffer, uint32_t timeout,
|
||||
uint8_t transfer_blocks, uint32_t *duration, uint32_t *sense, uint32_t *buf_len)
|
||||
{
|
||||
*duration = 0;
|
||||
*sense = 0;
|
||||
unsigned char cdb[16];
|
||||
char* sense_buf;
|
||||
char *sense_buf;
|
||||
uint32_t sense_len;
|
||||
DeviceContext* ctx = device_ctx;
|
||||
DeviceContext *ctx = device_ctx;
|
||||
|
||||
if(!ctx) return -1;
|
||||
|
||||
@@ -68,8 +64,12 @@ int32_t SendAtaChsCommand(void* device_ctx,
|
||||
switch(protocol)
|
||||
{
|
||||
case AARUREMOTE_ATA_PROTOCOL_PIO_IN:
|
||||
case AARUREMOTE_ATA_PROTOCOL_UDMA_IN: cdb[2] = 0x08; break;
|
||||
default: cdb[2] = 0x00; break;
|
||||
case AARUREMOTE_ATA_PROTOCOL_UDMA_IN:
|
||||
cdb[2] = 0x08;
|
||||
break;
|
||||
default:
|
||||
cdb[2] = 0x00;
|
||||
break;
|
||||
}
|
||||
|
||||
if(transfer_blocks) cdb[2] |= 0x04;
|
||||
@@ -85,17 +85,8 @@ int32_t SendAtaChsCommand(void* device_ctx,
|
||||
cdb[13] = registers.device_head;
|
||||
cdb[14] = registers.command;
|
||||
|
||||
int error = SendScsiCommand(ctx,
|
||||
(char*)cdb,
|
||||
buffer,
|
||||
&sense_buf,
|
||||
timeout,
|
||||
AtaProtocolToScsiDirection(protocol),
|
||||
duration,
|
||||
sense,
|
||||
16,
|
||||
buf_len,
|
||||
&sense_len);
|
||||
int error = SendScsiCommand(ctx, (char *)cdb, buffer, &sense_buf, timeout, AtaProtocolToScsiDirection(protocol),
|
||||
duration, sense, 16, buf_len, &sense_len);
|
||||
|
||||
if(sense_len < 22 || (sense_buf[8] != 0x09 && sense_buf[9] != 0x0C)) return error;
|
||||
|
||||
@@ -113,24 +104,16 @@ int32_t SendAtaChsCommand(void* device_ctx,
|
||||
return error;
|
||||
}
|
||||
|
||||
int32_t SendAtaLba28Command(void* device_ctx,
|
||||
AtaRegistersLba28 registers,
|
||||
AtaErrorRegistersLba28* error_registers,
|
||||
uint8_t protocol,
|
||||
uint8_t transfer_register,
|
||||
char* buffer,
|
||||
uint32_t timeout,
|
||||
uint8_t transfer_blocks,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len)
|
||||
int32_t SendAtaLba28Command(void *device_ctx, AtaRegistersLba28 registers, AtaErrorRegistersLba28 *error_registers,
|
||||
uint8_t protocol, uint8_t transfer_register, char *buffer, uint32_t timeout,
|
||||
uint8_t transfer_blocks, uint32_t *duration, uint32_t *sense, uint32_t *buf_len)
|
||||
{
|
||||
*duration = 0;
|
||||
*sense = 0;
|
||||
unsigned char cdb[16];
|
||||
char* sense_buf;
|
||||
char *sense_buf;
|
||||
uint32_t sense_len;
|
||||
DeviceContext* ctx = device_ctx;
|
||||
DeviceContext *ctx = device_ctx;
|
||||
|
||||
if(!ctx) return -1;
|
||||
|
||||
@@ -143,8 +126,12 @@ int32_t SendAtaLba28Command(void* device_ctx,
|
||||
switch(protocol)
|
||||
{
|
||||
case AARUREMOTE_ATA_PROTOCOL_PIO_IN:
|
||||
case AARUREMOTE_ATA_PROTOCOL_UDMA_IN: cdb[2] = 0x08; break;
|
||||
default: cdb[2] = 0x00; break;
|
||||
case AARUREMOTE_ATA_PROTOCOL_UDMA_IN:
|
||||
cdb[2] = 0x08;
|
||||
break;
|
||||
default:
|
||||
cdb[2] = 0x00;
|
||||
break;
|
||||
}
|
||||
|
||||
if(transfer_blocks) cdb[2] |= 0x04;
|
||||
@@ -162,17 +149,8 @@ int32_t SendAtaLba28Command(void* device_ctx,
|
||||
cdb[13] = registers.device_head;
|
||||
cdb[14] = registers.command;
|
||||
|
||||
int error = SendScsiCommand(ctx,
|
||||
(char*)cdb,
|
||||
buffer,
|
||||
&sense_buf,
|
||||
timeout,
|
||||
AtaProtocolToScsiDirection(protocol),
|
||||
duration,
|
||||
sense,
|
||||
16,
|
||||
buf_len,
|
||||
&sense_len);
|
||||
int error = SendScsiCommand(ctx, (char *)cdb, buffer, &sense_buf, timeout, AtaProtocolToScsiDirection(protocol),
|
||||
duration, sense, 16, buf_len, &sense_len);
|
||||
|
||||
if(sense_len < 22 || (sense_buf[8] != 0x09 && sense_buf[9] != 0x0C)) return error;
|
||||
|
||||
@@ -190,24 +168,16 @@ int32_t SendAtaLba28Command(void* device_ctx,
|
||||
return error;
|
||||
}
|
||||
|
||||
int32_t SendAtaLba48Command(void* device_ctx,
|
||||
AtaRegistersLba48 registers,
|
||||
AtaErrorRegistersLba48* error_registers,
|
||||
uint8_t protocol,
|
||||
uint8_t transfer_register,
|
||||
char* buffer,
|
||||
uint32_t timeout,
|
||||
uint8_t transfer_blocks,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len)
|
||||
int32_t SendAtaLba48Command(void *device_ctx, AtaRegistersLba48 registers, AtaErrorRegistersLba48 *error_registers,
|
||||
uint8_t protocol, uint8_t transfer_register, char *buffer, uint32_t timeout,
|
||||
uint8_t transfer_blocks, uint32_t *duration, uint32_t *sense, uint32_t *buf_len)
|
||||
{
|
||||
*duration = 0;
|
||||
*sense = 0;
|
||||
unsigned char cdb[16];
|
||||
char* sense_buf;
|
||||
char *sense_buf;
|
||||
uint32_t sense_len;
|
||||
DeviceContext* ctx = device_ctx;
|
||||
DeviceContext *ctx = device_ctx;
|
||||
|
||||
if(!ctx) return -1;
|
||||
|
||||
@@ -221,8 +191,12 @@ int32_t SendAtaLba48Command(void* device_ctx,
|
||||
switch(protocol)
|
||||
{
|
||||
case AARUREMOTE_ATA_PROTOCOL_PIO_IN:
|
||||
case AARUREMOTE_ATA_PROTOCOL_UDMA_IN: cdb[2] = 0x08; break;
|
||||
default: cdb[2] = 0x00; break;
|
||||
case AARUREMOTE_ATA_PROTOCOL_UDMA_IN:
|
||||
cdb[2] = 0x08;
|
||||
break;
|
||||
default:
|
||||
cdb[2] = 0x00;
|
||||
break;
|
||||
}
|
||||
|
||||
if(transfer_blocks) cdb[2] |= 0x04;
|
||||
@@ -245,17 +219,8 @@ int32_t SendAtaLba48Command(void* device_ctx,
|
||||
cdb[13] = registers.device_head;
|
||||
cdb[14] = registers.command;
|
||||
|
||||
int error = SendScsiCommand(ctx,
|
||||
(char*)cdb,
|
||||
buffer,
|
||||
&sense_buf,
|
||||
timeout,
|
||||
AtaProtocolToScsiDirection(protocol),
|
||||
duration,
|
||||
sense,
|
||||
16,
|
||||
buf_len,
|
||||
&sense_len);
|
||||
int error = SendScsiCommand(ctx, (char *)cdb, buffer, &sense_buf, timeout, AtaProtocolToScsiDirection(protocol),
|
||||
duration, sense, 16, buf_len, &sense_len);
|
||||
|
||||
if(sense_len < 22 || (sense_buf[8] != 0x09 && sense_buf[9] != 0x0C)) return error;
|
||||
|
||||
|
||||
156
linux/device.c
156
linux/device.c
@@ -30,9 +30,9 @@
|
||||
#include "../aaruremote.h"
|
||||
#include "linux.h"
|
||||
|
||||
void* DeviceOpen(const char* device_path)
|
||||
void *DeviceOpen(const char *device_path)
|
||||
{
|
||||
DeviceContext* ctx;
|
||||
DeviceContext *ctx;
|
||||
|
||||
char *real_device_path = realpath(device_path, NULL);
|
||||
if(real_device_path != NULL)
|
||||
@@ -68,9 +68,9 @@ void* DeviceOpen(const char* device_path)
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void DeviceClose(void* device_ctx)
|
||||
void DeviceClose(void *device_ctx)
|
||||
{
|
||||
DeviceContext* ctx = device_ctx;
|
||||
DeviceContext *ctx = device_ctx;
|
||||
|
||||
if(!ctx) return;
|
||||
|
||||
@@ -79,17 +79,17 @@ void DeviceClose(void* device_ctx)
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
int32_t GetDeviceType(void* device_ctx)
|
||||
int32_t GetDeviceType(void *device_ctx)
|
||||
{
|
||||
DeviceContext* ctx = device_ctx;
|
||||
DeviceContext *ctx = device_ctx;
|
||||
|
||||
if(!ctx) return -1;
|
||||
|
||||
#ifdef HAS_UDEV
|
||||
struct udev* udev;
|
||||
struct udev_device* udev_device;
|
||||
const char* tmp_string;
|
||||
char* chrptr;
|
||||
struct udev *udev;
|
||||
struct udev_device *udev_device;
|
||||
const char *tmp_string;
|
||||
char *chrptr;
|
||||
int32_t device_type = AARUREMOTE_DEVICE_TYPE_UNKNOWN;
|
||||
|
||||
udev = udev_new();
|
||||
@@ -112,7 +112,7 @@ int32_t GetDeviceType(void* device_ctx)
|
||||
{
|
||||
device_type = AARUREMOTE_DEVICE_TYPE_ATA;
|
||||
|
||||
free((void*)tmp_string);
|
||||
free((void *)tmp_string);
|
||||
tmp_string = udev_device_get_property_value(udev_device, "ID_TYPE");
|
||||
|
||||
if(tmp_string)
|
||||
@@ -120,30 +120,30 @@ int32_t GetDeviceType(void* device_ctx)
|
||||
// TODO: ATAPI removable non optical disks
|
||||
if(strncmp(tmp_string, "cd", 2) == 0) { device_type = AARUREMOTE_DEVICE_TYPE_ATAPI; }
|
||||
|
||||
free((void*)tmp_string);
|
||||
free((void *)tmp_string);
|
||||
}
|
||||
}
|
||||
else if(strncmp(tmp_string, "mmc", 3) == 0)
|
||||
{
|
||||
free((void*)tmp_string);
|
||||
free((void *)tmp_string);
|
||||
tmp_string = malloc(1024);
|
||||
|
||||
device_type = AARUREMOTE_DEVICE_TYPE_MMC;
|
||||
|
||||
if(tmp_string)
|
||||
{
|
||||
memset((void*)tmp_string, 0, 1024);
|
||||
snprintf((char*)tmp_string, 1024, "/sys/block/%s/device/scr", chrptr);
|
||||
memset((void *)tmp_string, 0, 1024);
|
||||
snprintf((char *)tmp_string, 1024, "/sys/block/%s/device/scr", chrptr);
|
||||
|
||||
if(access(tmp_string, R_OK) == 0) device_type = AARUREMOTE_DEVICE_TYPE_SECURE_DIGITAL;
|
||||
|
||||
free((void*)tmp_string);
|
||||
free((void *)tmp_string);
|
||||
}
|
||||
}
|
||||
else if(strncmp(tmp_string, "scsi", 4) == 0 || strncmp(tmp_string, "ieee1394", 8) == 0 ||
|
||||
strncmp(tmp_string, "usb", 3) == 0)
|
||||
{
|
||||
free((void*)tmp_string);
|
||||
free((void *)tmp_string);
|
||||
tmp_string = udev_device_get_property_value(udev_device, "ID_TYPE");
|
||||
|
||||
if(tmp_string)
|
||||
@@ -152,12 +152,12 @@ int32_t GetDeviceType(void* device_ctx)
|
||||
strncmp(tmp_string, "optical", 7) == 0)
|
||||
device_type = AARUREMOTE_DEVICE_TYPE_SCSI;
|
||||
|
||||
free((void*)tmp_string);
|
||||
free((void *)tmp_string);
|
||||
}
|
||||
}
|
||||
else if(strncmp(tmp_string, "nvme", 4) == 0)
|
||||
{
|
||||
free((void*)tmp_string);
|
||||
free((void *)tmp_string);
|
||||
device_type = AARUREMOTE_DEVICE_TYPE_NVME;
|
||||
}
|
||||
}
|
||||
@@ -168,20 +168,20 @@ int32_t GetDeviceType(void* device_ctx)
|
||||
return device_type;
|
||||
#else
|
||||
int32_t dev_type = AARUREMOTE_DEVICE_TYPE_UNKNOWN;
|
||||
const char* dev_name;
|
||||
const char* sysfs_path;
|
||||
char* dev_path;
|
||||
char* dev_path2;
|
||||
char* host_no;
|
||||
char* scsi_path;
|
||||
char* iscsi_path;
|
||||
char* spi_path;
|
||||
char* fc_path;
|
||||
char* sas_path;
|
||||
const char *dev_name;
|
||||
const char *sysfs_path;
|
||||
char *dev_path;
|
||||
char *dev_path2;
|
||||
char *host_no;
|
||||
char *scsi_path;
|
||||
char *iscsi_path;
|
||||
char *spi_path;
|
||||
char *fc_path;
|
||||
char *sas_path;
|
||||
int ret;
|
||||
char* chrptr;
|
||||
char* sysfs_path_scr;
|
||||
FILE* file;
|
||||
char *chrptr;
|
||||
char *sysfs_path_scr;
|
||||
FILE *file;
|
||||
size_t len = 4096;
|
||||
|
||||
if(strlen(ctx->device_path) <= 5) return dev_type;
|
||||
@@ -219,40 +219,40 @@ int32_t GetDeviceType(void* device_ctx)
|
||||
|
||||
if(!sysfs_path || !dev_path || !host_no || !scsi_path || !iscsi_path || !spi_path || !fc_path || !sas_path)
|
||||
{
|
||||
free((void*)sysfs_path);
|
||||
free((void*)dev_path);
|
||||
free((void*)host_no);
|
||||
free((void*)iscsi_path);
|
||||
free((void*)scsi_path);
|
||||
free((void*)spi_path);
|
||||
free((void*)fc_path);
|
||||
free((void*)sas_path);
|
||||
free((void *)sysfs_path);
|
||||
free((void *)dev_path);
|
||||
free((void *)host_no);
|
||||
free((void *)iscsi_path);
|
||||
free((void *)scsi_path);
|
||||
free((void *)spi_path);
|
||||
free((void *)fc_path);
|
||||
free((void *)sas_path);
|
||||
return dev_type;
|
||||
}
|
||||
|
||||
memset((void*)sysfs_path, 0, len);
|
||||
memset((void*)dev_path, 0, len);
|
||||
memset((void*)host_no, 0, len);
|
||||
memset((void*)iscsi_path, 0, len);
|
||||
memset((void*)scsi_path, 0, len);
|
||||
memset((void*)spi_path, 0, len);
|
||||
memset((void*)fc_path, 0, len);
|
||||
memset((void*)sas_path, 0, len);
|
||||
memset((void *)sysfs_path, 0, len);
|
||||
memset((void *)dev_path, 0, len);
|
||||
memset((void *)host_no, 0, len);
|
||||
memset((void *)iscsi_path, 0, len);
|
||||
memset((void *)scsi_path, 0, len);
|
||||
memset((void *)spi_path, 0, len);
|
||||
memset((void *)fc_path, 0, len);
|
||||
memset((void *)sas_path, 0, len);
|
||||
|
||||
snprintf((char*)sysfs_path, len, "%s/%s/device", PATH_SYS_DEVBLOCK, dev_name);
|
||||
snprintf((char *)sysfs_path, len, "%s/%s/device", PATH_SYS_DEVBLOCK, dev_name);
|
||||
|
||||
ret = readlink(sysfs_path, dev_path, len);
|
||||
|
||||
if(ret <= 0)
|
||||
{
|
||||
free((void*)sysfs_path);
|
||||
free((void*)dev_path);
|
||||
free((void*)host_no);
|
||||
free((void*)iscsi_path);
|
||||
free((void*)scsi_path);
|
||||
free((void*)spi_path);
|
||||
free((void*)fc_path);
|
||||
free((void*)sas_path);
|
||||
free((void *)sysfs_path);
|
||||
free((void *)dev_path);
|
||||
free((void *)host_no);
|
||||
free((void *)iscsi_path);
|
||||
free((void *)scsi_path);
|
||||
free((void *)spi_path);
|
||||
free((void *)fc_path);
|
||||
free((void *)sas_path);
|
||||
return dev_type;
|
||||
}
|
||||
|
||||
@@ -275,14 +275,14 @@ int32_t GetDeviceType(void* device_ctx)
|
||||
|
||||
if(!chrptr)
|
||||
{
|
||||
free((void*)sysfs_path);
|
||||
free((void*)dev_path);
|
||||
free((void*)host_no);
|
||||
free((void*)iscsi_path);
|
||||
free((void*)scsi_path);
|
||||
free((void*)spi_path);
|
||||
free((void*)fc_path);
|
||||
free((void*)sas_path);
|
||||
free((void *)sysfs_path);
|
||||
free((void *)dev_path);
|
||||
free((void *)host_no);
|
||||
free((void *)iscsi_path);
|
||||
free((void *)scsi_path);
|
||||
free((void *)spi_path);
|
||||
free((void *)fc_path);
|
||||
free((void *)sas_path);
|
||||
return dev_type;
|
||||
}
|
||||
|
||||
@@ -339,22 +339,22 @@ int32_t GetDeviceType(void* device_ctx)
|
||||
}
|
||||
}
|
||||
|
||||
free((void*)sysfs_path);
|
||||
free((void*)dev_path);
|
||||
free((void*)host_no);
|
||||
free((void*)iscsi_path);
|
||||
free((void*)scsi_path);
|
||||
free((void*)spi_path);
|
||||
free((void*)fc_path);
|
||||
free((void*)sas_path);
|
||||
free((void *)sysfs_path);
|
||||
free((void *)dev_path);
|
||||
free((void *)host_no);
|
||||
free((void *)iscsi_path);
|
||||
free((void *)scsi_path);
|
||||
free((void *)spi_path);
|
||||
free((void *)fc_path);
|
||||
free((void *)sas_path);
|
||||
|
||||
return dev_type;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t ReOpen(void* device_ctx, uint32_t* closeFailed)
|
||||
int32_t ReOpen(void *device_ctx, uint32_t *closeFailed)
|
||||
{
|
||||
DeviceContext* ctx = device_ctx;
|
||||
DeviceContext *ctx = device_ctx;
|
||||
int ret;
|
||||
*closeFailed = 0;
|
||||
|
||||
@@ -375,9 +375,9 @@ int32_t ReOpen(void* device_ctx, uint32_t* closeFailed)
|
||||
return ctx->fd <= 0 ? errno : 0;
|
||||
}
|
||||
|
||||
int32_t OsRead(void* device_ctx, char* buffer, uint64_t offset, uint32_t length, uint32_t* duration)
|
||||
int32_t OsRead(void *device_ctx, char *buffer, uint64_t offset, uint32_t length, uint32_t *duration)
|
||||
{
|
||||
DeviceContext* ctx = device_ctx;
|
||||
DeviceContext *ctx = device_ctx;
|
||||
ssize_t ret;
|
||||
*duration = 0;
|
||||
off_t pos;
|
||||
@@ -390,7 +390,7 @@ int32_t OsRead(void* device_ctx, char* buffer, uint64_t offset, uint32_t length,
|
||||
if(pos < 0) return errno;
|
||||
|
||||
// TODO: Timing
|
||||
ret = read(ctx->fd, (void*)buffer, (size_t)length);
|
||||
ret = read(ctx->fd, (void *)buffer, (size_t)length);
|
||||
|
||||
return ret < 0 ? errno : 0;
|
||||
}
|
||||
@@ -24,22 +24,18 @@
|
||||
#include "../aaruremote.h"
|
||||
#include "linux.h"
|
||||
|
||||
uint8_t GetFireWireData(void* device_ctx,
|
||||
uint32_t* id_model,
|
||||
uint32_t* id_vendor,
|
||||
uint64_t* guid,
|
||||
char* vendor,
|
||||
char* model)
|
||||
uint8_t GetFireWireData(void *device_ctx, uint32_t *id_model, uint32_t *id_vendor, uint64_t *guid, char *vendor,
|
||||
char *model)
|
||||
{
|
||||
DeviceContext* ctx = device_ctx;
|
||||
char* dev_path;
|
||||
DeviceContext *ctx = device_ctx;
|
||||
char *dev_path;
|
||||
char tmp_path[4096];
|
||||
char resolved_link[4096];
|
||||
struct stat sb;
|
||||
ssize_t len;
|
||||
char* rchr;
|
||||
char *rchr;
|
||||
int found;
|
||||
FILE* file;
|
||||
FILE *file;
|
||||
|
||||
if(!ctx) return 0;
|
||||
|
||||
@@ -53,7 +49,7 @@ uint8_t GetFireWireData(void* device_ctx,
|
||||
strncmp(ctx->device_path, "/dev/st", 7) != 0)
|
||||
return 0;
|
||||
|
||||
dev_path = (char*)ctx->device_path + 5;
|
||||
dev_path = (char *)ctx->device_path + 5;
|
||||
|
||||
snprintf(tmp_path, 4096, "/sys/block/%s", dev_path);
|
||||
|
||||
|
||||
@@ -26,4 +26,4 @@ typedef struct
|
||||
char device_path[4096];
|
||||
} DeviceContext;
|
||||
|
||||
#endif // AARUREMOTE_LINUX_LINUX_H_
|
||||
#endif // AARUREMOTE_LINUX_LINUX_H_
|
||||
|
||||
@@ -31,21 +31,21 @@
|
||||
#include "../aaruremote.h"
|
||||
#include "linux.h"
|
||||
|
||||
DeviceInfoList* ListDevices()
|
||||
DeviceInfoList *ListDevices()
|
||||
{
|
||||
DIR* dir;
|
||||
struct dirent* dirent;
|
||||
DIR *dir;
|
||||
struct dirent *dirent;
|
||||
int i;
|
||||
DeviceInfoList *list_start = NULL, *list_current = NULL, *list_next = NULL;
|
||||
const char* tmp_string;
|
||||
FILE* file;
|
||||
char* line_str;
|
||||
const char *tmp_string;
|
||||
FILE *file;
|
||||
char *line_str;
|
||||
size_t n, ret;
|
||||
char* chrptr;
|
||||
char *chrptr;
|
||||
int has_udev = 0;
|
||||
#ifdef HAS_UDEV
|
||||
struct udev* udev;
|
||||
struct udev_device* udev_device;
|
||||
struct udev *udev;
|
||||
struct udev_device *udev_device;
|
||||
|
||||
udev = udev_new();
|
||||
has_udev = udev != 0;
|
||||
@@ -95,14 +95,14 @@ DeviceInfoList* ListDevices()
|
||||
if(tmp_string)
|
||||
{
|
||||
strncpy(list_next->this.vendor, tmp_string, 256);
|
||||
free((void*)tmp_string);
|
||||
free((void *)tmp_string);
|
||||
}
|
||||
|
||||
tmp_string = udev_device_get_property_value(udev_device, "ID_MODEL");
|
||||
if(tmp_string)
|
||||
{
|
||||
strncpy(list_next->this.model, tmp_string, 256);
|
||||
free((void*)tmp_string);
|
||||
free((void *)tmp_string);
|
||||
|
||||
for(i = 0; i < 256; i++)
|
||||
{
|
||||
@@ -116,7 +116,7 @@ DeviceInfoList* ListDevices()
|
||||
if(tmp_string)
|
||||
{
|
||||
strncpy(list_next->this.serial, tmp_string, 256);
|
||||
free((void*)tmp_string);
|
||||
free((void *)tmp_string);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -124,7 +124,7 @@ DeviceInfoList* ListDevices()
|
||||
if(tmp_string)
|
||||
{
|
||||
strncpy(list_next->this.serial, tmp_string, 256);
|
||||
free((void*)tmp_string);
|
||||
free((void *)tmp_string);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,11 +132,11 @@ DeviceInfoList* ListDevices()
|
||||
if(tmp_string)
|
||||
{
|
||||
strncpy(list_next->this.bus, tmp_string, 256);
|
||||
free((void*)tmp_string);
|
||||
free((void *)tmp_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else // Use sysfs
|
||||
#else // Use sysfs
|
||||
if(!has_udev && !strstr(dirent->d_name, "loop"))
|
||||
{
|
||||
memset((void*)tmp_ctx.device_path, 0, 4096);
|
||||
@@ -144,11 +144,19 @@ DeviceInfoList* ListDevices()
|
||||
|
||||
switch(GetDeviceType(&tmp_ctx))
|
||||
{
|
||||
case AARUREMOTE_DEVICE_TYPE_ATA: strncpy(list_next->this.bus, "ATA", 256); break;
|
||||
case AARUREMOTE_DEVICE_TYPE_ATAPI: strncpy(list_next->this.bus, "ATAPI", 256); break;
|
||||
case AARUREMOTE_DEVICE_TYPE_ATA:
|
||||
strncpy(list_next->this.bus, "ATA", 256);
|
||||
break;
|
||||
case AARUREMOTE_DEVICE_TYPE_ATAPI:
|
||||
strncpy(list_next->this.bus, "ATAPI", 256);
|
||||
break;
|
||||
case AARUREMOTE_DEVICE_TYPE_MMC:
|
||||
case AARUREMOTE_DEVICE_TYPE_SECURE_DIGITAL: strncpy(list_next->this.bus, "MMC/SD", 256); break;
|
||||
case AARUREMOTE_DEVICE_TYPE_NVME: strncpy(list_next->this.bus, "NVMe", 256); break;
|
||||
case AARUREMOTE_DEVICE_TYPE_SECURE_DIGITAL:
|
||||
strncpy(list_next->this.bus, "MMC/SD", 256);
|
||||
break;
|
||||
case AARUREMOTE_DEVICE_TYPE_NVME:
|
||||
strncpy(list_next->this.bus, "NVMe", 256);
|
||||
break;
|
||||
case AARUREMOTE_DEVICE_TYPE_SCSI:
|
||||
tmp_string = malloc(1024);
|
||||
memset((void*)tmp_string, 0, 1024);
|
||||
@@ -175,10 +183,10 @@ DeviceInfoList* ListDevices()
|
||||
chrptr--;
|
||||
}
|
||||
|
||||
memset((void*)tmp_string, 0, 1024);
|
||||
memcpy((void*)tmp_string, chrptr, ret);
|
||||
snprintf((char*)line_str, 1024, "/sys/class/scsi_host/host%s/proc_name", tmp_string);
|
||||
memset((void*)tmp_string, 0, 1024);
|
||||
memset((void *)tmp_string, 0, 1024);
|
||||
memcpy((void *)tmp_string, chrptr, ret);
|
||||
snprintf((char *)line_str, 1024, "/sys/class/scsi_host/host%s/proc_name", tmp_string);
|
||||
memset((void *)tmp_string, 0, 1024);
|
||||
|
||||
file = fopen(line_str, "r");
|
||||
if(file)
|
||||
@@ -188,7 +196,8 @@ DeviceInfoList* ListDevices()
|
||||
|
||||
if(ret > 0)
|
||||
{
|
||||
if(strncmp(line_str, "sbp2", 4) == 0) strncpy(list_next->this.bus, "FireWire", 256);
|
||||
if(strncmp(line_str, "sbp2", 4) == 0)
|
||||
strncpy(list_next->this.bus, "FireWire", 256);
|
||||
else if(strncmp(line_str, "usb-storage", 11) == 0)
|
||||
strncpy(list_next->this.bus, "USB", 256);
|
||||
else
|
||||
@@ -212,14 +221,16 @@ DeviceInfoList* ListDevices()
|
||||
|
||||
free((void*)tmp_string);
|
||||
break;
|
||||
default: memset(&list_next->this.bus, 0, 256); break;
|
||||
default:
|
||||
memset(&list_next->this.bus, 0, 256);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
tmp_string = malloc(1024);
|
||||
memset((void*)tmp_string, 0, 1024);
|
||||
snprintf((char*)tmp_string, 1024, "%s/%s/device/vendor", PATH_SYS_DEVBLOCK, dirent->d_name);
|
||||
memset((void *)tmp_string, 0, 1024);
|
||||
snprintf((char *)tmp_string, 1024, "%s/%s/device/vendor", PATH_SYS_DEVBLOCK, dirent->d_name);
|
||||
|
||||
if(access(tmp_string, R_OK) == 0 && strlen(list_next->this.vendor) == 0)
|
||||
{
|
||||
@@ -237,7 +248,8 @@ DeviceInfoList* ListDevices()
|
||||
strncpy(list_next->this.vendor, line_str, 256);
|
||||
for(i = 255; i >= 0; i--)
|
||||
{
|
||||
if(list_next->this.vendor[i] == 0) continue;
|
||||
if(list_next->this.vendor[i] == 0)
|
||||
continue;
|
||||
|
||||
else if(list_next->this.vendor[i] == 0x0A || list_next->this.vendor[i] == 0x0D ||
|
||||
list_next->this.vendor[i] == ' ')
|
||||
@@ -251,15 +263,12 @@ DeviceInfoList* ListDevices()
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
else if(strncmp(dirent->d_name, "loop", 4) == 0)
|
||||
{
|
||||
strncpy(list_next->this.vendor, "Linux", 256);
|
||||
}
|
||||
free((void*)tmp_string);
|
||||
else if(strncmp(dirent->d_name, "loop", 4) == 0) { strncpy(list_next->this.vendor, "Linux", 256); }
|
||||
free((void *)tmp_string);
|
||||
|
||||
tmp_string = malloc(1024);
|
||||
memset((void*)tmp_string, 0, 1024);
|
||||
snprintf((char*)tmp_string, 1024, "%s/%s/device/model", PATH_SYS_DEVBLOCK, dirent->d_name);
|
||||
memset((void *)tmp_string, 0, 1024);
|
||||
snprintf((char *)tmp_string, 1024, "%s/%s/device/model", PATH_SYS_DEVBLOCK, dirent->d_name);
|
||||
|
||||
if(access(tmp_string, R_OK) == 0 &&
|
||||
(strlen(list_next->this.model) == 0 || strncmp(list_next->this.bus, "ata", 3) == 0))
|
||||
@@ -278,7 +287,8 @@ DeviceInfoList* ListDevices()
|
||||
strncpy(list_next->this.model, line_str, 256);
|
||||
for(i = 255; i >= 0; i--)
|
||||
{
|
||||
if(list_next->this.model[i] == 0) continue;
|
||||
if(list_next->this.model[i] == 0)
|
||||
continue;
|
||||
|
||||
else if(list_next->this.model[i] == 0x0A || list_next->this.model[i] == 0x0D ||
|
||||
list_next->this.model[i] == ' ')
|
||||
@@ -292,15 +302,12 @@ DeviceInfoList* ListDevices()
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
else if(strncmp(dirent->d_name, "loop", 4) == 0)
|
||||
{
|
||||
strncpy(list_next->this.model, "Linux", 256);
|
||||
}
|
||||
free((void*)tmp_string);
|
||||
else if(strncmp(dirent->d_name, "loop", 4) == 0) { strncpy(list_next->this.model, "Linux", 256); }
|
||||
free((void *)tmp_string);
|
||||
|
||||
tmp_string = malloc(1024);
|
||||
memset((void*)tmp_string, 0, 1024);
|
||||
snprintf((char*)tmp_string, 1024, "%s/%s/device/serial", PATH_SYS_DEVBLOCK, dirent->d_name);
|
||||
memset((void *)tmp_string, 0, 1024);
|
||||
snprintf((char *)tmp_string, 1024, "%s/%s/device/serial", PATH_SYS_DEVBLOCK, dirent->d_name);
|
||||
|
||||
if(access(tmp_string, R_OK) == 0 && (strlen(list_next->this.serial) == 0))
|
||||
{
|
||||
@@ -318,7 +325,8 @@ DeviceInfoList* ListDevices()
|
||||
strncpy(list_next->this.serial, line_str, 256);
|
||||
for(i = 255; i >= 0; i--)
|
||||
{
|
||||
if(list_next->this.serial[i] == 0) continue;
|
||||
if(list_next->this.serial[i] == 0)
|
||||
continue;
|
||||
|
||||
else if(list_next->this.serial[i] == 0x0A || list_next->this.serial[i] == 0x0D ||
|
||||
list_next->this.serial[i] == ' ')
|
||||
@@ -332,14 +340,14 @@ DeviceInfoList* ListDevices()
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
free((void*)tmp_string);
|
||||
free((void *)tmp_string);
|
||||
|
||||
if(strlen(list_next->this.vendor) == 0 || strncmp(list_next->this.vendor, "ATA", 3) == 0)
|
||||
{
|
||||
if(strlen(list_next->this.model) > 0)
|
||||
{
|
||||
tmp_string = malloc(256);
|
||||
strncpy((void*)tmp_string, list_next->this.model, 256);
|
||||
strncpy((void *)tmp_string, list_next->this.model, 256);
|
||||
|
||||
chrptr = strchr(tmp_string, ' ');
|
||||
|
||||
@@ -351,14 +359,15 @@ DeviceInfoList* ListDevices()
|
||||
strncpy(list_next->this.model, chrptr + 1, 256 - (chrptr - tmp_string) - 1);
|
||||
}
|
||||
|
||||
free((void*)tmp_string);
|
||||
free((void *)tmp_string);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Get better device type from sysfs paths
|
||||
if(strlen(list_next->this.bus) == 0)
|
||||
{
|
||||
if(strncmp(dirent->d_name, "loop", 4) == 0) strncpy(list_next->this.bus, "loop", 4);
|
||||
if(strncmp(dirent->d_name, "loop", 4) == 0)
|
||||
strncpy(list_next->this.bus, "loop", 4);
|
||||
else if(strncmp(dirent->d_name, "nvme", 4) == 0)
|
||||
strncpy(list_next->this.bus, "NVMe", 4);
|
||||
else if(strncmp(dirent->d_name, "mmc", 3) == 0)
|
||||
|
||||
@@ -55,6 +55,7 @@ struct mmc_ioc_cmd
|
||||
/* DAT buffer */
|
||||
uint64_t data_ptr;
|
||||
};
|
||||
|
||||
#define mmc_ioc_cmd_set_data(ic, ptr) ic.data_ptr = (__u64)(unsigned long)ptr
|
||||
|
||||
/**
|
||||
@@ -69,7 +70,7 @@ struct mmc_ioc_multi_cmd
|
||||
struct mmc_ioc_cmd cmds[0];
|
||||
};
|
||||
|
||||
#define MMC_IOC_CMD _IOWR(MMC_BLOCK_MAJOR, 0, struct mmc_ioc_cmd)
|
||||
#define MMC_IOC_CMD _IOWR(MMC_BLOCK_MAJOR, 0, struct mmc_ioc_cmd)
|
||||
/*
|
||||
* MMC_IOC_MULTI_CMD: Used to send an array of MMC commands described by
|
||||
* the structure mmc_ioc_multi_cmd. The MMC driver will issue all
|
||||
@@ -83,7 +84,7 @@ struct mmc_ioc_multi_cmd
|
||||
* block device operations.
|
||||
*/
|
||||
#define MMC_IOC_MAX_BYTES (512L * 1024)
|
||||
#define MMC_IOC_MAX_CMDS 255
|
||||
#define MMC_IOC_MAX_CMDS 255
|
||||
|
||||
#endif
|
||||
#endif // AARUREMOTE_LINUX_MMC_IOCTL_H_
|
||||
#endif // AARUREMOTE_LINUX_MMC_IOCTL_H_
|
||||
|
||||
@@ -25,18 +25,18 @@
|
||||
#include "../aaruremote.h"
|
||||
#include "linux.h"
|
||||
|
||||
uint8_t GetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis)
|
||||
uint8_t GetPcmciaData(void *device_ctx, uint16_t *cis_len, char *cis)
|
||||
{
|
||||
DeviceContext* ctx = device_ctx;
|
||||
char* dev_path;
|
||||
DeviceContext *ctx = device_ctx;
|
||||
char *dev_path;
|
||||
char tmp_path[4096];
|
||||
char resolved_link[4096];
|
||||
struct stat sb;
|
||||
ssize_t len;
|
||||
char* rchr;
|
||||
FILE* file;
|
||||
DIR* dir;
|
||||
struct dirent* dent;
|
||||
char *rchr;
|
||||
FILE *file;
|
||||
DIR *dir;
|
||||
struct dirent *dent;
|
||||
*cis_len = 0;
|
||||
|
||||
if(!ctx) return 0;
|
||||
@@ -48,7 +48,7 @@ uint8_t GetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis)
|
||||
strncmp(ctx->device_path, "/dev/st", 7) != 0)
|
||||
return 0;
|
||||
|
||||
dev_path = (char*)ctx->device_path + 5;
|
||||
dev_path = (char *)ctx->device_path + 5;
|
||||
|
||||
snprintf(tmp_path, 4096, "/sys/block/%s", dev_path);
|
||||
|
||||
|
||||
40
linux/scsi.c
40
linux/scsi.c
@@ -24,19 +24,11 @@
|
||||
#include "../aaruremote.h"
|
||||
#include "linux.h"
|
||||
|
||||
int32_t SendScsiCommand(void* device_ctx,
|
||||
char* cdb,
|
||||
char* buffer,
|
||||
char** sense_buffer,
|
||||
uint32_t timeout,
|
||||
int32_t direction,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t cdb_len,
|
||||
uint32_t* buf_len,
|
||||
uint32_t* sense_len)
|
||||
int32_t SendScsiCommand(void *device_ctx, char *cdb, char *buffer, char **sense_buffer, uint32_t timeout,
|
||||
int32_t direction, uint32_t *duration, uint32_t *sense, uint32_t cdb_len, uint32_t *buf_len,
|
||||
uint32_t *sense_len)
|
||||
{
|
||||
DeviceContext* ctx = device_ctx;
|
||||
DeviceContext *ctx = device_ctx;
|
||||
sg_io_hdr_t hdr;
|
||||
int dir, ret;
|
||||
*sense_len = 32;
|
||||
@@ -50,12 +42,20 @@ int32_t SendScsiCommand(void* device_ctx,
|
||||
|
||||
switch(direction)
|
||||
{
|
||||
case AARUREMOTE_SCSI_DIRECTION_IN: dir = SG_DXFER_FROM_DEV; break;
|
||||
case AARUREMOTE_SCSI_DIRECTION_OUT: dir = SG_DXFER_TO_DEV; break;
|
||||
case AARUREMOTE_SCSI_DIRECTION_IN:
|
||||
dir = SG_DXFER_FROM_DEV;
|
||||
break;
|
||||
case AARUREMOTE_SCSI_DIRECTION_OUT:
|
||||
dir = SG_DXFER_TO_DEV;
|
||||
break;
|
||||
case AARUREMOTE_SCSI_DIRECTION_INOUT:
|
||||
case AARUREMOTE_SCSI_DIRECTION_UNSPECIFIED: dir = SG_DXFER_TO_FROM_DEV; break;
|
||||
case AARUREMOTE_SCSI_DIRECTION_UNSPECIFIED:
|
||||
dir = SG_DXFER_TO_FROM_DEV;
|
||||
break;
|
||||
case AARUREMOTE_SCSI_DIRECTION_NONE:
|
||||
default: dir = SG_DXFER_NONE; break;
|
||||
default:
|
||||
dir = SG_DXFER_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
hdr.interface_id = 'S';
|
||||
@@ -64,17 +64,17 @@ int32_t SendScsiCommand(void* device_ctx,
|
||||
hdr.dxfer_direction = dir;
|
||||
hdr.dxfer_len = *buf_len;
|
||||
hdr.dxferp = buffer;
|
||||
hdr.cmdp = (unsigned char*)cdb;
|
||||
hdr.sbp = (unsigned char*)*sense_buffer;
|
||||
hdr.cmdp = (unsigned char *)cdb;
|
||||
hdr.sbp = (unsigned char *)*sense_buffer;
|
||||
hdr.timeout = timeout;
|
||||
hdr.flags = SG_FLAG_DIRECT_IO;
|
||||
|
||||
ret = ioctl(ctx->fd, SG_IO, &hdr);
|
||||
|
||||
*sense = (hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK;
|
||||
*sense = (hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK;
|
||||
// TODO: Manual timing if duration is 0
|
||||
*duration = hdr.duration;
|
||||
*sense_len = hdr.sb_len_wr;
|
||||
|
||||
return ret; // TODO: Implement
|
||||
return ret; // TODO: Implement
|
||||
}
|
||||
@@ -27,22 +27,11 @@
|
||||
#include "linux.h"
|
||||
#include "mmc/ioctl.h"
|
||||
|
||||
int32_t SendSdhciCommand(void* device_ctx,
|
||||
uint8_t command,
|
||||
uint8_t write,
|
||||
uint8_t application,
|
||||
uint32_t flags,
|
||||
uint32_t argument,
|
||||
uint32_t block_size,
|
||||
uint32_t blocks,
|
||||
char* buffer,
|
||||
uint32_t buf_len,
|
||||
uint32_t timeout,
|
||||
uint32_t* response,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense)
|
||||
int32_t SendSdhciCommand(void *device_ctx, uint8_t command, uint8_t write, uint8_t application, uint32_t flags,
|
||||
uint32_t argument, uint32_t block_size, uint32_t blocks, char *buffer, uint32_t buf_len,
|
||||
uint32_t timeout, uint32_t *response, uint32_t *duration, uint32_t *sense)
|
||||
{
|
||||
DeviceContext* ctx = device_ctx;
|
||||
DeviceContext *ctx = device_ctx;
|
||||
struct mmc_ioc_cmd mmc_ioc_cmd;
|
||||
int32_t error;
|
||||
*duration = 0;
|
||||
@@ -74,29 +63,22 @@ int32_t SendSdhciCommand(void* device_ctx,
|
||||
|
||||
*sense = error < 0;
|
||||
|
||||
memcpy((char*)response, (char*)&mmc_ioc_cmd.response, sizeof(uint32_t) * 4);
|
||||
memcpy((char *)response, (char *)&mmc_ioc_cmd.response, sizeof(uint32_t) * 4);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int32_t GetSdhciRegisters(void* device_ctx,
|
||||
char** csd,
|
||||
char** cid,
|
||||
char** ocr,
|
||||
char** scr,
|
||||
uint32_t* csd_len,
|
||||
uint32_t* cid_len,
|
||||
uint32_t* ocr_len,
|
||||
uint32_t* scr_len)
|
||||
int32_t GetSdhciRegisters(void *device_ctx, char **csd, char **cid, char **ocr, char **scr, uint32_t *csd_len,
|
||||
uint32_t *cid_len, uint32_t *ocr_len, uint32_t *scr_len)
|
||||
{
|
||||
DeviceContext* ctx = device_ctx;
|
||||
char* tmp_string;
|
||||
char* sysfs_path_csd;
|
||||
char* sysfs_path_cid;
|
||||
char* sysfs_path_scr;
|
||||
char* sysfs_path_ocr;
|
||||
DeviceContext *ctx = device_ctx;
|
||||
char *tmp_string;
|
||||
char *sysfs_path_csd;
|
||||
char *sysfs_path_cid;
|
||||
char *sysfs_path_scr;
|
||||
char *sysfs_path_ocr;
|
||||
size_t len;
|
||||
FILE* file;
|
||||
FILE *file;
|
||||
*csd = NULL;
|
||||
*cid = NULL;
|
||||
*ocr = NULL;
|
||||
@@ -149,7 +131,7 @@ int32_t GetSdhciRegisters(void* device_ctx,
|
||||
len = getline(&tmp_string, &n, file);
|
||||
if(len > 0)
|
||||
{
|
||||
*csd_len = Hexs2Bin(tmp_string, (unsigned char**)csd);
|
||||
*csd_len = Hexs2Bin(tmp_string, (unsigned char **)csd);
|
||||
|
||||
if(*csd_len <= 0)
|
||||
{
|
||||
@@ -171,7 +153,7 @@ int32_t GetSdhciRegisters(void* device_ctx,
|
||||
len = getline(&tmp_string, &n, file);
|
||||
if(len > 0)
|
||||
{
|
||||
*cid_len = Hexs2Bin(tmp_string, (unsigned char**)cid);
|
||||
*cid_len = Hexs2Bin(tmp_string, (unsigned char **)cid);
|
||||
|
||||
if(*cid_len <= 0)
|
||||
{
|
||||
@@ -193,7 +175,7 @@ int32_t GetSdhciRegisters(void* device_ctx,
|
||||
len = getline(&tmp_string, &n, file);
|
||||
if(len > 0)
|
||||
{
|
||||
*scr_len = Hexs2Bin(tmp_string, (unsigned char**)scr);
|
||||
*scr_len = Hexs2Bin(tmp_string, (unsigned char **)scr);
|
||||
|
||||
if(*scr_len <= 0)
|
||||
{
|
||||
@@ -215,7 +197,7 @@ int32_t GetSdhciRegisters(void* device_ctx,
|
||||
len = getline(&tmp_string, &n, file);
|
||||
if(len > 0)
|
||||
{
|
||||
*ocr_len = Hexs2Bin(tmp_string, (unsigned char**)ocr);
|
||||
*ocr_len = Hexs2Bin(tmp_string, (unsigned char **)ocr);
|
||||
|
||||
if(*ocr_len <= 0)
|
||||
{
|
||||
@@ -237,16 +219,13 @@ int32_t GetSdhciRegisters(void* device_ctx,
|
||||
return csd_len != 0 || cid_len != 0 || scr_len != 0 || ocr_len != 0;
|
||||
}
|
||||
|
||||
int32_t SendMultiSdhciCommand(void* device_ctx,
|
||||
uint64_t count,
|
||||
MmcSingleCommand commands[],
|
||||
uint32_t* duration,
|
||||
uint32_t* sense)
|
||||
int32_t SendMultiSdhciCommand(void *device_ctx, uint64_t count, MmcSingleCommand commands[], uint32_t *duration,
|
||||
uint32_t *sense)
|
||||
{
|
||||
DeviceContext* ctx = device_ctx;
|
||||
DeviceContext *ctx = device_ctx;
|
||||
*duration = 0;
|
||||
*sense = 0;
|
||||
struct mmc_ioc_multi_cmd* mmc_ioc_multi_cmd;
|
||||
struct mmc_ioc_multi_cmd *mmc_ioc_multi_cmd;
|
||||
uint64_t i;
|
||||
int32_t error;
|
||||
if(!ctx) return -1;
|
||||
@@ -279,7 +258,7 @@ int32_t SendMultiSdhciCommand(void* device_ctx,
|
||||
mmc_ioc_multi_cmd->cmds[i].cmd_timeout_ms = commands[i].timeout * 1000;
|
||||
}
|
||||
*/
|
||||
mmc_ioc_multi_cmd->cmds[i].data_ptr = (uint64_t)commands[i].buffer;
|
||||
mmc_ioc_multi_cmd->cmds[i].data_ptr = (uint64_t)commands[i].buffer;
|
||||
}
|
||||
|
||||
error = ioctl(ctx->fd, MMC_IOC_MULTI_CMD, mmc_ioc_multi_cmd);
|
||||
@@ -289,7 +268,7 @@ int32_t SendMultiSdhciCommand(void* device_ctx,
|
||||
*sense = error < 0;
|
||||
|
||||
for(i = 0; i < count; i++)
|
||||
memcpy((char*)commands[i].response, (char*)mmc_ioc_multi_cmd->cmds[i].response, sizeof(uint32_t) * 4);
|
||||
memcpy((char *)commands[i].response, (char *)mmc_ioc_multi_cmd->cmds[i].response, sizeof(uint32_t) * 4);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
20
linux/usb.c
20
linux/usb.c
@@ -24,24 +24,18 @@
|
||||
#include "../aaruremote.h"
|
||||
#include "linux.h"
|
||||
|
||||
uint8_t GetUsbData(void* device_ctx,
|
||||
uint16_t* desc_len,
|
||||
char* descriptors,
|
||||
uint16_t* id_vendor,
|
||||
uint16_t* id_product,
|
||||
char* manufacturer,
|
||||
char* product,
|
||||
char* serial)
|
||||
uint8_t GetUsbData(void *device_ctx, uint16_t *desc_len, char *descriptors, uint16_t *id_vendor, uint16_t *id_product,
|
||||
char *manufacturer, char *product, char *serial)
|
||||
{
|
||||
DeviceContext* ctx = device_ctx;
|
||||
char* dev_path;
|
||||
DeviceContext *ctx = device_ctx;
|
||||
char *dev_path;
|
||||
char tmp_path[4096];
|
||||
char resolved_link[4096];
|
||||
struct stat sb;
|
||||
ssize_t len;
|
||||
char* rchr;
|
||||
char *rchr;
|
||||
int found = 1;
|
||||
FILE* file;
|
||||
FILE *file;
|
||||
|
||||
if(!ctx) return -1;
|
||||
|
||||
@@ -55,7 +49,7 @@ uint8_t GetUsbData(void* device_ctx,
|
||||
strncmp(ctx->device_path, "/dev/st", 7) != 0)
|
||||
return 0;
|
||||
|
||||
dev_path = (char*)ctx->device_path + 5;
|
||||
dev_path = (char *)ctx->device_path + 5;
|
||||
|
||||
snprintf(tmp_path, 4096, "/sys/block/%s", dev_path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user