[WinAPI] Cati bytes are un sector?

Folosire Windows API in programe C/C++ (forum moderat)
Post Reply
User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

[WinAPI] Cati bytes are un sector?

Post by Ovidiu Cucu » 01 Sep 2009, 17:22

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



Post Reply