1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
6 #include <linux/blkdev.h>
7 #include <linux/buffer_head.h>
11 void exfat_bdev_open(struct super_block *sb)
13 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
18 p_bd->sector_size = bdev_logical_block_size(sb->s_bdev);
19 p_bd->sector_size_bits = ilog2(p_bd->sector_size);
20 p_bd->sector_size_mask = p_bd->sector_size - 1;
21 p_bd->num_sectors = i_size_read(sb->s_bdev->bd_inode) >>
22 p_bd->sector_size_bits;
26 void exfat_bdev_close(struct super_block *sb)
28 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
33 int exfat_bdev_read(struct super_block *sb, sector_t secno, struct buffer_head **bh,
34 u32 num_secs, bool read)
36 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
37 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
38 #ifdef CONFIG_EXFAT_KERNEL_DEBUG
39 struct exfat_sb_info *sbi = EXFAT_SB(sb);
40 long flags = sbi->debug_flags;
42 if (flags & EXFAT_DEBUGFLAGS_ERROR_RW)
44 #endif /* CONFIG_EXFAT_KERNEL_DEBUG */
53 *bh = __bread(sb->s_bdev, secno,
54 num_secs << p_bd->sector_size_bits);
56 *bh = __getblk(sb->s_bdev, secno,
57 num_secs << p_bd->sector_size_bits);
62 WARN(!p_fs->dev_ejected,
63 "[EXFAT] No bh, device seems wrong or to be ejected.\n");
68 int exfat_bdev_write(struct super_block *sb, sector_t secno, struct buffer_head *bh,
69 u32 num_secs, bool sync)
72 struct buffer_head *bh2;
73 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
74 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
75 #ifdef CONFIG_EXFAT_KERNEL_DEBUG
76 struct exfat_sb_info *sbi = EXFAT_SB(sb);
77 long flags = sbi->debug_flags;
79 if (flags & EXFAT_DEBUGFLAGS_ERROR_RW)
81 #endif /* CONFIG_EXFAT_KERNEL_DEBUG */
86 if (secno == bh->b_blocknr) {
88 set_buffer_uptodate(bh);
89 mark_buffer_dirty(bh);
91 if (sync && (sync_dirty_buffer(bh) != 0))
94 count = num_secs << p_bd->sector_size_bits;
96 bh2 = __getblk(sb->s_bdev, secno, count);
101 memcpy(bh2->b_data, bh->b_data, count);
102 set_buffer_uptodate(bh2);
103 mark_buffer_dirty(bh2);
105 if (sync && (sync_dirty_buffer(bh2) != 0)) {
115 WARN(!p_fs->dev_ejected,
116 "[EXFAT] No bh, device seems wrong or to be ejected.\n");
121 int exfat_bdev_sync(struct super_block *sb)
123 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
124 #ifdef CONFIG_EXFAT_KERNEL_DEBUG
125 struct exfat_sb_info *sbi = EXFAT_SB(sb);
126 long flags = sbi->debug_flags;
128 if (flags & EXFAT_DEBUGFLAGS_ERROR_RW)
130 #endif /* CONFIG_EXFAT_KERNEL_DEBUG */
135 return sync_blockdev(sb->s_bdev);