Page 1 of 1

[WinAPI] Cati bytes are un sector?

Posted: 01 Sep 2009, 17:22
by Ovidiu Cucu
Intrebare: Cum pot afla cati bytes pe sector are un disc (drive)?

Raspuns: Se poate folosi functia GetDiskFreeSpace. Pe langa numarul de sectoare pe cluster, numarul total de clustere si numarul de clustere libere, aceasta intoarce si numarul de bytes pe sector.

Exemplu:

Code: Select all

#include <windows.h>
#include <tchar.h>
#include <stdio.h>

DWORD GetBytesPerSector(LPCTSTR pszRootPath, DWORD& dwBytesPerSector)
{
   DWORD dwRetCode = ERROR_SUCCESS;
   if(!::GetDiskFreeSpace(pszRootPath, NULL, &dwBytesPerSector, NULL, NULL))
   {
      dwRetCode = ::GetLastError(); 
   }
   return dwRetCode;
}

int main()
{
   LPCTSTR pszRootPath = _T("c:\\");
   DWORD dwBytesPerSector = 0;

   DWORD dwRetCode = GetBytesPerSector(pszRootPath, dwBytesPerSector);
   if(ERROR_SUCCESS != dwRetCode)
   {
      _tprintf(_T("GetBytesPerSector failed. Error: %u\n"), dwRetCode);
      system("pause");
      return dwRetCode;
   }
   _tprintf(_T("Volume: %s has %u bytes per sector.\n"), pszRootPath, dwBytesPerSector);
   system("pause");
   return 0;
}

<< Back to Windows API Index