VERSION 5.00
Begin VB.Form Form16 
   Caption         =   " Seeking Linux Partition"
   ClientHeight    =   1680
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3525
   Icon            =   "ext4seek.frx":0000
   LinkTopic       =   "Form16"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   1680
   ScaleWidth      =   3525
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command1 
      Caption         =   "Seek"
      Height          =   375
      Left            =   1800
      TabIndex        =   2
      Top             =   960
      Width           =   1455
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Cancel"
      Height          =   375
      Left            =   240
      TabIndex        =   1
      Top             =   960
      Width           =   1335
   End
   Begin VB.ComboBox Combo1 
      Height          =   315
      Left            =   1560
      TabIndex        =   0
      Text            =   "PhysicalDrive0"
      Top             =   240
      Width           =   1695
   End
   Begin VB.Label Label1 
      Caption         =   "Physical  Drive :"
      Height          =   255
      Left            =   240
      TabIndex        =   3
      Top             =   285
      Width           =   1215
   End
End
Attribute VB_Name = "Form16"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim PT(63) As Byte
Dim DriveName As String

Private Sub Combo1_Change()
Combo1.ListIndex = C1LI
End Sub

Private Sub Combo1_Click()
C1LI = Combo1.ListIndex
End Sub

Private Sub Combo1_LostFocus()
DriveName = Combo1.Text
End Sub

Private Sub Command1_Click()
On Error GoTo ErrMsg
Dim LinuxDetected As Boolean
Dim x As Integer
Dim y As Integer
Dim T As Integer
Dim Z As Long
Dim SystemId(3) As Byte
Dim S1 As Double
Dim S2 As Long
Dim S3 As Long
Dim BeginningSector As Double
Me.Caption = " Reading Master Boot Sector"
Z = DirectReadDriveNT(DriveName, 0, 0, abResult(), 512)
If Z > 0 Then
   For x = 0 To 63
       PT(x) = abResult(446 + x)
   Next x
   SystemId(0) = PT(4)
   SystemId(1) = PT(20)
   SystemId(2) = PT(36)
   SystemId(3) = PT(52)
   For y = 0 To 3
       If SystemId(y) = &H83 Then
          LinuxDetected = True
          S1 = CDbl(PT(11 + (y * 16)))
          S1 = S1 * 16777216
          S2 = CLng(PT(10 + (y * 16)))
          S2 = S2 * 65536
          S3 = CLng(PT(9 + (y * 16)))
          S3 = S3 * 256
          BeginningSector = S1 + S2 + S3 + PT(8 + (y * 16))
       End If
   Next y
   If LinuxDetected = False Then
      For y = 0 To 3
          If SystemId(y) = &H5 Then
             Me.Caption = " Reading Extended Partition's BS"
             S1 = CDbl(PT(11 + (y * 16)))
             S1 = S1 * 16777216
             S2 = CLng(PT(10 + (y * 16)))
             S2 = S2 * 65536
             S3 = CLng(PT(9 + (y * 16)))
             S3 = S3 * 256
             BeginningSector = S1 + S2 + S3 + PT(8 + (y * 16))
             Z = DirectReadDriveNT(DriveName, CLng(BeginningSector), 0, abResult(), 512)
             If Z > 0 Then
                For x = 0 To 63
                    PT(x) = abResult(446 + x)
                Next x
                SystemId(0) = PT(4)
                SystemId(1) = PT(20)
                SystemId(2) = PT(36)
                SystemId(3) = PT(52)
                For T = 0 To 3
                    If SystemId(T) = &H83 Then
                       LinuxDetected = True
                       S1 = CDbl(PT(11 + (T * 16)))
                       S1 = S1 * 16777216
                       S2 = CLng(PT(10 + (T * 16)))
                       S2 = S2 * 65536
                       S3 = CLng(PT(9 + (T * 16)))
                       S3 = S3 * 256
                       BeginningSector = BeginningSector + S1 + S2 + S3 + PT(8 + (T * 16))
                    End If
                Next T
                If LinuxDetected = True Then
                   Exit For
                End If
             Else
                GoTo IHV
             End If
          End If
      Next y
    End If
    If LinuxDetected = True Then
       Form8.Combo1.Text = DriveName
       Form8.Text1.Text = CStr(BeginningSector)
       Form8.Text2.Text = "4"
       PBootSector = BeginningSector
       MsgBox (DriveName + " sector " + CStr(BeginningSector) + " is Linux Boot Sector..." + Chr$(13) + Chr$(10) + Chr$(13) + Chr$(10) + "Use 'Physical Disk Read' menu/command for reading the linux boot sector..." + Chr$(13) + Chr$(10) + Chr$(13) + Chr$(10) + "NOTE: Linux Super Block is on Sector " + CStr(BeginningSector + 2) + ". You can see the super block parameters there..."), 0, " LINUX PARTITION (83h) FOUND !"
    End If
Else
IHV:
   MsgBox ("Invalid handle value !" + Chr$(13) + Chr$(10) + "(Disk not ready or read error.)"), 48, " Physical Disk " + Right(DriveName, 1) + " Read Error !"
   GoTo Cikis
End If
If LinuxDetected = False Then
   MsgBox ("Linux partition (83h) could not be detected on the drive " + DriveName + " ..."), 0, " LINUX PARTITION (83h) NOT FOUND !"
End If
Cikis:
Unload Me
Exit Sub
ErrMsg:
Beep
MsgBox ("Drive could not read!..." + Chr$(13) + Chr$(13) + "Error Number: " + Str$(Err)), 48, "! ERROR !"
C1LI = 0
Resume Cikis
End Sub

Private Sub Command2_Click()
Rem C1LI = 0
Unload Me
End Sub

Private Sub Form_Load()
Rem 4-11-2008
Combo1.AddItem "PhysicalDrive0"
Combo1.AddItem "PhysicalDrive1"
Combo1.AddItem "PhysicalDrive2"
Combo1.AddItem "PhysicalDrive3"
Rem 16-11-2008
Combo1.ListIndex = C1LI
DriveName = "PhysicalDrive0"
End Sub

Private Sub Form_Unload(Cancel As Integer)
Combo1.ListIndex = 0
End Sub
