From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NzTte-0001fx-GV for qemu-devel@nongnu.org; Wed, 07 Apr 2010 07:58:14 -0400 Received: from [140.186.70.92] (port=50176 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NzTtZ-0001dn-48 for qemu-devel@nongnu.org; Wed, 07 Apr 2010 07:58:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NzTtK-0007k1-CZ for qemu-devel@nongnu.org; Wed, 07 Apr 2010 07:57:58 -0400 Received: from verein.lst.de ([213.95.11.210]:34889) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NzTtK-0007jo-0z for qemu-devel@nongnu.org; Wed, 07 Apr 2010 07:57:54 -0400 Received: from verein.lst.de (localhost [127.0.0.1]) by verein.lst.de (8.12.3/8.12.3/Debian-7.1) with ESMTP id o37BvrWY012537 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Wed, 7 Apr 2010 13:57:53 +0200 Received: (from hch@localhost) by verein.lst.de (8.12.3/8.12.3/Debian-7.2) id o37BvrEK012536 for qemu-devel@nongnu.org; Wed, 7 Apr 2010 13:57:53 +0200 Date: Wed, 7 Apr 2010 13:57:53 +0200 From: Christoph Hellwig Message-ID: <20100407115753.GB12452@lst.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] block: reject O_RDWR open for read-only images List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Various obscure image format drivers do not allow write access. Instead of silently falling back to read-only access reject attempts to open these images for write access. Signed-off-by: Christoph Hellwig Index: qemu/block/bochs.c =================================================================== --- qemu.orig/block/bochs.c 2010-04-07 13:48:34.448003761 +0200 +++ qemu/block/bochs.c 2010-04-07 13:49:21.088256030 +0200 @@ -116,13 +116,15 @@ static int bochs_open(BlockDriverState * struct bochs_header bochs; struct bochs_header_v1 header_v1; + if (flags & BDRV_O_RDWR) { + return -EROFS; + } + fd = open(filename, O_RDONLY | O_BINARY); if (fd < 0) { return -1; } - bs->read_only = 1; // no write support yet - s->fd = fd; if (read(fd, &bochs, sizeof(bochs)) != sizeof(bochs)) { Index: qemu/block/cloop.c =================================================================== --- qemu.orig/block/cloop.c 2010-04-07 13:49:35.420004250 +0200 +++ qemu/block/cloop.c 2010-04-07 13:50:01.978005226 +0200 @@ -56,10 +56,13 @@ static int cloop_open(BlockDriverState * BDRVCloopState *s = bs->opaque; uint32_t offsets_size,max_compressed_block_size=1,i; + if (flags & BDRV_O_RDWR) { + return -EROFS; + } + s->fd = open(filename, O_RDONLY | O_BINARY); if (s->fd < 0) return -errno; - bs->read_only = 1; /* read header */ if(lseek(s->fd,128,SEEK_SET)<0) { Index: qemu/block/dmg.c =================================================================== --- qemu.orig/block/dmg.c 2010-04-07 13:49:35.435254424 +0200 +++ qemu/block/dmg.c 2010-04-07 13:49:56.004013608 +0200 @@ -81,10 +81,13 @@ static int dmg_open(BlockDriverState *bs uint32_t count; uint32_t max_compressed_size=1,max_sectors_per_chunk=1,i; + if (flags & BDRV_O_RDWR) { + return -EROFS; + } + s->fd = open(filename, O_RDONLY | O_BINARY); if (s->fd < 0) return -errno; - bs->read_only = 1; s->n_chunks = 0; s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL; Index: qemu/block/parallels.c =================================================================== --- qemu.orig/block/parallels.c 2010-04-07 13:49:35.455261059 +0200 +++ qemu/block/parallels.c 2010-04-07 13:49:59.009004250 +0200 @@ -74,13 +74,15 @@ static int parallels_open(BlockDriverSta int fd, i; struct parallels_header ph; + if (flags & BDRV_O_RDWR) { + return -EROFS; + } + fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE); if (fd < 0) { return -1; } - bs->read_only = 1; // no write support yet - s->fd = fd; if (read(fd, &ph, sizeof(ph)) != sizeof(ph))