Skip to content

Commit

Permalink
bug: Fixing an error in filesystem detection for linux, solaris, freebsd
Browse files Browse the repository at this point in the history
Fixing a bug in setting up the structure for file system detected information. The validity field was missing and the cases for raw disks were missing setting the other fields to false to note no file systems and no system disk.

Signed-off-by: Tyler Erickson <[email protected]>
  • Loading branch information
vonericsen committed Jun 21, 2022
1 parent 7e19e5d commit 8c0b0ea
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 22 deletions.
9 changes: 9 additions & 0 deletions src/cam_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ static int set_Device_Partition_Info(tDevice* device)
#endif
if (partitionCount > 0)
{
device->os_info.fileSystemInfo.fileSystemInfoValid = true;
device->os_info.fileSystemInfo.hasFileSystem = false;
device->os_info.fileSystemInfo.isSystemDisk = false;
ptrsPartitionInfo parts = C_CAST(ptrsPartitionInfo, calloc(partitionCount, sizeof(spartitionInfo)));
if (parts)
{
Expand Down Expand Up @@ -174,6 +177,12 @@ static int set_Device_Partition_Info(tDevice* device)
ret = MEMORY_FAILURE;
}
}
else
{
device->os_info.fileSystemInfo.fileSystemInfoValid = true;
device->os_info.fileSystemInfo.hasFileSystem = false;
device->os_info.fileSystemInfo.isSystemDisk = false;
}
return ret;
}

Expand Down
37 changes: 23 additions & 14 deletions src/sg_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,42 +936,45 @@ int map_Block_To_Generic_Handle(const char *handle, char **genericHandle, char *
return UNKNOWN;
}

static int set_Device_Partition_Info(tDevice *device)
static int set_Device_Partition_Info(tDevice* device)
{
int ret = SUCCESS;
int partitionCount = 0;
char *blockHandle = device->os_info.name;
if(device->os_info.secondHandleValid && !is_Block_Device_Handle(blockHandle))
char* blockHandle = device->os_info.name;
if (device->os_info.secondHandleValid && !is_Block_Device_Handle(blockHandle))
{
blockHandle = device->os_info.secondName;
}
partitionCount = get_Partition_Count(blockHandle);
#if defined (_DEBUG)
#if defined (_DEBUG)
printf("Partition count for %s = %d\n", blockHandle, partitionCount);
#endif
if(partitionCount > 0)
#endif
if (partitionCount > 0)
{
device->os_info.fileSystemInfo.fileSystemInfoValid = true;
device->os_info.fileSystemInfo.hasFileSystem = false;
device->os_info.fileSystemInfo.isSystemDisk = false;
ptrsPartitionInfo parts = C_CAST(ptrsPartitionInfo, calloc(partitionCount, sizeof(spartitionInfo)));
if(parts)
if (parts)
{
if(SUCCESS == get_Partition_List(blockHandle, parts, partitionCount))
if (SUCCESS == get_Partition_List(blockHandle, parts, partitionCount))
{
int iter = 0;
for(; iter < partitionCount; ++iter)
for (; iter < partitionCount; ++iter)
{
//since we found a partition, set the "has file system" bool to true
device->os_info.fileSystemInfo.hasFileSystem = true;
#if defined (_DEBUG)
#if defined (_DEBUG)
printf("Found mounted file system: %s - %s\n", (parts + iter)->fsName, (parts + iter)->mntPath);
#endif
#endif
//check if one of the partitions is /boot and mark the system disk when this is found
//TODO: Should / be treated as a system disk too?
if(strncmp((parts + iter)->mntPath, "/boot", 5) == 0)
if (strncmp((parts + iter)->mntPath, "/boot", 5) == 0)
{
device->os_info.fileSystemInfo.isSystemDisk = true;
#if defined (_DEBUG)
#if defined (_DEBUG)
printf("found system disk\n");
#endif
#endif
}
}
}
Expand All @@ -982,6 +985,12 @@ static int set_Device_Partition_Info(tDevice *device)
ret = MEMORY_FAILURE;
}
}
else
{
device->os_info.fileSystemInfo.fileSystemInfoValid = true;
device->os_info.fileSystemInfo.hasFileSystem = false;
device->os_info.fileSystemInfo.isSystemDisk = false;
}
return ret;
}

Expand Down
9 changes: 9 additions & 0 deletions src/uscsi_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ static int set_Device_Partition_Info(tDevice* device)
#endif
if (partitionCount > 0)
{
device->os_info.fileSystemInfo.fileSystemInfoValid = true;
device->os_info.fileSystemInfo.hasFileSystem = false;
device->os_info.fileSystemInfo.isSystemDisk = false;
ptrsPartitionInfo parts = C_CAST(ptrsPartitionInfo, calloc(partitionCount, sizeof(spartitionInfo)));
if (parts)
{
Expand Down Expand Up @@ -163,6 +166,12 @@ static int set_Device_Partition_Info(tDevice* device)
ret = MEMORY_FAILURE;
}
}
else
{
device->os_info.fileSystemInfo.fileSystemInfoValid = true;
device->os_info.fileSystemInfo.hasFileSystem = false;
device->os_info.fileSystemInfo.isSystemDisk = false;
}
return ret;
}

Expand Down
18 changes: 10 additions & 8 deletions src/vm_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ bool os_Is_Infinite_Timeout_Supported(void)
extern bool validate_Device_Struct(versionBlock);

// Local helper functions for debugging
void print_io_hdr( sg_io_hdr_t *pIo )
#if defined (_DEBUG)
static void print_io_hdr( sg_io_hdr_t *pIo )
{
time_t time_now;
char timeFormat[TIME_STRING_LENGTH];
Expand Down Expand Up @@ -72,6 +73,7 @@ void print_io_hdr( sg_io_hdr_t *pIo )
printf("type unsigned int info 0x%x\n", pIo->info); /* [o] */
printf("-----------------------------------------\n");
}
#endif //_DEBUG

static int sg_filter( const struct dirent *entry )
{
Expand Down Expand Up @@ -153,7 +155,7 @@ static int sd_filter( const struct dirent *entry )
// return linkMappingSupported;
//}

bool is_Block_Device_Handle(const char *handle)
static bool is_Block_Device_Handle(const char *handle)
{
bool isBlockDevice = false;
if (handle && strlen(handle))
Expand All @@ -166,7 +168,7 @@ bool is_Block_Device_Handle(const char *handle)
return isBlockDevice;
}

bool is_SCSI_Generic_Handle(const char *handle)
static bool is_SCSI_Generic_Handle(const char *handle)
{
bool isGenericDevice = false;
if (handle && strlen(handle))
Expand All @@ -179,7 +181,7 @@ bool is_SCSI_Generic_Handle(const char *handle)
return isGenericDevice;
}

bool is_Block_SCSI_Generic_Handle(const char *handle)
static bool is_Block_SCSI_Generic_Handle(const char *handle)
{
bool isBlockGenericDevice = false;
if (handle && strlen(handle))
Expand Down Expand Up @@ -215,7 +217,7 @@ static void set_Device_Fields_From_Handle(const char* handle, tDevice *device)
bool bsg = false;
char incomingHandleClassPath[PATH_MAX] = { 0 };
//char *incomingClassName = NULL;
common_String_Concat(incomingHandleClassPath, PATH_MAX, "/sys/class");
common_String_Concat(incomingHandleClassPath, PATH_MAX, "/sys/class/");
if (is_Block_Device_Handle(handle))
{
common_String_Concat(incomingHandleClassPath, PATH_MAX, "block/");
Expand Down Expand Up @@ -675,7 +677,7 @@ int map_Block_To_Generic_Handle(const char *handle, char **genericHandle, char *
struct stat inHandleStat;
if (stat(incomingHandleClassPath, &inHandleStat) == 0 && S_ISDIR(inHandleStat.st_mode))
{
common_String_Concat(incomingHandleClassPath, PATH_MAX, basename(handle));
common_String_Concat(incomingHandleClassPath, PATH_MAX, basename(C_CAST(char*, handle)));
//now read the link with the handle appended on the end
char inHandleLink[PATH_MAX] = { 0 };
if (readlink(incomingHandleClassPath, inHandleLink, PATH_MAX) > 0)
Expand Down Expand Up @@ -778,13 +780,13 @@ int map_Block_To_Generic_Handle(const char *handle, char **genericHandle, char *
{
if (incomingBlock)
{
*blockHandle = strndup(basename(handle), strlen(basename(handle)));
*blockHandle = strndup(basename(C_CAST(char*, handle)), strlen(basename(C_CAST(char*, handle))));
*genericHandle = strdup(basename(classPtr));
}
else
{
*blockHandle = strndup(basename(classPtr), strlen(basename(classPtr)));
*genericHandle = strdup(basename(handle));
*genericHandle = strdup(basename(C_CAST(char *, handle)));
}
safe_Free(className)
safe_Free(incomingClassName)
Expand Down

0 comments on commit 8c0b0ea

Please sign in to comment.