From patchwork Mon Jul 19 17:33:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 59214 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DF5B7B6EF2 for ; Tue, 20 Jul 2010 03:35:35 +1000 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1OauDp-0005GA-Qe; Mon, 19 Jul 2010 17:33:45 +0000 Received: from mms1.broadcom.com ([216.31.210.17]) by bombadil.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1OauDk-0005FD-Ty for linux-mtd@lists.infradead.org; Mon, 19 Jul 2010 17:33:41 +0000 Received: from [10.9.200.131] by mms1.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.3.2)); Mon, 19 Jul 2010 10:33:32 -0700 X-Server-Uuid: 02CED230-5797-4B57-9875-D5D2FEE4708A Received: from mail-irva-12.broadcom.com (10.11.16.101) by IRVEXCHHUB01.corp.ad.broadcom.com (10.9.200.131) with Microsoft SMTP Server id 8.2.247.2; Mon, 19 Jul 2010 10:33:32 -0700 Received: from localhost.localdomain (ld-irv-0074.broadcom.com [10.12.160.50]) by mail-irva-12.broadcom.com (Postfix) with ESMTP id 6830969CA8; Mon, 19 Jul 2010 10:33:32 -0700 (PDT) From: "Brian Norris" To: "Artem Bityutskiy" Subject: [PATCH v2 6/6] mtd-utils/nanddump.c: Add "forcebinary" flag Date: Mon, 19 Jul 2010 10:33:16 -0700 Message-ID: <1279560796-6388-3-git-send-email-norris@broadcom.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1279437819.16247.19.camel@localhost.localdomain> References: <1279437819.16247.19.camel@localhost.localdomain> MIME-Version: 1.0 X-WSS-ID: 605A53E637O28169964-01-01 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100719_133341_180938_6FE11884 X-CRM114-Status: GOOD ( 18.20 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.3.1 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: linux-mtd@lists.infradead.org, Brian Norris X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Restrict binary dumping so that by default, binary garbage is not printed directly to a terminal. Output redicted to files or piped to other commands should not be affected (as judged by "isatty(ofd)"). A new flag "-a" or "--forcebinary" is included so that users can override this behavior if necessary. Signed-off-by: Brian Norris --- nanddump.c | 22 +++++++++++++++++++++- 1 files changed, 21 insertions(+), 1 deletions(-) diff --git a/nanddump.c b/nanddump.c index cd018c6..acfdb33 100644 --- a/nanddump.c +++ b/nanddump.c @@ -45,6 +45,7 @@ static void display_help (void) "\n" " --help Display this help and exit\n" " --version Output version information and exit\n" +"-a --forcebinary Force printing of binary data to tty\n" "-c --canonicalprint Print canonical Hex+ASCII dump\n" "-f file --file=file Dump to file\n" "-i --ignoreerrors Ignore errors\n" @@ -85,6 +86,7 @@ static const char *dumpfile; // dump file name static bool omitbad = false; static bool quiet = false; // suppress diagnostic output static bool canonical = false; // print nice + ascii +static bool forcebinary = false; // force printing binary to tty static void process_options (int argc, char * const argv[]) { @@ -92,10 +94,11 @@ static void process_options (int argc, char * const argv[]) for (;;) { int option_index = 0; - static const char *short_options = "bs:f:il:opqnc"; + static const char *short_options = "bs:f:il:opqnca"; static const struct option long_options[] = { {"help", no_argument, 0, 0}, {"version", no_argument, 0, 0}, + {"forcebinary", no_argument, 0, 'a'}, {"canonicalprint", no_argument, 0, 'c'}, {"file", required_argument, 0, 'f'}, {"ignoreerrors", no_argument, 0, 'i'}, @@ -147,6 +150,9 @@ static void process_options (int argc, char * const argv[]) case 'o': omitoob = true; break; + case 'a': + forcebinary = true; + break; case 'c': canonical = true; case 'p': @@ -170,6 +176,13 @@ static void process_options (int argc, char * const argv[]) exit(EXIT_FAILURE); } + if (forcebinary && pretty_print) { + fprintf(stderr, "The forcebinary and pretty print options are\n" + "mutually-exclusive. Choose one or the " + "other.\n"); + exit(EXIT_FAILURE); + } + if ((argc - optind) != 1 || error) display_help (); @@ -355,6 +368,13 @@ int main(int argc, char * const argv[]) exit(EXIT_FAILURE); } + if (!pretty_print && !forcebinary && isatty(ofd)) { + fprintf(stderr, "Not printing binary garbage to tty. Use '-a'\n" + "or '--forcebinary' to override.\n"); + close(fd); + exit(EXIT_FAILURE); + } + /* Initialize start/end addresses and block size */ if (length) end_addr = start_addr + length;