Break up vl.h.
[qemu] / block-raw.c
index 05f830a..732b4b8 100644 (file)
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include "vl.h"
+#include "qemu-common.h"
+#ifndef QEMU_IMG
+#include "qemu-timer.h"
+#include "exec-all.h"
+#endif
 #include "block_int.h"
 #include <assert.h>
 #ifndef _WIN32
 #include <aio.h>
 
-#ifndef QEMU_TOOL
-#include "exec-all.h"
-#endif
-
 #ifdef CONFIG_COCOA
 #include <paths.h>
 #include <sys/param.h>
@@ -59,8 +59,8 @@
 
 //#define DEBUG_FLOPPY
 
-#define DEBUG_BLOCK
-#if defined(DEBUG_BLOCK) && !defined(QEMU_TOOL)
+//#define DEBUG_BLOCK
+#if defined(DEBUG_BLOCK) && !defined(QEMU_IMG)
 #define DEBUG_BLOCK_PRINT(formatCstr, args...) do { if (loglevel != 0) \
     { fprintf(logfile, formatCstr, ##args); fflush(logfile); } } while (0)
 #else
@@ -151,7 +151,8 @@ static int raw_pread(BlockDriverState *bs, int64_t offset,
     if (lseek(s->fd, offset, SEEK_SET) == (off_t)-1) {
         ++(s->lseek_err_cnt);
         if(s->lseek_err_cnt <= 10) {
-            DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %lld, %p, %d) [%lld] lseek failed : %d = %s\n",
+            DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %" PRId64 ", %p, %d) [%" PRId64
+                              "] lseek failed : %d = %s\n",
                               s->fd, bs->filename, offset, buf, count,
                               bs->total_sectors, errno, strerror(errno));
         }
@@ -163,7 +164,8 @@ static int raw_pread(BlockDriverState *bs, int64_t offset,
     if (ret == count)
         goto label__raw_read__success;
 
-    DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %lld, %p, %d) [%lld] read failed %d : %d = %s\n",
+    DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %" PRId64 ", %p, %d) [%" PRId64
+                      "] read failed %d : %d = %s\n",
                       s->fd, bs->filename, offset, buf, count,
                       bs->total_sectors, ret, errno, strerror(errno));
 
@@ -178,7 +180,8 @@ static int raw_pread(BlockDriverState *bs, int64_t offset,
         if (ret == count)
             goto label__raw_read__success;
 
-        DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %lld, %p, %d) [%lld] retry read failed %d : %d = %s\n",
+        DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %" PRId64 ", %p, %d) [%" PRId64
+                          "] retry read failed %d : %d = %s\n",
                           s->fd, bs->filename, offset, buf, count,
                           bs->total_sectors, ret, errno, strerror(errno));
     }
@@ -201,7 +204,8 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset,
     if (lseek(s->fd, offset, SEEK_SET) == (off_t)-1) {
         ++(s->lseek_err_cnt);
         if(s->lseek_err_cnt) {
-            DEBUG_BLOCK_PRINT("raw_pwrite(%d:%s, %lld, %p, %d) [%lld] lseek failed : %d = %s\n",
+            DEBUG_BLOCK_PRINT("raw_pwrite(%d:%s, %" PRId64 ", %p, %d) [%"
+                              PRId64 "] lseek failed : %d = %s\n",
                               s->fd, bs->filename, offset, buf, count,
                               bs->total_sectors, errno, strerror(errno));
         }
@@ -213,7 +217,8 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset,
     if (ret == count)
         goto label__raw_write__success;
 
-    DEBUG_BLOCK_PRINT("raw_pwrite(%d:%s, %lld, %p, %d) [%lld] write failed %d : %d = %s\n",
+    DEBUG_BLOCK_PRINT("raw_pwrite(%d:%s, %" PRId64 ", %p, %d) [%" PRId64
+                      "] write failed %d : %d = %s\n",
                       s->fd, bs->filename, offset, buf, count,
                       bs->total_sectors, ret, errno, strerror(errno));
 
@@ -237,7 +242,7 @@ static int aio_initialized = 0;
 
 static void aio_signal_handler(int signum)
 {
-#ifndef QEMU_TOOL
+#ifndef QEMU_IMG
     CPUState *env = cpu_single_env;
     if (env) {
         /* stop the currently executing cpu because a timer occured */
@@ -347,7 +352,7 @@ void qemu_aio_wait(void)
     sigset_t set;
     int nb_sigs;
 
-#ifndef QEMU_TOOL
+#ifndef QEMU_IMG
     if (qemu_bh_poll())
         return;
 #endif
@@ -688,7 +693,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
     return 0;
 }
 
-#if defined(__linux__) && !defined(QEMU_TOOL)
+#if defined(__linux__) && !defined(QEMU_IMG)
 
 /* Note: we do not have a reliable method to detect if the floppy is
    present. The current method is to try to open the floppy at every
@@ -971,7 +976,7 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags)
     } else {
         create_flags = OPEN_EXISTING;
     }
-#ifdef QEMU_TOOL
+#ifdef QEMU_IMG
     overlapped = FILE_ATTRIBUTE_NORMAL;
 #else
     overlapped = FILE_FLAG_OVERLAPPED;
@@ -1034,7 +1039,7 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset,
 }
 
 #if 0
-#ifndef QEMU_TOOL
+#ifndef QEMU_IMG
 static void raw_aio_cb(void *opaque)
 {
     RawAIOCB *acb = opaque;
@@ -1073,7 +1078,7 @@ static RawAIOCB *raw_aio_setup(BlockDriverState *bs,
     acb->ov.OffsetHigh = offset >> 32;
     acb->ov.hEvent = acb->hEvent;
     acb->count = nb_sectors * 512;
-#ifndef QEMU_TOOL
+#ifndef QEMU_IMG
     qemu_add_wait_object(acb->ov.hEvent, raw_aio_cb, acb);
 #endif
     return acb;
@@ -1095,7 +1100,7 @@ static BlockDriverAIOCB *raw_aio_read(BlockDriverState *bs,
         qemu_aio_release(acb);
         return NULL;
     }
-#ifdef QEMU_TOOL
+#ifdef QEMU_IMG
     qemu_aio_release(acb);
 #endif
     return (BlockDriverAIOCB *)acb;
@@ -1117,7 +1122,7 @@ static BlockDriverAIOCB *raw_aio_write(BlockDriverState *bs,
         qemu_aio_release(acb);
         return NULL;
     }
-#ifdef QEMU_TOOL
+#ifdef QEMU_IMG
     qemu_aio_release(acb);
 #endif
     return (BlockDriverAIOCB *)acb;
@@ -1125,7 +1130,7 @@ static BlockDriverAIOCB *raw_aio_write(BlockDriverState *bs,
 
 static void raw_aio_cancel(BlockDriverAIOCB *blockacb)
 {
-#ifndef QEMU_TOOL
+#ifndef QEMU_IMG
     RawAIOCB *acb = (RawAIOCB *)blockacb;
     BlockDriverState *bs = acb->common.bs;
     BDRVRawState *s = bs->opaque;
@@ -1169,7 +1174,7 @@ static int64_t raw_getlength(BlockDriverState *bs)
     BDRVRawState *s = bs->opaque;
     LARGE_INTEGER l;
     ULARGE_INTEGER available, total, total_free;
-    DISK_GEOMETRY dg;
+    DISK_GEOMETRY_EX dg;
     DWORD count;
     BOOL status;
 
@@ -1185,11 +1190,10 @@ static int64_t raw_getlength(BlockDriverState *bs)
         l.QuadPart = total.QuadPart;
         break;
     case FTYPE_HARDDISK:
-        status = DeviceIoControl(s->hfile, IOCTL_DISK_GET_DRIVE_GEOMETRY,
+        status = DeviceIoControl(s->hfile, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
                                  NULL, 0, &dg, sizeof(dg), &count, NULL);
-        if (status != FALSE) {
-            l.QuadPart = dg.Cylinders.QuadPart * dg.TracksPerCylinder
-                * dg.SectorsPerTrack * dg.BytesPerSector;
+        if (status != 0) {
+            l = dg.DiskSize;
         }
         break;
     default:
@@ -1234,7 +1238,7 @@ void qemu_aio_wait_start(void)
 
 void qemu_aio_wait(void)
 {
-#ifndef QEMU_TOOL
+#ifndef QEMU_IMG
     qemu_bh_poll();
 #endif
 }
@@ -1340,7 +1344,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
     }
     create_flags = OPEN_EXISTING;
 
-#ifdef QEMU_TOOL
+#ifdef QEMU_IMG
     overlapped = FILE_ATTRIBUTE_NORMAL;
 #else
     overlapped = FILE_FLAG_OVERLAPPED;