mirror of
https://github.com/aaru-dps/aaruremote.git
synced 2025-12-16 19:24:37 +00:00
Add conditional for udev presence in Linux.
This commit is contained in:
@@ -19,12 +19,15 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <libudev.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef HAS_UDEV
|
||||
#include <libudev.h>
|
||||
#endif
|
||||
|
||||
int LinuxOpenDevice(const char* device_path)
|
||||
{
|
||||
int fd;
|
||||
@@ -38,6 +41,9 @@ int LinuxOpenDevice(const char* device_path)
|
||||
|
||||
int32_t LinuxGetDeviceType(const char* device_path)
|
||||
{
|
||||
#ifndef HAS_UDEV
|
||||
return DICMOTE_DEVICE_TYPE_UNKNOWN;
|
||||
#else
|
||||
struct udev* udev;
|
||||
struct udev_device* udev_device;
|
||||
const char* tmp_string;
|
||||
@@ -120,26 +126,26 @@ int32_t LinuxGetDeviceType(const char* device_path)
|
||||
}
|
||||
|
||||
int32_t LinuxGetSdhciRegisters(const char* device_path,
|
||||
char** csd,
|
||||
char** cid,
|
||||
char** ocr,
|
||||
char** scr,
|
||||
uint32_t* csd_len,
|
||||
uint32_t* cid_len,
|
||||
uint32_t* ocr_len,
|
||||
uint32_t* scr_len)
|
||||
char** csd,
|
||||
char** cid,
|
||||
char** ocr,
|
||||
char** scr,
|
||||
uint32_t* csd_len,
|
||||
uint32_t* cid_len,
|
||||
uint32_t* ocr_len,
|
||||
uint32_t* scr_len)
|
||||
{
|
||||
char* tmp_string;
|
||||
char* sysfs_path_csd;
|
||||
char* sysfs_path_cid;
|
||||
char* sysfs_path_scr;
|
||||
char* sysfs_path_ocr;
|
||||
char* tmp_string;
|
||||
char* sysfs_path_csd;
|
||||
char* sysfs_path_cid;
|
||||
char* sysfs_path_scr;
|
||||
char* sysfs_path_ocr;
|
||||
size_t len;
|
||||
FILE* file;
|
||||
*csd = NULL;
|
||||
*cid = NULL;
|
||||
*ocr = NULL;
|
||||
*scr = NULL;
|
||||
FILE* file;
|
||||
*csd = NULL;
|
||||
*cid = NULL;
|
||||
*ocr = NULL;
|
||||
*scr = NULL;
|
||||
*csd_len = 0;
|
||||
*cid_len = 0;
|
||||
*ocr_len = 0;
|
||||
@@ -148,12 +154,12 @@ int32_t LinuxGetSdhciRegisters(const char* device_path,
|
||||
|
||||
if(strncmp(device_path, "/dev/mmcblk", 11) != 0) return 0;
|
||||
|
||||
len = strlen(device_path) + 19;
|
||||
len = strlen(device_path) + 19;
|
||||
sysfs_path_csd = malloc(len);
|
||||
sysfs_path_cid = malloc(len);
|
||||
sysfs_path_scr = malloc(len);
|
||||
sysfs_path_ocr = malloc(len);
|
||||
tmp_string = malloc(1024);
|
||||
tmp_string = malloc(1024);
|
||||
|
||||
if(!sysfs_path_csd || !sysfs_path_cid || !sysfs_path_scr || !sysfs_path_ocr || !tmp_string)
|
||||
{
|
||||
@@ -191,7 +197,7 @@ int32_t LinuxGetSdhciRegisters(const char* device_path,
|
||||
if(*csd_len <= 0)
|
||||
{
|
||||
*csd_len = 0;
|
||||
*csd = NULL;
|
||||
*csd = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +219,7 @@ int32_t LinuxGetSdhciRegisters(const char* device_path,
|
||||
if(*cid_len <= 0)
|
||||
{
|
||||
*cid_len = 0;
|
||||
*cid = NULL;
|
||||
*cid = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +241,7 @@ int32_t LinuxGetSdhciRegisters(const char* device_path,
|
||||
if(*scr_len <= 0)
|
||||
{
|
||||
*scr_len = 0;
|
||||
*scr = NULL;
|
||||
*scr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,7 +263,7 @@ int32_t LinuxGetSdhciRegisters(const char* device_path,
|
||||
if(*ocr_len <= 0)
|
||||
{
|
||||
*ocr_len = 0;
|
||||
*ocr = NULL;
|
||||
*ocr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,4 +278,5 @@ int32_t LinuxGetSdhciRegisters(const char* device_path,
|
||||
free(tmp_string);
|
||||
|
||||
return csd_len != 0 || cid_len != 0 || scr_len != 0 || ocr_len != 0;
|
||||
#endif
|
||||
}
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <libudev.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
@@ -28,23 +27,29 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef HAS_UDEV
|
||||
#include <libudev.h>
|
||||
#endif
|
||||
|
||||
DeviceInfoList* LinuxListDevices()
|
||||
{
|
||||
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;
|
||||
size_t n, ret;
|
||||
char* chrptr;
|
||||
#ifdef HAS_UDEV
|
||||
int has_udev;
|
||||
struct udev* udev;
|
||||
int has_udev = false, i;
|
||||
DeviceInfoList * list_start = NULL, *list_current = NULL, *list_next = NULL;
|
||||
struct udev_device* udev_device;
|
||||
const char* tmp_string;
|
||||
FILE* file;
|
||||
char* line_str;
|
||||
size_t n, ret;
|
||||
char* chrptr;
|
||||
|
||||
udev = udev_new();
|
||||
|
||||
udev = udev_new();
|
||||
has_udev = udev != 0;
|
||||
#endif
|
||||
|
||||
dir = opendir(PATH_SYS_DEVBLOCK);
|
||||
if(!dir) return NULL;
|
||||
@@ -66,8 +71,9 @@ DeviceInfoList* LinuxListDevices()
|
||||
{
|
||||
closedir(dir);
|
||||
|
||||
#ifdef HAS_UDEV
|
||||
if(has_udev) udev_unref(udev);
|
||||
|
||||
#endif
|
||||
return list_start;
|
||||
}
|
||||
|
||||
@@ -77,6 +83,7 @@ DeviceInfoList* LinuxListDevices()
|
||||
|
||||
snprintf(list_next->this.path, 1024, "/dev/%s", dirent->d_name);
|
||||
|
||||
#ifdef HAS_UDEV
|
||||
if(has_udev)
|
||||
{
|
||||
udev_device = udev_device_new_from_subsystem_sysname(udev, "block", dirent->d_name);
|
||||
@@ -127,6 +134,7 @@ DeviceInfoList* LinuxListDevices()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
tmp_string = malloc(1024);
|
||||
memset((void*)tmp_string, 0, 1024);
|
||||
@@ -299,7 +307,9 @@ DeviceInfoList* LinuxListDevices()
|
||||
|
||||
closedir(dir);
|
||||
|
||||
#ifdef HAS_UDEV
|
||||
if(has_udev) udev_unref(udev);
|
||||
#endif
|
||||
|
||||
return list_start;
|
||||
}
|
||||
Reference in New Issue
Block a user