mirror of https://github.com/xemu-project/xemu.git
Merge remote-tracking branch 'stefanha/block' into staging
* stefanha/block: Revert "block/vpc: Fix size calculation" block/raw-posix: detect readonly Linux block devices using BLKROGET
This commit is contained in:
commit
0231ed4f22
|
@ -1257,9 +1257,43 @@ static int hdev_probe_device(const char *filename)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int check_hdev_writable(BDRVRawState *s)
|
||||||
|
{
|
||||||
|
#if defined(BLKROGET)
|
||||||
|
/* Linux block devices can be configured "read-only" using blockdev(8).
|
||||||
|
* This is independent of device node permissions and therefore open(2)
|
||||||
|
* with O_RDWR succeeds. Actual writes fail with EPERM.
|
||||||
|
*
|
||||||
|
* bdrv_open() is supposed to fail if the disk is read-only. Explicitly
|
||||||
|
* check for read-only block devices so that Linux block devices behave
|
||||||
|
* properly.
|
||||||
|
*/
|
||||||
|
struct stat st;
|
||||||
|
int readonly = 0;
|
||||||
|
|
||||||
|
if (fstat(s->fd, &st)) {
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!S_ISBLK(st.st_mode)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ioctl(s->fd, BLKROGET, &readonly) < 0) {
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (readonly) {
|
||||||
|
return -EACCES;
|
||||||
|
}
|
||||||
|
#endif /* defined(BLKROGET) */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
|
static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
|
||||||
{
|
{
|
||||||
BDRVRawState *s = bs->opaque;
|
BDRVRawState *s = bs->opaque;
|
||||||
|
int ret;
|
||||||
|
|
||||||
#if defined(__APPLE__) && defined(__MACH__)
|
#if defined(__APPLE__) && defined(__MACH__)
|
||||||
if (strstart(filename, "/dev/cdrom", NULL)) {
|
if (strstart(filename, "/dev/cdrom", NULL)) {
|
||||||
|
@ -1300,7 +1334,20 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return raw_open_common(bs, filename, flags, 0);
|
ret = raw_open_common(bs, filename, flags, 0);
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & BDRV_O_RDWR) {
|
||||||
|
ret = check_hdev_writable(s);
|
||||||
|
if (ret < 0) {
|
||||||
|
raw_close(bs);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
|
|
14
block/vpc.c
14
block/vpc.c
|
@ -34,8 +34,6 @@
|
||||||
|
|
||||||
#define HEADER_SIZE 512
|
#define HEADER_SIZE 512
|
||||||
|
|
||||||
#define VHD_SECTOR_SIZE 512
|
|
||||||
|
|
||||||
//#define CACHE
|
//#define CACHE
|
||||||
|
|
||||||
enum vhd_type {
|
enum vhd_type {
|
||||||
|
@ -206,13 +204,11 @@ static int vpc_open(BlockDriverState *bs, int flags)
|
||||||
/* Write 'checksum' back to footer, or else will leave it with zero. */
|
/* Write 'checksum' back to footer, or else will leave it with zero. */
|
||||||
footer->checksum = be32_to_cpu(checksum);
|
footer->checksum = be32_to_cpu(checksum);
|
||||||
|
|
||||||
/* The visible size of a image in Virtual PC depends on the guest:
|
// The visible size of a image in Virtual PC depends on the geometry
|
||||||
* QEMU and other emulators report the real size (here in sectors).
|
// rather than on the size stored in the footer (the size in the footer
|
||||||
* All modern operating systems use this real size.
|
// is too large usually)
|
||||||
* Very old operating systems use CHS values to calculate the total size.
|
bs->total_sectors = (int64_t)
|
||||||
* This calculated size is usually smaller than the real size.
|
be16_to_cpu(footer->cyls) * footer->heads * footer->secs_per_cyl;
|
||||||
*/
|
|
||||||
bs->total_sectors = be64_to_cpu(footer->size) / VHD_SECTOR_SIZE;
|
|
||||||
|
|
||||||
/* Allow a maximum disk size of approximately 2 TB */
|
/* Allow a maximum disk size of approximately 2 TB */
|
||||||
if (bs->total_sectors >= 65535LL * 255 * 255) {
|
if (bs->total_sectors >= 65535LL * 255 * 255) {
|
||||||
|
|
Loading…
Reference in New Issue