ffi-vix_disk_lib 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,360 @@
1
+ require 'ffi'
2
+
3
+ module FFI
4
+ module VixDiskLib
5
+ module API
6
+ extend FFI::Library
7
+
8
+ def self.enum(*args)
9
+ s = super
10
+ # Expose enums as constants
11
+ s.symbols.each { |sym| const_set(sym, s[sym]) }
12
+ s
13
+ end
14
+
15
+ # The error codes are returned by all public VIX routines.
16
+ VixErrorType = enum(
17
+ :VIX_OK, 0,
18
+
19
+ # General errors
20
+ :VIX_E_FAIL, 1,
21
+ :VIX_E_OUT_OF_MEMORY, 2,
22
+ :VIX_E_INVALID_ARG, 3,
23
+ :VIX_E_FILE_NOT_FOUND, 4,
24
+ :VIX_E_OBJECT_IS_BUSY, 5,
25
+ :VIX_E_NOT_SUPPORTED, 6,
26
+ :VIX_E_FILE_ERROR, 7,
27
+ :VIX_E_DISK_FULL, 8,
28
+ :VIX_E_INCORRECT_FILE_TYPE, 9,
29
+ :VIX_E_CANCELLED, 10,
30
+ :VIX_E_FILE_READ_ONLY, 11,
31
+ :VIX_E_FILE_ALREADY_EXISTS, 12,
32
+ :VIX_E_FILE_ACCESS_ERROR, 13,
33
+ :VIX_E_REQUIRES_LARGE_FILES, 14,
34
+ :VIX_E_FILE_ALREADY_LOCKED, 15,
35
+ :VIX_E_VMDB, 16,
36
+ :VIX_E_NOT_SUPPORTED_ON_REMOTE_OBJECT, 20,
37
+ :VIX_E_FILE_TOO_BIG, 21,
38
+ :VIX_E_FILE_NAME_INVALID, 22,
39
+ :VIX_E_ALREADY_EXISTS, 23,
40
+ :VIX_E_BUFFER_TOOSMALL, 24,
41
+ :VIX_E_OBJECT_NOT_FOUND, 25,
42
+ :VIX_E_HOST_NOT_CONNECTED, 26,
43
+ :VIX_E_INVALID_UTF8_STRING, 27,
44
+ :VIX_E_OPERATION_ALREADY_IN_PROGRESS, 31,
45
+ :VIX_E_UNFINISHED_JOB, 29,
46
+ :VIX_E_NEED_KEY, 30,
47
+ :VIX_E_LICENSE, 32,
48
+ :VIX_E_VM_HOST_DISCONNECTED, 34,
49
+ :VIX_E_AUTHENTICATION_FAIL, 35,
50
+ :VIX_E_HOST_CONNECTION_LOST, 36,
51
+ :VIX_E_DUPLICATE_NAME, 41,
52
+
53
+ # Handle Errors
54
+ :VIX_E_INVALID_HANDLE, 1000,
55
+ :VIX_E_NOT_SUPPORTED_ON_HANDLE_TYPE, 1001,
56
+ :VIX_E_TOO_MANY_HANDLES, 1002,
57
+
58
+ # XML errors
59
+ :VIX_E_NOT_FOUND, 2000,
60
+ :VIX_E_TYPE_MISMATCH, 2001,
61
+ :VIX_E_INVALID_XML, 2002,
62
+
63
+ # VM Control Errors
64
+ :VIX_E_TIMEOUT_WAITING_FOR_TOOLS, 3000,
65
+ :VIX_E_UNRECOGNIZED_COMMAND, 3001,
66
+ :VIX_E_OP_NOT_SUPPORTED_ON_GUEST, 3003,
67
+ :VIX_E_PROGRAM_NOT_STARTED, 3004,
68
+ :VIX_E_CANNOT_START_READ_ONLY_VM, 3005,
69
+ :VIX_E_VM_NOT_RUNNING, 3006,
70
+ :VIX_E_VM_IS_RUNNING, 3007,
71
+ :VIX_E_CANNOT_CONNECT_TO_VM, 3008,
72
+ :VIX_E_POWEROP_SCRIPTS_NOT_AVAILABLE, 3009,
73
+ :VIX_E_NO_GUEST_OS_INSTALLED, 3010,
74
+ :VIX_E_VM_INSUFFICIENT_HOST_MEMORY, 3011,
75
+ :VIX_E_SUSPEND_ERROR, 3012,
76
+ :VIX_E_VM_NOT_ENOUGH_CPUS, 3013,
77
+ :VIX_E_HOST_USER_PERMISSIONS, 3014,
78
+ :VIX_E_GUEST_USER_PERMISSIONS, 3015,
79
+ :VIX_E_TOOLS_NOT_RUNNING, 3016,
80
+ :VIX_E_GUEST_OPERATIONS_PROHIBITED, 3017,
81
+ :VIX_E_ANON_GUEST_OPERATIONS_PROHIBITED, 3018,
82
+ :VIX_E_ROOT_GUEST_OPERATIONS_PROHIBITED, 3019,
83
+ :VIX_E_MISSING_ANON_GUEST_ACCOUNT, 3023,
84
+ :VIX_E_CANNOT_AUTHENTICATE_WITH_GUEST, 3024,
85
+ :VIX_E_UNRECOGNIZED_COMMAND_IN_GUEST, 3025,
86
+ :VIX_E_CONSOLE_GUEST_OPERATIONS_PROHIBITED, 3026,
87
+ :VIX_E_MUST_BE_CONSOLE_USER, 3027,
88
+ :VIX_E_VMX_MSG_DIALOG_AND_NO_UI, 3028,
89
+ # VIX_E_NOT_ALLOWED_DURING_VM_RECORDING, 3029, Removed in version 1.11
90
+ # VIX_E_NOT_ALLOWED_DURING_VM_REPLAY, 3030, Removed in version 1.11
91
+ :VIX_E_OPERATION_NOT_ALLOWED_FOR_LOGIN_TYPE, 3031,
92
+ :VIX_E_LOGIN_TYPE_NOT_SUPPORTED, 3032,
93
+ :VIX_E_EMPTY_PASSWORD_NOT_ALLOWED_IN_GUEST, 3033,
94
+ :VIX_E_INTERACTIVE_SESSION_NOT_PRESENT, 3034,
95
+ :VIX_E_INTERACTIVE_SESSION_USER_MISMATCH, 3035,
96
+ # VIX_E_UNABLE_TO_REPLAY_VM, 3039, Removed in version 1.11
97
+ :VIX_E_CANNOT_POWER_ON_VM, 3041,
98
+ :VIX_E_NO_DISPLAY_SERVER, 3043,
99
+ # VIX_E_VM_NOT_RECORDING, 3044, Removed in version 1.11
100
+ # VIX_E_VM_NOT_REPLAYING, 3045, Removed in version 1.11
101
+ :VIX_E_TOO_MANY_LOGONS, 3046,
102
+ :VIX_E_INVALID_AUTHENTICATION_SESSION, 3047,
103
+
104
+ # VM Errors
105
+ :VIX_E_VM_NOT_FOUND, 4000,
106
+ :VIX_E_NOT_SUPPORTED_FOR_VM_VERSION, 4001,
107
+ :VIX_E_CANNOT_READ_VM_CONFIG, 4002,
108
+ :VIX_E_TEMPLATE_VM, 4003,
109
+ :VIX_E_VM_ALREADY_LOADED, 4004,
110
+ :VIX_E_VM_ALREADY_UP_TO_DATE, 4006,
111
+ :VIX_E_VM_UNSUPPORTED_GUEST, 4011,
112
+
113
+ # Property Errors
114
+ :VIX_E_UNRECOGNIZED_PROPERTY, 6000,
115
+ :VIX_E_INVALID_PROPERTY_VALUE, 6001,
116
+ :VIX_E_READ_ONLY_PROPERTY, 6002,
117
+ :VIX_E_MISSING_REQUIRED_PROPERTY, 6003,
118
+ :VIX_E_INVALID_SERIALIZED_DATA, 6004,
119
+ :VIX_E_PROPERTY_TYPE_MISMATCH, 6005,
120
+
121
+ # Completion Errors
122
+ :VIX_E_BAD_VM_INDEX, 8000,
123
+
124
+ # Message errors
125
+ :VIX_E_INVALID_MESSAGE_HEADER, 10_000,
126
+ :VIX_E_INVALID_MESSAGE_BODY, 10_001,
127
+
128
+ # Snapshot errors
129
+ :VIX_E_SNAPSHOT_INVAL, 13_000,
130
+ :VIX_E_SNAPSHOT_DUMPER, 13_001,
131
+ :VIX_E_SNAPSHOT_DISKLIB, 13_002,
132
+ :VIX_E_SNAPSHOT_NOTFOUND, 13_003,
133
+ :VIX_E_SNAPSHOT_EXISTS, 13_004,
134
+ :VIX_E_SNAPSHOT_VERSION, 13_005,
135
+ :VIX_E_SNAPSHOT_NOPERM, 13_006,
136
+ :VIX_E_SNAPSHOT_CONFIG, 13_007,
137
+ :VIX_E_SNAPSHOT_NOCHANGE, 13_008,
138
+ :VIX_E_SNAPSHOT_CHECKPOINT, 13_009,
139
+ :VIX_E_SNAPSHOT_LOCKED, 13_010,
140
+ :VIX_E_SNAPSHOT_INCONSISTENT, 13_011,
141
+ :VIX_E_SNAPSHOT_NAMETOOLONG, 13_012,
142
+ :VIX_E_SNAPSHOT_VIXFILE, 13_013,
143
+ :VIX_E_SNAPSHOT_DISKLOCKED, 13_014,
144
+ :VIX_E_SNAPSHOT_DUPLICATEDDISK, 13_015,
145
+ :VIX_E_SNAPSHOT_INDEPENDENTDISK, 13_016,
146
+ :VIX_E_SNAPSHOT_NONUNIQUE_NAME, 13_017,
147
+ :VIX_E_SNAPSHOT_MEMORY_ON_INDEPENDENT_DISK, 13_018,
148
+ :VIX_E_SNAPSHOT_MAXSNAPSHOTS, 13_019,
149
+ :VIX_E_SNAPSHOT_MIN_FREE_SPACE, 13_020,
150
+ :VIX_E_SNAPSHOT_HIERARCHY_TOODEEP, 13_021,
151
+ :VIX_E_SNAPSHOT_RRSUSPEND, 13_022,
152
+ :VIX_E_SNAPSHOT_NOT_REVERTABLE, 13_024,
153
+
154
+ # Host Errors
155
+ :VIX_E_HOST_DISK_INVALID_VALUE, 14_003,
156
+ :VIX_E_HOST_DISK_SECTORSIZE, 14_004,
157
+ :VIX_E_HOST_FILE_ERROR_EOF, 14_005,
158
+ :VIX_E_HOST_NETBLKDEV_HANDSHAKE, 14_006,
159
+ :VIX_E_HOST_SOCKET_CREATION_ERROR, 14_007,
160
+ :VIX_E_HOST_SERVER_NOT_FOUND, 14_008,
161
+ :VIX_E_HOST_NETWORK_CONN_REFUSED, 14_009,
162
+ :VIX_E_HOST_TCP_SOCKET_ERROR, 14_010,
163
+ :VIX_E_HOST_TCP_CONN_LOST, 14_011,
164
+ :VIX_E_HOST_NBD_HASHFILE_VOLUME, 14_012,
165
+ :VIX_E_HOST_NBD_HASHFILE_INIT, 14_013,
166
+
167
+ # Disklib errors
168
+ :VIX_E_DISK_INVAL, 16_000,
169
+ :VIX_E_DISK_NOINIT, 16_001,
170
+ :VIX_E_DISK_NOIO, 16_002,
171
+ :VIX_E_DISK_PARTIALCHAIN, 16_003,
172
+ :VIX_E_DISK_NEEDSREPAIR, 16_006,
173
+ :VIX_E_DISK_OUTOFRANGE, 16_007,
174
+ :VIX_E_DISK_CID_MISMATCH, 16_008,
175
+ :VIX_E_DISK_CANTSHRINK, 16_009,
176
+ :VIX_E_DISK_PARTMISMATCH, 16_010,
177
+ :VIX_E_DISK_UNSUPPORTEDDISKVERSION, 16_011,
178
+ :VIX_E_DISK_OPENPARENT, 16_012,
179
+ :VIX_E_DISK_NOTSUPPORTED, 16_013,
180
+ :VIX_E_DISK_NEEDKEY, 16_014,
181
+ :VIX_E_DISK_NOKEYOVERRIDE, 16_015,
182
+ :VIX_E_DISK_NOTENCRYPTED, 16_016,
183
+ :VIX_E_DISK_NOKEY, 16_017,
184
+ :VIX_E_DISK_INVALIDPARTITIONTABLE, 16_018,
185
+ :VIX_E_DISK_NOTNORMAL, 16_019,
186
+ :VIX_E_DISK_NOTENCDESC, 16_020,
187
+ :VIX_E_DISK_NEEDVMFS, 16_022,
188
+ :VIX_E_DISK_RAWTOOBIG, 16_024,
189
+ :VIX_E_DISK_TOOMANYOPENFILES, 16_027,
190
+ :VIX_E_DISK_TOOMANYREDO, 16_028,
191
+ :VIX_E_DISK_RAWTOOSMALL, 16_029,
192
+ :VIX_E_DISK_INVALIDCHAIN, 16_030,
193
+ :VIX_E_DISK_KEY_NOTFOUND, 16_052, # metadata key is not found
194
+ :VIX_E_DISK_SUBSYSTEM_INIT_FAIL, 16_053,
195
+ :VIX_E_DISK_INVALID_CONNECTION, 16_054,
196
+ :VIX_E_DISK_ENCODING, 16_061,
197
+ :VIX_E_DISK_CANTREPAIR, 16_062,
198
+ :VIX_E_DISK_INVALIDDISK, 16_063,
199
+ :VIX_E_DISK_NOLICENSE, 16_064,
200
+ :VIX_E_DISK_NODEVICE, 16_065,
201
+ :VIX_E_DISK_UNSUPPORTEDDEVICE, 16_066,
202
+ :VIX_E_DISK_CAPACITY_MISMATCH, 16_067,
203
+ :VIX_E_DISK_PARENT_NOTALLOWED, 16_068,
204
+ :VIX_E_DISK_ATTACH_ROOTLINK, 16_069,
205
+
206
+ # Crypto Library Errors
207
+ :VIX_E_CRYPTO_UNKNOWN_ALGORITHM, 17_000,
208
+ :VIX_E_CRYPTO_BAD_BUFFER_SIZE, 17_001,
209
+ :VIX_E_CRYPTO_INVALID_OPERATION, 17_002,
210
+ :VIX_E_CRYPTO_RANDOM_DEVICE, 17_003,
211
+ :VIX_E_CRYPTO_NEED_PASSWORD, 17_004,
212
+ :VIX_E_CRYPTO_BAD_PASSWORD, 17_005,
213
+ :VIX_E_CRYPTO_NOT_IN_DICTIONARY, 17_006,
214
+ :VIX_E_CRYPTO_NO_CRYPTO, 17_007,
215
+ :VIX_E_CRYPTO_ERROR, 17_008,
216
+ :VIX_E_CRYPTO_BAD_FORMAT, 17_009,
217
+ :VIX_E_CRYPTO_LOCKED, 17_010,
218
+ :VIX_E_CRYPTO_EMPTY, 17_011,
219
+ :VIX_E_CRYPTO_KEYSAFE_LOCATOR, 17_012,
220
+
221
+ # Remoting Errors.
222
+ :VIX_E_CANNOT_CONNECT_TO_HOST, 18_000,
223
+ :VIX_E_NOT_FOR_REMOTE_HOST, 18_001,
224
+ :VIX_E_INVALID_HOSTNAME_SPECIFICATION, 18_002,
225
+
226
+ # Screen Capture Errors.
227
+ :VIX_E_SCREEN_CAPTURE_ERROR, 19_000,
228
+ :VIX_E_SCREEN_CAPTURE_BAD_FORMAT, 19_001,
229
+ :VIX_E_SCREEN_CAPTURE_COMPRESSION_FAIL, 19_002,
230
+ :VIX_E_SCREEN_CAPTURE_LARGE_DATA, 19_003,
231
+
232
+ # Guest Errors
233
+ :VIX_E_GUEST_VOLUMES_NOT_FROZEN, 20_000,
234
+ :VIX_E_NOT_A_FILE, 20_001,
235
+ :VIX_E_NOT_A_DIRECTORY, 20_002,
236
+ :VIX_E_NO_SUCH_PROCESS, 20_003,
237
+ :VIX_E_FILE_NAME_TOO_LONG, 20_004,
238
+ :VIX_E_OPERATION_DISABLED, 20_005,
239
+
240
+ # Tools install errors
241
+ :VIX_E_TOOLS_INSTALL_NO_IMAGE, 21_000,
242
+ :VIX_E_TOOLS_INSTALL_IMAGE_INACCESIBLE, 21_001,
243
+ :VIX_E_TOOLS_INSTALL_NO_DEVICE, 21_002,
244
+ :VIX_E_TOOLS_INSTALL_DEVICE_NOT_CONNECTED, 21_003,
245
+ :VIX_E_TOOLS_INSTALL_CANCELLED, 21_004,
246
+ :VIX_E_TOOLS_INSTALL_INIT_FAILED, 21_005,
247
+ :VIX_E_TOOLS_INSTALL_AUTO_NOT_SUPPORTED, 21_006,
248
+ :VIX_E_TOOLS_INSTALL_GUEST_NOT_READY, 21_007,
249
+ :VIX_E_TOOLS_INSTALL_SIG_CHECK_FAILED, 21_008,
250
+ :VIX_E_TOOLS_INSTALL_ERROR, 21_009,
251
+ :VIX_E_TOOLS_INSTALL_ALREADY_UP_TO_DATE, 21_010,
252
+ :VIX_E_TOOLS_INSTALL_IN_PROGRESS, 21_011,
253
+ :VIX_E_TOOLS_INSTALL_IMAGE_COPY_FAILED, 21_012,
254
+
255
+ # Wrapper Errors
256
+ :VIX_E_WRAPPER_WORKSTATION_NOT_INSTALLED, 22_001,
257
+ :VIX_E_WRAPPER_VERSION_NOT_FOUND, 22_002,
258
+ :VIX_E_WRAPPER_SERVICEPROVIDER_NOT_FOUND, 22_003,
259
+ :VIX_E_WRAPPER_PLAYER_NOT_INSTALLED, 22_004,
260
+ :VIX_E_WRAPPER_RUNTIME_NOT_INSTALLED, 22_005,
261
+ :VIX_E_WRAPPER_MULTIPLE_SERVICEPROVIDERS, 22_006,
262
+
263
+ # FuseMnt errors
264
+ :VIX_E_MNTAPI_MOUNTPT_NOT_FOUND, 24_000,
265
+ :VIX_E_MNTAPI_MOUNTPT_IN_USE, 24_001,
266
+ :VIX_E_MNTAPI_DISK_NOT_FOUND, 24_002,
267
+ :VIX_E_MNTAPI_DISK_NOT_MOUNTED, 24_003,
268
+ :VIX_E_MNTAPI_DISK_IS_MOUNTED, 24_004,
269
+ :VIX_E_MNTAPI_DISK_NOT_SAFE, 24_005,
270
+ :VIX_E_MNTAPI_DISK_CANT_OPEN, 24_006,
271
+ :VIX_E_MNTAPI_CANT_READ_PARTS, 24_007,
272
+ :VIX_E_MNTAPI_UMOUNT_APP_NOT_FOUND, 24_008,
273
+ :VIX_E_MNTAPI_UMOUNT, 24_009,
274
+ :VIX_E_MNTAPI_NO_MOUNTABLE_PARTITONS, 24_010,
275
+ :VIX_E_MNTAPI_PARTITION_RANGE, 24_011,
276
+ :VIX_E_MNTAPI_PERM, 24_012,
277
+ :VIX_E_MNTAPI_DICT, 24_013,
278
+ :VIX_E_MNTAPI_DICT_LOCKED, 24_014,
279
+ :VIX_E_MNTAPI_OPEN_HANDLES, 24_015,
280
+ :VIX_E_MNTAPI_CANT_MAKE_VAR_DIR, 24_016,
281
+ :VIX_E_MNTAPI_NO_ROOT, 24_017,
282
+ :VIX_E_MNTAPI_LOOP_FAILED, 24_018,
283
+ :VIX_E_MNTAPI_DAEMON, 24_019,
284
+ :VIX_E_MNTAPI_INTERNAL, 24_020,
285
+ :VIX_E_MNTAPI_SYSTEM, 24_021,
286
+ :VIX_E_MNTAPI_NO_CONNECTION_DETAILS, 24_022,
287
+ # FuseMnt errors: Do not exceed 24299
288
+
289
+ # VixMntapi errors
290
+ :VIX_E_MNTAPI_INCOMPATIBLE_VERSION, 24_300,
291
+ :VIX_E_MNTAPI_OS_ERROR, 24_301,
292
+ :VIX_E_MNTAPI_DRIVE_LETTER_IN_USE, 24_302,
293
+ :VIX_E_MNTAPI_DRIVE_LETTER_ALREADY_ASSIGNED, 24_303,
294
+ :VIX_E_MNTAPI_VOLUME_NOT_MOUNTED, 24_304,
295
+ :VIX_E_MNTAPI_VOLUME_ALREADY_MOUNTED, 24_305,
296
+ :VIX_E_MNTAPI_FORMAT_FAILURE, 24_306,
297
+ :VIX_E_MNTAPI_NO_DRIVER, 24_307,
298
+ :VIX_E_MNTAPI_ALREADY_OPENED, 24_308,
299
+ :VIX_E_MNTAPI_ITEM_NOT_FOUND, 24_309,
300
+ :VIX_E_MNTAPI_UNSUPPROTED_BOOT_LOADER, 24_310,
301
+ :VIX_E_MNTAPI_UNSUPPROTED_OS, 24_311,
302
+ :VIX_E_MNTAPI_CODECONVERSION, 24_312,
303
+ :VIX_E_MNTAPI_REGWRITE_ERROR, 24_313,
304
+ :VIX_E_MNTAPI_UNSUPPORTED_FT_VOLUME, 24_314,
305
+ :VIX_E_MNTAPI_PARTITION_NOT_FOUND, 24_315,
306
+ :VIX_E_MNTAPI_PUTFILE_ERROR, 24_316,
307
+ :VIX_E_MNTAPI_GETFILE_ERROR, 24_317,
308
+ :VIX_E_MNTAPI_REG_NOT_OPENED, 24_318,
309
+ :VIX_E_MNTAPI_REGDELKEY_ERROR, 24_319,
310
+ :VIX_E_MNTAPI_CREATE_PARTITIONTABLE_ERROR, 24_320,
311
+ :VIX_E_MNTAPI_OPEN_FAILURE, 24_321,
312
+ :VIX_E_MNTAPI_VOLUME_NOT_WRITABLE, 24_322,
313
+
314
+ # Network Errors
315
+ :VIX_E_NET_HTTP_UNSUPPORTED_PROTOCOL, 30_001,
316
+ :VIX_E_NET_HTTP_URL_MALFORMAT, 30_003,
317
+ :VIX_E_NET_HTTP_COULDNT_RESOLVE_PROXY, 30_005,
318
+ :VIX_E_NET_HTTP_COULDNT_RESOLVE_HOST, 30_006,
319
+ :VIX_E_NET_HTTP_COULDNT_CONNECT, 30_007,
320
+ :VIX_E_NET_HTTP_HTTP_RETURNED_ERROR, 30_022,
321
+ :VIX_E_NET_HTTP_OPERATION_TIMEDOUT, 30_028,
322
+ :VIX_E_NET_HTTP_SSL_CONNECT_ERROR, 30_035,
323
+ :VIX_E_NET_HTTP_TOO_MANY_REDIRECTS, 30_047,
324
+ :VIX_E_NET_HTTP_TRANSFER, 30_200,
325
+ :VIX_E_NET_HTTP_SSL_SECURITY, 30_201,
326
+ :VIX_E_NET_HTTP_GENERIC, 30_202
327
+ )
328
+
329
+ # Disk types
330
+ DiskType = enum(
331
+ :DISK_MONOLITHIC_SPARSE, 1, # monolithic file, sparse
332
+ :DISK_MONOLITHIC_FLAT, 2, # monolithic file, all space pre-allocated
333
+ :DISK_SPLIT_SPARSE, 3, # disk split into 2GB extents, sparse
334
+ :DISK_SPLIT_FLAT, 4, # disk split into 2GB extents, pre-allocated
335
+ :DISK_VMFS_FLAT, 5, # ESX 3.0 and above flat disks
336
+ :DISK_STREAM_OPTIMIZED, 6, # compressed monolithic sparse
337
+ :DISK_VMFS_THIN, 7, # ESX 3.0 and above thin provisioned
338
+ :DISK_VMFS_SPARSE, 8, # ESX 3.0 and above sparse disks
339
+ :DISK_UNKNOWN, 256 # unknown type
340
+ )
341
+
342
+ # Disk adapter types
343
+ AdapterType = enum(
344
+ :ADAPTER_IDE, 1,
345
+ :ADAPTER_SCSI_BUSLOGIC, 2,
346
+ :ADAPTER_SCSI_LSILOGIC, 3,
347
+ :ADAPTER_UNKNOWN, 256
348
+ )
349
+
350
+ # Credential Type - SessionId not yet supported
351
+ CredType = enum(
352
+ :VIXDISKLIB_CRED_UID, 1, # use userid password
353
+ :VIXDISKLIB_CRED_SESSIONID, 2, # http session id
354
+ :VIXDISKLIB_CRED_TICKETID, 3, # vim ticket id
355
+ :VIXDISKLIB_CRED_SSPI, 4, # Windows only - use current thread credentials.
356
+ :VIXDISKLIB_CRED_UNKNOWN, 256
357
+ )
358
+ end
359
+ end
360
+ end
@@ -0,0 +1,8 @@
1
+ module FFI
2
+ module VixDiskLib
3
+ module API
4
+ class VixDiskLibError < RuntimeError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,19 @@
1
+ require 'ffi'
2
+
3
+ module FFI
4
+ module VixDiskLib
5
+ module LIBC
6
+ extend FFI::Library
7
+ ffi_lib FFI::Library::LIBC
8
+
9
+ attach_function :vsnprintf, # http://www.cpluscplus.com/reference/cstdio/vsnprintf/
10
+ [
11
+ :buffer_in, # s
12
+ :int, # n
13
+ :string, # format
14
+ :pointer, # arg
15
+ ],
16
+ :int
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,141 @@
1
+ module FFI
2
+ module VixDiskLib
3
+ extend API
4
+ extend FFI::Library
5
+
6
+ class SafeConnectParams
7
+ UidPasswd = API::UidPasswdCreds
8
+ SessionId = API::SessionIdCreds
9
+
10
+ attr_reader :connect_params
11
+
12
+ def set_param(in_conn_parms, symbol)
13
+ conn_parms = @connect_params + API::ConnectParams.offset_of(symbol)
14
+ memory_pointer = get_mem_ptr_from_str(in_conn_parms[symbol])
15
+ conn_parms.put_pointer(0, memory_pointer)
16
+ end
17
+
18
+ #
19
+ # Read the contents of a ConnectParams structure
20
+ # into FFI memory for use when calling out to VixDiskLib
21
+ #
22
+ def initialize(in_conn_parms)
23
+ conn_parms = FFI::MemoryPointer.new(API::ConnectParams, 1, true)
24
+ @connect_params = conn_parms
25
+ set_param(in_conn_parms, :vmxSpec)
26
+ # Increment structure pointer to server_name
27
+ set_param(in_conn_parms, :serverName)
28
+ # Increment structure pointer to thumbPrint
29
+ set_param(in_conn_parms, :thumbPrint)
30
+ # Increment structure pointer to privateUse
31
+ conn_parms = @connect_params + API::ConnectParams.offset_of(:privateUse)
32
+ conn_parms.write_long(in_conn_parms[:privateUse]) unless in_conn_parms[:privateUse].nil?
33
+ # Increment structure pointer to credType
34
+ cred_type = in_conn_parms[:credType]
35
+ conn_parms = @connect_params + API::ConnectParams.offset_of(:credType)
36
+ conn_parms.write_int(cred_type) unless cred_type.nil?
37
+ get_safe_creds(cred_type, in_conn_parms, @connect_params + API::ConnectParams.offset_of(:creds))
38
+ conn_parms = @connect_params + API::ConnectParams.offset_of(:port)
39
+ conn_parms.write_uint32(in_conn_parms[:port]) unless in_conn_parms[:port].nil?
40
+ @connect_params
41
+ end
42
+
43
+ #
44
+ # Read a ConnectParams structure returned from the FFI layer from VixDiskLib_GetConnectParams
45
+ # into a ruby hash.
46
+ #
47
+ def self.read(ffi_connect_parms)
48
+ out_connect_parms = {}
49
+ spec_ptr = ffi_connect_parms.get_pointer(API::ConnectParams.offset_of(:vmxSpec))
50
+ out_connect_parms[:vmxSpec] = spec_ptr.read_string unless spec_ptr.null?
51
+ serv_ptr = ffi_connect_parms.get_pointer(API::ConnectParams.offset_of(:serverName))
52
+ out_connect_parms[:serverName] = serv_ptr.read_string unless serv_ptr.null?
53
+ thumb_ptr = ffi_connect_parms.get_pointer(API::ConnectParams.offset_of(:thumbPrint))
54
+ out_connect_parms[:thumbPrint] = thumb_ptr.read_string unless thumb_ptr.null?
55
+ out_connect_parms[:privateUse] = ffi_connect_parms.get_long(API::ConnectParams.offset_of(:privateUse))
56
+ out_connect_parms[:credType] = ffi_connect_parms.get_long(API::ConnectParams.offset_of(:credType))
57
+ cred_type = out_connect_parms[:credType]
58
+ read_creds(cred_type, out_connect_parms, ffi_connect_parms + API::ConnectParams.offset_of(:creds))
59
+ out_connect_parms
60
+ end
61
+
62
+ def self.set_params(id_symbol, name_symbol, creds, params)
63
+ pointer = creds + API::Creds.offset_of(id_symbol) + UidPasswd.offset_of(name_symbol)
64
+ params[name_symbol] = read_safe_str_from_mem(pointer)
65
+ end
66
+
67
+ #
68
+ # Read a ConnectParams Creds sub-structure returned from the FFI layer from VixDiskLib_GetConnectParams
69
+ # into a ruby hash.
70
+ #
71
+ def self.read_creds(cred_type, conn_parms, ffi_creds)
72
+ if cred_type == API::CredType[:VIXDISKLIB_CRED_UID]
73
+ set_params(:uid, :userName, ffi_creds, conn_parms)
74
+ set_params(:uid, :password, ffi_creds, conn_parms)
75
+ elsif cred_type == API::CredType[:VIXDISKLIB_CRED_SESSIONID]
76
+ set_params(:sessionId, :cookie, ffi_creds, conn_parms)
77
+ set_params(:sessionId, :sessionUserName, ffi_creds, conn_parms)
78
+ set_params(:sessionId, :key, ffi_creds, conn_parms)
79
+ elsif cred_type == API::CredType[:VIXDISKLIB_CRED_TICKETID]
80
+ set_params(:ticketId, :dummy, ffi_creds, conn_parms)
81
+ end
82
+ end
83
+
84
+ private
85
+
86
+ def self.read_safe_str_from_mem(mem_ptr)
87
+ mem_str = mem_ptr.read_pointer
88
+ mem_str.read_string unless mem_str.null?
89
+ end
90
+
91
+ def get_mem_ptr_from_str(str)
92
+ return nil if str.nil?
93
+ FFI::MemoryPointer.from_string(str)
94
+ end
95
+
96
+ def get_safe_creds(cred_type, in_creds, out_cred_ptr)
97
+ if cred_type == API::VIXDISKLIB_CRED_UID
98
+ get_safe_uid_creds(in_creds, out_cred_ptr)
99
+ elsif cred_type == API::VIXDISKLIB_CRED_SESSIONID
100
+ get_safe_sessionid_creds(in_creds, out_cred_ptr)
101
+ elsif cred_type == API::VIXDISKLIB_CRED_TICKETID
102
+ get_safe_ticketid_creds(in_creds, out_cred_ptr)
103
+ elsif cred_type == API::VIXDISKLIB_CRED_SSPI
104
+ vix_disk_lib_log.error "VixDiskLibApi.connect - Connection Parameters Credentials Type SSPI"
105
+ elsif cred_type == API::VIXDISKLIB_CRED_UNKNOWN
106
+ vix_disk_lib_log.error "VixDiskLibApi.connect - unknown Connection Parameters Credentials Type"
107
+ end
108
+ end
109
+
110
+ def get_safe_uid_creds(in_creds, out_cred_ptr)
111
+ # Increment structure pointer to creds field's username
112
+ # This should take care of any padding necessary for the Union.
113
+ conn_parms = out_cred_ptr + API::Creds.offset_of(:uid) + UidPasswd.offset_of(:userName)
114
+ @user_name = in_creds[:userName] && FFI::MemoryPointer.from_string(in_creds[:userName])
115
+ conn_parms.put_pointer(0, @user_name)
116
+ # Increment structure pointer to creds field's password
117
+ conn_parms = out_cred_ptr + API::Creds.offset_of(:uid) + UidPasswd.offset_of(:password)
118
+ @password = in_creds[:password] && FFI::MemoryPointer.from_string(in_creds[:password])
119
+ conn_parms.put_pointer(0, @password)
120
+ end
121
+
122
+ def get_safe_sessionid_creds(in_creds, out_cred_ptr)
123
+ conn_parms = out_cred_ptr + API::Creds.offset_of(:sessionId) + SessionId.offset_of(:cookie)
124
+ @cookie = in_creds[:cookie] && FFI::MemoryPointer.from_string(in_creds[:cookie])
125
+ conn_parms.put_pointer(0, @cookie)
126
+ conn_parms = out_cred_ptr + API::Creds.offset_of(:sessionId) + SessionId.offset_of(:sessionUserName)
127
+ @session_user_name = in_creds[:sessionUserName] && FFI::MemoryPointer.from_string(in_creds[:sessionUserName])
128
+ conn_parms.put_pointer(0, @session_user_name)
129
+ conn_parms = out_cred_ptr + API::Creds.offset_of(:sessionId) + SessionId.offset_of(:key)
130
+ @key = in_creds[:key] && FFI::MemoryPointer.from_string(in_creds[:key])
131
+ conn_parms.put_pointer(0, @key)
132
+ end
133
+
134
+ def get_safe_ticketid_creds(in_creds, out_cred_ptr)
135
+ conn_parms = out_cred_ptr + API::Creds.offset_of(:ticketId) + SessionId.offset_of(:dummy)
136
+ @dummy = in_creds[:dummy] && FFI::MemoryPointer.from_string(in_creds[:dummy])
137
+ conn_parms.put_pointer(0, @dummy)
138
+ end
139
+ end
140
+ end
141
+ end # class SafeConnectParams
@@ -0,0 +1,31 @@
1
+ module FFI
2
+ module VixDiskLib
3
+ class SafeCreateParams
4
+ extend API
5
+ extend FFI::Library
6
+
7
+ attr_reader :create_params
8
+
9
+ #
10
+ # Read the contents of a CreateParams structure passed as an argument
11
+ # into FFI memory which will be allocated to be used when calling out to
12
+ # VixDiskLib
13
+ #
14
+ def initialize(in_create_parms)
15
+ create_parms = FFI::MemoryPointer.new(VixDiskLib::CreateParams, 1, true)
16
+ create_parms_start = create_parms
17
+ disk_type = in_create_parms[:diskType]
18
+ create_parms = create_parms_start + VixDiskLib::CreateParams.offset_of(:diskType)
19
+ create_parms.write_int(DiskType[disk_type]) unless in_create_parms[:diskType].nil?
20
+ adapter_type = in_create_parms[:adapterType]
21
+ create_parms = create_parms_start + VixDiskLib::CreateParams.offset_of(:adapterType)
22
+ create_parms.write_int(AdapterType[adapter_type]) unless in_create_parms[:adapterType].nil?
23
+ create_parms = create_parms_start + VixDiskLib::CreateParams.offset_of(:hwVersion)
24
+ create_parms.write_uint16(in_create_parms[:hwVersion]) unless in_create_parms[:hwVersion].nil?
25
+ create_parms = create_parms_start + VixDiskLib::CreateParams.offset_of(:capacity)
26
+ create_parms.write_uint64(in_create_parms[:capacity]) unless in_create_parms[:capacity].nil?
27
+ @create_params = create_parms_start
28
+ end
29
+ end
30
+ end
31
+ end # class SafeCreateParams
@@ -0,0 +1,89 @@
1
+ require 'ffi'
2
+
3
+ module FFI
4
+ module VixDiskLib
5
+ module API
6
+ extend FFI::Library
7
+
8
+ # Geometry
9
+ class Geometry < FFI::Struct
10
+ layout :cylinders, :uint32,
11
+ :heads, :uint32,
12
+ :sectors, :uint32
13
+ end
14
+
15
+ # CreateParams
16
+ class CreateParams < FFI::Struct
17
+ layout :diskType, DiskType,
18
+ :adapterType, AdapterType,
19
+ :hwVersion, :uint16,
20
+ :capacity, :SectorType
21
+ end
22
+
23
+ class UidPasswdCreds < FFI::Struct
24
+ layout :userName, :pointer, # User id and password on the
25
+ :password, :pointer # VC/ESX host.
26
+ end
27
+
28
+ class SessionIdCreds < FFI::Struct # Not supported in 1.0
29
+ layout :cookie, :pointer,
30
+ :sessionUserName, :pointer,
31
+ :key, :pointer
32
+ end
33
+
34
+ class TicketIdCreds < FFI::Struct # Internal use only.
35
+ layout :dummy, :char
36
+ end
37
+
38
+ class Creds < FFI::Union
39
+ layout :uid, UidPasswdCreds,
40
+ :sessionId, SessionIdCreds,
41
+ :ticketId, TicketIdCreds
42
+ end
43
+
44
+ # ConnectParams - Connection setup parameters.
45
+ #
46
+ # vmxSpec is required for opening a virtual disk on a datastore through
47
+ # the Virtual Center or ESX server.
48
+ # vmxSpec is of the form:
49
+ # <vmxPathName>?dcPath=<dcpath>&dsName=<dsname>
50
+ # where
51
+ # vmxPathName is the fullpath for the VMX file,
52
+ # dcpath is the inventory path of the datacenter and
53
+ # dsname is the datastore name.
54
+ #
55
+ # Inventory path for the datacenter can be read off the Virtual Center
56
+ # client's inventory tree.
57
+ #
58
+ # Example VM spec:
59
+ # "MyVm/MyVm.vmx?dcPath=Path/to/MyDatacenter&dsName=storage1"
60
+ class ConnectParams < FFI::Struct
61
+ layout :vmxSpec, :pointer,
62
+ :serverName, :pointer,
63
+ :thumbPrint, :pointer,
64
+ :privateUse, :long,
65
+ :credType, CredType,
66
+ :creds, Creds,
67
+ :port, :uint32
68
+ end
69
+
70
+ class Info < FFI::Struct
71
+ layout :biosGeo, Geometry.by_value, # BIOS geometry for booting and partitioning
72
+ :physGeo, Geometry.by_value, # physical geometry
73
+ :capacity, :SectorType, # total capacity in sectors
74
+ :adapterType, AdapterType, # adapter type
75
+ :numLinks, :int, # number of links (i.e. base disk + redo logs)
76
+ :parentFileNameHint, :pointer, # parent file for a redo log
77
+ :uuid, :pointer # disk UUID
78
+ end
79
+
80
+ class HandleStruct < FFI::Struct
81
+ layout :dummy, :char
82
+ end
83
+
84
+ class ConnectParam < FFI::Struct
85
+ layout :dummy, :char
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,5 @@
1
+ module FFI
2
+ module VixDiskLib
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'ffi'
2
+ require 'ffi-vix_disk_lib/version'
3
+ require 'ffi-vix_disk_lib/const'
4
+ require 'ffi-vix_disk_lib/enum'
5
+ require 'ffi-vix_disk_lib/struct'
6
+ require 'ffi-vix_disk_lib/exceptions'
7
+ require 'ffi-vix_disk_lib/api'
8
+ require 'ffi-vix_disk_lib/libc'
@@ -0,0 +1,17 @@
1
+ require 'minitest'
2
+ require 'minitest/autorun'
3
+
4
+ begin
5
+ require 'ffi-vix_disk_lib'
6
+ rescue LoadError
7
+ STDERR.puts <<-EOMSG
8
+
9
+ The VMware VDDK must be installed in order to run specs.
10
+
11
+ The VMware VDDK is not redistributable, and not available on MacOSX.
12
+ See https://www.vmware.com/support/developer/vddk/ for more information.
13
+
14
+ EOMSG
15
+
16
+ exit 1
17
+ end