Revision 93c65b47 block-raw-posix.c
b/block-raw-posix.c | ||
---|---|---|
1378 | 1378 |
} |
1379 | 1379 |
#endif /* !linux && !FreeBSD */ |
1380 | 1380 |
|
1381 |
#if defined(__linux__) || defined(__FreeBSD__) |
|
1382 |
static int hdev_create(const char *filename, int64_t total_size, |
|
1383 |
const char *backing_file, int flags) |
|
1384 |
{ |
|
1385 |
int fd; |
|
1386 |
int ret = 0; |
|
1387 |
struct stat stat_buf; |
|
1388 |
|
|
1389 |
if (flags || backing_file) |
|
1390 |
return -ENOTSUP; |
|
1391 |
|
|
1392 |
fd = open(filename, O_WRONLY | O_BINARY); |
|
1393 |
if (fd < 0) |
|
1394 |
return -EIO; |
|
1395 |
|
|
1396 |
if (fstat(fd, &stat_buf) < 0) |
|
1397 |
ret = -EIO; |
|
1398 |
else if (!S_ISBLK(stat_buf.st_mode)) |
|
1399 |
ret = -EIO; |
|
1400 |
else if (lseek(fd, 0, SEEK_END) < total_size * 512) |
|
1401 |
ret = -ENOSPC; |
|
1402 |
|
|
1403 |
close(fd); |
|
1404 |
return ret; |
|
1405 |
} |
|
1406 |
|
|
1407 |
#else /* !(linux || freebsd) */ |
|
1408 |
|
|
1409 |
static int hdev_create(const char *filename, int64_t total_size, |
|
1410 |
const char *backing_file, int flags) |
|
1411 |
{ |
|
1412 |
return -ENOTSUP; |
|
1413 |
} |
|
1414 |
#endif |
|
1415 |
|
|
1381 | 1416 |
BlockDriver bdrv_host_device = { |
1382 | 1417 |
.format_name = "host_device", |
1383 | 1418 |
.instance_size = sizeof(BDRVRawState), |
1384 | 1419 |
.bdrv_open = hdev_open, |
1385 | 1420 |
.bdrv_close = raw_close, |
1421 |
.bdrv_create = hdev_create, |
|
1386 | 1422 |
.bdrv_flush = raw_flush, |
1387 | 1423 |
|
1388 | 1424 |
#ifdef CONFIG_AIO |
Also available in: Unified diff