From patchwork Mon Dec 21 08:41:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongsheng Yang X-Patchwork-Id: 559456 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 EBCC81409A0 for ; Mon, 21 Dec 2015 19:58:53 +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 1aAwGt-0008Av-8D; Mon, 21 Dec 2015 08:56:47 +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 1aAwBS-0001xO-C0 for linux-mtd@lists.infradead.org; Mon, 21 Dec 2015 08:51:13 +0000 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="1805888" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Dec 2015 16:50:18 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 1488741887CB; Mon, 21 Dec 2015 16:50:01 +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:50:00 +0800 From: Dongsheng Yang To: , , Subject: [PATCH 36/38] ubifs: Add more key helper functions Date: Mon, 21 Dec 2015 16:41:59 +0800 Message-ID: <1450687321-12381-37-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: 1488741887CB.A1F2B 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_005110_872362_B3B7A42B X-CRM114-Status: GOOD ( 11.36 ) 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: linux-mtd@lists.infradead.org Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: David Gstir Signed-off-by: David Gstir Signed-off-by: Richard Weinberger --- ubifs-utils/include/key.h | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/ubifs-utils/include/key.h b/ubifs-utils/include/key.h index ebcf79c..3210cf2 100644 --- a/ubifs-utils/include/key.h +++ b/ubifs-utils/include/key.h @@ -138,6 +138,17 @@ static inline void xent_key_init(const struct ubifs_info *c, } /** + * lowest_dent_key - get the lowest possible directory entry key. + * @key: where to store the lowest key + * @inum: parent inode number + */ +static inline void lowest_dent_key(union ubifs_key *key, ino_t inum) +{ + key->u32[0] = inum; + key->u32[1] = UBIFS_DENT_KEY << UBIFS_S_KEY_HASH_BITS; +} + +/** * data_key_init - initialize data key. * @c: UBIFS file-system description object * @key: key to initialize @@ -182,6 +193,17 @@ static inline void key_write_idx(const union ubifs_key *from, void *to) } /** + * key_copy - copy a key. + * @c: UBIFS file-system description object + * @from: the key to copy from + * @to: the key to copy to + */ +static inline void key_copy(const union ubifs_key *from, union ubifs_key *to) +{ + to->u64[0] = from->u64[0]; +} + +/** * keys_cmp - compare keys. * @c: UBIFS file-system description object * @key1: the first key to compare @@ -219,6 +241,22 @@ static inline void key_read(const void *from, union ubifs_key *to) } /** + * trun_key_init - initialize truncation node key. + * @c: UBIFS file-system description object + * @key: key to initialize + * @inum: inode number + * + * Note, UBIFS does not have truncation keys on the media and this function is + * only used for purposes of replay. + */ +static inline void trun_key_init(const struct ubifs_info *c __attribute__((unused)), + union ubifs_key *key, ino_t inum) +{ + key->u32[0] = inum; + key->u32[1] = UBIFS_TRUN_KEY << UBIFS_S_KEY_BLOCK_BITS; +} + +/** * invalid_key_init - initialize invalid node key. * @key: key to initialize * @@ -238,6 +276,18 @@ static inline int key_type(const union ubifs_key *key) return key->u32[1] >> UBIFS_S_KEY_BLOCK_BITS; } +/** + * key_type_flash - get type of a on-flash formatted key. + * @c: UBIFS file-system description object + * @k: key to get type of + */ +static inline int key_type_flash(const void *k) +{ + const union ubifs_key *key = k; + + return le32_to_cpu(key->j32[1]) >> UBIFS_S_KEY_BLOCK_BITS; +} + /* * key_hash - get directory entry hash. * @key: the key to get hash from @@ -266,4 +316,32 @@ static inline unsigned int key_block(const union ubifs_key *key) { return key->u32[1] & UBIFS_S_KEY_BLOCK_MASK; } + +/** + * is_hash_key - is a key vulnerable to hash collisions. + * @key: key + * + * This function returns %1 if @key is a hashed key or %0 otherwise. + */ +static inline int is_hash_key(const union ubifs_key *key) +{ + int type = key_type(key); + + return type == UBIFS_DENT_KEY || type == UBIFS_XENT_KEY; +} + +/** + * key_max_inode_size - get maximum file size allowed by current key format. + * @c: UBIFS file-system description object + */ +static inline unsigned long long key_max_inode_size(const struct ubifs_info *c) +{ + switch (c->key_fmt) { + case UBIFS_SIMPLE_KEY_FMT: + return (1ULL << UBIFS_S_KEY_BLOCK_BITS) * UBIFS_BLOCK_SIZE; + default: + return 0; + } +} + #endif /* !__UBIFS_KEY_H__ */