Merge pull request #12 from kkaisershot/2.6.26-scsi-fix

Detect SCSI devices on 2.6.26 kernel PowerPC system.
This commit is contained in:
2022-12-05 14:25:06 +00:00
committed by GitHub
2 changed files with 34 additions and 22 deletions

View File

@@ -164,6 +164,7 @@ int32_t GetDeviceType(void* device_ctx)
char* fc_path;
char* sas_path;
int ret;
char delim;
char* chrptr;
char* sysfs_path_scr;
FILE* file;
@@ -242,23 +243,26 @@ int32_t GetDeviceType(void* device_ctx)
}
ret = 0;
chrptr = strchr(dev_path, ':');
delim = '.';
chrptr = strrchr(dev_path, delim);
if(!chrptr)
{
chrptr = strrchr(dev_path, '.');
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);
return dev_type;
}
delim = ':';
chrptr = strrchr(dev_path, delim);
}
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);
return dev_type;
}
chrptr--;
@@ -270,8 +274,15 @@ int32_t GetDeviceType(void* device_ctx)
chrptr++;
break;
}
else if(chrptr[0] == delim)
{
ret = 0;
}
else
{
ret++;
}
ret++;
chrptr--;
}

View File

@@ -49,6 +49,8 @@ DeviceInfoList* ListDevices()
udev = udev_new();
has_udev = udev != 0;
#else
DeviceContext tmp_ctx;
#endif
dir = opendir(PATH_SYS_DEVBLOCK);
@@ -58,7 +60,7 @@ DeviceInfoList* ListDevices()
while(dirent)
{
if(dirent->d_type != DT_REG && dirent->d_type != DT_LNK)
if((dirent->d_type != DT_DIR && dirent->d_type != DT_LNK) || dirent->d_name[0] == '.')
{
dirent = readdir(dir);
continue;
@@ -137,11 +139,10 @@ DeviceInfoList* ListDevices()
#else // Use sysfs
if(!has_udev && !strstr(dirent->d_name, "loop"))
{
tmp_string = malloc(1024);
memset((void*)tmp_string, 0, 1024);
snprintf((char*)tmp_string, 1024, "/dev/%s", dirent->d_name);
memset((void*)tmp_ctx.device_path, 0, 4096);
snprintf((char*)tmp_ctx.device_path, 4096, "/dev/%s", dirent->d_name);
switch(GetDeviceType(tmp_string))
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;
@@ -149,6 +150,7 @@ DeviceInfoList* ListDevices()
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);
snprintf((char*)tmp_string, 1024, "%s/%s/device", PATH_SYS_DEVBLOCK, dirent->d_name);
line_str = malloc(1024);
@@ -208,11 +210,10 @@ DeviceInfoList* ListDevices()
free(line_str);
}
free((void*)tmp_string);
break;
default: memset(&list_next->this.bus, 0, 256); break;
}
free((void*)tmp_string);
}
#endif