-
Notifications
You must be signed in to change notification settings - Fork 7
/
vddr.c
130 lines (112 loc) · 3.51 KB
/
vddr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*================================================================================*/
/* Copyright (C) 2009, Don Milne. */
/* All rights reserved. */
/* See LICENSE.TXT for conditions on copying, distribution, modification and use. */
/*================================================================================*/
#include "djwarning.h"
#include "djtypes.h"
#include "vddr.h"
#include "vdir.h"
#include "vhdr.h"
#include "vmdkr.h"
#include "hddr.h"
#include "filename.h"
#include "mem.h"
#include "env.h"
#include "ids.h"
#include "cow.h"
#include "djstring.h"
#include "mediareg.h"
UINT VDDR_LastError;
static PSTR pszUNKERROR /* = "Unknown Error" */;
static PSTR pszOK /* = "Ok" */;
/*...........................................................................*/
PUBLIC UINT
VDDR_GetLastError(void)
{
return VDDR_LastError;
}
/*...........................................................................*/
PUBLIC PSTR
VDDR_GetErrorString(UINT nErr)
{
PSTR pszErr = RSTR(UNKERROR);
if (nErr==0xFFFFFFFF) nErr = VDDR_LastError;
if (nErr==0) pszErr = RSTR(OK);
else {
switch (nErr>>16) {
case VDD_TYPE_VDI:
pszErr = VDIR_GetErrorString(nErr);
break;
case VDD_TYPE_VHD:
pszErr = VHDR_GetErrorString(nErr);
break;
case VDD_TYPE_VMDK:
case VDD_TYPE_RAW:
case VDD_TYPE_PART_RAW:
pszErr = VMDKR_GetErrorString(nErr);
break;
case VDD_TYPE_PARALLELS:
pszErr = HDDR_GetErrorString(nErr);
break;
case VDD_TYPE_COW:
pszErr = COW_GetErrorString(nErr);
break;
default:
;
}
}
return pszErr;
}
/*...........................................................................*/
PUBLIC BOOL
VDDR_OpenMediaRegistry(CPFN fn)
{
MediaReg_Discard();
MediaReg_ScanFolder(fn);
return FALSE;
}
/*...........................................................................*/
PUBLIC HVDDR
VDDR_Open(CPFN fn, UINT iChain)
{
HVDDR pObj=NULL;
if (Mem_Compare(fn,"\\\\.\\",4)==0) { // if UNC name for physical drive
pObj = VMDKR_OpenRaw(fn, iChain);
} else if (Filename_IsExtension(fn,"vdi")) {
pObj = VDIR_Open(fn, iChain);
} else if (Filename_IsExtension(fn,"vhd")) {
pObj = VHDR_Open(fn, iChain);
} else if (Filename_IsExtension(fn,"vmdk")) {
pObj = VMDKR_Open(fn, iChain);
} else if (Filename_IsExtension(fn,"raw") || Filename_IsExtension(fn,"img")) {
pObj = VMDKR_OpenRaw(fn, iChain);
} else if (Filename_IsExtension(fn,"hdd")) {
pObj = HDDR_Open(fn, iChain);
}
return pObj;
}
/*...........................................................................*/
PUBLIC HVDDR
VDDR_OpenByUUID(S_UUID *pUUID, UINT iChain)
{
PFN pfn = MediaReg_FilenameFromUUID(pUUID);
VDDR_LastError = VDIR_ERR_BADFORMAT;
if (pfn) return VDDR_Open(pfn,iChain);
return NULL;
}
/*...........................................................................*/
PUBLIC BOOL
VDDR_QuickGetUUID(CPFN fn, S_UUID *UUID)
{
if (Filename_IsExtension(fn,"vdi")) {
return VDIR_QuickGetUUID(fn, UUID);
} else if (Filename_IsExtension(fn,"vmdk")) {
return VMDKR_QuickGetUUID(fn, UUID);
} else if (Filename_IsExtension(fn,"vhd")) {
return VHDR_QuickGetUUID(fn, UUID);
}
return FALSE;
}
/*...........................................................................*/
/* end of vddr.c */