From nobody Sat Sep 26 01:54:43 2026 Received: from embla.dev.snart.me (embla.dev.snart.me [54.252.183.203]) (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 EC34133F5BE for ; Sat, 5 Sep 2026 17:11:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.252.183.203 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788628273; cv=none; b=qzj3jhwHr5IlhubE3tSr87f6V3OvA7coiPOi7Fk6FvKV2mXWqXvpgM1cugo+5zE/RPv/U5Klcw72RApJi22aWp5OyVBpEipqVY5ddYR7xKN23oVB7VU20QkbIWlkhrNowXeMBtjkBqcErUdZWvBO8DQr2Gpz6pPC/muZU5+spc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788628273; c=relaxed/simple; bh=ZcpigCO04nwSFMw9aDXCYxAPZsH9b//hAQGEEKo49DY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M3bOhZB2jtGOYh3I5AKpw7Yom5OT9/CHVSzTvg+omr9jMZWw7l5BUSWHL33DjYy5rfTj+zscuvGPbPG9OtHSB+zwUxwERGYKQXtmrdZHSZdiXdi11CEY4RMzVSa1cLOGScLnVHgDVlX5ZEl7CC6Nv7ldff69JmhbPc1ibYOLPX8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=dev.snart.me; spf=pass smtp.mailfrom=dev.snart.me; dkim=pass (1024-bit key) header.d=dev.snart.me header.i=@dev.snart.me header.b=h2K11CSO; arc=none smtp.client-ip=54.252.183.203 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=dev.snart.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dev.snart.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=dev.snart.me header.i=@dev.snart.me header.b="h2K11CSO" Received: from embla.dev.snart.me (localhost [IPv6:::1]) by embla.dev.snart.me (Postfix) with ESMTP id 3AEDA1D452; Sat, 5 Sep 2026 17:11:09 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 embla.dev.snart.me 3AEDA1D452 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dev.snart.me; s=00; t=1788628270; bh=ZcpigCO04nwSFMw9aDXCYxAPZsH9b//hAQGEEKo49DY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h2K11CSOkc5qM/OzFTB5DDm6VfjDH2YN/JaAmTAXNKNJ6YRcYVhGz3GMiRSR1D/d1 l1C+lMvwuyjCocyZQKQJSjJ+JNsfHPEQbGkI5r5LZqkC2KnOPfYRppWSpTku/prSAM bIDK4UxiFXlQ6fgy/GLfj0zgvCFT8uROfbJ0U0HY= Received: from maya.d.snart.me ([182.226.25.243]) by embla.dev.snart.me with ESMTPSA id 30O2ECVNnGrEmwUA8KYfjw:T2 (envelope-from ); Sat, 05 Sep 2026 17:11:09 +0000 From: David Timber To: Namjae Jeon , Sungjong Seo , Yuezhang Mo Cc: exfat@lists.linux.dev, Hyunchul Lee , linux-kernel@vger.kernel.org, David Timber Subject: [PATCH v1 1/2] exfat: update percent_in_use field when updating volume flags Date: Sat, 5 Sep 2026 17:10:42 +0000 Message-ID: <20260905171043.922793-2-dxdt@dev.snart.me> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260905171043.922793-1-dxdt@dev.snart.me> References: <20260905171043.922793-1-dxdt@dev.snart.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, the exfat fs implementation does not modify the percent_in_use in the boot sector header at all. Although the field is only an advisory field for situations where bit counting is not feasible, not updating the field at all can cause confusion if the the value is actually exposed to the user. Calculate the value using integer arithmetic only when the dirty flag is cleared. If the dirty flag is set, set to 0xFF. It is set to 0xFF when mounting under the assumption that the number of used clusters will change - this is basically what is recommended in the SD Association's specs. When clearing the dirty flag, if overridden by sbi->vol_flags_persistent, set to 0xFF. This is intentional because if there are orphan clusters, the calculated value would be incorrect and correcting the fs error is fsck.exfat's job. Signed-off-by: David Timber --- fs/exfat/super.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/exfat/super.c b/fs/exfat/super.c index a9ea36ba2693..2409e57e7370 100644 --- a/fs/exfat/super.c +++ b/fs/exfat/super.c @@ -18,6 +18,7 @@ #include #include #include +#include =20 #include "exfat_raw.h" #include "exfat_fs.h" @@ -69,16 +70,28 @@ static int exfat_statfs(struct dentry *dentry, struct k= statfs *buf) return 0; } =20 +static inline __u8 exfat_calc_perc_in_use(const struct exfat_sb_info *sbi) +{ + return (__u8)mul_u64_u32_div(sbi->used_clusters, 100, + EXFAT_DATA_CLUSTER_COUNT(sbi)); +} + static int exfat_set_vol_flags(struct super_block *sb, unsigned short new_= flags) { struct exfat_sb_info *sbi =3D EXFAT_SB(sb); struct boot_sector *p_boot =3D (struct boot_sector *)sbi->boot_bh->b_data; + __u8 new_piu; =20 /* retain persistent-flags */ new_flags |=3D sbi->vol_flags_persistent; =20 + if (new_flags & VOLUME_DIRTY) + new_piu =3D 0xFF; + else + new_piu =3D exfat_calc_perc_in_use(sbi); + /* flags are not changed */ - if (sbi->vol_flags =3D=3D new_flags) + if (sbi->vol_flags =3D=3D new_flags && new_piu =3D=3D p_boot->percent_in_= use) return 0; =20 sbi->vol_flags =3D new_flags; @@ -90,6 +103,7 @@ static int exfat_set_vol_flags(struct super_block *sb, u= nsigned short new_flags) return 0; =20 p_boot->vol_flags =3D cpu_to_le16(new_flags); + p_boot->percent_in_use =3D new_piu; =20 set_buffer_uptodate(sbi->boot_bh); mark_buffer_dirty(sbi->boot_bh); --=20 2.55.0 From nobody Sat Sep 26 01:54:43 2026 Received: from embla.dev.snart.me (embla.dev.snart.me [54.252.183.203]) (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 ABDCA4E56CE for ; Sat, 5 Sep 2026 17:11:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.252.183.203 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788628275; cv=none; b=ZxUEBN0rnmvY9t28v1jCiubIojNZXY4g4OWzWAOx6S/Od78v04nd2r5slXkTKZoAYU1Ctg64MZMIKskEl7vgpOlEt4PwjUhLcP7mggQ0wR1rqOmJeFYaAHbfJo1MeV4m+kLSTIabw1NCn59AYSGZeHx9EB5wP92mjmpv4ug9AcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788628275; c=relaxed/simple; bh=pra9F6jW6/XJVLvZOuOu4MQjBgq6OC90I4ypiyb2yJo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YsW7lcYAtNkKslAFpU0dEhPyrphu7uV7xnyszZRR48B0yZojUu2mFPxuoZwDJQW8U4wfxF4cYzcjq3N4cdbUQRJGsvHi0stW6bQbjwT9Stf7+qlMCUKJetBPULIeFZnvNkQWM0N/f0StBcj2YfA8EllmT66G+5GXLhLKxmeDgfg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=dev.snart.me; spf=pass smtp.mailfrom=dev.snart.me; dkim=pass (1024-bit key) header.d=dev.snart.me header.i=@dev.snart.me header.b=g1NMmSXo; arc=none smtp.client-ip=54.252.183.203 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=dev.snart.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dev.snart.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=dev.snart.me header.i=@dev.snart.me header.b="g1NMmSXo" Received: from embla.dev.snart.me (localhost [IPv6:::1]) by embla.dev.snart.me (Postfix) with ESMTP id D1B531D454; Sat, 5 Sep 2026 17:11:10 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 embla.dev.snart.me D1B531D454 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dev.snart.me; s=00; t=1788628272; bh=pra9F6jW6/XJVLvZOuOu4MQjBgq6OC90I4ypiyb2yJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g1NMmSXo2VrgGqAlUl0pt8sZ5aWT34QBA0S19+H+fk4hQsl/TFulq9CccHNJYGUyK avG8NDvKMKBYZrHzp5v/dBSRqVqAJ0F99LK+oiqn/+dUQYVX1YeJTx1ecCjRj0oCTJ zkQm1mm/B5a7uYxXBfQERvNSUW+rc6E4nC3SCfAQ= Received: from maya.d.snart.me ([182.226.25.243]) by embla.dev.snart.me with ESMTPSA id 30O2ECVNnGrEmwUA8KYfjw:T3 (envelope-from ); Sat, 05 Sep 2026 17:11:10 +0000 From: David Timber To: Namjae Jeon , Sungjong Seo , Yuezhang Mo Cc: exfat@lists.linux.dev, Hyunchul Lee , linux-kernel@vger.kernel.org, David Timber Subject: [PATCH v1 2/2] exfat: remove runtime integer division Date: Sat, 5 Sep 2026 17:10:43 +0000 Message-ID: <20260905171043.922793-3-dxdt@dev.snart.me> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260905171043.922793-1-dxdt@dev.snart.me> References: <20260905171043.922793-1-dxdt@dev.snart.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace the arithmetic ops that compiles to the use of actual integer division with bitwise ops. As the divisors involved are all power of two, integer division is not necessary. No functional change. Signed-off-by: David Timber --- fs/exfat/dir.c | 3 ++- fs/exfat/exfat_fs.h | 1 + fs/exfat/namei.c | 4 ++-- fs/exfat/super.c | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index fa9abedf4d84..46514b13bebd 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -1309,7 +1309,8 @@ static int exfat_get_volume_label_dentry(struct super= _block *sb, es->bh =3D es->__bh; es->bh[0] =3D bh; es->num_bh =3D 1; - es->start_off =3D exfat_dentries_to_bytes(i) % sb->s_blocksize; + es->start_off =3D exfat_dentries_to_bytes(i) & + ((u32)sb->s_blocksize - 1); =20 return 0; } diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index a9131fe03302..41a2c7dfc479 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -232,6 +232,7 @@ struct exfat_sb_info { unsigned int num_FAT_sectors; /* num of FAT sectors */ unsigned int root_dir; /* root dir cluster */ unsigned int dentries_per_clu; /* num of dentries per cluster */ + unsigned int dentries_per_clu_bits; unsigned int vol_flags; /* volume flags */ unsigned int vol_flags_persistent; /* volume flags to retain */ struct buffer_head *boot_bh; /* buffer_head of BOOT sector */ diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index 80f60e80786e..3c5746fc57d9 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -386,7 +386,7 @@ int exfat_find_empty_entry(struct inode *inode, } =20 p_dir->dir =3D exfat_sector_to_cluster(sbi, es->bh[0]->b_blocknr); - p_dir->size -=3D dentry / sbi->dentries_per_clu; + p_dir->size -=3D dentry >> sbi->dentries_per_clu_bits; =20 return dentry & (sbi->dentries_per_clu - 1); } @@ -638,7 +638,7 @@ static int exfat_find(struct inode *dir, const struct q= str *qname, /* adjust cdir to the optimized value */ cdir.dir =3D hint_opt.clu; if (cdir.flags & ALLOC_NO_FAT_CHAIN) - cdir.size -=3D dentry / sbi->dentries_per_clu; + cdir.size -=3D dentry >> sbi->dentries_per_clu_bits; dentry =3D hint_opt.eidx; =20 info->dir =3D cdir; diff --git a/fs/exfat/super.c b/fs/exfat/super.c index 2409e57e7370..217d150652cf 100644 --- a/fs/exfat/super.c +++ b/fs/exfat/super.c @@ -519,8 +519,8 @@ static int exfat_read_boot_sector(struct super_block *s= b) EXFAT_RESERVED_CLUSTERS; =20 sbi->root_dir =3D le32_to_cpu(p_boot->root_cluster); - sbi->dentries_per_clu =3D 1 << - (sbi->cluster_size_bits - DENTRY_SIZE_BITS); + sbi->dentries_per_clu_bits =3D sbi->cluster_size_bits - DENTRY_SIZE_BITS; + sbi->dentries_per_clu =3D 1 << sbi->dentries_per_clu_bits; =20 sbi->vol_flags =3D le16_to_cpu(p_boot->vol_flags); sbi->vol_flags_persistent =3D sbi->vol_flags & (VOLUME_DIRTY | MEDIA_FAIL= URE); --=20 2.55.0