From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQgO9-00028Z-5Q for qemu-devel@nongnu.org; Wed, 25 Feb 2015 13:08:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQgO8-0001cc-AT for qemu-devel@nongnu.org; Wed, 25 Feb 2015 13:08:49 -0500 From: Max Reitz Date: Wed, 25 Feb 2015 13:08:15 -0500 Message-Id: <1424887718-10800-3-git-send-email-mreitz@redhat.com> In-Reply-To: <1424887718-10800-1-git-send-email-mreitz@redhat.com> References: <1424887718-10800-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH 02/25] qemu-nbd: Detect unused partitions by system == 0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Unused partitions do not necessarily have a total sector count of 0 (although they should have), but they always do have the system field set to 0, so use that for testing whether a partition is in use rather than the sector count field alone. Signed-off-by: Max Reitz --- qemu-nbd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index ac1e5d6..cfdc4dc 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -167,8 +167,9 @@ static int find_partition(BlockBackend *blk, int partition, for (i = 0; i < 4; i++) { read_partition(&data[446 + 16 * i], &mbr[i]); - if (!mbr[i].nb_sectors_abs) + if (!mbr[i].system || !mbr[i].nb_sectors_abs) { continue; + } if (mbr[i].system == 0xF || mbr[i].system == 0x5) { struct partition_record ext[4]; @@ -182,8 +183,9 @@ static int find_partition(BlockBackend *blk, int partition, for (j = 0; j < 4; j++) { read_partition(&data1[446 + 16 * j], &ext[j]); - if (!ext[j].nb_sectors_abs) + if (!ext[j].system || !ext[j].nb_sectors_abs) { continue; + } if ((ext_partnum + j + 1) == partition) { *offset = (uint64_t)ext[j].start_sector_abs << 9; -- 2.1.0