[C Programming]Accessing Connected Linux Drives/Partitions

Questions about Wine on Linux
Locked
Sircole
Newbie
Newbie
Posts: 1
Joined: Thu Oct 08, 2015 12:35 pm

[C Programming]Accessing Connected Linux Drives/Partitions

Post by Sircole »

If this is a repeat post, I'd really appreciate direction to the information I need as my searching on Google and the Wine forums thus far haven't yielded the results I need. Also note I have very minimal experience with Linux. And I'd also prefer to avoid third party libraries and anything licensed if I can at all help it.

So, I'm trying to write an executable that needs to access the drives connected to a device (Read/Write). My problem however is finding a process that can relay to me all the possible drives/partitions programmatically and provide their file paths. I can do it on Windows (kinda) via things like "GetLogicalDrives" (for lettered drives) or alternatives... And I can do it on Linux with things like "fdisk -l" and such. But, I can't seem to figure out how to get a program readable list that will work on Windows and Linux (running via Wine). I basically want a 2D array if I can, of drive paths that I could use with Windows function calls (that Wine will redirect to Linux calls when needed) like "FindFirstFileA" and such.

Will I have to hard code each case? And if so, what are the cases? What are all the possible default drive paths on Linux? Will I need to programmatically mount them?
eg:

Code: Select all

bool DoesDriveExist(char* szDrivePath);
void ProcessDrive(char* szDrivePath);

ProcessDrive("C:\\"); // Note the different drive names
ProcessDrive("\\dev\\sda1");
ProcessDrive("\\dev\\sda2");
ProcessDrive("\\dev\\sdb1"); 
ProcessDrive("\\dev\\hdb1"); 
ProcessDrive("\\root\\");
// etc...

bool DoesDriveExist(char* szDrivePath)
{
        BOOL bResult = false;

        // GetFileAttributes or Drive/Partition compliant equivalent
        ...

        return bResult;
}

void ProcessDrive(char* szDrivePath)
{
        if(DoesDriveExist(szDrivePath))
        {
                // Do Stuff eg. FindFirstFileA(szDrivePath, FileData);
                ...
        }
}
I get that this is kind of a big question maybe, and I didn't explain it very eloquently so if you need further clarification on anything, please tell me. I just want to do this right and not hack it together like I fear I'll need to.

Thanks in advance for any help or insight y'all can provide.
Locked