From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:36581) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGXcz-0002n2-D9 for qemu-devel@nongnu.org; Wed, 19 Oct 2011 11:00:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RGXcr-0006GQ-AB for qemu-devel@nongnu.org; Wed, 19 Oct 2011 11:00:20 -0400 Received: from mail-qy0-f173.google.com ([209.85.216.173]:33390) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGXcr-0006GE-0v for qemu-devel@nongnu.org; Wed, 19 Oct 2011 11:00:13 -0400 Received: by qyk10 with SMTP id 10so4228308qyk.4 for ; Wed, 19 Oct 2011 08:00:12 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 19 Oct 2011 16:59:51 +0200 Message-Id: <1319036398-14320-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1319036398-14320-1-git-send-email-pbonzini@redhat.com> References: <1319036398-14320-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 1/8] vpc: detect floppy disk geometries List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@linux.vnet.ibm.com Converting a floppy image from RAW to VPC and back will generate a zero-padded file of the wrong size, because the geometry is not computed correctly. Special case floppy disk images, handling standard MS-DOS capacities (160/180/320/360 for low density 5.25" disks, 1200 for high density 5.25" disks, 720/1440/2880 for 3.5" disks). Signed-off-by: Paolo Bonzini --- block/vpc.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index cb6c570..549a632 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -463,6 +463,14 @@ static int calculate_geometry(int64_t total_sectors, uint16_t* cyls, { uint32_t cyls_times_heads; + if (total_sectors <= 5760) { + /* Floppy disk geometry */ + *heads = total_sectors < 640 ? 1 : 2; /* 1 = single side 5.25" */ + *cyls = total_sectors < 1440 ? 40 : 80; /* 40 = low density 5.25" */ + *secs_per_cyl = total_sectors / *heads / *cyls; + return 0; + } + if (total_sectors > 65535 * 16 * 255) return -EFBIG; -- 1.7.6