3 * Copyright (C) 1998-2002 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.
31 GEOMETRY DriveGeometry
;
33 } DRIVE_GEOMETRY
, *PDRIVE_GEOMETRY
;
36 PDRIVE_GEOMETRY DriveGeometryListHead
= NULL
;
39 BOOL
DiskGetDriveGeometry(ULONG DriveNumber
, PGEOMETRY DriveGeometry
)
41 PDRIVE_GEOMETRY DriveGeometryListEntry
;
44 // Search the drive geometry list for the requested drive
46 DriveGeometryListEntry
= DriveGeometryListHead
;
47 while (DriveGeometryListEntry
!= NULL
)
50 // Check to see if this is the drive we want
52 if (DriveGeometryListEntry
->DriveNumber
== DriveNumber
)
55 // Yep - return the information
57 RtlCopyMemory(DriveGeometry
, &DriveGeometryListEntry
->DriveGeometry
, sizeof(GEOMETRY
));
62 // Nope, get next item
64 DriveGeometryListEntry
= (PDRIVE_GEOMETRY
)RtlListGetNext((PLIST_ITEM
)DriveGeometryListEntry
);
67 DiskError("Drive geometry unknown.");
71 BOOL
DiskSetDriveGeometry(ULONG DriveNumber
, ULONG Cylinders
, ULONG Heads
, ULONG Sectors
, ULONG BytesPerSector
)
73 PDRIVE_GEOMETRY DriveGeometryListEntry
;
76 // Search the drive geometry list for the requested drive
78 DriveGeometryListEntry
= DriveGeometryListHead
;
79 while (DriveGeometryListEntry
!= NULL
)
82 // Check to see if this is the drive
84 if (DriveGeometryListEntry
->DriveNumber
== DriveNumber
)
87 // Yes, we already have this drive's geometry information
94 // Nope, get next item
96 DriveGeometryListEntry
= (PDRIVE_GEOMETRY
)RtlListGetNext((PLIST_ITEM
)DriveGeometryListEntry
);
100 // If we get here then this is a new drive and we have
101 // to add it's information to our list
103 DriveGeometryListEntry
= (PDRIVE_GEOMETRY
)AllocateMemory(sizeof(DRIVE_GEOMETRY
));
104 if (DriveGeometryListEntry
== NULL
)
109 RtlZeroMemory(DriveGeometryListEntry
, sizeof(DRIVE_GEOMETRY
));
110 DriveGeometryListEntry
->DriveNumber
= DriveNumber
;
111 DriveGeometryListEntry
->DriveGeometry
.Cylinders
= Cylinders
;
112 DriveGeometryListEntry
->DriveGeometry
.Heads
= Heads
;
113 DriveGeometryListEntry
->DriveGeometry
.Sectors
= Sectors
;
114 DriveGeometryListEntry
->DriveGeometry
.BytesPerSector
= BytesPerSector
;
116 if (DriveGeometryListHead
== NULL
)
118 DriveGeometryListHead
= DriveGeometryListEntry
;
122 RtlListInsertTail((PLIST_ITEM
)DriveGeometryListHead
, (PLIST_ITEM
)DriveGeometryListEntry
);