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

Last change on this file since 9298 was 9298, checked in by sandervl, 23 years ago

lots of fixes/changes for physical disk & volume access

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