Commit 3b9f94e1a8757ac223a51c662e4278aab738f0cd

Authored by bellard
1 parent f5e25d70

win32 block device fixes (initial patch by kazu)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2305 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 2 changed files with 40 additions and 16 deletions
block-raw.c
@@ -906,13 +906,13 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags) @@ -906,13 +906,13 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags)
906 create_flags = OPEN_EXISTING; 906 create_flags = OPEN_EXISTING;
907 } 907 }
908 #ifdef QEMU_TOOL 908 #ifdef QEMU_TOOL
909 - overlapped = 0; 909 + overlapped = FILE_ATTRIBUTE_NORMAL;
910 #else 910 #else
911 overlapped = FILE_FLAG_OVERLAPPED; 911 overlapped = FILE_FLAG_OVERLAPPED;
912 #endif 912 #endif
913 s->hfile = CreateFile(filename, access_flags, 913 s->hfile = CreateFile(filename, access_flags,
914 FILE_SHARE_READ, NULL, 914 FILE_SHARE_READ, NULL,
915 - create_flags, overlapped, 0); 915 + create_flags, overlapped, NULL);
916 if (s->hfile == INVALID_HANDLE_VALUE) 916 if (s->hfile == INVALID_HANDLE_VALUE)
917 return -1; 917 return -1;
918 return 0; 918 return 0;
@@ -962,6 +962,7 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset, @@ -962,6 +962,7 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset,
962 return ret_count; 962 return ret_count;
963 } 963 }
964 964
  965 +#if 0
965 #ifndef QEMU_TOOL 966 #ifndef QEMU_TOOL
966 static void raw_aio_cb(void *opaque) 967 static void raw_aio_cb(void *opaque)
967 { 968 {
@@ -1064,10 +1065,12 @@ static void raw_aio_cancel(BlockDriverAIOCB *blockacb) @@ -1064,10 +1065,12 @@ static void raw_aio_cancel(BlockDriverAIOCB *blockacb)
1064 qemu_aio_release(acb); 1065 qemu_aio_release(acb);
1065 #endif 1066 #endif
1066 } 1067 }
  1068 +#endif /* #if 0 */
1067 1069
1068 static void raw_flush(BlockDriverState *bs) 1070 static void raw_flush(BlockDriverState *bs)
1069 { 1071 {
1070 - /* XXX: add it */ 1072 + BDRVRawState *s = bs->opaque;
  1073 + FlushFileBuffers(s->hfile);
1071 } 1074 }
1072 1075
1073 static void raw_close(BlockDriverState *bs) 1076 static void raw_close(BlockDriverState *bs)
@@ -1143,6 +1146,10 @@ void qemu_aio_flush(void) @@ -1143,6 +1146,10 @@ void qemu_aio_flush(void)
1143 { 1146 {
1144 } 1147 }
1145 1148
  1149 +void qemu_aio_flush(void)
  1150 +{
  1151 +}
  1152 +
1146 void qemu_aio_wait_start(void) 1153 void qemu_aio_wait_start(void)
1147 { 1154 {
1148 } 1155 }
@@ -1254,13 +1261,13 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags) @@ -1254,13 +1261,13 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
1254 create_flags = OPEN_EXISTING; 1261 create_flags = OPEN_EXISTING;
1255 1262
1256 #ifdef QEMU_TOOL 1263 #ifdef QEMU_TOOL
1257 - overlapped = 0; 1264 + overlapped = FILE_ATTRIBUTE_NORMAL;
1258 #else 1265 #else
1259 overlapped = FILE_FLAG_OVERLAPPED; 1266 overlapped = FILE_FLAG_OVERLAPPED;
1260 #endif 1267 #endif
1261 s->hfile = CreateFile(filename, access_flags, 1268 s->hfile = CreateFile(filename, access_flags,
1262 FILE_SHARE_READ, NULL, 1269 FILE_SHARE_READ, NULL,
1263 - create_flags, overlapped, 0); 1270 + create_flags, overlapped, NULL);
1264 if (s->hfile == INVALID_HANDLE_VALUE) 1271 if (s->hfile == INVALID_HANDLE_VALUE)
1265 return -1; 1272 return -1;
1266 return 0; 1273 return 0;
@@ -56,12 +56,6 @@ static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num, @@ -56,12 +56,6 @@ static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num,
56 static BlockDriverState *bdrv_first; 56 static BlockDriverState *bdrv_first;
57 static BlockDriver *first_drv; 57 static BlockDriver *first_drv;
58 58
59 -#ifdef _WIN32  
60 -#define PATH_SEP '\\'  
61 -#else  
62 -#define PATH_SEP '/'  
63 -#endif  
64 -  
65 int path_is_absolute(const char *path) 59 int path_is_absolute(const char *path)
66 { 60 {
67 const char *p; 61 const char *p;
@@ -70,7 +64,11 @@ int path_is_absolute(const char *path) @@ -70,7 +64,11 @@ int path_is_absolute(const char *path)
70 p++; 64 p++;
71 else 65 else
72 p = path; 66 p = path;
73 - return (*p == PATH_SEP); 67 +#ifdef _WIN32
  68 + return (*p == '/' || *p == '\\');
  69 +#else
  70 + return (*p == '/');
  71 +#endif
74 } 72 }
75 73
76 /* if filename is absolute, just copy it to dest. Otherwise, build a 74 /* if filename is absolute, just copy it to dest. Otherwise, build a
@@ -93,7 +91,15 @@ void path_combine(char *dest, int dest_size, @@ -93,7 +91,15 @@ void path_combine(char *dest, int dest_size,
93 p++; 91 p++;
94 else 92 else
95 p = base_path; 93 p = base_path;
96 - p1 = strrchr(base_path, PATH_SEP); 94 + p1 = strrchr(base_path, '/');
  95 +#ifdef _WIN32
  96 + {
  97 + const char *p2;
  98 + p2 = strrchr(base_path, '\\');
  99 + if (!p1 || p2 > p1)
  100 + p1 = p2;
  101 + }
  102 +#endif
97 if (p1) 103 if (p1)
98 p1++; 104 p1++;
99 else 105 else
@@ -168,7 +174,10 @@ int bdrv_create(BlockDriver *drv, @@ -168,7 +174,10 @@ int bdrv_create(BlockDriver *drv,
168 #ifdef _WIN32 174 #ifdef _WIN32
169 void get_tmp_filename(char *filename, int size) 175 void get_tmp_filename(char *filename, int size)
170 { 176 {
171 - tmpnam(filename); 177 + char temp_dir[MAX_PATH];
  178 +
  179 + GetTempPath(MAX_PATH, temp_dir);
  180 + GetTempFileName(temp_dir, "qem", 0, filename);
172 } 181 }
173 #else 182 #else
174 void get_tmp_filename(char *filename, int size) 183 void get_tmp_filename(char *filename, int size)
@@ -996,7 +1005,11 @@ char *get_human_readable_size(char *buf, int buf_size, int64_t size) @@ -996,7 +1005,11 @@ char *get_human_readable_size(char *buf, int buf_size, int64_t size)
996 char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn) 1005 char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
997 { 1006 {
998 char buf1[128], date_buf[128], clock_buf[128]; 1007 char buf1[128], date_buf[128], clock_buf[128];
  1008 +#ifdef _WIN32
  1009 + struct tm *ptm;
  1010 +#else
999 struct tm tm; 1011 struct tm tm;
  1012 +#endif
1000 time_t ti; 1013 time_t ti;
1001 int64_t secs; 1014 int64_t secs;
1002 1015
@@ -1006,11 +1019,15 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn) @@ -1006,11 +1019,15 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
1006 "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK"); 1019 "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");
1007 } else { 1020 } else {
1008 ti = sn->date_sec; 1021 ti = sn->date_sec;
1009 -#ifndef _WIN32 1022 +#ifdef _WIN32
  1023 + ptm = localtime(&ti);
  1024 + strftime(date_buf, sizeof(date_buf),
  1025 + "%Y-%m-%d %H:%M:%S", ptm);
  1026 +#else
1010 localtime_r(&ti, &tm); 1027 localtime_r(&ti, &tm);
1011 -#endif  
1012 strftime(date_buf, sizeof(date_buf), 1028 strftime(date_buf, sizeof(date_buf),
1013 "%Y-%m-%d %H:%M:%S", &tm); 1029 "%Y-%m-%d %H:%M:%S", &tm);
  1030 +#endif
1014 secs = sn->vm_clock_nsec / 1000000000; 1031 secs = sn->vm_clock_nsec / 1000000000;
1015 snprintf(clock_buf, sizeof(clock_buf), 1032 snprintf(clock_buf, sizeof(clock_buf),
1016 "%02d:%02d:%02d.%03d", 1033 "%02d:%02d:%02d.%03d",