Use opaque packet for device context.

This commit is contained in:
2019-10-26 16:11:19 +01:00
parent bcae241162
commit adcd54d992
17 changed files with 282 additions and 213 deletions

View File

@@ -23,23 +23,26 @@
#include <sys/stat.h>
#include <unistd.h>
uint8_t LinuxGetUsbData(const char* device_path,
uint16_t* desc_len,
char* descriptors,
uint16_t* id_vendor,
uint16_t* id_product,
char* manufacturer,
char* product,
char* serial)
uint8_t LinuxGetUsbData(void* device_ctx,
uint16_t* desc_len,
char* descriptors,
uint16_t* id_vendor,
uint16_t* id_product,
char* manufacturer,
char* product,
char* serial)
{
char* dev_path;
char tmp_path[4096];
char resolved_link[4096];
struct stat sb;
ssize_t len;
char* rchr;
int found = 1;
FILE* file;
LinuxDeviceContext* ctx = device_ctx;
char* dev_path;
char tmp_path[4096];
char resolved_link[4096];
struct stat sb;
ssize_t len;
char* rchr;
int found = 1;
FILE* file;
if(!ctx) return -1;
*desc_len = 0;
*id_vendor = 0;
@@ -47,11 +50,11 @@ uint8_t LinuxGetUsbData(const char* device_path,
memset(tmp_path, 0, 4096);
memset(resolved_link, 0, 4096);
if(strncmp(device_path, "/dev/sd", 7) != 0 && strncmp(device_path, "/dev/sr", 7) != 0 &&
strncmp(device_path, "/dev/st", 7) != 0)
if(strncmp(ctx->device_path, "/dev/sd", 7) != 0 && strncmp(ctx->device_path, "/dev/sr", 7) != 0 &&
strncmp(ctx->device_path, "/dev/st", 7) != 0)
return 0;
dev_path = (char*)device_path + 5;
dev_path = (char*)ctx->device_path + 5;
snprintf(tmp_path, 4096, "/sys/block/%s", dev_path);