Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp806981lqt; Thu, 6 Jun 2024 21:30:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWETaYmorgnudENbU3DcIMeW7q5bBQ47pppluGIeVCPwunP8Dd1x+d6yZmjo137SzEDDdgRiMa8Tpzd1jmEgENH7i9o4AAUajJ+M27HLw== X-Google-Smtp-Source: AGHT+IF+cx/OCL2RctF3C5dTeFf38e/UplXyQlpGEO12p3OVXoUhfVtev0rAJD0hnPanOiw9furL X-Received: by 2002:a50:8ad2:0:b0:57a:2817:477b with SMTP id 4fb4d7f45d1cf-57c5092e7f6mr833224a12.22.1717734613068; Thu, 06 Jun 2024 21:30:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717734613; cv=pass; d=google.com; s=arc-20160816; b=z+fjviCv9NI+NrBp6rdXyO/9GqTXAt3Hj6DMvwzHA9HL6eU+qKE3xYVHLZnWVlV0EV h7CXKkfxoFPjYdyASiRGliaMjNQmuSEWbqHOfRjPqfiqO76F3Jy3NzKHmx8P+Y2oG1Fd vbc+eWJW5NmjnUoz8TUv+zU/lcLjb18KxzZYqRJxWgm7BVYsQQxC+8476mGr2ITrx80C Sy7ZidOBQwCCEDkgKoYV72IGPDmksR1z5gmS1E8WEV7T7Os8OVuWNwLTMGaMJ2qnIUzJ lHM9aJU0Wk8veRtsVcsJjZX0+d9pQ/r6HYpP6acQSrzQ4JYLclFQ5N6xg2vX8y4qLO/F jXSA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=+Sg6FuDzlxkstDosuQBfjHaobeVdASeFw40NMCnNLhM=; fh=yXYChwFvQA/NaaLzCC0IJdkW11OhjXgO4DHXzVmnGFw=; b=CmwUGqfZJRGAcvxs17dQij7mSb93mYrvE2eYiGxppnzseYkgQqyJYaHCmLQjV1To43 2jVcVsFzl3se/vp8um+rKlcNePqqxvOH4cGwqegGZMrxyNvyOo1iF/yLjW7mJQR4HOep GI6v8r/T4/XEcj0sM//18L1PfLfQTRfRZQsWGN+pvvuJy/lK2zpa3rWTT/rXjflTfJgo 1z6W35eLUEdtRl4SvPz0uiNi5G30peovfjOv0zX3u/DJZrOz43/Pe5Lb8dPE6HufmQlr NDK1YtCEnLmshfvhr1F2TNtyGWgXiNVsjMolTYYAEIO6LTSN4kLsZ75k98ItfYYlzWa5 2WaQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-205297-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205297-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57aae230c24si1452129a12.434.2024.06.06.21.30.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 21:30:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205297-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-205297-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205297-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 95CE11F25CAA for ; Fri, 7 Jun 2024 04:30:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B925214B076; Fri, 7 Jun 2024 04:26:56 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E52C13E3F2 for ; Fri, 7 Jun 2024 04:26:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717734415; cv=none; b=eNbo+Sg/TIwyt8dY+/YRoYuFPPJ9/iobD4gTaTgoTueja7JioRfxGpOVaCKsZDE5j5DTvH2vzPlO5TNZkNrFFAWIDQLeUgeyG3cxgkmMOJctKIqzgjIioP4fJ6AAzix9PZzFIJaoDIqp95CRKfaFvCK0Tfc5LkXzRoGnIzBRPX0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717734415; c=relaxed/simple; bh=3aUqBoDI9TJI8uywQ+vjApH/7H+Tswt28IIEqBix3kQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ozAebvL4kPEACoIvTfjSeDeFhu5u+sBr1pYV5jvYnjGQEaq7e2S75NsArw94cRDXJ35UsKgdmvxsUBIEKQsOMxJd0T1ic3Y/+qZCLOs0NXEmxG5o1qHkoPQNz+j/7z/v7AEZ3sym+44OYxrYSYhItQJnIEBwgw+ieGterG4FiYs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VwShl4fRFzmYRQ; Fri, 7 Jun 2024 12:22:15 +0800 (CST) Received: from kwepemm600013.china.huawei.com (unknown [7.193.23.68]) by mail.maildlp.com (Postfix) with ESMTPS id 7B15D14038F; Fri, 7 Jun 2024 12:26:51 +0800 (CST) Received: from huawei.com (10.175.104.67) by kwepemm600013.china.huawei.com (7.193.23.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 7 Jun 2024 12:26:41 +0800 From: Zhihao Cheng To: , , , , , CC: , Subject: [RFC PATCH mtd-utils 020/110] ubifs-utils: Add linux type definitions Date: Fri, 7 Jun 2024 12:24:45 +0800 Message-ID: <20240607042615.2069840-21-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240607042615.2069840-1-chengzhihao1@huawei.com> References: <20240607042615.2069840-1-chengzhihao1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600013.china.huawei.com (7.193.23.68) Add linux type definitions, because there are many types (eg. u8/u16/u64) used in UBIFS linux kernel libs. Besides move type conversions (eg. cpu_to_le16, cpu_to_le32, etc.) into type definitions header file. This is a preparation for replacing implementation of UBIFS utils with linux kernel libs. Signed-off-by: Zhihao Cheng --- ubifs-utils/Makemodule.am | 1 + ubifs-utils/common/crypto.c | 1 + ubifs-utils/common/defs.h | 30 ------------- ubifs-utils/common/fscrypt.c | 3 +- ubifs-utils/common/fscrypt.h | 7 +-- ubifs-utils/common/linux_types.h | 89 +++++++++++++++++++++++++++++++++++++ ubifs-utils/common/sign.c | 2 +- ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 9 ++-- 8 files changed, 104 insertions(+), 38 deletions(-) create mode 100644 ubifs-utils/common/linux_types.h diff --git a/ubifs-utils/Makemodule.am b/ubifs-utils/Makemodule.am index d58570fe..0f9c0fa6 100644 --- a/ubifs-utils/Makemodule.am +++ b/ubifs-utils/Makemodule.am @@ -1,5 +1,6 @@ common_SOURCES = \ ubifs-utils/common/compiler_attributes.h \ + ubifs-utils/common/linux_types.h \ ubifs-utils/common/defs.h \ ubifs-utils/common/crc16.h \ ubifs-utils/common/crc16.c \ diff --git a/ubifs-utils/common/crypto.c b/ubifs-utils/common/crypto.c index 2ecd8da1..e4ef3491 100644 --- a/ubifs-utils/common/crypto.c +++ b/ubifs-utils/common/crypto.c @@ -23,6 +23,7 @@ #include #include +#include "linux_types.h" #include "fscrypt.h" #include "defs.h" #include "ubifs.h" diff --git a/ubifs-utils/common/defs.h b/ubifs-utils/common/defs.h index cafc94af..dd3b806e 100644 --- a/ubifs-utils/common/defs.h +++ b/ubifs-utils/common/defs.h @@ -9,7 +9,6 @@ #include #include #include -#include #include #include "ubifs.h" @@ -27,37 +26,8 @@ enum { MKFS_PROGRAM_TYPE = 0 }; printf("%s: %s: " fmt "\n", PROGRAM_NAME, __FUNCTION__, ##__VA_ARGS__); \ } while(0) -#define t16(x) ({ \ - uint16_t __b = (x); \ - (__LITTLE_ENDIAN==__BYTE_ORDER) ? __b : bswap_16(__b); \ -}) - -#define t32(x) ({ \ - uint32_t __b = (x); \ - (__LITTLE_ENDIAN==__BYTE_ORDER) ? __b : bswap_32(__b); \ -}) - -#define t64(x) ({ \ - uint64_t __b = (x); \ - (__LITTLE_ENDIAN==__BYTE_ORDER) ? __b : bswap_64(__b); \ -}) - -#define cpu_to_le16(x) ((__le16){t16(x)}) -#define cpu_to_le32(x) ((__le32){t32(x)}) -#define cpu_to_le64(x) ((__le64){t64(x)}) - -#define le16_to_cpu(x) (t16((x))) -#define le32_to_cpu(x) (t32((x))) -#define le64_to_cpu(x) (t64((x))) - #define unlikely(x) (x) -struct qstr -{ - char *name; - size_t len; -}; - /** * fls - find last (most-significant) bit set * @x: the word to search diff --git a/ubifs-utils/common/fscrypt.c b/ubifs-utils/common/fscrypt.c index 895d5c72..f39faa76 100644 --- a/ubifs-utils/common/fscrypt.c +++ b/ubifs-utils/common/fscrypt.c @@ -20,6 +20,7 @@ #include +#include "linux_types.h" #include "fscrypt.h" #include "defs.h" #include "ubifs.h" @@ -88,7 +89,7 @@ unsigned int fscrypt_fname_encrypted_size(struct fscrypt_context *fctx, return round_up(ilen, padding); } -int encrypt_path(void **outbuf, void *data, unsigned int data_len, +int encrypt_path(void **outbuf, const void *data, unsigned int data_len, unsigned int max_namelen, struct fscrypt_context *fctx) { void *inbuf, *crypt_key; diff --git a/ubifs-utils/common/fscrypt.h b/ubifs-utils/common/fscrypt.h index b8a599de..4a073e97 100644 --- a/ubifs-utils/common/fscrypt.h +++ b/ubifs-utils/common/fscrypt.h @@ -107,7 +107,7 @@ struct fscrypt_context *inherit_fscrypt_context(struct fscrypt_context *fctx); void free_fscrypt_context(struct fscrypt_context *fctx); unsigned int fscrypt_fname_encrypted_size(struct fscrypt_context *fctx, unsigned int ilen); -int encrypt_path(void **outbuf, void *data, unsigned int data_len, +int encrypt_path(void **outbuf, const void *data, unsigned int data_len, unsigned int max_namelen, struct fscrypt_context *fctx); int encrypt_data_node(struct fscrypt_context *fctx, unsigned int block_no, struct ubifs_data_node *dn, size_t length); @@ -138,8 +138,9 @@ static inline void free_fscrypt_context(struct fscrypt_context *fctx) assert(!fctx); } -static inline int encrypt_path(void **outbuf, void *data, unsigned int data_len, - unsigned int max_namelen, struct fscrypt_context *fctx) +static inline int encrypt_path(void **outbuf, const void *data, + unsigned int data_len, unsigned int max_namelen, + struct fscrypt_context *fctx) { (void)outbuf; (void)data; diff --git a/ubifs-utils/common/linux_types.h b/ubifs-utils/common/linux_types.h new file mode 100644 index 00000000..556b2e25 --- /dev/null +++ b/ubifs-utils/common/linux_types.h @@ -0,0 +1,89 @@ +#ifndef __LINUX_TYPES_H__ +#define __LINUX_TYPES_H__ + +#include +#include +#include +#include +#include + +#include "compiler_attributes.h" + +typedef __u8 u8; +typedef __u16 u16; +typedef __u32 u32; +typedef __u64 u64; + +typedef __s64 time64_t; + +struct qstr { + const char *name; + size_t len; +}; + +struct fscrypt_name { + struct qstr disk_name; +}; + +#define fname_name(p) ((p)->disk_name.name) +#define fname_len(p) ((p)->disk_name.len) + +#define t16(x) ({ \ + uint16_t __b = (x); \ + (__LITTLE_ENDIAN==__BYTE_ORDER) ? __b : bswap_16(__b); \ +}) + +#define t32(x) ({ \ + uint32_t __b = (x); \ + (__LITTLE_ENDIAN==__BYTE_ORDER) ? __b : bswap_32(__b); \ +}) + +#define t64(x) ({ \ + uint64_t __b = (x); \ + (__LITTLE_ENDIAN==__BYTE_ORDER) ? __b : bswap_64(__b); \ +}) + +#define cpu_to_le16(x) ((__le16){t16(x)}) +#define cpu_to_le32(x) ((__le32){t32(x)}) +#define cpu_to_le64(x) ((__le64){t64(x)}) + +#define le16_to_cpu(x) (t16((x))) +#define le32_to_cpu(x) (t32((x))) +#define le64_to_cpu(x) (t64((x))) + +#define check_mul_overflow(a, b, d) ({ \ + typeof(a) __a = (a); \ + typeof(b) __b = (b); \ + typeof(d) __d = (d); \ + (void) (&__a == &__b); \ + (void) (&__a == __d); \ + __builtin_mul_overflow(__a, __b, __d); \ +}) + +static inline __must_check size_t array_size(size_t a, size_t b) +{ + size_t bytes; + if (check_mul_overflow(a, b, &bytes)) + return SIZE_MAX; + + return bytes; +} + +static inline int int_log2(unsigned int arg) +{ + int l = 0; + + arg >>= 1; + while (arg) { + l++; + arg >>= 1; + } + return l; +} + +#undef PAGE_SIZE +#define PAGE_SIZE (getpagesize()) +#undef PAGE_SHIFT +#define PAGE_SHIFT (int_log2(PAGE_SIZE)) + +#endif diff --git a/ubifs-utils/common/sign.c b/ubifs-utils/common/sign.c index 7530503a..dfbc96bf 100644 --- a/ubifs-utils/common/sign.c +++ b/ubifs-utils/common/sign.c @@ -28,7 +28,7 @@ #include #include -#include "compiler_attributes.h" +#include "linux_types.h" #include "sign.h" #include "defs.h" #include "ubifs.h" diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c index 2181595e..c2f5a29d 100644 --- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c @@ -46,6 +46,7 @@ #include #endif +#include "linux_types.h" #include "defs.h" #include "crypto.h" #include "fscrypt.h" @@ -1207,12 +1208,14 @@ static int add_xattr(struct ubifs_ino_node *host_ino, struct stat *st, struct ubifs_ino_node *ino; struct ubifs_dent_node *xent; struct qstr nm; + char *tmp_name; union ubifs_key xkey, nkey; int len, ret; nm.len = strlen(name); - nm.name = xmalloc(nm.len + 1); - memcpy(nm.name, name, nm.len + 1); + tmp_name = xmalloc(nm.len + 1); + memcpy(tmp_name, name, nm.len + 1); + nm.name = tmp_name; host_ino->xattr_cnt++; host_ino->xattr_size += CALC_DENT_SIZE(nm.len); @@ -1240,7 +1243,7 @@ static int add_xattr(struct ubifs_ino_node *host_ino, struct stat *st, xent->inum = cpu_to_le64(inum); - ret = add_node(&xkey, nm.name, nm.len, xent, len); + ret = add_node(&xkey, tmp_name, nm.len, xent, len); if (ret) goto out; -- 2.13.6