aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
authorAdi Nata <adinata.softwareengineer@gmail.com>2026-04-05 09:19:20 +0800
committerAndrew Morton <akpm@linux-foundation.org>2026-05-28 21:24:40 -0700
commit410002f8139cbf902f1567f0a8cbf0c5b6f43da2 (patch)
treee4995e4e80cadb74dea92a87cebc150c5d1cff4d /fs
parent1877a09b64f89278ce3dc83e0cf6a8b1516660cb (diff)
downloadlinux-next-history-410002f8139cbf902f1567f0a8cbf0c5b6f43da2.tar.gz
kunit: fat: test cluster and directory i_pos layout helpers
Add KUnit coverage for fat_clus_to_blknr() and fat_get_blknr_offset() using stub msdos_sb_info values so cluster-to-sector and i_pos split math stays correct. Link: https://lore.kernel.org/20260405011920.28622-1-adinata.softwareengineer@gmail.com Signed-off-by: Adi Nata <adinata.softwareengineer@gmail.com> Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Cc: Christian Brauner <brauner@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/fat/fat_test.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/fs/fat/fat_test.c b/fs/fat/fat_test.c
index 886bf044a9f1d..4eeed9dca5494 100644
--- a/fs/fat/fat_test.c
+++ b/fs/fat/fat_test.c
@@ -20,6 +20,37 @@ static void fat_checksum_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, fat_checksum("ABCDEFGHA "), (u8)98);
}
+static void fat_clus_to_blknr_test(struct kunit *test)
+{
+ struct msdos_sb_info sbi = {
+ .sec_per_clus = 4,
+ .data_start = 100,
+ };
+
+ KUNIT_EXPECT_EQ(test, (sector_t)100,
+ fat_clus_to_blknr(&sbi, FAT_START_ENT));
+ KUNIT_EXPECT_EQ(test, (sector_t)112, fat_clus_to_blknr(&sbi, 5));
+}
+
+static void fat_get_blknr_offset_test(struct kunit *test)
+{
+ struct msdos_sb_info sbi = {
+ .dir_per_block = 16,
+ .dir_per_block_bits = 4,
+ };
+
+ sector_t blknr;
+ int offset;
+
+ fat_get_blknr_offset(&sbi, 0, &blknr, &offset);
+ KUNIT_EXPECT_EQ(test, (sector_t)0, blknr);
+ KUNIT_EXPECT_EQ(test, 0, offset);
+
+ fat_get_blknr_offset(&sbi, (10 << 4) | 7, &blknr, &offset);
+ KUNIT_EXPECT_EQ(test, (sector_t)10, blknr);
+ KUNIT_EXPECT_EQ(test, 7, offset);
+}
+
struct fat_timestamp_testcase {
const char *name;
struct timespec64 ts;
@@ -341,6 +372,8 @@ static void fat_truncate_atime_test(struct kunit *test)
static struct kunit_case fat_test_cases[] = {
KUNIT_CASE(fat_checksum_test),
+ KUNIT_CASE(fat_clus_to_blknr_test),
+ KUNIT_CASE(fat_get_blknr_offset_test),
KUNIT_CASE_PARAM(fat_time_fat2unix_test, fat_time_gen_params),
KUNIT_CASE_PARAM(fat_time_unix2fat_test, fat_time_gen_params),
KUNIT_CASE_PARAM(fat_time_unix2fat_clamp_test,