File: patch.example-vdisk-dll

package info (click to toggle)
bochs 2.7%2Bdfsg-4%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 21,940 kB
  • sloc: cpp: 250,055; ansic: 17,183; sh: 8,428; makefile: 4,786; yacc: 1,311; asm: 395; perl: 359; lex: 307; csh: 3
file content (160 lines) | stat: -rw-r--r-- 4,985 bytes parent folder | download | duplicates (4)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
----------------------------------------------------------------------
Patch name: patch.example-vdisk-dll
Author:     Volker Ruppert
Date:       11 Mar 2013
Status:     Demo

Detailed description:
  This patch shows how to write the source for the VDISK.DLL required for the
  disk image mode 'dll'. This demo can be compiled with MSVC nmake and it can
  be used to access 'flat' type images. Some disk images formats have licenses
  incompatible with the Bochs one and writing an external DLL could be a way
  to fix this. The DLL needs to implement these functions:

  int vdisk_open(const char *path, int flags)
  BOOL vdisk_read(int vunit, LONGLONG blk, void *buf)
  BOOL vdisk_write(int vunit, LONGLONG blk, const void *buf)
  void vdisk_close(int vunit)
  LONGLONG vdisk_get_size(int vunit)

  The function vdisk_open() returns the 'vunit' value to be used in the other
  functions or -1 on failure. The demo is limited to 8 flat disk images and
  does not handle the flags value. The 'blk' value is the sector address and
  the returned size is the sector count.

Apply patch to what version:
  svn revision 11650
----------------------------------------------------------------------
diff -urN ../bochs/misc/vdisk/Makefile ./misc/vdisk/Makefile
--- ../bochs/misc/vdisk/Makefile	1970-01-01 01:00:00.000000000 +0100
+++ ./misc/vdisk/Makefile	2013-03-11 17:58:03.526467800 +0100
@@ -0,0 +1,2 @@
+all:
+	cl /nologo /Ox /LD /Tc vdisk.c /link
diff -urN ../bochs/misc/vdisk/vdisk.c ./misc/vdisk/vdisk.c
--- ../bochs/misc/vdisk/vdisk.c	1970-01-01 01:00:00.000000000 +0100
+++ ./misc/vdisk/vdisk.c	2013-03-09 12:12:19.687570500 +0100
@@ -0,0 +1,123 @@
+//  Copyright (C) 2013  Volker Ruppert
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2 of the License, or (at your option) any later version.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+// VDISK.DLL (demo for disk image mode 'dll')
+
+#include <windows.h>
+
+#define VUNIT_MAX 8
+
+HANDLE hFile[VUNIT_MAX];
+BOOL vunit_open[VUNIT_MAX];
+UINT vunit_count;
+
+__declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
+{
+  int i;
+
+  switch (fdwReason) {
+    case DLL_PROCESS_ATTACH:
+      vunit_count = 0;
+      for (i = 0; i < VUNIT_MAX; i++)
+        vunit_open[i] = FALSE;
+      break;
+    case DLL_PROCESS_DETACH:
+      break;
+    case DLL_THREAD_ATTACH:
+      break;
+    case DLL_THREAD_DETACH:
+      break;
+  }
+  return TRUE;
+}
+
+__declspec(dllexport) int vdisk_open(const char *path, int flags)
+{
+  if (vunit_count == VUNIT_MAX)
+    return -1;
+
+  hFile[vunit_count] = CreateFile(path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL,
+                                  OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+  if (hFile[vunit_count] != INVALID_HANDLE_VALUE) {
+    vunit_open[vunit_count] = TRUE;
+    return vunit_count++;
+  } else {
+    return -1;
+  }
+}
+
+__declspec(dllexport) BOOL vdisk_read(int vunit, LONGLONG blk, void *buf)
+{
+  LONG offlo, offhi;
+  DWORD len2;
+
+  if ((vunit < 0) || (vunit >= VUNIT_MAX))
+    return FALSE;
+
+  if (vunit_open[vunit]) {
+    offlo = (LONG)(blk << 9);
+    offhi = (LONG)(blk >> 23);
+    if (SetFilePointer(hFile[vunit], offlo, &offhi, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
+      return FALSE;
+    }
+    return ReadFile(hFile[vunit], buf, 512, &len2, NULL);
+  }
+  return FALSE;
+}
+
+__declspec(dllexport) BOOL vdisk_write(int vunit, LONGLONG blk, const void *buf)
+{
+  LONG offlo, offhi;
+  DWORD len2;
+
+  if ((vunit < 0) || (vunit >= VUNIT_MAX))
+    return FALSE;
+
+  if (vunit_open[vunit]) {
+    offlo = (LONG)(blk << 9);
+    offhi = (LONG)(blk >> 23);
+    if (SetFilePointer(hFile[vunit], offlo, &offhi, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
+      return FALSE;
+    }
+    return WriteFile(hFile[vunit], buf, 512, &len2, NULL);
+  }
+  return FALSE;
+}
+
+__declspec(dllexport) void vdisk_close(int vunit)
+{
+  if ((vunit < 0) || (vunit >= VUNIT_MAX))
+    return;
+
+  if (vunit_open[vunit]) {
+    CloseHandle(hFile[vunit]);
+    vunit_open[vunit] = FALSE;
+  }
+}
+
+__declspec(dllexport) LONGLONG vdisk_get_size(int vunit)
+{
+  LARGE_INTEGER fSize;
+
+  if ((vunit < 0) || (vunit >= VUNIT_MAX))
+    return 0;
+
+  if (vunit_open[vunit]) {
+    GetFileSizeEx(hFile[vunit], &fSize);
+    return (LONGLONG)(fSize.QuadPart >> 9);
+  }
+  return 0;
+}