1 | /* $Id: osliblvm.h,v 1.2 2002-05-10 14:55:13 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * OS/2 LVM (Logical Volume Management) functions
|
---|
4 | *
|
---|
5 | * Copyright 2002 Sander van Leeuwen
|
---|
6 | *
|
---|
7 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
8 | *
|
---|
9 | */
|
---|
10 | #ifndef __OSLIBLVM_H__
|
---|
11 | #define __OSLIBLVM_H__
|
---|
12 |
|
---|
13 | #include <win\winioctl.h>
|
---|
14 |
|
---|
15 | #ifdef OS2_INCLUDED
|
---|
16 |
|
---|
17 | typedef unsigned short int CARDINAL16;
|
---|
18 | typedef unsigned long CARDINAL32;
|
---|
19 | typedef unsigned int CARDINAL;
|
---|
20 | typedef unsigned char BOOLEAN;
|
---|
21 | typedef short int INTEGER16;
|
---|
22 | typedef long int INTEGER32;
|
---|
23 | typedef int INTEGER;
|
---|
24 | typedef unsigned long DoubleWord;
|
---|
25 | typedef short unsigned int Word;
|
---|
26 | typedef unsigned long LBA;
|
---|
27 |
|
---|
28 | /* Define a Partition Sector Number. A Partition Sector Number is
|
---|
29 | relative to the start of a partition. The first sector in a partition
|
---|
30 | is PSN 0. */
|
---|
31 | typedef unsigned long PSN;
|
---|
32 |
|
---|
33 | /* Define the size of a Partition Name. Partition Names are user defined names given to a partition. */
|
---|
34 | #define PARTITION_NAME_SIZE 20
|
---|
35 |
|
---|
36 | /* Define the size of a volume name. Volume Names are user defined names given to a volume. */
|
---|
37 | #define VOLUME_NAME_SIZE 20
|
---|
38 |
|
---|
39 | /* Define the size of a disk name. Disk Names are user defined names given to physical disk drives in the system. */
|
---|
40 | #define DISK_NAME_SIZE 20
|
---|
41 |
|
---|
42 | /* The name of the filesystem in use on a partition. This name may be up to 12 ( + NULL terminator) characters long. */
|
---|
43 | #define FILESYSTEM_NAME_SIZE 20
|
---|
44 |
|
---|
45 | /* The number of bytes in a sector on the disk. */
|
---|
46 | #define BYTES_PER_SECTOR 512
|
---|
47 |
|
---|
48 | /* The following are invariant for a disk drive. */
|
---|
49 | typedef struct _Drive_Control_Record {
|
---|
50 | CARDINAL32 Drive_Number; /* OS/2 Drive Number for this drive. */
|
---|
51 | CARDINAL32 Drive_Size; /* The total number of sectors on the drive. */
|
---|
52 | DoubleWord Drive_Serial_Number; /* The serial number assigned to this drive.
|
---|
53 | For info. purposes only. */
|
---|
54 | ULONG Drive_Handle; /* Handle used for operations on the disk that
|
---|
55 | this record corresponds to. */
|
---|
56 | CARDINAL32 Cylinder_Count; /* The number of cylinders on the drive. */
|
---|
57 | CARDINAL32 Heads_Per_Cylinder; /* The number of heads per cylinder for this drive. */
|
---|
58 | CARDINAL32 Sectors_Per_Track; /* The number of sectors per track for this drive. */
|
---|
59 | BOOLEAN Drive_Is_PRM; /* Set to TRUE if this drive is a PRM. */
|
---|
60 | BYTE Reserved[3]; /* Alignment. */
|
---|
61 | } Drive_Control_Record;
|
---|
62 |
|
---|
63 | /* The following structure is returned by the Get_Drive_Control_Data function. */
|
---|
64 | typedef struct _Drive_Control_Array{
|
---|
65 | Drive_Control_Record * Drive_Control_Data; /* An array of drive control records. */
|
---|
66 | CARDINAL32 Count; /* The number of entries in the array
|
---|
67 | of drive control records. */
|
---|
68 | } Drive_Control_Array;
|
---|
69 |
|
---|
70 |
|
---|
71 | /* The following structure defines the information that can be changed for a specific disk drive. */
|
---|
72 | typedef struct _Drive_Information_Record {
|
---|
73 | CARDINAL32 Total_Available_Sectors; /* The number of sectors on the disk which are not currently assigned to a partition. */
|
---|
74 | CARDINAL32 Largest_Free_Block_Of_Sectors; /* The number of sectors in the largest contiguous block of available sectors. */
|
---|
75 | BOOLEAN Corrupt_Partition_Table; /* If TRUE, then the partitioning information found on the drive is incorrect! */
|
---|
76 | BOOLEAN Unusable; /* If TRUE, the drive's MBR is not accessible and the drive can not be partitioned. */
|
---|
77 | BOOLEAN IO_Error; /* If TRUE, then the last I/O operation on this drive failed! */
|
---|
78 | BOOLEAN Is_Big_Floppy; /* If TRUE, then the drive is a PRM formatted as a big floppy (i.e. the old style removable media support). */
|
---|
79 | char Drive_Name[DISK_NAME_SIZE]; /* User assigned name for this disk drive. */
|
---|
80 | } Drive_Information_Record;
|
---|
81 |
|
---|
82 | typedef struct _Partition_Information_Record {
|
---|
83 | ULONG Partition_Handle; /* The handle used to perform
|
---|
84 | operations on this partition. */
|
---|
85 | ULONG Volume_Handle; /* If this partition is part
|
---|
86 | of a volume, this will be the
|
---|
87 | handle of the volume. If
|
---|
88 | this partition is NOT
|
---|
89 | part of a volume, then
|
---|
90 | this handle will be 0. */
|
---|
91 | ULONG Drive_Handle; /* The handle for the drive
|
---|
92 | this partition resides on. */
|
---|
93 | DoubleWord Partition_Serial_Number; /* The serial number assigned
|
---|
94 | to this partition. */
|
---|
95 | CARDINAL32 Partition_Start; /* The LBA of the first
|
---|
96 | sector of the partition. */
|
---|
97 | CARDINAL32 True_Partition_Size; /* The total number of
|
---|
98 | sectors comprising the partition. */
|
---|
99 | CARDINAL32 Usable_Partition_Size; /* The size of the partition
|
---|
100 | as reported to the IFSM. This is the
|
---|
101 | size of the partition less
|
---|
102 | any LVM overhead. */
|
---|
103 | CARDINAL32 Boot_Limit; /* The maximum number of
|
---|
104 | sectors from this block
|
---|
105 | of free space that can be
|
---|
106 | used to create a bootable
|
---|
107 | partition if you allocate
|
---|
108 | from the beginning of the block
|
---|
109 | of free space. */
|
---|
110 | BOOLEAN Spanned_Volume; /* TRUE if this partition is
|
---|
111 | part of a multi-partition
|
---|
112 | volume. */
|
---|
113 | BOOLEAN Primary_Partition; /* True or False. Any
|
---|
114 | non-zero value here indicates
|
---|
115 | that this partition is
|
---|
116 | a primary partition. Zero
|
---|
117 | here indicates that this
|
---|
118 | partition is a "logical drive"
|
---|
119 | - i.e. it resides inside of
|
---|
120 | an extended partition. */
|
---|
121 | BYTE Active_Flag; /* 80 = Partition is marked
|
---|
122 | as being active.
|
---|
123 | 0 = Partition is not
|
---|
124 | active. */
|
---|
125 | BYTE OS_Flag; /* This field is from the
|
---|
126 | partition table. It is
|
---|
127 | known as the OS flag, the
|
---|
128 | Partition Type Field,
|
---|
129 | Filesystem Type, and
|
---|
130 | various other names.
|
---|
131 | Values of interest
|
---|
132 | If this field is: (values
|
---|
133 | are in hex)
|
---|
134 | 07 = The partition is a
|
---|
135 | compatibility
|
---|
136 | partition formatted
|
---|
137 | for use with an
|
---|
138 | installable
|
---|
139 | filesystem, such as
|
---|
140 | HPFS or JFS.
|
---|
141 | 00 = Unformatted partition
|
---|
142 | 01 = FAT12 filesystem is
|
---|
143 | in use on this
|
---|
144 | partition.
|
---|
145 | 04 = FAT16 filesystem is
|
---|
146 | in use on this
|
---|
147 | partition.
|
---|
148 | 0A = OS/2 Boot Manager
|
---|
149 | Partition
|
---|
150 | 35 = LVM partition
|
---|
151 | 06 = OS/2 FAT16 partition */
|
---|
152 | BYTE Partition_Type; /* 0 = Free Space
|
---|
153 | 1 = LVM Partition (Part of
|
---|
154 | an LVM Volume.)
|
---|
155 | 2 = Compatibility Partition
|
---|
156 | All other values are reserved
|
---|
157 | for future use. */
|
---|
158 | BYTE Partition_Status; /* 0 = Free Space
|
---|
159 | 1 = In Use - i.e. already
|
---|
160 | assigned to a volume.
|
---|
161 | 2 = Available - i.e. not
|
---|
162 | currently assigned
|
---|
163 | to a volume. */
|
---|
164 | BOOLEAN On_Boot_Manager_Menu; /* Set to TRUE if this
|
---|
165 | partition is not part of
|
---|
166 | a Volume yet is on the
|
---|
167 | Boot Manager Menu. */
|
---|
168 | BYTE Reserved; /* Alignment. */
|
---|
169 | char Volume_Drive_Letter; /* The drive letter assigned
|
---|
170 | to the volume that this
|
---|
171 | partition is a part of. */
|
---|
172 | char Drive_Name[DISK_NAME_SIZE]; /* User assigned name for
|
---|
173 | this disk drive. */
|
---|
174 | char File_System_Name[FILESYSTEM_NAME_SIZE];/* The name of the filesystem
|
---|
175 | in use on this partition,
|
---|
176 | if it is known. */
|
---|
177 | char Partition_Name[PARTITION_NAME_SIZE]; /* The user assigned name for
|
---|
178 | this partition. */
|
---|
179 | char Volume_Name[VOLUME_NAME_SIZE]; /* If this partition is part
|
---|
180 | of a volume, then this
|
---|
181 | will be the name of the
|
---|
182 | volume that this partition
|
---|
183 | is a part of. If this record
|
---|
184 | represents free space,
|
---|
185 | then the Volume_Name will be
|
---|
186 | "FS xx", where xx is a unique
|
---|
187 | numeric ID generated by
|
---|
188 | LVM.DLL. Otherwise it
|
---|
189 | will be an empty string. */
|
---|
190 | } Partition_Information_Record;
|
---|
191 |
|
---|
192 | /* The following defines are for use with the Partition_Type field in the Partition_Information_Record. */
|
---|
193 | #define FREE_SPACE_PARTITION 0
|
---|
194 | #define LVM_PARTITION 1
|
---|
195 | #define COMPATIBILITY_PARTITION 2
|
---|
196 |
|
---|
197 | /* The following defines are for use with the Partition_Status field in the Partition_Information_Record. */
|
---|
198 | #define PARTITION_IS_IN_USE 1
|
---|
199 | #define PARTITION_IS_AVAILABLE 2
|
---|
200 | #define PARTITION_IS_FREE_SPACE 0
|
---|
201 |
|
---|
202 |
|
---|
203 | /* The following structure is returned by various functions in the LVM Engine. */
|
---|
204 | typedef struct _Partition_Information_Array {
|
---|
205 | Partition_Information_Record * Partition_Array; /* An array of Partition_Information_Records. */
|
---|
206 | CARDINAL32 Count; /* The number of entries in the Partition_Array. */
|
---|
207 | } Partition_Information_Array;
|
---|
208 |
|
---|
209 | /* The following items are invariant for a volume. */
|
---|
210 | typedef struct _Volume_Control_Record {
|
---|
211 | DoubleWord Volume_Serial_Number; /* The serial number assigned to this volume. */
|
---|
212 | ULONG Volume_Handle; /* The handle used to perform operations on this volume. */
|
---|
213 | BOOLEAN Compatibility_Volume; /* TRUE indicates that this volume is compatible with older versions of OS/2.
|
---|
214 | FALSE indicates that this is an LVM specific volume and can not be used without OS2LVM.DMD. */
|
---|
215 | BYTE Device_Type; /* Indicates what type of device the Volume resides on:
|
---|
216 | 0 = Hard Drive under LVM Control
|
---|
217 | 1 = PRM under LVM Control
|
---|
218 | 2 = CD-ROM
|
---|
219 | 3 = Network drive
|
---|
220 | 4 = Unknown device NOT under LVM Control
|
---|
221 | */
|
---|
222 | BYTE Reserved[2]; /* Alignment. */
|
---|
223 | } Volume_Control_Record;
|
---|
224 |
|
---|
225 | /* The following define the device types used in the Device_Type field of the Volume_Control_Record. */
|
---|
226 | #define LVM_HARD_DRIVE 0
|
---|
227 | #define LVM_PRM 1
|
---|
228 | #define NON_LVM_CDROM 2
|
---|
229 | #define NETWORK_DRIVE 3
|
---|
230 | #define NON_LVM_DEVICE 4
|
---|
231 |
|
---|
232 | /* The following structure is returned by the Get_Volume_Control_Data function. */
|
---|
233 | typedef struct _Volume_Control_Array{
|
---|
234 | Volume_Control_Record * Volume_Control_Data; /* An array of volume control records. */
|
---|
235 | CARDINAL32 Count; /* The number of entries in the array of volume control records. */
|
---|
236 | } Volume_Control_Array;
|
---|
237 |
|
---|
238 |
|
---|
239 | /* The following information about a volume can (and often does) vary. */
|
---|
240 | typedef struct _Volume_Information_Record {
|
---|
241 | CARDINAL32 Volume_Size; /* The number of sectors comprising the volume. */
|
---|
242 | CARDINAL32 Partition_Count; /* The number of partitions which comprise this volume. */
|
---|
243 | CARDINAL32 Drive_Letter_Conflict; /* 0 indicates that the drive letter preference for this volume is unique.
|
---|
244 | 1 indicates that the drive letter preference for this volume
|
---|
245 | is not unique, but this volume got its preferred drive letter anyway.
|
---|
246 | 2 indicates that the drive letter preference for this volume
|
---|
247 | is not unique, and this volume did NOT get its preferred drive letter.
|
---|
248 | 4 indicates that this volume is currently "hidden" - i.e. it has
|
---|
249 | no drive letter preference at the current time. */
|
---|
250 | BOOLEAN Compatibility_Volume; /* TRUE if this is for a compatibility volume, FALSE otherwise. */
|
---|
251 | BOOLEAN Bootable; /* Set to TRUE if this volume appears on the Boot Manager menu, or if it is
|
---|
252 | a compatibility volume and its corresponding partition is the first active
|
---|
253 | primary partition on the first drive. */
|
---|
254 | char Drive_Letter_Preference; /* The drive letter that this volume desires to be. */
|
---|
255 | char Current_Drive_Letter; /* The drive letter currently used to access this volume. May be different than
|
---|
256 | Drive_Letter_Preference if there was a conflict ( i.e. Drive_Letter_Preference
|
---|
257 | is already in use by another volume ). */
|
---|
258 | char Initial_Drive_Letter; /* The drive letter assigned to this volume by the operating system when LVM was started.
|
---|
259 | This may be different from the Drive_Letter_Preference if there were conflicts, and
|
---|
260 | may be different from the Current_Drive_Letter. This will be 0x0 if the Volume did
|
---|
261 | not exist when the LVM Engine was opened (i.e. it was created during this LVM session). */
|
---|
262 | BOOLEAN New_Volume; /* Set to FALSE if this volume existed before the LVM Engine was opened. Set to
|
---|
263 | TRUE if this volume was created after the LVM Engine was opened. */
|
---|
264 | BYTE Status; /* 0 = None.
|
---|
265 | 1 = Bootable
|
---|
266 | 2 = Startable
|
---|
267 | 3 = Installable. */
|
---|
268 | BYTE Reserved_1;
|
---|
269 | char Volume_Name[VOLUME_NAME_SIZE]; /* The user assigned name for this volume. */
|
---|
270 | char File_System_Name[FILESYSTEM_NAME_SIZE];/* The name of the filesystem in use on this partition, if it is known. */
|
---|
271 | } Volume_Information_Record;
|
---|
272 |
|
---|
273 |
|
---|
274 | /* Error codes returned by the LVM Engine. */
|
---|
275 | #define LVM_ENGINE_NO_ERROR 0
|
---|
276 | #define LVM_ENGINE_OUT_OF_MEMORY 1
|
---|
277 | #define LVM_ENGINE_IO_ERROR 2
|
---|
278 | #define LVM_ENGINE_BAD_HANDLE 3
|
---|
279 | #define LVM_ENGINE_INTERNAL_ERROR 4
|
---|
280 | #define LVM_ENGINE_ALREADY_OPEN 5
|
---|
281 | #define LVM_ENGINE_NOT_OPEN 6
|
---|
282 | #define LVM_ENGINE_NAME_TOO_BIG 7
|
---|
283 | #define LVM_ENGINE_OPERATION_NOT_ALLOWED 8
|
---|
284 | #define LVM_ENGINE_DRIVE_OPEN_FAILURE 9
|
---|
285 | #define LVM_ENGINE_BAD_PARTITION 10
|
---|
286 | #define LVM_ENGINE_CAN_NOT_MAKE_PRIMARY_PARTITION 11
|
---|
287 | #define LVM_ENGINE_TOO_MANY_PRIMARY_PARTITIONS 12
|
---|
288 | #define LVM_ENGINE_CAN_NOT_MAKE_LOGICAL_DRIVE 13
|
---|
289 | #define LVM_ENGINE_REQUESTED_SIZE_TOO_BIG 14
|
---|
290 | #define LVM_ENGINE_1024_CYLINDER_LIMIT 15
|
---|
291 | #define LVM_ENGINE_PARTITION_ALIGNMENT_ERROR 16
|
---|
292 | #define LVM_ENGINE_REQUESTED_SIZE_TOO_SMALL 17
|
---|
293 | #define LVM_ENGINE_NOT_ENOUGH_FREE_SPACE 18
|
---|
294 | #define LVM_ENGINE_BAD_ALLOCATION_ALGORITHM 19
|
---|
295 | #define LVM_ENGINE_DUPLICATE_NAME 20
|
---|
296 | #define LVM_ENGINE_BAD_NAME 21
|
---|
297 | #define LVM_ENGINE_BAD_DRIVE_LETTER_PREFERENCE 22
|
---|
298 | #define LVM_ENGINE_NO_DRIVES_FOUND 23
|
---|
299 | #define LVM_ENGINE_WRONG_VOLUME_TYPE 24
|
---|
300 | #define LVM_ENGINE_VOLUME_TOO_SMALL 25
|
---|
301 | #define LVM_ENGINE_BOOT_MANAGER_ALREADY_INSTALLED 26
|
---|
302 | #define LVM_ENGINE_BOOT_MANAGER_NOT_FOUND 27
|
---|
303 | #define LVM_ENGINE_INVALID_PARAMETER 28
|
---|
304 | #define LVM_ENGINE_BAD_FEATURE_SET 29
|
---|
305 | #define LVM_ENGINE_TOO_MANY_PARTITIONS_SPECIFIED 30
|
---|
306 | #define LVM_ENGINE_LVM_PARTITIONS_NOT_BOOTABLE 31
|
---|
307 | #define LVM_ENGINE_PARTITION_ALREADY_IN_USE 32
|
---|
308 | #define LVM_ENGINE_SELECTED_PARTITION_NOT_BOOTABLE 33
|
---|
309 | #define LVM_ENGINE_VOLUME_NOT_FOUND 34
|
---|
310 | #define LVM_ENGINE_DRIVE_NOT_FOUND 35
|
---|
311 | #define LVM_ENGINE_PARTITION_NOT_FOUND 36
|
---|
312 | #define LVM_ENGINE_TOO_MANY_FEATURES_ACTIVE 37
|
---|
313 | #define LVM_ENGINE_PARTITION_TOO_SMALL 38
|
---|
314 | #define LVM_ENGINE_MAX_PARTITIONS_ALREADY_IN_USE 39
|
---|
315 | #define LVM_ENGINE_IO_REQUEST_OUT_OF_RANGE 40
|
---|
316 | #define LVM_ENGINE_SPECIFIED_PARTITION_NOT_STARTABLE 41
|
---|
317 | #define LVM_ENGINE_SELECTED_VOLUME_NOT_STARTABLE 42
|
---|
318 | #define LVM_ENGINE_EXTENDFS_FAILED 43
|
---|
319 | #define LVM_ENGINE_REBOOT_REQUIRED 44
|
---|
320 |
|
---|
321 | #endif
|
---|
322 |
|
---|
323 | #define VOLUME_NAME_PREFIX "\\\\?\\Volume\\"
|
---|
324 |
|
---|
325 | BOOL OSLibLVMInit();
|
---|
326 | void OSLibLVMExit();
|
---|
327 | HANDLE OSLibLVMQueryVolumeControlData();
|
---|
328 | void OSLibLVMFreeVolumeControlData(HANDLE hVolumeControlData);
|
---|
329 | BOOL OSLibLVMQueryVolumeName(HANDLE hVolumeControlData, ULONG volindex,
|
---|
330 | LPSTR lpszVolumeName, DWORD cchBufferLength);
|
---|
331 |
|
---|
332 | BOOL OSLibLVMGetPartitionInfo(ULONG driveLetter, LPSTR lpszVolumeName, PPARTITION_INFORMATION pPartition);
|
---|
333 | BOOL OSLibLVMGetVolumeExtents(ULONG driveLetter, LPSTR lpszVolumeName, PVOLUME_DISK_EXTENTS pVolExtent, BOOL *pfLVMVolume = NULL);
|
---|
334 |
|
---|
335 | ULONG OSLibLVMGetDriveType(LPCSTR lpszVolume);
|
---|
336 | CHAR OSLibLVMQueryDriveFromVolumeName(LPCSTR lpszVolume);
|
---|
337 | BOOL OSLibLVMGetVolumeNameForVolumeMountPoint(LPCSTR lpszVolumeMountPoint, LPSTR lpszVolumeName,
|
---|
338 | DWORD cchBufferLength);
|
---|
339 |
|
---|
340 |
|
---|
341 | DWORD OSLibLVMQueryVolumeFS(LPSTR lpszVolume, LPSTR lpFileSystemNameBuffer, DWORD nFileSystemNameSize);
|
---|
342 | DWORD OSLibLVMQueryVolumeSerialAndName(LPSTR lpszVolume, LPDWORD lpVolumeSerialNumber, LPSTR lpVolumeNameBuffer, DWORD nVolumeNameSize);
|
---|
343 |
|
---|
344 | BOOL OSLibLVMStripVolumeName(LPCSTR lpszWin32VolumeName, LPSTR lpszOS2VolumeName, DWORD cchBufferLength);
|
---|
345 |
|
---|
346 | #endif //__OSLIBLVM_H__
|
---|