From patchwork Sun Dec 20 01:39:15 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A . Shutemov" X-Patchwork-Id: 41492 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 2CD1CB6F17 for ; Sun, 20 Dec 2009 12:47:48 +1100 (EST) Received: from localhost ([127.0.0.1]:44475 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NMAtd-0002g1-3v for incoming@patchwork.ozlabs.org; Sat, 19 Dec 2009 20:47:45 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NMAlw-0007tT-KW for qemu-devel@nongnu.org; Sat, 19 Dec 2009 20:39:48 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NMAlr-0007nf-Oi for qemu-devel@nongnu.org; Sat, 19 Dec 2009 20:39:48 -0500 Received: from [199.232.76.173] (port=54472 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NMAlr-0007nB-8L for qemu-devel@nongnu.org; Sat, 19 Dec 2009 20:39:43 -0500 Received: from mail-fx0-f222.google.com ([209.85.220.222]:56134) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NMAlq-0004ms-Py for qemu-devel@nongnu.org; Sat, 19 Dec 2009 20:39:43 -0500 Received: by mail-fx0-f222.google.com with SMTP id 22so4042062fxm.2 for ; Sat, 19 Dec 2009 17:39:42 -0800 (PST) Received: by 10.223.81.85 with SMTP id w21mr3760696fak.94.1261273182393; Sat, 19 Dec 2009 17:39:42 -0800 (PST) Received: from localhost.localdomain (a88-114-220-92.elisa-laajakaista.fi [88.114.220.92]) by mx.google.com with ESMTPS id 13sm6982256fks.45.2009.12.19.17.39.40 (version=SSLv3 cipher=RC4-MD5); Sat, 19 Dec 2009 17:39:41 -0800 (PST) From: "Kirill A. Shutemov" To: qemu-devel@nongnu.org Date: Sun, 20 Dec 2009 03:39:15 +0200 Message-Id: <1261273167-3240-6-git-send-email-kirill@shutemov.name> X-Mailer: git-send-email 1.6.5.6 In-Reply-To: <1261273167-3240-5-git-send-email-kirill@shutemov.name> References: <1261273167-3240-1-git-send-email-kirill@shutemov.name> <1261273167-3240-2-git-send-email-kirill@shutemov.name> <1261273167-3240-3-git-send-email-kirill@shutemov.name> <1261273167-3240-4-git-send-email-kirill@shutemov.name> <1261273167-3240-5-git-send-email-kirill@shutemov.name> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: "Kirill A. Shutemov" Subject: [Qemu-devel] [PATCH 06/18] 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 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 --- block/vmdk.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 40 insertions(+), 10 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 4e48622..38e6c62 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 = write(fd, &magic, sizeof(magic)); + if (ret != sizeof(magic)) { + ret = -errno; + goto exit; + } + ret = write(fd, &header, sizeof(header)); + if (ret != sizeof(header)) { + ret = -errno; + goto exit; + } - ftruncate(fd, header.grain_offset << 9); + ret = ftruncate(fd, header.grain_offset << 9); + if (ret < 0) { + ret = -errno; + 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 = write(fd, &tmp, sizeof(tmp)); + if (ret != sizeof(tmp)) { + ret = -errno; + 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 = write(fd, &tmp, sizeof(tmp)); + if (ret != sizeof(tmp)) { + ret = -errno; + 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 = write(fd, desc, strlen(desc)); + if (ret != strlen(desc)) { + ret = -errno; + goto exit; + } + ret = 0; +exit: close(fd); - return 0; + return ret; } static void vmdk_close(BlockDriverState *bs)