Pregunta

I am working on a app where I need to check the file format of the drive/SD Card (FAT 32/NTFS etc) and display it. This app is a Qt based application which I should run on both MAC and Windows. There is no Qt Api which can let me achieve the result so only I went for this approach.

This is how I achieved it in Windows:

TCHAR volumeName[MAX_PATH + 1] = { 0 };
TCHAR fileSystemName[MAX_PATH + 1] = { 0 };
DWORD serialNumber = 0;
DWORD maxComponentLen = 0;
DWORD fileSystemFlags = 0;

LPCWSTR path = deviceData->m_strPath.utf16(); //deviceData->m_strpath gives me the drive path

if (GetVolumeInformation(
    path,
    volumeName,
    ARRAYSIZE(volumeName),
    &serialNumber,
    &maxComponentLen,
    &fileSystemFlags,
    fileSystemName,
    ARRAYSIZE(fileSystemName)))
{
         newData.strFileSystem = QString::fromUtf16(fileSystemName);
}   

    QList m_SDInfoList;
    m_SDInfoList.append(newData);

My concern is, I am not able to find a MAC API which can give me the file format details when I connect the same drive/SD Card in a MAC machine. Please help :)

¿Fue útil?

Solución

I've had similar problems finding osx equivalents of quite a few winapi methods. And what i've found to be the quickest solution to implement is using the commandline utilities on osx through QProcess. Its probably a lot slower then any api call would be, but if you're using it infrequently it should be fine.

For instance:

diskutil info /dev/disk0s2

gives the following output

(...)
Partition Type:           Apple_HFS
(...)

which you can read from QProcess output.

QProcess p;
p.start("diskutil",QStringList() << "info" "/path/to/dev");
p.waitForFinished();
foreach(QString line, QString(p.readAll()).split("\n"))
   if(line.contains("Partition Type:"))
       qDebug() << line

Something like this should work.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top