3 * Copyright (C) 1999, 2000, 2001 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 /////////////////////////////////////////////////////////////////////////////////////////////
31 /////////////////////////////////////////////////////////////////////////////////////////////
33 GEOMETRY DriveGeometry
;
34 ULONG VolumeHiddenSectors
;
35 ULONG CurrentlyOpenDriveNumber
;
37 /////////////////////////////////////////////////////////////////////////////////////////////
39 /////////////////////////////////////////////////////////////////////////////////////////////
41 VOID
DiskError(PUCHAR ErrorString
)
43 DbgPrint((DPRINT_DISK
, "%s\n", ErrorString
));
47 MessageBox(ErrorString
);
51 printf("%s", ErrorString
);
52 printf("\nPress any key\n");
57 VOID
DiskSetDriveGeometry(ULONG Cylinders
, ULONG Heads
, ULONG Sectors
, ULONG BytesPerSector
)
59 DriveGeometry
.Cylinders
= Cylinders
;
60 DriveGeometry
.Heads
= Heads
;
61 DriveGeometry
.Sectors
= Sectors
;
62 DriveGeometry
.BytesPerSector
= BytesPerSector
;
64 DbgPrint((DPRINT_DISK
, "DriveGeometry.Cylinders: %d\n", DriveGeometry
.Cylinders
));
65 DbgPrint((DPRINT_DISK
, "DriveGeometry.Heads: %d\n", DriveGeometry
.Heads
));
66 DbgPrint((DPRINT_DISK
, "DriveGeometry.Sectors: %d\n", DriveGeometry
.Sectors
));
67 DbgPrint((DPRINT_DISK
, "DriveGeometry.BytesPerSector: %d\n", DriveGeometry
.BytesPerSector
));
70 VOID
DiskSetVolumeProperties(ULONG HiddenSectors
)
72 VolumeHiddenSectors
= HiddenSectors
;
75 BOOL
DiskReadMultipleLogicalSectors(ULONG SectorNumber
, ULONG SectorCount
, PVOID Buffer
)
83 nSect += nHiddenSectors;
85 while (nNumberOfSectors)
87 PhysicalSector = 1 + (nSect % nSectorsPerTrack);
88 PhysicalHead = (nSect / nSectorsPerTrack) % nNumberOfHeads;
89 PhysicalTrack = nSect / (nSectorsPerTrack * nNumberOfHeads);
91 if (PhysicalSector > 1)
93 if (nNumberOfSectors >= (nSectorsPerTrack - (PhysicalSector - 1)))
94 nNum = (nSectorsPerTrack - (PhysicalSector - 1));
96 nNum = nNumberOfSectors;
100 if (nNumberOfSectors >= nSectorsPerTrack)
101 nNum = nSectorsPerTrack;
103 nNum = nNumberOfSectors;
106 bRetVal = biosdisk(CurrentlyOpenDriveNumber, PhysicalHead, PhysicalTrack, PhysicalSector, nNum, pBuffer);
110 FS_DO_ERROR("Disk Error");
114 pBuffer += (nNum * 512);
115 nNumberOfSectors -= nNum;
120 PVOID RealBuffer
= Buffer
;
122 for (CurrentSector
=SectorNumber
; CurrentSector
<(SectorNumber
+ SectorCount
); CurrentSector
++)
124 if (!DiskReadLogicalSector(CurrentSector
, RealBuffer
) )
129 RealBuffer
+= DriveGeometry
.BytesPerSector
;
135 BOOL
DiskReadLogicalSector(ULONG SectorNumber
, PVOID Buffer
)
137 ULONG PhysicalSector
;
141 DbgPrint((DPRINT_DISK
, "ReadLogicalSector() SectorNumber: %d Buffer: 0x%x\n", SectorNumber
, Buffer
));
143 SectorNumber
+= VolumeHiddenSectors
;
144 PhysicalSector
= 1 + (SectorNumber
% DriveGeometry
.Sectors
);
145 PhysicalHead
= (SectorNumber
/ DriveGeometry
.Sectors
) % DriveGeometry
.Heads
;
146 PhysicalTrack
= (SectorNumber
/ DriveGeometry
.Sectors
) / DriveGeometry
.Heads
;
148 //DbgPrint((DPRINT_FILESYSTEM, "Calling BiosInt13Read() with PhysicalHead: %d\n", PhysicalHead));
149 //DbgPrint((DPRINT_FILESYSTEM, "Calling BiosInt13Read() with PhysicalTrack: %d\n", PhysicalTrack));
150 //DbgPrint((DPRINT_FILESYSTEM, "Calling BiosInt13Read() with PhysicalSector: %d\n", PhysicalSector));
151 if (PhysicalHead
>= DriveGeometry
.Heads
)
153 BugCheck((DPRINT_DISK
, "PhysicalHead >= DriveGeometry.Heads\nPhysicalHead = %d\nDriveGeometry.Heads = %d\n", PhysicalHead
, DriveGeometry
.Heads
));
155 if (PhysicalTrack
>= DriveGeometry
.Cylinders
)
157 BugCheck((DPRINT_DISK
, "PhysicalTrack >= DriveGeometry.Cylinders\nPhysicalTrack = %d\nDriveGeometry.Cylinders = %d\n", PhysicalTrack
, DriveGeometry
.Cylinders
));
159 if (PhysicalSector
> DriveGeometry
.Sectors
)
161 BugCheck((DPRINT_DISK
, "PhysicalSector > DriveGeometry.Sectors\nPhysicalSector = %d\nDriveGeometry.Sectors = %d\n", PhysicalSector
, DriveGeometry
.Sectors
));
165 // Check to see if it is a fixed disk drive
166 // If so then check to see if Int13 extensions work
167 // If they do then use them, otherwise default back to BIOS calls
169 if ((CurrentlyOpenDriveNumber
>= 0x80) && (BiosInt13ExtensionsSupported(CurrentlyOpenDriveNumber
)) && (SectorNumber
> (DriveGeometry
.Cylinders
* DriveGeometry
.Heads
* DriveGeometry
.Sectors
)))
171 DbgPrint((DPRINT_DISK
, "Using Int 13 Extensions for read. BiosInt13ExtensionsSupported(%d) = %s\n", CurrentlyOpenDriveNumber
, BiosInt13ExtensionsSupported(CurrentlyOpenDriveNumber
) ? "TRUE" : "FALSE"));
172 if ( !BiosInt13ReadExtended(CurrentlyOpenDriveNumber
, SectorNumber
, 1, Buffer
) )
174 DiskError("Disk read error.");
180 if ( !BiosInt13Read(CurrentlyOpenDriveNumber
, PhysicalHead
, PhysicalTrack
, PhysicalSector
, 1, Buffer
) )
182 DiskError("Disk read error.");