From patchwork Sat Jan 2 03:45:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A . Shutemov" X-Patchwork-Id: 41995 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 559A7B6EEA for ; Sat, 2 Jan 2010 14:52:24 +1100 (EST) Received: from localhost ([127.0.0.1]:43814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NQv2J-0008Ue-OX for incoming@patchwork.ozlabs.org; Fri, 01 Jan 2010 22:52:19 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NQuw0-0006W9-Qs for qemu-devel@nongnu.org; Fri, 01 Jan 2010 22:45:48 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NQuvx-0006U3-11 for qemu-devel@nongnu.org; Fri, 01 Jan 2010 22:45:48 -0500 Received: from [199.232.76.173] (port=53810 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NQuvw-0006U0-KI for qemu-devel@nongnu.org; Fri, 01 Jan 2010 22:45:44 -0500 Received: from mail-fx0-f222.google.com ([209.85.220.222]:55673) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NQuvw-00082i-CJ for qemu-devel@nongnu.org; Fri, 01 Jan 2010 22:45:44 -0500 Received: by mail-fx0-f222.google.com with SMTP id 22so16659813fxm.2 for ; Fri, 01 Jan 2010 19:45:43 -0800 (PST) Received: by 10.223.94.200 with SMTP id a8mr469174fan.77.1262403943875; Fri, 01 Jan 2010 19:45:43 -0800 (PST) Received: from localhost.localdomain (a88-114-220-92.elisa-laajakaista.fi [88.114.220.92]) by mx.google.com with ESMTPS id 35sm22820386fkt.40.2010.01.01.19.45.42 (version=SSLv3 cipher=RC4-MD5); Fri, 01 Jan 2010 19:45:43 -0800 (PST) From: "Kirill A. Shutemov" To: qemu-devel@nongnu.org Date: Sat, 2 Jan 2010 05:45:23 +0200 Message-Id: <1262403933-26881-5-git-send-email-kirill@shutemov.name> X-Mailer: git-send-email 1.6.5.7 In-Reply-To: <1262403933-26881-4-git-send-email-kirill@shutemov.name> References: <1262403933-26881-1-git-send-email-kirill@shutemov.name> <1262403933-26881-2-git-send-email-kirill@shutemov.name> <1262403933-26881-3-git-send-email-kirill@shutemov.name> <1262403933-26881-4-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 05/15] 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..58fc04b 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 = -errno; + goto exit; + } + ret = qemu_write_full(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 = qemu_write_full(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 = qemu_write_full(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 = qemu_write_full(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)