From patchwork Mon Dec 21 08:41:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongsheng Yang X-Patchwork-Id: 559430 X-Patchwork-Delegate: david.oberhollenzer@sigma-star.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9FE6E1409C3 for ; Mon, 21 Dec 2015 19:52:52 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aAwBq-0002ba-B2; Mon, 21 Dec 2015 08:51:34 +0000 Received: from [59.151.112.132] (helo=heian.cn.fujitsu.com) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aAwAz-0001wk-Tw for linux-mtd@lists.infradead.org; Mon, 21 Dec 2015 08:50:44 +0000 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="1805864" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Dec 2015 16:50:04 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id A02E7406CF6E; Mon, 21 Dec 2015 16:49:45 +0800 (CST) Received: from yds-PC.g08.fujitsu.local (10.167.226.66) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Mon, 21 Dec 2015 16:49:45 +0800 From: Dongsheng Yang To: , , Subject: [PATCH 14/38] ubifs: io: introduce ubifs_read function to read ubi volume Date: Mon, 21 Dec 2015 16:41:37 +0800 Message-ID: <1450687321-12381-15-git-send-email-yangds.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.4.2 In-Reply-To: <1450687321-12381-1-git-send-email-yangds.fnst@cn.fujitsu.com> References: <1450687321-12381-1-git-send-email-yangds.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.66] X-yoursite-MailScanner-ID: A02E7406CF6E.A4371 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangds.fnst@cn.fujitsu.com X-Spam-Status: No X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151221_005042_485030_EF5783AF X-CRM114-Status: UNSURE ( 7.84 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.1 (-) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-1.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.8 RDNS_NONE Delivered to internal network by a host with no rDNS X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dongsheng Yang , linux-mtd@lists.infradead.org Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Implement a ubifs_read function in io lib. This function will read the data at offset in length of len from ubi volume to buf. Signed-off-by: Dongsheng Yang --- ubifs-utils/include/io.h | 2 ++ ubifs-utils/lib/io.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/ubifs-utils/include/io.h b/ubifs-utils/include/io.h index 920645d..11f568c 100644 --- a/ubifs-utils/include/io.h +++ b/ubifs-utils/include/io.h @@ -16,4 +16,6 @@ int write_leb(struct ubifs_info *c, int lnum, int len, void *buf); int close_target(void); int open_target(struct ubifs_info *c, int yes); int open_ubi(struct ubifs_info *c, const char *node); + +int ubifs_read(loff_t offset, int len, void *buf); #endif diff --git a/ubifs-utils/lib/io.c b/ubifs-utils/lib/io.c index 9817d2a..d05cf86 100644 --- a/ubifs-utils/lib/io.c +++ b/ubifs-utils/lib/io.c @@ -132,3 +132,21 @@ int write_leb(struct ubifs_info *c, int lnum, int len, void *buf) return 0; } + +/** + * ubifs_read - read data from ubi volume. + * @offset: offset of data in volume + * @len: length of data in the buffer + * @buf: buffer (must be at least c->leb_size bytes) + */ +int ubifs_read(loff_t offset, int len, void *buf) +{ + if (lseek(out_fd, offset, SEEK_SET) != offset) + return sys_err_msg("lseek failed seeking %"PRIdoff_t, offset); + + if (read(out_fd, buf, len) != len) + return sys_err_msg("write failed writing %d bytes at pos %"PRIdoff_t, + len, offset); + + return 0; +}