From patchwork Fri Sep 23 12:50:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 116060 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D7AE2B6F80 for ; Fri, 23 Sep 2011 22:51:42 +1000 (EST) Received: from localhost ([::1]:34770 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R75EA-0005Ok-En for incoming@patchwork.ozlabs.org; Fri, 23 Sep 2011 08:51:38 -0400 Received: from eggs.gnu.org ([140.186.70.92]:38359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R75Dq-0005Go-K1 for qemu-devel@nongnu.org; Fri, 23 Sep 2011 08:51:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R75Dp-0003J0-8k for qemu-devel@nongnu.org; Fri, 23 Sep 2011 08:51:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41463) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R75Do-0003Ig-Sr for qemu-devel@nongnu.org; Fri, 23 Sep 2011 08:51:17 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p8NCpGgY017771 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 23 Sep 2011 08:51:16 -0400 Received: from neno.neno (ovpn-116-44.ams2.redhat.com [10.36.116.44]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p8NCpBpd018512; Fri, 23 Sep 2011 08:51:14 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 23 Sep 2011 14:50:37 +0200 Message-Id: <66d1d7ddad0e2bf068d810eb0556e78bc8c52c5b.1316781876.git.quintela@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 01/11] ds1225y: Use stdio instead of QEMUFile X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org QEMUFile * is only intended for migration nowadays. Using it for anything else just adds pain and a layer of buffers for no good reason. Signed-off-by: Juan Quintela --- hw/ds1225y.c | 28 ++++++++++++++++------------ 1 files changed, 16 insertions(+), 12 deletions(-) diff --git a/hw/ds1225y.c b/hw/ds1225y.c index 9875c44..6852a61 100644 --- a/hw/ds1225y.c +++ b/hw/ds1225y.c @@ -29,7 +29,7 @@ typedef struct { DeviceState qdev; uint32_t chip_size; char *filename; - QEMUFile *file; + FILE *file; uint8_t *contents; } NvRamState; @@ -70,9 +70,9 @@ static void nvram_writeb (void *opaque, target_phys_addr_t addr, uint32_t val) s->contents[addr] = val; if (s->file) { - qemu_fseek(s->file, addr, SEEK_SET); - qemu_put_byte(s->file, (int)val); - qemu_fflush(s->file); + fseek(s->file, addr, SEEK_SET); + fputc(val, s->file); + fflush(s->file); } } @@ -108,15 +108,17 @@ static int nvram_post_load(void *opaque, int version_id) /* Close file, as filename may has changed in load/store process */ if (s->file) { - qemu_fclose(s->file); + fclose(s->file); } /* Write back nvram contents */ - s->file = qemu_fopen(s->filename, "wb"); + s->file = fopen(s->filename, "wb"); if (s->file) { /* Write back contents, as 'wb' mode cleaned the file */ - qemu_put_buffer(s->file, s->contents, s->chip_size); - qemu_fflush(s->file); + if (fwrite(s->contents, s->chip_size, 1, s->file) != 1) { + printf("nvram_post_load: short write\n"); + } + fflush(s->file); } return 0; @@ -143,7 +145,7 @@ typedef struct { static int nvram_sysbus_initfn(SysBusDevice *dev) { NvRamState *s = &FROM_SYSBUS(SysBusNvRamState, dev)->nvram; - QEMUFile *file; + FILE *file; int s_io; s->contents = g_malloc0(s->chip_size); @@ -153,11 +155,13 @@ static int nvram_sysbus_initfn(SysBusDevice *dev) sysbus_init_mmio(dev, s->chip_size, s_io); /* Read current file */ - file = qemu_fopen(s->filename, "rb"); + file = fopen(s->filename, "rb"); if (file) { /* Read nvram contents */ - qemu_get_buffer(file, s->contents, s->chip_size); - qemu_fclose(file); + if (fread(s->contents, s->chip_size, 1, file) != 1) { + printf("nvram_sysbus_initfn: short read\n"); + } + fclose(file); } nvram_post_load(s, 0);