[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200311105245.125564-2-Kohada.Tetsuhiro@dc.MitsubishiElectric.co.jp>
Date: Wed, 11 Mar 2020 19:52:42 +0900
From: Tetsuhiro Kohada <Kohada.Tetsuhiro@...MitsubishiElectric.co.jp>
To: Kohada.Tetsuhiro@...MitsubishiElectric.co.jp
Cc: Mori.Takahiro@...MitsubishiElectric.co.jp,
motai.hirotaka@...mitsubishielectric.co.jp,
Valdis Kletnieks <valdis.kletnieks@...edu>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-fsdevel@...r.kernel.org, devel@...verdev.osuosl.org,
linux-kernel@...r.kernel.org
Subject: [PATCH 2/5] staging: exfat: separate and move exFAT-mount core processing.
Separate the mount process related to the exFAT specification in ffsMountVol() and move it to exfat_mount.c.
- Rename exfat_mount() to read_boot_sector().
- Separate exFAT-mount core process and move to exfat_mount.c as NEW exfat_mount().
- Move free_upcase_table()/free_alloc_bitmap() to exfat_mount.c as exfat_umount().
- Change some functions to static.
This also fixes the exfat_bdev_close() leak. :-)
Reviewed-by: Takahiro Mori <Mori.Takahiro@...MitsubishiElectric.co.jp>
Signed-off-by: Tetsuhiro Kohada <Kohada.Tetsuhiro@...MitsubishiElectric.co.jp>
---
drivers/staging/exfat/exfat.h | 11 +---
drivers/staging/exfat/exfat_core.c | 82 +++++++++++++++++++++++++++--
drivers/staging/exfat/exfat_super.c | 66 ++---------------------
3 files changed, 83 insertions(+), 76 deletions(-)
diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index 0f730090cb30..95c2a6ef0e71 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -581,14 +581,6 @@ void fs_error(struct super_block *sb);
s32 count_num_clusters(struct super_block *sb, struct chain_t *dir);
void exfat_chain_cont_cluster(struct super_block *sb, u32 chain, s32 len);
-/* allocation bitmap management functions */
-s32 load_alloc_bitmap(struct super_block *sb);
-void free_alloc_bitmap(struct super_block *sb);
-
-/* upcase table management functions */
-s32 load_upcase_table(struct super_block *sb);
-void free_upcase_table(struct super_block *sb);
-
/* dir entry management functions */
struct timestamp_t *tm_current(struct timestamp_t *tm);
@@ -616,7 +608,8 @@ s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir,
struct uni_name_t *p_uniname);
/* file operation functions */
-s32 exfat_mount(struct super_block *sb, struct boot_sector_t *p_boot);
+s32 exfat_mount(struct super_block *sb);
+void exfat_umount(struct super_block *sb);
s32 create_dir(struct inode *inode, struct chain_t *p_dir,
struct uni_name_t *p_uniname, struct file_id_t *fid);
s32 create_file(struct inode *inode, struct chain_t *p_dir,
diff --git a/drivers/staging/exfat/exfat_core.c b/drivers/staging/exfat/exfat_core.c
index ca1039b7977c..2d88ce85217c 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -472,7 +472,7 @@ void exfat_chain_cont_cluster(struct super_block *sb, u32 chain, s32 len)
* Allocation Bitmap Management Functions
*/
-s32 load_alloc_bitmap(struct super_block *sb)
+static s32 load_alloc_bitmap(struct super_block *sb)
{
int i, j, ret;
u32 map_size;
@@ -544,7 +544,7 @@ s32 load_alloc_bitmap(struct super_block *sb)
return -EFSCORRUPTED;
}
-void free_alloc_bitmap(struct super_block *sb)
+static void free_alloc_bitmap(struct super_block *sb)
{
int i;
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
@@ -561,6 +561,8 @@ void free_alloc_bitmap(struct super_block *sb)
/*
* Upcase table Management Functions
*/
+static void free_upcase_table(struct super_block *sb);
+
static s32 __load_upcase_table(struct super_block *sb, sector_t sector,
u32 num_sectors, u32 utbl_checksum)
{
@@ -706,7 +708,7 @@ static s32 __load_default_upcase_table(struct super_block *sb)
return ret;
}
-s32 load_upcase_table(struct super_block *sb)
+static s32 load_upcase_table(struct super_block *sb)
{
int i;
u32 tbl_clu, tbl_size;
@@ -754,7 +756,7 @@ s32 load_upcase_table(struct super_block *sb)
return __load_default_upcase_table(sb);
}
-void free_upcase_table(struct super_block *sb)
+static void free_upcase_table(struct super_block *sb)
{
u32 i;
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
@@ -2060,7 +2062,8 @@ s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir,
return 0;
}
-s32 exfat_mount(struct super_block *sb, struct boot_sector_t *p_boot)
+static s32 read_boot_sector(struct super_block *sb,
+ struct boot_sector_t *p_boot)
{
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
@@ -2104,6 +2107,75 @@ s32 exfat_mount(struct super_block *sb, struct boot_sector_t *p_boot)
return 0;
}
+s32 exfat_mount(struct super_block *sb)
+{
+ int i, ret;
+ struct boot_sector_t *p_boot;
+ struct buffer_head *tmp_bh = NULL;
+ struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
+
+ /* read Sector 0 */
+ if (sector_read(sb, 0, &tmp_bh, 1) != 0) {
+ ret = -EIO;
+ goto out;
+ }
+
+ p_boot = (struct boot_sector_t *)tmp_bh->b_data;
+
+ /* check the validity of BOOT sector */
+ if (le16_to_cpu(p_boot->boot_signature) != BOOT_SIGNATURE) {
+ brelse(tmp_bh);
+ ret = -EFSCORRUPTED;
+ goto out;
+ }
+
+ /* fill fs_struct */
+ for (i = 0; i < 53; i++)
+ if (p_boot->must_be_zero[i])
+ break;
+
+ if (i < 53) {
+ /* Not sure how we'd get here, but complain if it does */
+ ret = -EINVAL;
+ pr_info("EXFAT: Attempted to mount VFAT filesystem\n");
+ goto out;
+ } else {
+ ret = read_boot_sector(sb, p_boot);
+ }
+
+ brelse(tmp_bh);
+
+ if (ret)
+ goto out;
+
+ ret = load_alloc_bitmap(sb);
+ if (ret)
+ goto out;
+
+ ret = load_upcase_table(sb);
+ if (ret) {
+ free_alloc_bitmap(sb);
+ goto out;
+ }
+
+ if (p_fs->dev_ejected) {
+ free_upcase_table(sb);
+ free_alloc_bitmap(sb);
+ ret = -EIO;
+ goto out;
+ }
+
+ pr_info("[EXFAT] mounted successfully\n");
+out:
+ return ret;
+}
+
+void exfat_umount(struct super_block *sb)
+{
+ free_upcase_table(sb);
+ free_alloc_bitmap(sb);
+}
+
s32 create_dir(struct inode *inode, struct chain_t *p_dir,
struct uni_name_t *p_uniname, struct file_id_t *fid)
{
diff --git a/drivers/staging/exfat/exfat_super.c b/drivers/staging/exfat/exfat_super.c
index bd257d401f7b..978e1d5172ee 100644
--- a/drivers/staging/exfat/exfat_super.c
+++ b/drivers/staging/exfat/exfat_super.c
@@ -343,9 +343,7 @@ static inline void exfat_save_attr(struct inode *inode, u32 attr)
static int ffsMountVol(struct super_block *sb)
{
- int i, ret;
- struct boot_sector_t *p_boot;
- struct buffer_head *tmp_bh = NULL;
+ int ret;
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
@@ -370,66 +368,11 @@ static int ffsMountVol(struct super_block *sb)
if (p_bd->sector_size > sb->s_blocksize)
sb_set_blocksize(sb, p_bd->sector_size);
- /* read Sector 0 */
- if (sector_read(sb, 0, &tmp_bh, 1) != 0) {
- ret = -EIO;
- goto out;
- }
-
- p_boot = (struct boot_sector_t *)tmp_bh->b_data;
-
- /* check the validity of BOOT sector */
- if (le16_to_cpu(p_boot->boot_signature) != BOOT_SIGNATURE) {
- brelse(tmp_bh);
- exfat_bdev_close(sb);
- ret = -EFSCORRUPTED;
- goto out;
- }
-
- /* fill fs_struct */
- for (i = 0; i < 53; i++)
- if (p_boot->must_be_zero[i])
- break;
-
- if (i < 53) {
- /* Not sure how we'd get here, but complain if it does */
- ret = -EINVAL;
- pr_info("EXFAT: Attempted to mount VFAT filesystem\n");
- goto out;
- } else {
- ret = exfat_mount(sb, p_boot);
- }
-
- brelse(tmp_bh);
-
- if (ret) {
- exfat_bdev_close(sb);
- goto out;
- }
-
- ret = load_alloc_bitmap(sb);
- if (ret) {
- exfat_bdev_close(sb);
- goto out;
- }
- ret = load_upcase_table(sb);
+ ret = exfat_mount(sb);
+out:
if (ret) {
- free_alloc_bitmap(sb);
exfat_bdev_close(sb);
- goto out;
}
-
- if (p_fs->dev_ejected) {
- free_upcase_table(sb);
- free_alloc_bitmap(sb);
- exfat_bdev_close(sb);
- ret = -EIO;
- goto out;
- }
-
- pr_info("[EXFAT] mounted successfully\n");
-
-out:
mutex_unlock(&z_mutex);
return ret;
@@ -450,8 +393,7 @@ static int ffsUmountVol(struct super_block *sb)
fs_sync(sb, true);
fs_set_vol_flags(sb, VOL_CLEAN);
- free_upcase_table(sb);
- free_alloc_bitmap(sb);
+ exfat_umount(sb);
exfat_fat_release_all(sb);
exfat_buf_release_all(sb);
--
2.25.1
Powered by blists - more mailing lists