Commit f45512feac6622615e08cca33d172abb87b01921

Authored by bellard
1 parent 6b21b973

win32 compilation fixes


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2134 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 2 changed files with 23 additions and 32 deletions
block-raw.c
... ... @@ -826,7 +826,7 @@ BlockDriver bdrv_host_device = {
826 826 typedef struct BDRVRawState {
827 827 HANDLE hfile;
828 828 int type;
829   - char drive_letter[2];
  829 + char drive_path[16]; /* format: "d:\" */
830 830 } BDRVRawState;
831 831  
832 832 typedef struct RawAIOCB {
... ... @@ -876,23 +876,8 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags)
876 876 BDRVRawState *s = bs->opaque;
877 877 int access_flags, create_flags;
878 878 DWORD overlapped;
879   - char device_name[64];
880   - const char *p;
881 879  
882   - if (strstart(filename, "/dev/cdrom", NULL)) {
883   - if (find_cdrom(device_name, sizeof(device_name)) < 0)
884   - return -ENOENT;
885   - filename = device_name;
886   - } else {
887   - /* transform drive letters into device name */
888   - if (((filename[0] >= 'a' && filename[0] <= 'z') ||
889   - (filename[0] >= 'A' && filename[0] <= 'Z')) &&
890   - filename[1] == ':' && filename[2] == '\0') {
891   - snprintf(device_name, sizeof(device_name), "\\\\.\\%c:", filename[0]);
892   - filename = device_name;
893   - }
894   - }
895   - s->type = find_device_type(filename);
  880 + s->type = FTYPE_FILE;
896 881  
897 882 if ((flags & BDRV_O_ACCESS) == O_RDWR) {
898 883 access_flags = GENERIC_READ | GENERIC_WRITE;
... ... @@ -1089,22 +1074,22 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset)
1089 1074 return 0;
1090 1075 }
1091 1076  
1092   -static int64_t raw_getlength(BlockDriverState *bs)
  1077 +static int64_t raw_getlength(BlockDriverState *bs)
1093 1078 {
1094 1079 BDRVRawState *s = bs->opaque;
1095 1080 LARGE_INTEGER l;
1096 1081 ULARGE_INTEGER available, total, total_free;
1097 1082  
1098   - switch(s->ftype) {
  1083 + switch(s->type) {
1099 1084 case FTYPE_FILE:
1100 1085 l.LowPart = GetFileSize(s->hfile, &l.HighPart);
1101 1086 if (l.LowPart == 0xffffffffUL && GetLastError() != NO_ERROR)
1102 1087 return -EIO;
1103 1088 break;
1104 1089 case FTYPE_CD:
1105   - if (!GetDiskFreeSpaceEx(s->drive_letter, &available, &total, &total_free))
  1090 + if (!GetDiskFreeSpaceEx(s->drive_path, &available, &total, &total_free))
1106 1091 return -EIO;
1107   - l = total;
  1092 + l.QuadPart = total.QuadPart;
1108 1093 break;
1109 1094 default:
1110 1095 return -EIO;
... ... @@ -1182,7 +1167,7 @@ static int find_cdrom(char *cdrom_name, int cdrom_name_size)
1182 1167 char drives[256], *pdrv = drives;
1183 1168 UINT type;
1184 1169  
1185   - memset(drives, 0, sizeof(drivers));
  1170 + memset(drives, 0, sizeof(drives));
1186 1171 GetLogicalDriveStrings(sizeof(drives), drives);
1187 1172 while(pdrv[0] != '\0') {
1188 1173 type = GetDriveType(pdrv);
... ... @@ -1197,16 +1182,16 @@ static int find_cdrom(char *cdrom_name, int cdrom_name_size)
1197 1182 return -1;
1198 1183 }
1199 1184  
1200   -static int find_device_type(const char *filename)
  1185 +static int find_device_type(BlockDriverState *bs, const char *filename)
1201 1186 {
  1187 + BDRVRawState *s = bs->opaque;
1202 1188 UINT type;
1203 1189 const char *p;
1204 1190  
1205 1191 if (strstart(filename, "\\\\.\\", &p) ||
1206 1192 strstart(filename, "//./", &p)) {
1207   - s->drive_letter[0] = p[0];
1208   - s->drive_letter[1] = '\0';
1209   - type = GetDriveType(s->drive_letter);
  1193 + snprintf(s->drive_path, sizeof(s->drive_path), "%c:\\", p[0]);
  1194 + type = GetDriveType(s->drive_path);
1210 1195 if (type == DRIVE_CDROM)
1211 1196 return FTYPE_CD;
1212 1197 else
... ... @@ -1222,7 +1207,6 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
1222 1207 int access_flags, create_flags;
1223 1208 DWORD overlapped;
1224 1209 char device_name[64];
1225   - const char *p;
1226 1210  
1227 1211 if (strstart(filename, "/dev/cdrom", NULL)) {
1228 1212 if (find_cdrom(device_name, sizeof(device_name)) < 0)
... ... @@ -1237,7 +1221,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
1237 1221 filename = device_name;
1238 1222 }
1239 1223 }
1240   - s->type = find_device_type(filename);
  1224 + s->type = find_device_type(bs, filename);
1241 1225  
1242 1226 if ((flags & BDRV_O_ACCESS) == O_RDWR) {
1243 1227 access_flags = GENERIC_READ | GENERIC_WRITE;
... ...
... ... @@ -182,11 +182,17 @@ void get_tmp_filename(char *filename, int size)
182 182 #endif
183 183  
184 184 #ifdef _WIN32
  185 +static int is_windows_drive_prefix(const char *filename)
  186 +{
  187 + return (((filename[0] >= 'a' && filename[0] <= 'z') ||
  188 + (filename[0] >= 'A' && filename[0] <= 'Z')) &&
  189 + filename[1] == ':');
  190 +}
  191 +
185 192 static int is_windows_drive(const char *filename)
186 193 {
187   - if (((filename[0] >= 'a' && filename[0] <= 'z') ||
188   - (filename[0] >= 'A' && filename[0] <= 'Z')) &&
189   - filename[1] == ':' && filename[2] == '\0')
  194 + if (is_windows_drive_prefix(filename) &&
  195 + filename[2] == '\0')
190 196 return 1;
191 197 if (strstart(filename, "\\\\.\\", NULL) ||
192 198 strstart(filename, "//./", NULL))
... ... @@ -203,7 +209,8 @@ static BlockDriver *find_protocol(const char *filename)
203 209 const char *p;
204 210  
205 211 #ifdef _WIN32
206   - if (is_windows_drive(filename))
  212 + if (is_windows_drive(filename) ||
  213 + is_windows_drive_prefix(filename))
207 214 return &bdrv_raw;
208 215 #endif
209 216 p = strchr(filename, ':');
... ...