Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp806026lqt; Thu, 6 Jun 2024 21:26:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU1HpK5S3+y8Mzb8ZrAlF4Syn+J9Nq4QWdE+MyysjbC1EkwL3MyArJVvXIt0Ytucb5ZfX89oSaBbmjmZ+uO4OSxhkzUHbFLfuNecPXBTQ== X-Google-Smtp-Source: AGHT+IFrmncCvgbgL5apqWBJ2Ocx2Wi6l+5MgvnQyWgjuZ3P0yvKmQgcjEWxdlusnYXVCOH4r0NL X-Received: by 2002:a17:906:411:b0:a6c:8282:242e with SMTP id a640c23a62f3a-a6cd665d94amr94670266b.25.1717734401382; Thu, 06 Jun 2024 21:26:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717734401; cv=pass; d=google.com; s=arc-20160816; b=fq77z78hX6Knmm4R+6vEH3/Jd2dNr9uFyJEv112cMfZrdTiU3yL5dm6ZKnF01sTzYb 2jq4B+jUej4KqmR/+yAnk3Ru4E8Z4TI3lHuBrNOCcUI4wlPexDoVxmfl42wZGosAP0DJ wYvW8gbDZiDx2RH5wNV4u3U+MuStaz5afEfUA4jRGb5cp2Cum6y3PhpJVEt7KGUg/DCM +5WVqFM9tcgaQ5yYl12hP2oi/dP5PCjzQccARVfKoxeTK1GM0lk0ONo0exKAT/X/3N+Z 6yomMp4JGU2/LWCfuVX5tHpZfGzPT1rSwpqcwLPNLeoKxWYKkfVAcNM2FVX3jyoue6xt ckHg== 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=nF92/VdJ7nl0ojZwlKPUHT64gNqBANtwH+0MJByLFI8=; fh=yXYChwFvQA/NaaLzCC0IJdkW11OhjXgO4DHXzVmnGFw=; b=sRcogVUaMXOaWRi+2cHqqL95opwvQ36zGfg9X8gCFE5FH4LAG3pN5EcbQLsb4YC9xr vwuWkssR8C9aic0zn1L/X16ZvRgBGQUYDEdRf3zc0Ch7RmU0YwrOYlE1ZlEmpzXUvYE6 zcxgCrn61cIjnPnyXvoTUFNwKCRxcXUm/sauW2s67YdA9iF6yebTjBACO4NtPA3ZB83F A7WpnazSrptl6LenmaGsSYaCQu9fv1x3HNS31XYS3+KRHpHE/P4A+mBW18YQe0dKSYE8 rfWd/pDo6HHk9CWh4qKBlh1rhNDKbn/K0Z0ztwCPKFIXz0YtLE5pxmorlg3Vh0A/8ks8 vIsQ==; 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-205282-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205282-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. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6c806db0f0si143144566b.356.2024.06.06.21.26.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 21:26:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205282-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-205282-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205282-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 19E421F24DE0 for ; Fri, 7 Jun 2024 04:26:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 896C91B7F7; Fri, 7 Jun 2024 04:26:33 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 790DC17582 for ; Fri, 7 Jun 2024 04:26:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717734393; cv=none; b=jdMgxsXquNj8iK2PR/oZhNxE4ExLGdLGH80a9knoO603buN6o1NjazJx+z9Fj2bTQG1v8a2CH322hWRmtshWCDmYICFSkkkKKgidATH7EWqEWODgm8ytIIZKe3QRBBPz/cz2m/vU0Y0iIHlmSEtZXtWq4XPEzEIcuHI6oyXwZ1s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717734393; c=relaxed/simple; bh=jHtc/cF/ktkWBpBjDLIG23QKwR+A0mue9P5rqRX3Q20=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=unfyNE9Z2jqvq97192IHmT8G6aNevXodbORVtRDXyoixGbCMEif8JugbXOmq5Y5lwAjPLONrfPauzAAAh7R3AGs//wvjNDaRom7NLVkf8W87iIgPJoXnQVOyHYQf7LYUtdFeNtRpHvuHtlmdA9X0oWhettYEp4JuxpTku6lhlfQ= 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.187 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.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VwSj0733yzwSCp; Fri, 7 Jun 2024 12:22:28 +0800 (CST) Received: from kwepemm600013.china.huawei.com (unknown [7.193.23.68]) by mail.maildlp.com (Postfix) with ESMTPS id DE32418007B; Fri, 7 Jun 2024 12:26:27 +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:27 +0800 From: Zhihao Cheng To: , , , , , CC: , Subject: [RFC PATCH mtd-utils 001/110] mkfs.ubifs: Clear direct_write property when closing target Date: Fri, 7 Jun 2024 12:24:26 +0800 Message-ID: <20240607042615.2069840-2-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) Direct writing is not allowd on an UBI volume, unless the volume is set with direct_write property. The open_target sets direct_write property, don't forget to clear direct_write property for UBI volume when closing target. Fixes: a48340c335dab ("mkfs.ubifs: use libubi to format UBI volume") Signed-off-by: Zhihao Cheng --- ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c index 42a47f83..5ca01512 100644 --- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c @@ -2832,7 +2832,7 @@ static int open_target(void) return sys_err_msg("cannot open the UBI volume '%s'", output); if (ubi_set_property(out_fd, UBI_VOL_PROP_DIRECT_WRITE, 1)) - return sys_err_msg("ubi_set_property failed"); + return sys_err_msg("ubi_set_property(set direct_write) failed"); if (!yes && check_volume_empty()) { if (!prompt("UBI volume is not empty. Format anyways?", false)) @@ -2859,10 +2859,14 @@ static int open_target(void) */ static int close_target(void) { + if (out_fd >= 0) { + if (ubi && ubi_set_property(out_fd, UBI_VOL_PROP_DIRECT_WRITE, 0)) + return sys_err_msg("ubi_set_property(clear direct_write) failed"); + if (close(out_fd) == -1) + return sys_err_msg("cannot close the target '%s'", output); + } if (ubi) libubi_close(ubi); - if (out_fd >= 0 && close(out_fd) == -1) - return sys_err_msg("cannot close the target '%s'", output); if (output) free(output); return 0; -- 2.13.6