source: trunk/src/kernel32/osliblvm.cpp@ 21583

Last change on this file since 21583 was 21583, checked in by abwillis, 14 years ago

Ticket #32

File size: 27.1 KB
Line 
1/* $Id: osliblvm.cpp,v 1.5 2003-01-20 10:46:27 sandervl Exp $ */
2
3/*
4 * OS/2 LVM (Logical Volume Management) functions
5 *
6 * Copyright 2002 Sander van Leeuwen
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11#define INCL_DOSPROCESS
12#define INCL_DOSSEMAPHORES
13#define INCL_DOSQUEUES
14#define INCL_DOSMODULEMGR
15#define INCL_DOSEXCEPTIONS
16#define INCL_DOSERRORS
17#include <os2wrap.h>
18#include <stdlib.h>
19#include <string.h>
20#include <dbglog.h>
21#include <win32type.h>
22#include <winconst.h>
23#include <win\winioctl.h>
24#include "osliblvm.h"
25
26
27#define DBG_LOCALLOG DBG_osliblvm
28#include "dbglocal.h"
29
30static void (* SYSTEM pfnOpen_LVM_Engine)( BOOLEAN Ignore_CHS, CARDINAL32 * Error_Code );
31static void (* SYSTEM pfnClose_LVM_Engine) ( void );
32static Drive_Control_Array (* SYSTEM pfnGet_Drive_Control_Data)( CARDINAL32 * Error_Code );
33static Drive_Information_Record (* SYSTEM pfnGet_Drive_Status)( ULONG Drive_Handle, CARDINAL32 * Error_Code );
34static Partition_Information_Array (* SYSTEM pfnGet_Partitions)( ULONG Handle, CARDINAL32 * Error_Code );
35static ULONG (* SYSTEM pfnGet_Partition_Handle)( CARDINAL32 Serial_Number, CARDINAL32 * Error_Code );
36static Partition_Information_Record (* SYSTEM pfnGet_Partition_Information)( ULONG Partition_Handle, CARDINAL32 * Error_Code );
37static Volume_Control_Array (* SYSTEM pfnGet_Volume_Control_Data)( CARDINAL32 * Error_Code );
38static Volume_Information_Record (* SYSTEM pfnGet_Volume_Information)( ULONG Volume_Handle, CARDINAL32 * Error_Code );
39static void (* SYSTEM pfnFree_Engine_Memory)( ULONG Object );
40static void (* SYSTEM pfnRead_Sectors) ( CARDINAL32 Drive_Number,
41 LBA Starting_Sector,
42 CARDINAL32 Sectors_To_Read,
43 ULONG Buffer,
44 CARDINAL32 * Error);
45static void (* SYSTEM pfnWrite_Sectors) ( CARDINAL32 Drive_Number,
46 LBA Starting_Sector,
47 CARDINAL32 Sectors_To_Write,
48 ULONG Buffer,
49 CARDINAL32 * Error);
50
51static HMODULE hModLVM = 0;
52static BOOL fLVMOpened = FALSE;
53
54static void Close_LVM_Engine ( void );
55
56//******************************************************************************
57//******************************************************************************
58static BOOL OSLibLVMInit()
59{
60 APIRET rc;
61 CHAR szModuleFailure[CCHMAXPATH];
62
63 rc = DosLoadModule(szModuleFailure, sizeof(szModuleFailure), "LVM", (HMODULE *)&hModLVM);
64 if(rc) {
65 return FALSE;
66 }
67 rc = DosQueryProcAddr(hModLVM, 0, "Open_LVM_Engine", (PFN *)&pfnOpen_LVM_Engine);
68 if(rc) goto fail;
69 rc = DosQueryProcAddr(hModLVM, 0, "Close_LVM_Engine", (PFN *)&pfnClose_LVM_Engine);
70 if(rc) goto fail;
71 rc = DosQueryProcAddr(hModLVM, 0, "Get_Drive_Control_Data", (PFN *)&pfnGet_Drive_Control_Data);
72 if(rc) goto fail;
73 rc = DosQueryProcAddr(hModLVM, 0, "Get_Drive_Status", (PFN *)&pfnGet_Drive_Status);
74 if(rc) goto fail;
75 rc = DosQueryProcAddr(hModLVM, 0, "Get_Partitions", (PFN *)&pfnGet_Partitions);
76 if(rc) goto fail;
77 rc = DosQueryProcAddr(hModLVM, 0, "Get_Partition_Handle", (PFN *)&pfnGet_Partition_Handle);
78 if(rc) goto fail;
79 rc = DosQueryProcAddr(hModLVM, 0, "Get_Partition_Information", (PFN *)&pfnGet_Partition_Information);
80 if(rc) goto fail;
81 rc = DosQueryProcAddr(hModLVM, 0, "Get_Volume_Control_Data", (PFN *)&pfnGet_Volume_Control_Data);
82 if(rc) goto fail;
83 rc = DosQueryProcAddr(hModLVM, 0, "Get_Volume_Information", (PFN *)&pfnGet_Volume_Information);
84 if(rc) goto fail;
85 rc = DosQueryProcAddr(hModLVM, 0, "Free_Engine_Memory", (PFN *)&pfnFree_Engine_Memory);
86 if(rc) goto fail;
87 rc = DosQueryProcAddr(hModLVM, 0, "Read_Sectors", (PFN *)&pfnRead_Sectors);
88 if(rc) goto fail;
89 rc = DosQueryProcAddr(hModLVM, 0, "Write_Sectors", (PFN *)&pfnWrite_Sectors);
90 if(rc) goto fail;
91
92 return TRUE;
93
94fail:
95 if(hModLVM) {
96 DosFreeModule(hModLVM);
97 hModLVM = 0;
98 }
99 return FALSE;
100}
101//******************************************************************************
102//******************************************************************************
103void OSLibLVMExit()
104{
105 if(fLVMOpened) {
106 Close_LVM_Engine();
107 }
108 if(hModLVM) {
109 DosFreeModule(hModLVM);
110 hModLVM = 0;
111 }
112}
113//******************************************************************************
114//******************************************************************************
115static void Open_LVM_Engine( BOOLEAN Ignore_CHS, CARDINAL32 * Error_Code )
116{
117 USHORT sel;
118
119 //Load LVM dll
120 OSLibLVMInit();
121
122 sel = RestoreOS2FS();
123 pfnOpen_LVM_Engine(Ignore_CHS, Error_Code);
124 SetFS(sel);
125 return;
126}
127//******************************************************************************
128//******************************************************************************
129static void Close_LVM_Engine ( void )
130{
131 USHORT sel;
132
133 sel = RestoreOS2FS();
134 pfnClose_LVM_Engine();
135 SetFS(sel);
136 return;
137}
138//******************************************************************************
139//******************************************************************************
140static Drive_Control_Array Get_Drive_Control_Data( CARDINAL32 * Error_Code )
141{
142 Drive_Control_Array ret;
143 USHORT sel;
144
145 sel = RestoreOS2FS();
146 ret = pfnGet_Drive_Control_Data(Error_Code);
147 SetFS(sel);
148 return ret;
149}
150//******************************************************************************
151//******************************************************************************
152static Drive_Information_Record Get_Drive_Status( ULONG Drive_Handle, CARDINAL32 * Error_Code )
153{
154 Drive_Information_Record ret;
155 USHORT sel;
156
157 sel = RestoreOS2FS();
158 ret = pfnGet_Drive_Status(Drive_Handle, Error_Code);
159 SetFS(sel);
160 return ret;
161}
162//******************************************************************************
163//******************************************************************************
164static Partition_Information_Array Get_Partitions( ULONG Handle, CARDINAL32 * Error_Code )
165{
166 Partition_Information_Array ret;
167 USHORT sel;
168
169 sel = RestoreOS2FS();
170 ret = pfnGet_Partitions(Handle, Error_Code);
171 SetFS(sel);
172 return ret;
173}
174//******************************************************************************
175//******************************************************************************
176static ULONG Get_Partition_Handle( CARDINAL32 Serial_Number, CARDINAL32 * Error_Code )
177{
178 ULONG ret;
179 USHORT sel;
180
181 sel = RestoreOS2FS();
182 ret = pfnGet_Partition_Handle(Serial_Number, Error_Code);
183 SetFS(sel);
184 return ret;
185}
186//******************************************************************************
187//******************************************************************************
188static Partition_Information_Record Get_Partition_Information( ULONG Partition_Handle, CARDINAL32 * Error_Code )
189{
190 Partition_Information_Record ret;
191 USHORT sel;
192
193 sel = RestoreOS2FS();
194 ret = pfnGet_Partition_Information(Partition_Handle, Error_Code);
195 SetFS(sel);
196 return ret;
197}
198//******************************************************************************
199//******************************************************************************
200static Volume_Control_Array Get_Volume_Control_Data( CARDINAL32 * Error_Code )
201{
202 Volume_Control_Array ret;
203 USHORT sel;
204
205 sel = RestoreOS2FS();
206 ret = pfnGet_Volume_Control_Data(Error_Code);
207 SetFS(sel);
208 return ret;
209}
210//******************************************************************************
211//******************************************************************************
212static Volume_Information_Record Get_Volume_Information( ULONG Volume_Handle, CARDINAL32 * Error_Code )
213{
214 Volume_Information_Record ret;
215 USHORT sel;
216
217 sel = RestoreOS2FS();
218 ret = pfnGet_Volume_Information(Volume_Handle, Error_Code);
219 SetFS(sel);
220 return ret;
221}
222//******************************************************************************
223//******************************************************************************
224static void Free_Engine_Memory( ULONG Object )
225{
226 USHORT sel;
227
228 sel = RestoreOS2FS();
229 pfnFree_Engine_Memory(Object);
230 SetFS(sel);
231 return;
232}
233//******************************************************************************
234//******************************************************************************
235static void Read_Sectors ( CARDINAL32 Drive_Number,
236 LBA Starting_Sector,
237 CARDINAL32 Sectors_To_Read,
238 ULONG Buffer,
239 CARDINAL32 * Error)
240{
241 USHORT sel;
242
243 sel = RestoreOS2FS();
244 pfnRead_Sectors(Drive_Number, Starting_Sector, Sectors_To_Read, Buffer, Error);
245 SetFS(sel);
246 return;
247}
248//******************************************************************************
249//******************************************************************************
250static void Write_Sectors ( CARDINAL32 Drive_Number,
251 LBA Starting_Sector,
252 CARDINAL32 Sectors_To_Write,
253 ULONG Buffer,
254 CARDINAL32 * Error)
255{
256 USHORT sel;
257
258 sel = RestoreOS2FS();
259 pfnWrite_Sectors(Drive_Number, Starting_Sector, Sectors_To_Write, Buffer, Error);
260 SetFS(sel);
261 return;
262}
263//******************************************************************************
264//******************************************************************************
265HANDLE OSLibLVMQueryVolumeControlData()
266{
267 Volume_Control_Array *volctrl;
268 CARDINAL32 lasterror;
269
270 if(!hModLVM) {
271 dprintf(("LVM dll not loaded -> fail"));
272 return 0;
273 }
274
275 if(!fLVMOpened) {
276 Open_LVM_Engine(FALSE, &lasterror);
277 if(lasterror != LVM_ENGINE_NO_ERROR) {
278 DebugInt3();
279 return 0;
280 }
281 dprintf(("LVM engine opened"));
282 fLVMOpened = TRUE;
283 }
284
285 volctrl = (Volume_Control_Array *)malloc(sizeof(Volume_Control_Array));
286 if(volctrl == NULL) {
287 DebugInt3();
288 return 0;
289 }
290 *volctrl = Get_Volume_Control_Data(&lasterror);
291 if(lasterror != LVM_ENGINE_NO_ERROR) {
292 DebugInt3();
293 return 0;
294 }
295 return (HANDLE)volctrl;
296}
297//******************************************************************************
298//******************************************************************************
299void OSLibLVMFreeVolumeControlData(HANDLE hVolumeControlData)
300{
301 Volume_Control_Array *volctrl = (Volume_Control_Array *)hVolumeControlData;
302
303 if(volctrl == NULL) {
304 DebugInt3();
305 return;
306 }
307 Free_Engine_Memory((ULONG)volctrl->Volume_Control_Data);
308 free(volctrl);
309}
310//******************************************************************************
311//******************************************************************************
312BOOL OSLibLVMQueryVolumeName(HANDLE hVolumeControlData, ULONG *pVolIndex,
313 LPSTR lpszVolumeName, DWORD cchBufferLength)
314{
315 Volume_Control_Array *volctrl = (Volume_Control_Array *)hVolumeControlData;
316 Volume_Information_Record volinfo;
317 CARDINAL32 lasterror;
318
319 if(volctrl == NULL) {
320 DebugInt3();
321 return FALSE;
322 }
323 if(*pVolIndex >= volctrl->Count) {
324 return FALSE; //no more volumes
325 }
326 while(*pVolIndex < volctrl->Count) {
327 volinfo = Get_Volume_Information(volctrl->Volume_Control_Data[*pVolIndex].Volume_Handle, &lasterror);
328 if(lasterror != LVM_ENGINE_NO_ERROR) {
329 DebugInt3();
330 return FALSE;
331 }
332 //Don't report anything about LVM volumes until we support all those
333 //fancy features (like spanned volumes)
334 if(volinfo.Compatibility_Volume == TRUE) break;
335 dprintf(("Ignoring LVM volume %s", volinfo.Volume_Name));
336 (*pVolIndex)++;
337 }
338 if(*pVolIndex >= volctrl->Count) {
339 return FALSE; //no more volumes
340 }
341 strncpy(lpszVolumeName, volinfo.Volume_Name, min(sizeof(volinfo.Volume_Name), cchBufferLength)-1);
342 return TRUE;
343}
344//******************************************************************************
345//******************************************************************************
346static Volume_Information_Record OSLibLVMFindVolumeByDriveLetter(ULONG driveLetter,
347 Volume_Control_Record *pVolRec,
348 CARDINAL32 *lasterror)
349{
350 Volume_Control_Array *volctrl;
351 Volume_Information_Record volinfo;
352
353 volctrl = (Volume_Control_Array *) OSLibLVMQueryVolumeControlData();
354 if(volctrl == NULL) {
355 DebugInt3();
356 return volinfo;
357 }
358 for(int i=0;i<volctrl->Count;i++) {
359 volinfo = Get_Volume_Information(volctrl->Volume_Control_Data[i].Volume_Handle, lasterror);
360 if(*lasterror != LVM_ENGINE_NO_ERROR) {
361 goto fail;
362 }
363 if(volinfo.Current_Drive_Letter == (char) ('A' + driveLetter)) {
364 break;
365 }
366 }
367 if(i == volctrl->Count) goto fail;
368
369 if(pVolRec) {
370 *pVolRec = volctrl->Volume_Control_Data[i];
371 }
372 OSLibLVMFreeVolumeControlData((HANDLE)volctrl);
373 *lasterror = LVM_ENGINE_NO_ERROR;
374 return volinfo;
375
376fail:
377 DebugInt3();
378 OSLibLVMFreeVolumeControlData((HANDLE)volctrl);
379 *lasterror = LVM_ENGINE_NO_DRIVES_FOUND;
380 return volinfo;
381}
382//******************************************************************************
383//******************************************************************************
384static Volume_Information_Record OSLibLVMFindVolumeByName(LPSTR pszVolName,
385 Volume_Control_Record *pVolRec,
386 CARDINAL32 *lasterror)
387{
388 Volume_Control_Array *volctrl;
389 Volume_Information_Record volinfo;
390
391 volctrl = (Volume_Control_Array *) OSLibLVMQueryVolumeControlData();
392 if(volctrl == NULL) {
393 DebugInt3();
394 return volinfo;
395 }
396 for(int i=0;i<volctrl->Count;i++) {
397 volinfo = Get_Volume_Information(volctrl->Volume_Control_Data[i].Volume_Handle, lasterror);
398 if(*lasterror != LVM_ENGINE_NO_ERROR) {
399 goto fail;
400 }
401 if(!strcmp(volinfo.Volume_Name, pszVolName)) {
402 break;
403 }
404 }
405 if(i == volctrl->Count) goto fail;
406
407 if(pVolRec) {
408 *pVolRec = volctrl->Volume_Control_Data[i];
409 }
410 OSLibLVMFreeVolumeControlData((HANDLE)volctrl);
411 *lasterror = LVM_ENGINE_NO_ERROR;
412 return volinfo;
413
414fail:
415 DebugInt3();
416 OSLibLVMFreeVolumeControlData((HANDLE)volctrl);
417 *lasterror = LVM_ENGINE_NO_DRIVES_FOUND;
418 return volinfo;
419}
420//******************************************************************************
421//******************************************************************************
422BOOL OSLibLVMGetPartitionInfo(ULONG driveLetter, LPSTR lpszVolumeName, PPARTITION_INFORMATION pPartition)
423{
424 Volume_Information_Record volinfo;
425 Volume_Control_Record volctrl;
426 Partition_Information_Array partctrl;
427 CARDINAL32 lasterror;
428
429 if(lpszVolumeName && lpszVolumeName[0]) {
430 volinfo = OSLibLVMFindVolumeByName(lpszVolumeName, &volctrl, &lasterror);
431 }
432 else volinfo = OSLibLVMFindVolumeByDriveLetter(driveLetter, &volctrl, &lasterror);
433 if(lasterror != LVM_ENGINE_NO_ERROR) {
434 DebugInt3();
435 return FALSE;
436 }
437
438 partctrl = Get_Partitions(volctrl.Volume_Handle, &lasterror);
439 if(lasterror != LVM_ENGINE_NO_ERROR || partctrl.Count == 0) {
440 return FALSE;
441 }
442
443 pPartition->StartingOffset.u.HighPart = partctrl.Partition_Array[0].Partition_Start >> 23;
444 pPartition->StartingOffset.u.LowPart = partctrl.Partition_Array[0].Partition_Start << 9;
445// pPartition->PartitionLength.u.HighPart= partctrl.Partition_Array[0].True_Partition_Size >> 23;
446// pPartition->PartitionLength.u.LowPart = partctrl.Partition_Array[0].True_Partition_Size << 9;
447// pPartition->HiddenSectors = 0;
448 pPartition->PartitionLength.u.HighPart= partctrl.Partition_Array[0].Usable_Partition_Size >> 23;
449 pPartition->PartitionLength.u.LowPart = partctrl.Partition_Array[0].Usable_Partition_Size << 9;
450 pPartition->HiddenSectors = partctrl.Partition_Array[0].True_Partition_Size - partctrl.Partition_Array[0].Usable_Partition_Size;
451 pPartition->PartitionNumber = 0; //todo
452 pPartition->PartitionType = partctrl.Partition_Array[0].OS_Flag;
453 pPartition->BootIndicator = volinfo.Bootable;
454 pPartition->RecognizedPartition = TRUE;
455 pPartition->RewritePartition = 0;
456
457 Free_Engine_Memory((ULONG)partctrl.Partition_Array);
458 return TRUE;
459}
460//******************************************************************************
461//******************************************************************************
462BOOL OSLibLVMGetVolumeExtents(ULONG driveLetter, LPSTR lpszVolumeName, PVOLUME_DISK_EXTENTS pVolExtent,
463 BOOL *pfLVMVolume)
464{
465 Volume_Information_Record volinfo;
466 Volume_Control_Record volctrl;
467 Drive_Control_Array diskinfo;
468 Partition_Information_Array partctrl;
469 CARDINAL32 lasterror;
470 BOOL ret = TRUE;
471
472 if(lpszVolumeName && lpszVolumeName[0]) {
473 volinfo = OSLibLVMFindVolumeByName(lpszVolumeName, &volctrl, &lasterror);
474 }
475 else volinfo = OSLibLVMFindVolumeByDriveLetter(driveLetter, &volctrl, &lasterror);
476 if(lasterror != LVM_ENGINE_NO_ERROR) {
477 DebugInt3();
478 return FALSE;
479 }
480
481 partctrl = Get_Partitions(volctrl.Volume_Handle, &lasterror);
482 if(lasterror != LVM_ENGINE_NO_ERROR || partctrl.Count == 0) {
483 return FALSE;
484 }
485
486 //TODO: spanned volumes
487 pVolExtent->NumberOfDiskExtents = 1;
488 pVolExtent->Extents[0].DiskNumber = 0;
489 pVolExtent->Extents[0].StartingOffset.u.HighPart = partctrl.Partition_Array[0].Partition_Start >> 23;;
490 pVolExtent->Extents[0].StartingOffset.u.LowPart = partctrl.Partition_Array[0].Partition_Start << 9;
491// pVolExtent->Extents[0].ExtentLength.u.HighPart = partctrl.Partition_Array[0].True_Partition_Size >> 23;
492// pVolExtent->Extents[0].ExtentLength.u.LowPart = partctrl.Partition_Array[0].True_Partition_Size << 9;
493 pVolExtent->Extents[0].ExtentLength.u.HighPart = partctrl.Partition_Array[0].Usable_Partition_Size >> 23;
494 pVolExtent->Extents[0].ExtentLength.u.LowPart = partctrl.Partition_Array[0].Usable_Partition_Size << 9;
495
496 //find number of disk on which this volume is located
497 diskinfo = Get_Drive_Control_Data(&lasterror);
498 if(lasterror != LVM_ENGINE_NO_ERROR) {
499 return FALSE;
500 }
501 for(int i=0;i<diskinfo.Count;i++) {
502 if(diskinfo.Drive_Control_Data[i].Drive_Handle == partctrl.Partition_Array[0].Drive_Handle) {
503 //win32 base = 0, os2 base = 1
504 pVolExtent->Extents[0].DiskNumber = diskinfo.Drive_Control_Data[i].Drive_Number - 1;
505#ifdef DEBUG
506 if(diskinfo.Drive_Control_Data[i].Drive_Number == 0) DebugInt3();
507#endif
508 break;
509 }
510 }
511 if(i == diskinfo.Count) {
512 ret = FALSE;
513 }
514 dprintf(("pVolExtent->NumberOfDiskExtents %d", pVolExtent->NumberOfDiskExtents));
515 dprintf(("pVolExtent->Extents[0].DiskNumber %d", pVolExtent->Extents[0].DiskNumber));
516 dprintf(("pVolExtent->Extents[0].StartingOffset %08x%08x", pVolExtent->Extents[0].StartingOffset.u.HighPart, pVolExtent->Extents[0].StartingOffset.u.LowPart));
517 dprintf(("pVolExtent->Extents[0].ExtentLength %08x%08x", pVolExtent->Extents[0].ExtentLength.u.HighPart, pVolExtent->Extents[0].ExtentLength.u.LowPart));
518
519 if(pfLVMVolume) {
520 *pfLVMVolume = (volinfo.Compatibility_Volume == FALSE);
521 }
522 Free_Engine_Memory((ULONG)diskinfo.Drive_Control_Data);
523 Free_Engine_Memory((ULONG)partctrl.Partition_Array);
524 return ret;
525}
526//******************************************************************************
527//******************************************************************************
528ULONG OSLibLVMGetDriveType(LPCSTR lpszVolume)
529{
530 Volume_Information_Record volinfo;
531 Volume_Control_Record volctrl;
532 ULONG drivetype;
533 CARDINAL32 lasterror;
534
535 volinfo = OSLibLVMFindVolumeByName((char *)lpszVolume, &volctrl, &lasterror);
536 if(lasterror != LVM_ENGINE_NO_ERROR) {
537 DebugInt3();
538 return DRIVE_NO_ROOT_DIR_W; //return value checked in NT4, SP6 (GetDriveType(""), GetDriveType("4");
539 }
540
541 switch(volctrl.Device_Type) {
542 case LVM_HARD_DRIVE:
543 drivetype = DRIVE_FIXED_W;
544 break;
545 case NON_LVM_CDROM:
546 drivetype = DRIVE_CDROM_W;
547 break;
548 case NETWORK_DRIVE:
549 drivetype = DRIVE_REMOTE_W;
550 break;
551 case LVM_PRM:
552 drivetype = DRIVE_REMOVABLE_W;
553 break;
554 default:
555 return DRIVE_NO_ROOT_DIR_W; //return value checked in NT4, SP6 (GetDriveType(""), GetDriveType("4");
556 }
557 return drivetype;
558}
559//******************************************************************************
560// OSLibLVMQueryDriveFromVolumeName
561//
562// Returns:
563// - drive letter corresponding to volume name
564// - -1 if volume wasn't found
565// - 0 if volume is present, but not mounted
566//
567//******************************************************************************
568CHAR OSLibLVMQueryDriveFromVolumeName(LPCSTR lpszVolume)
569{
570 Volume_Information_Record volinfo;
571 ULONG drivetype;
572 CARDINAL32 lasterror;
573
574 volinfo = OSLibLVMFindVolumeByName((char *)lpszVolume, NULL, &lasterror);
575 if(lasterror != LVM_ENGINE_NO_ERROR) {
576 DebugInt3();
577 return -1; //not found
578 }
579 return volinfo.Current_Drive_Letter;
580}
581//******************************************************************************
582//******************************************************************************
583DWORD OSLibLVMQueryVolumeFS(LPSTR lpszVolume, LPSTR lpFileSystemNameBuffer, DWORD nFileSystemNameSize)
584{
585 Volume_Information_Record volinfo;
586 CARDINAL32 lasterror;
587
588 volinfo = OSLibLVMFindVolumeByName(lpszVolume, NULL, &lasterror);
589 if(lasterror != LVM_ENGINE_NO_ERROR) {
590 DebugInt3();
591 return ERROR_FILE_NOT_FOUND_W;
592 }
593 strncpy(lpFileSystemNameBuffer, volinfo.File_System_Name, nFileSystemNameSize-1);
594 return ERROR_SUCCESS_W;
595}
596//******************************************************************************
597//******************************************************************************
598DWORD OSLibLVMQueryVolumeSerialAndName(LPSTR lpszVolume, LPDWORD lpVolumeSerialNumber,
599 LPSTR lpVolumeNameBuffer, DWORD nVolumeNameSize)
600{
601 Volume_Information_Record volinfo;
602 Volume_Control_Record volctrl;
603 CARDINAL32 lasterror;
604 int i;
605
606 volinfo = OSLibLVMFindVolumeByName(lpszVolume, &volctrl, &lasterror);
607 if(lasterror != LVM_ENGINE_NO_ERROR) {
608 DebugInt3();
609 return ERROR_FILE_NOT_FOUND_W;
610 }
611
612 if(lpVolumeSerialNumber) {
613 *lpVolumeSerialNumber = volctrl.Volume_Serial_Number;
614 }
615 if(lpVolumeNameBuffer)
616 {
617 strncpy(lpVolumeNameBuffer, volinfo.Volume_Name, nVolumeNameSize-1);
618 }
619 return ERROR_SUCCESS_W;
620}
621//******************************************************************************
622//******************************************************************************
623BOOL OSLibLVMGetVolumeNameForVolumeMountPoint(LPCSTR lpszVolumeMountPoint,
624 LPSTR lpszVolumeName,
625 DWORD cchBufferLength)
626{
627 int drive;
628
629 //We only support drive letters as mountpoint names
630 if('A' <= *lpszVolumeMountPoint && *lpszVolumeMountPoint <= 'Z') {
631 drive = *lpszVolumeMountPoint - 'A';
632 }
633 else
634 if('a' <= *lpszVolumeMountPoint && *lpszVolumeMountPoint <= 'z') {
635 drive = *lpszVolumeMountPoint - 'a';
636 }
637 else {
638 return FALSE;
639 }
640 if(lpszVolumeMountPoint[1] != ':') {
641 return FALSE;
642 }
643
644 Volume_Information_Record volinfo;
645 CARDINAL32 lasterror;
646
647 volinfo = OSLibLVMFindVolumeByDriveLetter(drive, NULL, &lasterror);
648 if(lasterror != LVM_ENGINE_NO_ERROR) {
649 DebugInt3();
650 return FALSE;
651 }
652
653 strncpy(lpszVolumeName, volinfo.Volume_Name, cchBufferLength-1);
654 return TRUE;
655}
656//******************************************************************************
657//******************************************************************************
658BOOL OSLibLVMStripVolumeName(LPCSTR lpszWin32VolumeName, LPSTR lpszOS2VolumeName, DWORD cchBufferLength)
659{
660 int length;
661
662 //strip volume name prefix (\\\\?\\Volume\\)
663 length = strlen(lpszWin32VolumeName);
664
665 strncpy(lpszOS2VolumeName, &lpszWin32VolumeName[sizeof(VOLUME_NAME_PREFIX)-1+1], cchBufferLength-1); //-zero term + starting '{'
666 length -= sizeof(VOLUME_NAME_PREFIX)-1+1;
667 if(lpszOS2VolumeName[length-2] == '}')
668 {
669 lpszOS2VolumeName[length-2] = 0;
670 return TRUE;
671 }
672 else
673 if(lpszOS2VolumeName[length-1] == '}')
674 {
675 lpszOS2VolumeName[length-1] = 0;
676 return TRUE;
677 }
678 return FALSE;
679}
680//******************************************************************************
681//******************************************************************************
682BOOL OSLibLVMGetDiskGeometry(DWORD dwDiskNr, PDISK_GEOMETRY pGeom)
683{
684 Drive_Control_Array driveinfo;
685 Drive_Control_Record *pDriveRec;
686 CARDINAL32 lasterror;
687 BOOL ret = FALSE;
688 int i;
689
690 driveinfo = Get_Drive_Control_Data(&lasterror);
691 if(lasterror != LVM_ENGINE_NO_ERROR) {
692 DebugInt3();
693 return FALSE;
694 }
695 pDriveRec = driveinfo.Drive_Control_Data;
696 if(pDriveRec == NULL) {
697 DebugInt3();
698 return FALSE;
699 }
700 if(dwDiskNr > driveinfo.Count) {
701 DebugInt3();
702 ret = FALSE;
703 goto endfunc;
704 }
705 for(i=0;i<driveinfo.Count;i++) {
706 if(pDriveRec->Drive_Number == dwDiskNr) {
707 pGeom->Cylinders.u.LowPart = pDriveRec->Cylinder_Count;
708 pGeom->Cylinders.u.HighPart = 0;
709 pGeom->TracksPerCylinder = pDriveRec->Heads_Per_Cylinder;
710 pGeom->SectorsPerTrack = pDriveRec->Sectors_Per_Track;
711 pGeom->BytesPerSector = 512;
712 pGeom->MediaType = FixedMedia;
713
714 ret = TRUE;
715 break;
716 }
717 }
718endfunc:
719 Free_Engine_Memory((ULONG)driveinfo.Drive_Control_Data);
720 return ret;
721}
722//******************************************************************************
723//******************************************************************************
Note: See TracBrowser for help on using the repository browser.