From patchwork Tue Jan 19 23:56:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 43249 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1FFB2B7CD9 for ; Wed, 20 Jan 2010 11:19:29 +1100 (EST) Received: from localhost ([127.0.0.1]:55109 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXO90-0001kv-VV for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2010 19:09:59 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NXNwE-0005qD-S4 for qemu-devel@nongnu.org; Tue, 19 Jan 2010 18:56:47 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NXNw9-0005md-RA for qemu-devel@nongnu.org; Tue, 19 Jan 2010 18:56:46 -0500 Received: from [199.232.76.173] (port=59379 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXNw9-0005mV-AF for qemu-devel@nongnu.org; Tue, 19 Jan 2010 18:56:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34078) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NXNw8-0005vh-M1 for qemu-devel@nongnu.org; Tue, 19 Jan 2010 18:56:40 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0JNudXc015640 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 19 Jan 2010 18:56:39 -0500 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0JNuT3n027975; Tue, 19 Jan 2010 18:56:38 -0500 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 20 Jan 2010 00:56:13 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: kirill@shutemov.name Subject: [Qemu-devel] [PATCH 06/17] block/vmdk.o: fix warnings with _FORTIFY_SOURCE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Kirill A. Shutemov CC block/vmdk.o cc1: warnings being treated as errors block/vmdk.c: In function 'vmdk_snapshot_create': block/vmdk.c:236: error: ignoring return value of 'ftruncate', declared with attribute warn_unused_result block/vmdk.c: In function 'vmdk_create': block/vmdk.c:775: error: ignoring return value of 'write', declared with attribute warn_unused_result block/vmdk.c:776: error: ignoring return value of 'write', declared with attribute warn_unused_result block/vmdk.c:778: error: ignoring return value of 'ftruncate', declared with attribute warn_unused_result block/vmdk.c:784: error: ignoring return value of 'write', declared with attribute warn_unused_result block/vmdk.c:790: error: ignoring return value of 'write', declared with attribute warn_unused_result block/vmdk.c:807: error: ignoring return value of 'write', declared with attribute warn_unused_result make: *** [block/vmdk.o] Error 1 Signed-off-by: Kirill A. Shutemov Signed-off-by: Juan Quintela --- block/vmdk.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 40 insertions(+), 10 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 4e48622..18c691a 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -233,7 +233,8 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file) memset(&header, 0, sizeof(header)); memcpy(&header,&hdr[4], sizeof(header)); // skip the VMDK4_MAGIC - ftruncate(snp_fd, header.grain_offset << 9); + if (ftruncate(snp_fd, header.grain_offset << 9)) + goto fail; /* the descriptor offset = 0x200 */ if (lseek(p_fd, 0x200, SEEK_SET) == -1) goto fail; @@ -716,6 +717,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options) int64_t total_size = 0; const char *backing_file = NULL; int flags = 0; + int ret; // Read out options while (options && options->name) { @@ -772,22 +774,44 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options) header.check_bytes[3] = 0xa; /* write all the data */ - write(fd, &magic, sizeof(magic)); - write(fd, &header, sizeof(header)); + ret = qemu_write_full(fd, &magic, sizeof(magic)); + if (ret != sizeof(magic)) { + ret = -1; + goto exit; + } + ret = qemu_write_full(fd, &header, sizeof(header)); + if (ret != sizeof(header)) { + ret = -1; + goto exit; + } - ftruncate(fd, header.grain_offset << 9); + ret = ftruncate(fd, header.grain_offset << 9); + if (ret < 0) { + ret = -1; + goto exit; + } /* write grain directory */ lseek(fd, le64_to_cpu(header.rgd_offset) << 9, SEEK_SET); for (i = 0, tmp = header.rgd_offset + gd_size; - i < gt_count; i++, tmp += gt_size) - write(fd, &tmp, sizeof(tmp)); + i < gt_count; i++, tmp += gt_size) { + ret = qemu_write_full(fd, &tmp, sizeof(tmp)); + if (ret != sizeof(tmp)) { + ret = -1; + goto exit; + } + } /* write backup grain directory */ lseek(fd, le64_to_cpu(header.gd_offset) << 9, SEEK_SET); for (i = 0, tmp = header.gd_offset + gd_size; - i < gt_count; i++, tmp += gt_size) - write(fd, &tmp, sizeof(tmp)); + i < gt_count; i++, tmp += gt_size) { + ret = qemu_write_full(fd, &tmp, sizeof(tmp)); + if (ret != sizeof(tmp)) { + ret = -1; + goto exit; + } + } /* compose the descriptor */ real_filename = filename; @@ -804,10 +828,16 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options) /* write the descriptor */ lseek(fd, le64_to_cpu(header.desc_offset) << 9, SEEK_SET); - write(fd, desc, strlen(desc)); + ret = qemu_write_full(fd, desc, strlen(desc)); + if (ret != strlen(desc)) { + ret = -1; + goto exit; + } + ret = 0; +exit: close(fd); - return 0; + return ret; } static void vmdk_close(BlockDriverState *bs)