version 1.1.1.3, 2018/04/24 16:40:43
|
version 1.1.1.4, 2018/04/24 16:42:44
|
Line 615 const char *bdrv_get_device_name(BlockDr
|
Line 615 const char *bdrv_get_device_name(BlockDr
|
return bs->device_name; |
return bs->device_name; |
} |
} |
|
|
|
void bdrv_flush(BlockDriverState *bs) |
|
{ |
|
if (bs->drv->bdrv_flush) |
|
bs->drv->bdrv_flush(bs); |
|
if (bs->backing_hd) |
|
bdrv_flush(bs->backing_hd); |
|
} |
|
|
void bdrv_info(void) |
void bdrv_info(void) |
{ |
{ |
BlockDriverState *bs; |
BlockDriverState *bs; |
Line 753 static void raw_close(BlockDriverState *
|
Line 761 static void raw_close(BlockDriverState *
|
close(s->fd); |
close(s->fd); |
} |
} |
|
|
|
#ifdef _WIN32 |
|
#include <windows.h> |
|
#include <winioctl.h> |
|
|
|
int qemu_ftruncate64(int fd, int64_t length) |
|
{ |
|
LARGE_INTEGER li; |
|
LONG high; |
|
HANDLE h; |
|
BOOL res; |
|
|
|
if ((GetVersion() & 0x80000000UL) && (length >> 32) != 0) |
|
return -1; |
|
|
|
h = (HANDLE)_get_osfhandle(fd); |
|
|
|
/* get current position, ftruncate do not change position */ |
|
li.HighPart = 0; |
|
li.LowPart = SetFilePointer (h, 0, &li.HighPart, FILE_CURRENT); |
|
if (li.LowPart == 0xffffffffUL && GetLastError() != NO_ERROR) |
|
return -1; |
|
|
|
high = length >> 32; |
|
if (!SetFilePointer(h, (DWORD) length, &high, FILE_BEGIN)) |
|
return -1; |
|
res = SetEndOfFile(h); |
|
|
|
/* back to old position */ |
|
SetFilePointer(h, li.LowPart, &li.HighPart, FILE_BEGIN); |
|
return res ? 0 : -1; |
|
} |
|
|
|
static int set_sparse(int fd) |
|
{ |
|
DWORD returned; |
|
return (int) DeviceIoControl((HANDLE)_get_osfhandle(fd), FSCTL_SET_SPARSE, |
|
NULL, 0, NULL, 0, &returned, NULL); |
|
} |
|
#else |
|
static inline int set_sparse(int fd) |
|
{ |
|
return 1; |
|
} |
|
#endif |
|
|
static int raw_create(const char *filename, int64_t total_size, |
static int raw_create(const char *filename, int64_t total_size, |
const char *backing_file, int flags) |
const char *backing_file, int flags) |
{ |
{ |
Line 765 static int raw_create(const char *filena
|
Line 818 static int raw_create(const char *filena
|
0644); |
0644); |
if (fd < 0) |
if (fd < 0) |
return -EIO; |
return -EIO; |
|
set_sparse(fd); |
ftruncate(fd, total_size * 512); |
ftruncate(fd, total_size * 512); |
close(fd); |
close(fd); |
return 0; |
return 0; |
} |
} |
|
|
|
static void raw_flush(BlockDriverState *bs) |
|
{ |
|
BDRVRawState *s = bs->opaque; |
|
fsync(s->fd); |
|
} |
|
|
BlockDriver bdrv_raw = { |
BlockDriver bdrv_raw = { |
"raw", |
"raw", |
sizeof(BDRVRawState), |
sizeof(BDRVRawState), |
Line 779 BlockDriver bdrv_raw = {
|
Line 839 BlockDriver bdrv_raw = {
|
raw_write, |
raw_write, |
raw_close, |
raw_close, |
raw_create, |
raw_create, |
|
raw_flush, |
}; |
}; |
|
|
void bdrv_init(void) |
void bdrv_init(void) |