Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE '#Win 8.04#
#Dim All
%Unicode=1
#Include "Win32Api.inc"
%SectorSize = 512
%IOCTL_DISK_GET_LENGTH_INFO = &H7405C
'______________________________________________________________________________
Function DiskRead(ByVal Disk AS DWord, ByVal SectorLB AS QUAD, _
BYREF sSector As String * %SectorSize)As Long
Local DiskError As Long
Local Result As Long
Local hDisk AS DWord
Local dwRead AS DWord
Local FilePtr AS QUAD
Local pFilePtrLo AS DWord POINTER
Local pFilePtrHi AS DWord POINTER
Local zDisk As AsciiZ * 30
zDisk = "\\.\" & CHR$(Disk) & ":"
hDisk = CreateFile(zDisk, %GENERIC_READ, %FILE_SHARE_READ OR %FILE_SHARE_WRITE, _
ByVal 0, %OPEN_EXISTING, 0, 0)
IF hDisk <> %INVALID_HANDLE_VALUE THEN
FilePtr = SectorLB * %SectorSize
pFilePtrLo = VARPTR(FilePtr)
pFilePtrHi = pFilePtrLo + 4
SetFilePointer(hDisk, @pFilePtrLo, @pFilePtrHi, %FILE_BEGIN) 'h, Lo, Hi, Flag
Result = ReadFile(hDisk, ByVal VARPTR(sSector), %SectorSize, dwRead, ByVal %NULL)
IF Result THEN
IF dwRead <> %SectorSize THEN
sSector = NUL$(%SectorSize)
Function = %TRUE
END IF
ELSE
sSector = NUL$(%SectorSize)
Function = %TRUE
END IF
CloseHandle(hDisk)
END IF
End Function
'______________________________________________________________________________
Function PBMain() As Long
Local Disk AS DWord
Local SectorLB AS QUAD
Local sSector As String * %SectorSize
Local sBuffer As String
SectorLB = 0
DISK = ASC("C:")
DiskRead(Disk, SectorLB, sSector)
IF sSector <> NUL$(%SectorSize) THEN
sBuffer = "Drive: " & CHR$(Disk) & ":" & $CRLF & _
"System Id: " & MID$(sSector, 4, 8) & $CRLF
IF MID$(sSector, 4, 8) = "NTFS " THEN
'NTFS file system BIOS parameter block
sBuffer = sBuffer & _
"Bytes per sector:" & STR$(CVWRD(sSector, &HB + 1)) & $CRLF & _
"Sectors per cluster:" & STR$(CVBYT(sSector, &HD + 1)) & $CRLF & _
"Media descriptor (a):" & STR$(CVBYT(sSector, &H15 + 1)) & $CRLF & _
"Sectors per track:" & STR$(CVWRD(sSector, &H18 + 1)) & $CRLF & _
"Number of heads:" & STR$(CVWRD(sSector, &H1A + 1)) & $CRLF & _
"Usually 00800080: " & HEX$(CVDWD(sSector, &H24 + 1), 8) & $CRLF & _
"Number of sectors in the volume: " & FORMAT$(CVDWD(sSector, &H28 + 1), "###,###") & $CRLF & _
"LCN of VCN 0 of the $MFT:" & STR$(CVDWD(sSector, &H30 + 1)) & $CRLF & _
"LCN of VCN 0 of the $MFTMirr:" & STR$(CVDWD(sSector, &H38 + 1)) & $CRLF & _
"Clusters per MFT Record (c):" & STR$(CVWRD(sSector, &H40 + 1)) & $CRLF & _
"Clusters per Index Record (c):" & STR$(CVWRD(sSector, &H44 + 1)) & $CRLF & _
"Volume serial number: " & HEX$(CVWRD(sSector, &H48 + 3), 4) & "-" & HEX$(CVWRD(sSector, &H48 + 1), 4) & $CRLF & _
"End of Sector Marker: " & MID$(sSector, &H1FE + 1, 2) & $CRLF
ELSE
sBuffer = sBuffer & "Not a NTFS drive !"
END IF
ELSE
sBuffer = "Please run in " & $DQ & "Administrator mode" & $DQ
END IF
MessageBox(%HWND_DESKTOP, BYCOPY sBuffer, "Disk read", 64)
End Function
'______________________________________________________________________________
'
'gbs_00846
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm