From patchwork Wed Dec 18 01:03:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Bisson X-Patchwork-Id: 302587 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0CF962C0086 for ; Wed, 18 Dec 2013 12:04:30 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vt5Ye-0000Vq-KU; Wed, 18 Dec 2013 01:04:16 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vt5Yd-0008Gl-9v; Wed, 18 Dec 2013 01:04:15 +0000 Received: from mail-pb0-x231.google.com ([2607:f8b0:400e:c01::231]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vt5Ya-0008GH-Nr for linux-mtd@lists.infradead.org; Wed, 18 Dec 2013 01:04:13 +0000 Received: by mail-pb0-f49.google.com with SMTP id jt11so7721074pbb.36 for ; Tue, 17 Dec 2013 17:03:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=/vJjD5VzF280DkloHnXIqM8FrNNX+a6DP1xnpKnk8rE=; b=h9lO5vUqahfen5IVaL08hoiR+QkZi64lDnU/qCuLcc+agfp0YcYtApHGl9Qvjv4lRM psnB9FrmAAo6kR85mUlijFInAeY+fT1bpMzVWfyrHPPx15rLjHWXRefbxAtp9XnTMYz9 fF7iR73XjR36RLpq2/uzQPUQqMxATsUuFtAa5TT95T+VaZrekj3bSzjtsosfqusffQlt LldZLe5l8k/mOPVz3WyGipxF0zAP6hLXZd3SuaJVGAvV8E19wxqfauhgWpYvrUaEJKwi 826UsIeGcqQvaZEOHk3IqwEo2ryu5kCQVxSguRr0m/56y1YcCw7Fsvj+XD+vWEXsF2at zmVw== X-Received: by 10.68.89.162 with SMTP id bp2mr3312695pbb.151.1387328627514; Tue, 17 Dec 2013 17:03:47 -0800 (PST) Received: from N5520.adeneo-embedded.us (173-10-76-58-BusName-Washington.hfc.comcastbusiness.net. [173.10.76.58]) by mx.google.com with ESMTPSA id sy10sm49989060pac.15.2013.12.17.17.03.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Dec 2013 17:03:46 -0800 (PST) From: Gary Bisson To: linux-mtd@lists.infradead.org Subject: [PATCH] mtd-utils: nanddump: write requested length only Date: Tue, 17 Dec 2013 17:03:06 -0800 Message-Id: <1387328586-24356-1-git-send-email-bisson.gary@gmail.com> X-Mailer: git-send-email 1.8.5.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131217_200412_850405_DD3E36CD X-CRM114-Status: UNSURE ( 7.51 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (bisson.gary[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Gary Bisson X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org nanddump was always writing a whole page of data into the output discarding the length actually requested. This patch allows to write only the remaining length if oob is omitted. In case oob is needed, it makes sense to copy the entire page. --- nanddump.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/nanddump.c b/nanddump.c index 4ee7ed4..300aca6 100644 --- a/nanddump.c +++ b/nanddump.c @@ -445,8 +445,14 @@ int main(int argc, char * const argv[]) pretty_buf, PRETTY_BUF_LEN, true, canonical, ofs + i); write(ofd, pretty_buf, strlen(pretty_buf)); } - } else - write(ofd, readbuf, bs); + } else { + /* Write requested length if oob is omitted */ + size_t size_left = end_addr - ofs; + if (omitoob && (size_left < bs)) + write(ofd, readbuf, size_left); + else + write(ofd, readbuf, bs); + } if (omitoob) continue;