[PATCH v2] staging: exfat: remove fs_func struct.

2020-01-23 Thread Tetsuhiro Kohada
From: "Tetsuhiro Kohada" 

Remove 'fs_func struct' and change indirect calls to direct calls.

The following issues are described in exfat's TODO.
> Create helper function for exfat_set_entry_time () and
> exfat_set_entry_type () because it's sort of ugly to be calling the same 
> functionn directly and other code calling through  the fs_func struc ponters 
> ...

The fs_func struct was used for switching the helper functions of 
fat16/fat32/exfat.
Now, it has lost the role of switching, just making the code less readable.

Signed-off-by: Tetsuhiro Kohada 
---
 drivers/staging/exfat/exfat.h   |  79 +-
 drivers/staging/exfat/exfat_core.c  | 214 +++-
 drivers/staging/exfat/exfat_super.c | 119 
 3 files changed, 178 insertions(+), 234 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index 3865c17027..4d87360fab 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -516,49 +516,6 @@ struct buf_cache_t {
struct buffer_head   *buf_bh;
 };
 
-struct fs_func {
-   s32 (*alloc_cluster)(struct super_block *sb, s32 num_alloc,
-struct chain_t *p_chain);
-   void(*free_cluster)(struct super_block *sb, struct chain_t *p_chain,
-   s32 do_relse);
-   s32 (*count_used_clusters)(struct super_block *sb);
-
-   s32 (*init_dir_entry)(struct super_block *sb, struct chain_t *p_dir,
- s32 entry, u32 type, u32 start_clu, u64 size);
-   s32 (*init_ext_entry)(struct super_block *sb, struct chain_t *p_dir,
- s32 entry, s32 num_entries,
- struct uni_name_t *p_uniname,
- struct dos_name_t *p_dosname);
-   s32 (*find_dir_entry)(struct super_block *sb, struct chain_t *p_dir,
- struct uni_name_t *p_uniname, s32 num_entries,
- struct dos_name_t *p_dosname, u32 type);
-   void(*delete_dir_entry)(struct super_block *sb,
-   struct chain_t *p_dir, s32 entry,
-   s32 offset, s32 num_entries);
-   void(*get_uni_name_from_ext_entry)(struct super_block *sb,
-  struct chain_t *p_dir, s32 entry,
-  u16 *uniname);
-   s32 (*count_ext_entries)(struct super_block *sb,
-struct chain_t *p_dir, s32 entry,
-struct dentry_t *p_entry);
-   s32 (*calc_num_entries)(struct uni_name_t *p_uniname);
-
-   u32 (*get_entry_type)(struct dentry_t *p_entry);
-   void(*set_entry_type)(struct dentry_t *p_entry, u32 type);
-   u32 (*get_entry_attr)(struct dentry_t *p_entry);
-   void(*set_entry_attr)(struct dentry_t *p_entry, u32 attr);
-   u8  (*get_entry_flag)(struct dentry_t *p_entry);
-   void(*set_entry_flag)(struct dentry_t *p_entry, u8 flag);
-   u32 (*get_entry_clu0)(struct dentry_t *p_entry);
-   void(*set_entry_clu0)(struct dentry_t *p_entry, u32 clu0);
-   u64 (*get_entry_size)(struct dentry_t *p_entry);
-   void(*set_entry_size)(struct dentry_t *p_entry, u64 size);
-   void(*get_entry_time)(struct dentry_t *p_entry,
- struct timestamp_t *tp, u8 mode);
-   void(*set_entry_time)(struct dentry_t *p_entry,
- struct timestamp_t *tp, u8 mode);
-};
-
 struct fs_info_t {
u32  drv;/* drive ID */
u32  vol_type;   /* volume FAT type */
@@ -597,7 +554,6 @@ struct fs_info_t {
 
u32 dev_ejected;/* block device operation error flag */
 
-   struct fs_func *fs_func;
struct mutex v_mutex;
 
/* FAT cache */
@@ -829,5 +785,40 @@ int exfat_bdev_write(struct super_block *sb, sector_t 
secno,
   struct buffer_head *bh, u32 num_secs, bool sync);
 int exfat_bdev_sync(struct super_block *sb);
 
+/* cluster operation functions */
+s32 exfat_alloc_cluster(struct super_block *sb, s32 num_alloc,
+   struct chain_t *p_chain);
+void exfat_free_cluster(struct super_block *sb, struct chain_t *p_chain,
+   s32 do_relse);
+s32 exfat_count_used_clusters(struct super_block *sb);
+
+/* dir operation functions */
+s32 exfat_find_dir_entry(struct super_block *sb, struct chain_t *p_dir,
+struct uni_name_t *p_uniname, s32 num_entries,
+struct dos_name_t *p_dosname, u32 type);
+void exfat_delete_dir_entry(struct super_block *sb, struct chain_t *p_dir,
+   s32 entry, s32 order, s32 num_entries);
+void exfat_get_uni_

[PATCH v3] staging: exfat: remove fs_func struct.

2020-01-23 Thread Tetsuhiro Kohada
From: "Tetsuhiro Kohada" 

Remove 'fs_func struct' and change indirect calls to direct calls.

The following issues are described in exfat's TODO.
> Create helper function for exfat_set_entry_time () and
> exfat_set_entry_type () because it's sort of ugly to be calling the same 
> functionn directly and other code calling through  the fs_func struc ponters 
> ...

The fs_func struct was used for switching the helper functions of 
fat16/fat32/exfat.
Now, it has lost the role of switching, just making the code less readable.

Signed-off-by: Tetsuhiro Kohada 
---
Changes in v3:
- Add patch versions.

Changes in v2:
- Rebase to the 'linux-next' tree.
- Change signature to full name.

 drivers/staging/exfat/exfat.h   |  79 +-
 drivers/staging/exfat/exfat_core.c  | 214 +++-
 drivers/staging/exfat/exfat_super.c | 119 
 3 files changed, 178 insertions(+), 234 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index 3865c17027..4d87360fab 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -516,49 +516,6 @@ struct buf_cache_t {
struct buffer_head   *buf_bh;
 };
 
-struct fs_func {
-   s32 (*alloc_cluster)(struct super_block *sb, s32 num_alloc,
-struct chain_t *p_chain);
-   void(*free_cluster)(struct super_block *sb, struct chain_t *p_chain,
-   s32 do_relse);
-   s32 (*count_used_clusters)(struct super_block *sb);
-
-   s32 (*init_dir_entry)(struct super_block *sb, struct chain_t *p_dir,
- s32 entry, u32 type, u32 start_clu, u64 size);
-   s32 (*init_ext_entry)(struct super_block *sb, struct chain_t *p_dir,
- s32 entry, s32 num_entries,
- struct uni_name_t *p_uniname,
- struct dos_name_t *p_dosname);
-   s32 (*find_dir_entry)(struct super_block *sb, struct chain_t *p_dir,
- struct uni_name_t *p_uniname, s32 num_entries,
- struct dos_name_t *p_dosname, u32 type);
-   void(*delete_dir_entry)(struct super_block *sb,
-   struct chain_t *p_dir, s32 entry,
-   s32 offset, s32 num_entries);
-   void(*get_uni_name_from_ext_entry)(struct super_block *sb,
-  struct chain_t *p_dir, s32 entry,
-  u16 *uniname);
-   s32 (*count_ext_entries)(struct super_block *sb,
-struct chain_t *p_dir, s32 entry,
-struct dentry_t *p_entry);
-   s32 (*calc_num_entries)(struct uni_name_t *p_uniname);
-
-   u32 (*get_entry_type)(struct dentry_t *p_entry);
-   void(*set_entry_type)(struct dentry_t *p_entry, u32 type);
-   u32 (*get_entry_attr)(struct dentry_t *p_entry);
-   void(*set_entry_attr)(struct dentry_t *p_entry, u32 attr);
-   u8  (*get_entry_flag)(struct dentry_t *p_entry);
-   void(*set_entry_flag)(struct dentry_t *p_entry, u8 flag);
-   u32 (*get_entry_clu0)(struct dentry_t *p_entry);
-   void(*set_entry_clu0)(struct dentry_t *p_entry, u32 clu0);
-   u64 (*get_entry_size)(struct dentry_t *p_entry);
-   void(*set_entry_size)(struct dentry_t *p_entry, u64 size);
-   void(*get_entry_time)(struct dentry_t *p_entry,
- struct timestamp_t *tp, u8 mode);
-   void(*set_entry_time)(struct dentry_t *p_entry,
- struct timestamp_t *tp, u8 mode);
-};
-
 struct fs_info_t {
u32  drv;/* drive ID */
u32  vol_type;   /* volume FAT type */
@@ -597,7 +554,6 @@ struct fs_info_t {
 
u32 dev_ejected;/* block device operation error flag */
 
-   struct fs_func *fs_func;
struct mutex v_mutex;
 
/* FAT cache */
@@ -829,5 +785,40 @@ int exfat_bdev_write(struct super_block *sb, sector_t 
secno,
   struct buffer_head *bh, u32 num_secs, bool sync);
 int exfat_bdev_sync(struct super_block *sb);
 
+/* cluster operation functions */
+s32 exfat_alloc_cluster(struct super_block *sb, s32 num_alloc,
+   struct chain_t *p_chain);
+void exfat_free_cluster(struct super_block *sb, struct chain_t *p_chain,
+   s32 do_relse);
+s32 exfat_count_used_clusters(struct super_block *sb);
+
+/* dir operation functions */
+s32 exfat_find_dir_entry(struct super_block *sb, struct chain_t *p_dir,
+struct uni_name_t *p_uniname, s32 num_entries,
+struct dos_name_t *p_dosname, u32 type);
+void exfat_delete_dir

[PATCH] staging: exfat: remove 'vol_type' variable.

2020-01-29 Thread Tetsuhiro Kohada
remove 'vol_type' variable.

The following issues are described in exfat's TODO.
> clean up the remaining vol_type checks, which are of two types:
> some are ?: operators with magic numbers, and the rest are places
> where we're doing stuff with '.' and '..'.

The vol_type variable is always set to 'EXFAT'.
The variable checks are unnessesary, so remove unused code.

Signed-off-by: Tetsuhiro Kohada 
Reviewed-by: Mori Takahiro 
---
 drivers/staging/exfat/exfat.h   |  1 -
 drivers/staging/exfat/exfat_core.c  | 26 ++---
 drivers/staging/exfat/exfat_super.c | 30 +++--
 3 files changed, 13 insertions(+), 44 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index 4d87360fab35..28d245b10e82 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -518,7 +518,6 @@ struct buf_cache_t {
 
 struct fs_info_t {
u32  drv;/* drive ID */
-   u32  vol_type;   /* volume FAT type */
u32  vol_id; /* volume serial number */
 
u64  num_sectors;/* num of sectors in volume */
diff --git a/drivers/staging/exfat/exfat_core.c 
b/drivers/staging/exfat/exfat_core.c
index 07b460d01334..5a686289a1db 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -1560,11 +1560,7 @@ static s32 search_deleted_or_unused_entry(struct 
super_block *sb,
if (num_empty >= num_entries) {
p_fs->hint_uentry.dir = CLUSTER_32(~0);
p_fs->hint_uentry.entry = -1;
-
-   if (p_fs->vol_type == EXFAT)
-   return dentry - (num_entries - 1);
-   else
-   return dentry;
+   return dentry - (num_entries - 1);
}
}
 
@@ -1914,7 +1910,7 @@ s32 count_dos_name_entries(struct super_block *sb, struct 
chain_t *p_dir,
 
 bool is_dir_empty(struct super_block *sb, struct chain_t *p_dir)
 {
-   int i, count = 0;
+   int i;
s32 dentries_per_clu;
u32 type;
struct chain_t clu;
@@ -1943,15 +1939,7 @@ bool is_dir_empty(struct super_block *sb, struct chain_t 
*p_dir)
 
if (type == TYPE_UNUSED)
return true;
-   if ((type != TYPE_FILE) && (type != TYPE_DIR))
-   continue;
-
-   if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */
-   return false;
-
-   if (p_fs->vol_type == EXFAT)
-   return false;
-   if ((p_dir->dir == p_fs->root_dir) || ((++count) > 2))
+   if ((type == TYPE_FILE) || (type == TYPE_DIR))
return false;
}
 
@@ -2128,7 +2116,6 @@ s32 exfat_mount(struct super_block *sb, struct 
pbr_sector_t *p_pbr)
p_fs->num_clusters = GET32(p_bpb->clu_count) + 2;
/* because the cluster index starts with 2 */
 
-   p_fs->vol_type = EXFAT;
p_fs->vol_id = GET32(p_bpb->vol_serial);
 
p_fs->root_dir = GET32(p_bpb->root_cluster);
@@ -2165,7 +2152,7 @@ s32 create_dir(struct inode *inode, struct chain_t *p_dir,
 
clu.dir = CLUSTER_32(~0);
clu.size = 0;
-   clu.flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01;
+   clu.flags = 0x03;
 
/* (1) allocate a cluster */
ret = exfat_alloc_cluster(sb, 1, &clu);
@@ -2198,7 +2185,7 @@ s32 create_dir(struct inode *inode, struct chain_t *p_dir,
fid->entry = dentry;
 
fid->attr = ATTR_SUBDIR;
-   fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01;
+   fid->flags = 0x03;
fid->size = size;
fid->start_clu = clu.dir;
 
@@ -2215,7 +2202,6 @@ s32 create_file(struct inode *inode, struct chain_t 
*p_dir,
s32 ret, dentry, num_entries;
struct dos_name_t dos_name;
struct super_block *sb = inode->i_sb;
-   struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
 
ret = get_num_entries_and_dos_name(sb, p_dir, p_uniname, &num_entries,
   &dos_name);
@@ -2247,7 +2233,7 @@ s32 create_file(struct inode *inode, struct chain_t 
*p_dir,
fid->entry = dentry;
 
fid->attr = ATTR_ARCHIVE | mode;
-   fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01;
+   fid->flags = 0x03;
fid->size = 0;
fid->start_clu = CLUSTER_32(~0);
 
diff --git a/drivers/staging/exfat/exfat_super.c 
b/drivers/staging/exfat/exfat_super.c
index b81d2a87b82e..775920798

[PATCH v2] staging: exfat: remove 'vol_type' variable.

2020-01-29 Thread Tetsuhiro Kohada
remove 'vol_type' variable.

The following issues are described in exfat's TODO.
> clean up the remaining vol_type checks, which are of two types:
> some are ?: operators with magic numbers, and the rest are places
> where we're doing stuff with '.' and '..'.

The vol_type variable is always set to 'EXFAT'.
The variable checks are unnessesary, so remove unused code.

Signed-off-by: Tetsuhiro Kohada 
Reviewed-by: Mori Takahiro 
Suggested-by: Dan Carpenter 
---
Changes in v2:
- Remove wrong check in exfat_readdir(), as suggested by Dan Carpenter.
- Update comment in exfat_readdir().

 drivers/staging/exfat/exfat.h   |  1 -
 drivers/staging/exfat/exfat_core.c  | 26 +++--
 drivers/staging/exfat/exfat_super.c | 60 ++---
 3 files changed, 27 insertions(+), 60 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index 4d87360fab35..28d245b10e82 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -518,7 +518,6 @@ struct buf_cache_t {
 
 struct fs_info_t {
u32  drv;/* drive ID */
-   u32  vol_type;   /* volume FAT type */
u32  vol_id; /* volume serial number */
 
u64  num_sectors;/* num of sectors in volume */
diff --git a/drivers/staging/exfat/exfat_core.c 
b/drivers/staging/exfat/exfat_core.c
index 07b460d01334..5a686289a1db 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -1560,11 +1560,7 @@ static s32 search_deleted_or_unused_entry(struct 
super_block *sb,
if (num_empty >= num_entries) {
p_fs->hint_uentry.dir = CLUSTER_32(~0);
p_fs->hint_uentry.entry = -1;
-
-   if (p_fs->vol_type == EXFAT)
-   return dentry - (num_entries - 1);
-   else
-   return dentry;
+   return dentry - (num_entries - 1);
}
}
 
@@ -1914,7 +1910,7 @@ s32 count_dos_name_entries(struct super_block *sb, struct 
chain_t *p_dir,
 
 bool is_dir_empty(struct super_block *sb, struct chain_t *p_dir)
 {
-   int i, count = 0;
+   int i;
s32 dentries_per_clu;
u32 type;
struct chain_t clu;
@@ -1943,15 +1939,7 @@ bool is_dir_empty(struct super_block *sb, struct chain_t 
*p_dir)
 
if (type == TYPE_UNUSED)
return true;
-   if ((type != TYPE_FILE) && (type != TYPE_DIR))
-   continue;
-
-   if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */
-   return false;
-
-   if (p_fs->vol_type == EXFAT)
-   return false;
-   if ((p_dir->dir == p_fs->root_dir) || ((++count) > 2))
+   if ((type == TYPE_FILE) || (type == TYPE_DIR))
return false;
}
 
@@ -2128,7 +2116,6 @@ s32 exfat_mount(struct super_block *sb, struct 
pbr_sector_t *p_pbr)
p_fs->num_clusters = GET32(p_bpb->clu_count) + 2;
/* because the cluster index starts with 2 */
 
-   p_fs->vol_type = EXFAT;
p_fs->vol_id = GET32(p_bpb->vol_serial);
 
p_fs->root_dir = GET32(p_bpb->root_cluster);
@@ -2165,7 +2152,7 @@ s32 create_dir(struct inode *inode, struct chain_t *p_dir,
 
clu.dir = CLUSTER_32(~0);
clu.size = 0;
-   clu.flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01;
+   clu.flags = 0x03;
 
/* (1) allocate a cluster */
ret = exfat_alloc_cluster(sb, 1, &clu);
@@ -2198,7 +2185,7 @@ s32 create_dir(struct inode *inode, struct chain_t *p_dir,
fid->entry = dentry;
 
fid->attr = ATTR_SUBDIR;
-   fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01;
+   fid->flags = 0x03;
fid->size = size;
fid->start_clu = clu.dir;
 
@@ -2215,7 +2202,6 @@ s32 create_file(struct inode *inode, struct chain_t 
*p_dir,
s32 ret, dentry, num_entries;
struct dos_name_t dos_name;
struct super_block *sb = inode->i_sb;
-   struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
 
ret = get_num_entries_and_dos_name(sb, p_dir, p_uniname, &num_entries,
   &dos_name);
@@ -2247,7 +2233,7 @@ s32 create_file(struct inode *inode, struct chain_t 
*p_dir,
fid->entry = dentry;
 
fid->attr = ATTR_ARCHIVE | mode;
-   fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01;
+   fid->flags = 0x03;
fid->size = 0;
fid->sta

[PATCH 1/2] staging: exfat: remove DOSNAMEs.

2020-02-03 Thread Tetsuhiro Kohada
remove 'dos_name','ShortName' and related definitions.

'dos_name' and 'ShortName' are definitions before VFAT.
These are never used in exFAT.

Signed-off-by: Tetsuhiro Kohada 
---
 drivers/staging/exfat/exfat.h   | 52 +++--
 drivers/staging/exfat/exfat_core.c  | 47 +-
 drivers/staging/exfat/exfat_super.c | 38 -
 3 files changed, 34 insertions(+), 103 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index 4d87360fab35..62aba0feda12 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -189,8 +189,6 @@ static inline u16 get_row_index(u16 i)
 #define MAX_PATH_DEPTH 15  /* max depth of path name */
 #define MAX_NAME_LENGTH256 /* max len of filename 
including NULL */
 #define MAX_PATH_LENGTH260 /* max len of pathname 
including NULL */
-#define DOS_NAME_LENGTH11  /* DOS filename length 
excluding NULL */
-#define DOS_PATH_LENGTH80  /* DOS pathname length 
excluding NULL */
 
 /* file attributes */
 #define ATTR_NORMAL0x
@@ -210,9 +208,6 @@ static inline u16 get_row_index(u16 i)
 
 #define NUM_UPCASE  2918
 
-#define DOS_CUR_DIR_NAME".  "
-#define DOS_PAR_DIR_NAME".. "
-
 #ifdef __LITTLE_ENDIAN
 #define UNI_CUR_DIR_NAME".\0"
 #define UNI_PAR_DIR_NAME".\0.\0"
@@ -271,10 +266,6 @@ struct file_id_t {
 
 struct dir_entry_t {
char Name[MAX_NAME_LENGTH * MAX_CHARSET_SIZE];
-
-   /* used only for FAT12/16/32, not used for exFAT */
-   char ShortName[DOS_NAME_LENGTH + 2];
-
u32 Attr;
u64 Size;
u32 NumSubdirs;
@@ -391,33 +382,6 @@ struct dentry_t {
u8   dummy[32];
 };
 
-struct dos_dentry_t {
-   u8   name[DOS_NAME_LENGTH];
-   u8   attr;
-   u8   lcase;
-   u8   create_time_ms;
-   u8   create_time[2];
-   u8   create_date[2];
-   u8   access_date[2];
-   u8   start_clu_hi[2];
-   u8   modify_time[2];
-   u8   modify_date[2];
-   u8   start_clu_lo[2];
-   u8   size[4];
-};
-
-/* MS-DOS FAT extended directory entry (32 bytes) */
-struct ext_dentry_t {
-   u8   order;
-   u8   unicode_0_4[10];
-   u8   attr;
-   u8   sysid;
-   u8   checksum;
-   u8   unicode_5_10[12];
-   u8   start_clu[2];
-   u8   unicode_11_12[4];
-};
-
 /* MS-DOS EXFAT file directory entry (32 bytes) */
 struct file_dentry_t {
u8   type;
@@ -492,12 +456,6 @@ struct uentry_t {
struct chain_t clu;
 };
 
-/* DOS name structure */
-struct dos_name_t {
-   u8   name[DOS_NAME_LENGTH];
-   u8   name_case;
-};
-
 /* unicode name structure */
 struct uni_name_t {
u16  name[MAX_NAME_LENGTH];
@@ -736,8 +694,7 @@ struct entry_set_cache_t *get_entry_set_in_dir(struct 
super_block *sb,
   u32 type,
   struct dentry_t **file_ep);
 void release_entry_set(struct entry_set_cache_t *es);
-s32 count_dos_name_entries(struct super_block *sb, struct chain_t *p_dir,
-  u32 type);
+s32 count_entries(struct super_block *sb, struct chain_t *p_dir, u32 type);
 void update_dir_checksum(struct super_block *sb, struct chain_t *p_dir,
 s32 entry);
 void update_dir_checksum_with_entry_set(struct super_block *sb,
@@ -745,9 +702,8 @@ void update_dir_checksum_with_entry_set(struct super_block 
*sb,
 bool is_dir_empty(struct super_block *sb, struct chain_t *p_dir);
 
 /* name conversion functions */
-s32 get_num_entries_and_dos_name(struct super_block *sb, struct chain_t *p_dir,
-struct uni_name_t *p_uniname, s32 *entries,
-struct dos_name_t *p_dosname);
+s32 get_num_entries(struct super_block *sb, struct chain_t *p_dir,
+   struct uni_name_t *p_uniname, s32 *entries);
 u16 calc_checksum_2byte(void *data, s32 len, u16 chksum, s32 type);
 
 /* name resolution functions */
@@ -795,7 +751,7 @@ s32 exfat_count_used_clusters(struct super_block *sb);
 /* dir operation functions */
 s32 exfat_find_dir_entry(struct super_block *sb, struct chain_t *p_dir,
 struct uni_name_t *p_uniname, s32 num_entries,
-struct dos_name_t *p_dosname, u32 type);
+u32 type);
 void exfat_delete_dir_entry(struct super_block *sb, struct chain_t *p_dir,
s32 entry, s32 order, s32 num_entries);
 void exfat_get_uni_name_from_ext_entry(struct super_block *sb,
diff --git a/drivers/staging/exfat/exfat_core.c 
b/drivers/staging/exfat/exfat_core.c
index 07b460d01334..18

[PATCH 2/2] staging: exfat: dedicate count_entries() to sub-dir counting.

2020-02-03 Thread Tetsuhiro Kohada
count_entries() function is only used to count sub-dirs.
Clarify the role and rename to count_dir_entries().

Signed-off-by: Tetsuhiro Kohada 
---
 drivers/staging/exfat/exfat.h   | 2 +-
 drivers/staging/exfat/exfat_core.c  | 8 ++--
 drivers/staging/exfat/exfat_super.c | 4 ++--
 3 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index 62aba0feda12..be0ce8998cce 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -694,7 +694,7 @@ struct entry_set_cache_t *get_entry_set_in_dir(struct 
super_block *sb,
   u32 type,
   struct dentry_t **file_ep);
 void release_entry_set(struct entry_set_cache_t *es);
-s32 count_entries(struct super_block *sb, struct chain_t *p_dir, u32 type);
+s32 count_dir_entries(struct super_block *sb, struct chain_t *p_dir);
 void update_dir_checksum(struct super_block *sb, struct chain_t *p_dir,
 s32 entry);
 void update_dir_checksum_with_entry_set(struct super_block *sb,
diff --git a/drivers/staging/exfat/exfat_core.c 
b/drivers/staging/exfat/exfat_core.c
index 188349eeef5f..a9c86aae688b 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -1854,7 +1854,7 @@ s32 exfat_count_ext_entries(struct super_block *sb, 
struct chain_t *p_dir,
return count;
 }
 
-s32 count_entries(struct super_block *sb, struct chain_t *p_dir, u32 type)
+s32 count_dir_entries(struct super_block *sb, struct chain_t *p_dir)
 {
int i, count = 0;
s32 dentries_per_clu;
@@ -1885,11 +1885,7 @@ s32 count_entries(struct super_block *sb, struct chain_t 
*p_dir, u32 type)
 
if (entry_type == TYPE_UNUSED)
return count;
-   if (!(type & TYPE_CRITICAL_PRI) &&
-   !(type & TYPE_BENIGN_PRI))
-   continue;
-
-   if ((type == TYPE_ALL) || (type == entry_type))
+   if (entry_type == TYPE_DIR)
count++;
}
 
diff --git a/drivers/staging/exfat/exfat_super.c 
b/drivers/staging/exfat/exfat_super.c
index ae666f79ff48..e706fdd667ed 100644
--- a/drivers/staging/exfat/exfat_super.c
+++ b/drivers/staging/exfat/exfat_super.c
@@ -1476,7 +1476,7 @@ static int ffsReadStat(struct inode *inode, struct 
dir_entry_t *info)
p_fs->cluster_size_bits;
}
 
-   count = count_entries(sb, &dir, TYPE_DIR);
+   count = count_dir_entries(sb, &dir);
if (count < 0) {
ret = count; /* propagate error upward */
goto out;
@@ -1543,7 +1543,7 @@ static int ffsReadStat(struct inode *inode, struct 
dir_entry_t *info)
info->Size = (u64)count_num_clusters(sb, &dir) <<
p_fs->cluster_size_bits;
 
-   count = count_entries(sb, &dir, TYPE_DIR);
+   count = count_dir_entries(sb, &dir);
if (count < 0) {
ret = count; /* propagate error upward */
goto out;
-- 
2.25.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 1/2] staging: exfat: remove DOSNAMEs.

2020-02-13 Thread Tetsuhiro Kohada
remove 'dos_name','ShortName' and related definitions.

'dos_name' and 'ShortName' are definitions before VFAT.
These are never used in exFAT.

Signed-off-by: Tetsuhiro Kohada 
---
Changes in v2:
- Rebase to linux-next-next-20200213.

 drivers/staging/exfat/exfat.h   | 52 +++--
 drivers/staging/exfat/exfat_core.c  | 47 +-
 drivers/staging/exfat/exfat_super.c | 38 -
 3 files changed, 34 insertions(+), 103 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index e340b36ac519..79eb20068dce 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -189,8 +189,6 @@ static inline u16 get_row_index(u16 i)
 #define MAX_PATH_DEPTH 15  /* max depth of path name */
 #define MAX_NAME_LENGTH256 /* max len of filename 
including NULL */
 #define MAX_PATH_LENGTH260 /* max len of pathname 
including NULL */
-#define DOS_NAME_LENGTH11  /* DOS filename length 
excluding NULL */
-#define DOS_PATH_LENGTH80  /* DOS pathname length 
excluding NULL */
 
 /* file attributes */
 #define ATTR_NORMAL0x
@@ -210,9 +208,6 @@ static inline u16 get_row_index(u16 i)
 
 #define NUM_UPCASE  2918
 
-#define DOS_CUR_DIR_NAME".  "
-#define DOS_PAR_DIR_NAME".. "
-
 #ifdef __LITTLE_ENDIAN
 #define UNI_CUR_DIR_NAME".\0"
 #define UNI_PAR_DIR_NAME".\0.\0"
@@ -261,10 +256,6 @@ struct file_id_t {
 
 struct dir_entry_t {
char Name[MAX_NAME_LENGTH * MAX_CHARSET_SIZE];
-
-   /* used only for FAT12/16/32, not used for exFAT */
-   char ShortName[DOS_NAME_LENGTH + 2];
-
u32 Attr;
u64 Size;
u32 NumSubdirs;
@@ -381,33 +372,6 @@ struct dentry_t {
u8   dummy[32];
 };
 
-struct dos_dentry_t {
-   u8   name[DOS_NAME_LENGTH];
-   u8   attr;
-   u8   lcase;
-   u8   create_time_ms;
-   u8   create_time[2];
-   u8   create_date[2];
-   u8   access_date[2];
-   u8   start_clu_hi[2];
-   u8   modify_time[2];
-   u8   modify_date[2];
-   u8   start_clu_lo[2];
-   u8   size[4];
-};
-
-/* MS-DOS FAT extended directory entry (32 bytes) */
-struct ext_dentry_t {
-   u8   order;
-   u8   unicode_0_4[10];
-   u8   attr;
-   u8   sysid;
-   u8   checksum;
-   u8   unicode_5_10[12];
-   u8   start_clu[2];
-   u8   unicode_11_12[4];
-};
-
 /* MS-DOS EXFAT file directory entry (32 bytes) */
 struct file_dentry_t {
u8   type;
@@ -482,12 +446,6 @@ struct uentry_t {
struct chain_t clu;
 };
 
-/* DOS name structure */
-struct dos_name_t {
-   u8   name[DOS_NAME_LENGTH];
-   u8   name_case;
-};
-
 /* unicode name structure */
 struct uni_name_t {
u16  name[MAX_NAME_LENGTH];
@@ -725,8 +683,7 @@ struct entry_set_cache_t *get_entry_set_in_dir(struct 
super_block *sb,
   u32 type,
   struct dentry_t **file_ep);
 void release_entry_set(struct entry_set_cache_t *es);
-s32 count_dos_name_entries(struct super_block *sb, struct chain_t *p_dir,
-  u32 type);
+s32 count_entries(struct super_block *sb, struct chain_t *p_dir, u32 type);
 void update_dir_checksum(struct super_block *sb, struct chain_t *p_dir,
 s32 entry);
 void update_dir_checksum_with_entry_set(struct super_block *sb,
@@ -734,9 +691,8 @@ void update_dir_checksum_with_entry_set(struct super_block 
*sb,
 bool is_dir_empty(struct super_block *sb, struct chain_t *p_dir);
 
 /* name conversion functions */
-s32 get_num_entries_and_dos_name(struct super_block *sb, struct chain_t *p_dir,
-struct uni_name_t *p_uniname, s32 *entries,
-struct dos_name_t *p_dosname);
+s32 get_num_entries(struct super_block *sb, struct chain_t *p_dir,
+   struct uni_name_t *p_uniname, s32 *entries);
 u16 calc_checksum_2byte(void *data, s32 len, u16 chksum, s32 type);
 
 /* name resolution functions */
@@ -784,7 +740,7 @@ s32 exfat_count_used_clusters(struct super_block *sb);
 /* dir operation functions */
 s32 exfat_find_dir_entry(struct super_block *sb, struct chain_t *p_dir,
 struct uni_name_t *p_uniname, s32 num_entries,
-struct dos_name_t *p_dosname, u32 type);
+u32 type);
 void exfat_delete_dir_entry(struct super_block *sb, struct chain_t *p_dir,
s32 entry, s32 order, s32 num_entries);
 void exfat_get_uni_name_from_ext_entry(struct super_block *sb,
diff --git a/drivers/staging/exfat/exfat_core.c 
b/drivers/

[PATCH v2 2/2] staging: exfat: dedicate count_entries() to sub-dir counting.

2020-02-13 Thread Tetsuhiro Kohada
count_entries() function is only used to count sub-dirs.
Clarify the role and rename to count_dir_entries().

Signed-off-by: Tetsuhiro Kohada 
---
Changes in v2:
- Rebase to linux-next-next-20200213.

 drivers/staging/exfat/exfat.h   | 2 +-
 drivers/staging/exfat/exfat_core.c  | 8 ++--
 drivers/staging/exfat/exfat_super.c | 4 ++--
 3 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index 79eb20068dce..36ce23951be0 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -683,7 +683,7 @@ struct entry_set_cache_t *get_entry_set_in_dir(struct 
super_block *sb,
   u32 type,
   struct dentry_t **file_ep);
 void release_entry_set(struct entry_set_cache_t *es);
-s32 count_entries(struct super_block *sb, struct chain_t *p_dir, u32 type);
+s32 count_dir_entries(struct super_block *sb, struct chain_t *p_dir);
 void update_dir_checksum(struct super_block *sb, struct chain_t *p_dir,
 s32 entry);
 void update_dir_checksum_with_entry_set(struct super_block *sb,
diff --git a/drivers/staging/exfat/exfat_core.c 
b/drivers/staging/exfat/exfat_core.c
index 94a10c5984ac..7308e50c0aaf 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -1850,7 +1850,7 @@ s32 exfat_count_ext_entries(struct super_block *sb, 
struct chain_t *p_dir,
return count;
 }
 
-s32 count_entries(struct super_block *sb, struct chain_t *p_dir, u32 type)
+s32 count_dir_entries(struct super_block *sb, struct chain_t *p_dir)
 {
int i, count = 0;
s32 dentries_per_clu;
@@ -1881,11 +1881,7 @@ s32 count_entries(struct super_block *sb, struct chain_t 
*p_dir, u32 type)
 
if (entry_type == TYPE_UNUSED)
return count;
-   if (!(type & TYPE_CRITICAL_PRI) &&
-   !(type & TYPE_BENIGN_PRI))
-   continue;
-
-   if ((type == TYPE_ALL) || (type == entry_type))
+   if (entry_type == TYPE_DIR)
count++;
}
 
diff --git a/drivers/staging/exfat/exfat_super.c 
b/drivers/staging/exfat/exfat_super.c
index ce9eb75258f8..b80a2c886d61 100644
--- a/drivers/staging/exfat/exfat_super.c
+++ b/drivers/staging/exfat/exfat_super.c
@@ -1468,7 +1468,7 @@ static int ffsReadStat(struct inode *inode, struct 
dir_entry_t *info)
p_fs->cluster_size_bits;
}
 
-   count = count_entries(sb, &dir, TYPE_DIR);
+   count = count_dir_entries(sb, &dir);
if (count < 0) {
ret = count; /* propagate error upward */
goto out;
@@ -1535,7 +1535,7 @@ static int ffsReadStat(struct inode *inode, struct 
dir_entry_t *info)
info->Size = (u64)count_num_clusters(sb, &dir) <<
p_fs->cluster_size_bits;
 
-   count = count_entries(sb, &dir, TYPE_DIR);
+   count = count_dir_entries(sb, &dir);
if (count < 0) {
ret = count; /* propagate error upward */
goto out;
-- 
2.25.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 1/2] staging: exfat: remove DOSNAMEs.

2020-02-16 Thread Tetsuhiro Kohada
remove 'dos_name','short_name' and related definitions.

'dos_name' and 'short_name' are definitions before VFAT.
These are never used in exFAT.

Signed-off-by: Tetsuhiro Kohada 
---
Changes in v3:
- Rebase to staging-next.

Changes in v2:
- Rebase to linux-next-next-20200213.

 drivers/staging/exfat/exfat.h   | 52 +++--
 drivers/staging/exfat/exfat_core.c  | 47 +-
 drivers/staging/exfat/exfat_super.c | 37 
 3 files changed, 33 insertions(+), 103 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index 05e21839b349..ca9d3b5a3076 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -189,8 +189,6 @@ static inline u16 get_row_index(u16 i)
 #define MAX_PATH_DEPTH 15  /* max depth of path name */
 #define MAX_NAME_LENGTH256 /* max len of filename 
including NULL */
 #define MAX_PATH_LENGTH260 /* max len of pathname 
including NULL */
-#define DOS_NAME_LENGTH11  /* DOS filename length 
excluding NULL */
-#define DOS_PATH_LENGTH80  /* DOS pathname length 
excluding NULL */
 
 /* file attributes */
 #define ATTR_NORMAL0x
@@ -210,9 +208,6 @@ static inline u16 get_row_index(u16 i)
 
 #define NUM_UPCASE  2918
 
-#define DOS_CUR_DIR_NAME".  "
-#define DOS_PAR_DIR_NAME".. "
-
 #ifdef __LITTLE_ENDIAN
 #define UNI_CUR_DIR_NAME".\0"
 #define UNI_PAR_DIR_NAME".\0.\0"
@@ -261,10 +256,6 @@ struct file_id_t {
 
 struct dir_entry_t {
char name[MAX_NAME_LENGTH * MAX_CHARSET_SIZE];
-
-   /* used only for FAT12/16/32, not used for exFAT */
-   char short_name[DOS_NAME_LENGTH + 2];
-
u32 attr;
u64 Size;
u32 num_subdirs;
@@ -381,33 +372,6 @@ struct dentry_t {
u8   dummy[32];
 };
 
-struct dos_dentry_t {
-   u8   name[DOS_NAME_LENGTH];
-   u8   attr;
-   u8   lcase;
-   u8   create_time_ms;
-   u8   create_time[2];
-   u8   create_date[2];
-   u8   access_date[2];
-   u8   start_clu_hi[2];
-   u8   modify_time[2];
-   u8   modify_date[2];
-   u8   start_clu_lo[2];
-   u8   size[4];
-};
-
-/* MS-DOS FAT extended directory entry (32 bytes) */
-struct ext_dentry_t {
-   u8   order;
-   u8   unicode_0_4[10];
-   u8   attr;
-   u8   sysid;
-   u8   checksum;
-   u8   unicode_5_10[12];
-   u8   start_clu[2];
-   u8   unicode_11_12[4];
-};
-
 /* MS-DOS EXFAT file directory entry (32 bytes) */
 struct file_dentry_t {
u8   type;
@@ -482,12 +446,6 @@ struct uentry_t {
struct chain_t clu;
 };
 
-/* DOS name structure */
-struct dos_name_t {
-   u8   name[DOS_NAME_LENGTH];
-   u8   name_case;
-};
-
 /* unicode name structure */
 struct uni_name_t {
u16  name[MAX_NAME_LENGTH];
@@ -725,8 +683,7 @@ struct entry_set_cache_t *get_entry_set_in_dir(struct 
super_block *sb,
   u32 type,
   struct dentry_t **file_ep);
 void release_entry_set(struct entry_set_cache_t *es);
-s32 count_dos_name_entries(struct super_block *sb, struct chain_t *p_dir,
-  u32 type);
+s32 count_entries(struct super_block *sb, struct chain_t *p_dir, u32 type);
 void update_dir_checksum(struct super_block *sb, struct chain_t *p_dir,
 s32 entry);
 void update_dir_checksum_with_entry_set(struct super_block *sb,
@@ -734,9 +691,8 @@ void update_dir_checksum_with_entry_set(struct super_block 
*sb,
 bool is_dir_empty(struct super_block *sb, struct chain_t *p_dir);
 
 /* name conversion functions */
-s32 get_num_entries_and_dos_name(struct super_block *sb, struct chain_t *p_dir,
-struct uni_name_t *p_uniname, s32 *entries,
-struct dos_name_t *p_dosname);
+s32 get_num_entries(struct super_block *sb, struct chain_t *p_dir,
+   struct uni_name_t *p_uniname, s32 *entries);
 u16 calc_checksum_2byte(void *data, s32 len, u16 chksum, s32 type);
 
 /* name resolution functions */
@@ -784,7 +740,7 @@ s32 exfat_count_used_clusters(struct super_block *sb);
 /* dir operation functions */
 s32 exfat_find_dir_entry(struct super_block *sb, struct chain_t *p_dir,
 struct uni_name_t *p_uniname, s32 num_entries,
-struct dos_name_t *p_dosname, u32 type);
+u32 type);
 void exfat_delete_dir_entry(struct super_block *sb, struct chain_t *p_dir,
s32 entry, s32 order, s32 num_entries);
 void exfat_get_uni_name_from_ext_entry(struct super_block *sb,
diff --git 

[PATCH v3 2/2] staging: exfat: dedicate count_entries() to sub-dir counting.

2020-02-16 Thread Tetsuhiro Kohada
count_entries() function is only used to count sub-dirs.
Clarify the role and rename to count_dir_entries().

Signed-off-by: Tetsuhiro Kohada 
---
Changes in v3:
- Rebase to staging-next.

Changes in v2:
- Rebase to linux-next-next-20200213.

 drivers/staging/exfat/exfat.h   | 2 +-
 drivers/staging/exfat/exfat_core.c  | 8 ++--
 drivers/staging/exfat/exfat_super.c | 4 ++--
 3 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index ca9d3b5a3076..c4ef6c2de329 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -683,7 +683,7 @@ struct entry_set_cache_t *get_entry_set_in_dir(struct 
super_block *sb,
   u32 type,
   struct dentry_t **file_ep);
 void release_entry_set(struct entry_set_cache_t *es);
-s32 count_entries(struct super_block *sb, struct chain_t *p_dir, u32 type);
+s32 count_dir_entries(struct super_block *sb, struct chain_t *p_dir);
 void update_dir_checksum(struct super_block *sb, struct chain_t *p_dir,
 s32 entry);
 void update_dir_checksum_with_entry_set(struct super_block *sb,
diff --git a/drivers/staging/exfat/exfat_core.c 
b/drivers/staging/exfat/exfat_core.c
index 94a10c5984ac..7308e50c0aaf 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -1850,7 +1850,7 @@ s32 exfat_count_ext_entries(struct super_block *sb, 
struct chain_t *p_dir,
return count;
 }
 
-s32 count_entries(struct super_block *sb, struct chain_t *p_dir, u32 type)
+s32 count_dir_entries(struct super_block *sb, struct chain_t *p_dir)
 {
int i, count = 0;
s32 dentries_per_clu;
@@ -1881,11 +1881,7 @@ s32 count_entries(struct super_block *sb, struct chain_t 
*p_dir, u32 type)
 
if (entry_type == TYPE_UNUSED)
return count;
-   if (!(type & TYPE_CRITICAL_PRI) &&
-   !(type & TYPE_BENIGN_PRI))
-   continue;
-
-   if ((type == TYPE_ALL) || (type == entry_type))
+   if (entry_type == TYPE_DIR)
count++;
}
 
diff --git a/drivers/staging/exfat/exfat_super.c 
b/drivers/staging/exfat/exfat_super.c
index f31f771a3dc0..b398114c2604 100644
--- a/drivers/staging/exfat/exfat_super.c
+++ b/drivers/staging/exfat/exfat_super.c
@@ -1468,7 +1468,7 @@ static int ffsReadStat(struct inode *inode, struct 
dir_entry_t *info)
p_fs->cluster_size_bits;
}
 
-   count = count_entries(sb, &dir, TYPE_DIR);
+   count = count_dir_entries(sb, &dir);
if (count < 0) {
ret = count; /* propagate error upward */
goto out;
@@ -1535,7 +1535,7 @@ static int ffsReadStat(struct inode *inode, struct 
dir_entry_t *info)
info->Size = (u64)count_num_clusters(sb, &dir) <<
p_fs->cluster_size_bits;
 
-   count = count_entries(sb, &dir, TYPE_DIR);
+   count = count_dir_entries(sb, &dir);
if (count < 0) {
ret = count; /* propagate error upward */
goto out;
-- 
2.25.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[RFC PATCH] staging: exfat: remove symlink feature.

2020-02-18 Thread Tetsuhiro Kohada
Remove symlink feature completely.

Becouse
-Uses reserved areas(defined in the Microsoft exfat specification), causing 
future incompatibilities.
-Not described in Microsoft exfat specifications or SD standards.
-For REMOVABLE media, causes incompatibility with other implementations.
-Not supported by other major exfat drivers.
-Not implemented symlink feature in linux FAT/VFAT.

Remove this feature completely because of serious media compatibility issues.
(Can't enable even with CONFIG)

If you have any questions about this patch, please let me know.

Reviewed-by: Takahiro Mori 
Signed-off-by: Tetsuhiro Kohada 
---
 drivers/staging/exfat/exfat_super.c | 450 
 1 file changed, 450 deletions(-)

diff --git a/drivers/staging/exfat/exfat_super.c 
b/drivers/staging/exfat/exfat_super.c
index b398114c2604..c7bc07e91c45 100644
--- a/drivers/staging/exfat/exfat_super.c
+++ b/drivers/staging/exfat/exfat_super.c
@@ -660,375 +660,6 @@ static int ffsCreateFile(struct inode *inode, char *path, 
u8 mode,
return ret;
 }
 
-static int ffsReadFile(struct inode *inode, struct file_id_t *fid, void 
*buffer,
-  u64 count, u64 *rcount)
-{
-   s32 offset, sec_offset, clu_offset;
-   u32 clu;
-   int ret = 0;
-   sector_t LogSector;
-   u64 oneblkread, read_bytes;
-   struct buffer_head *tmp_bh = NULL;
-   struct super_block *sb = inode->i_sb;
-   struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
-   struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
-
-   /* check the validity of the given file id */
-   if (!fid)
-   return -EINVAL;
-
-   /* check the validity of pointer parameters */
-   if (!buffer)
-   return -EINVAL;
-
-   /* acquire the lock for file system critical section */
-   mutex_lock(&p_fs->v_mutex);
-
-   /* check if the given file ID is opened */
-   if (fid->type != TYPE_FILE) {
-   ret = -EPERM;
-   goto out;
-   }
-
-   if (fid->rwoffset > fid->size)
-   fid->rwoffset = fid->size;
-
-   if (count > (fid->size - fid->rwoffset))
-   count = fid->size - fid->rwoffset;
-
-   if (count == 0) {
-   if (rcount)
-   *rcount = 0;
-   ret = 0;
-   goto out;
-   }
-
-   read_bytes = 0;
-
-   while (count > 0) {
-   clu_offset = (s32)(fid->rwoffset >> p_fs->cluster_size_bits);
-   clu = fid->start_clu;
-
-   if (fid->flags == 0x03) {
-   clu += clu_offset;
-   } else {
-   /* hint information */
-   if ((clu_offset > 0) && (fid->hint_last_off > 0) &&
-   (clu_offset >= fid->hint_last_off)) {
-   clu_offset -= fid->hint_last_off;
-   clu = fid->hint_last_clu;
-   }
-
-   while (clu_offset > 0) {
-   /* clu = exfat_fat_read(sb, clu); */
-   if (exfat_fat_read(sb, clu, &clu) == -1) {
-   ret = -EIO;
-   goto out;
-   }
-
-   clu_offset--;
-   }
-   }
-
-   /* hint information */
-   fid->hint_last_off = (s32)(fid->rwoffset >>
-  p_fs->cluster_size_bits);
-   fid->hint_last_clu = clu;
-
-   /* byte offset in cluster */
-   offset = (s32)(fid->rwoffset & (p_fs->cluster_size - 1));
-
-   /* sector offset in cluster */
-   sec_offset = offset >> p_bd->sector_size_bits;
-
-   /* byte offset in sector */
-   offset &= p_bd->sector_size_mask;
-
-   LogSector = START_SECTOR(clu) + sec_offset;
-
-   oneblkread = (u64)(p_bd->sector_size - offset);
-   if (oneblkread > count)
-   oneblkread = count;
-
-   if ((offset == 0) && (oneblkread == p_bd->sector_size)) {
-   if (sector_read(sb, LogSector, &tmp_bh, 1) !=
-   0)
-   goto err_out;
-   memcpy((char *)buffer + read_bytes,
-  (char *)tmp_bh->b_data, (s32)oneblkread);
-   } else {
-   if (sector_read(sb, LogSector, &tmp_bh, 1) !=
-   0)
-   goto err_out;
-   memcpy((char *)buffer + read_bytes,
-  (char *)t

[PATCH] staging: exfat: remove symlink feature : Additional patch

2020-02-25 Thread Tetsuhiro Kohada
Completely remove symlink codes and definitions.
In the previous patch, it was not completely removed.

Signed-off-by: Tetsuhiro Kohada 
---
 drivers/staging/exfat/exfat.h   |  3 ---
 drivers/staging/exfat/exfat_core.c  |  3 ---
 drivers/staging/exfat/exfat_super.c | 27 ---
 3 files changed, 33 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index 4a0a481fe010..cd3479fc78ba 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -63,7 +63,6 @@
 #define TYPE_VOLUME0x0103
 #define TYPE_DIR   0x0104
 #define TYPE_FILE  0x011F
-#define TYPE_SYMLINK   0x015F
 #define TYPE_CRITICAL_SEC  0x0200
 #define TYPE_STREAM0x0201
 #define TYPE_EXTEND0x0202
@@ -198,13 +197,11 @@ static inline u16 get_row_index(u16 i)
 #define ATTR_VOLUME0x0008
 #define ATTR_SUBDIR0x0010
 #define ATTR_ARCHIVE   0x0020
-#define ATTR_SYMLINK   0x0040
 #define ATTR_EXTEND0x000F
 #define ATTR_RWMASK0x007E
 
 /* file creation modes */
 #define FM_REGULAR  0x00
-#define FM_SYMLINK  0x40
 
 #define NUM_UPCASE  2918
 
diff --git a/drivers/staging/exfat/exfat_core.c 
b/drivers/staging/exfat/exfat_core.c
index d30dc050411e..941094b08dd9 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -844,9 +844,6 @@ static void exfat_set_entry_type(struct dentry_t *p_entry, 
u32 type)
} else if (type == TYPE_FILE) {
ep->type = 0x85;
SET16_A(ep->attr, ATTR_ARCHIVE);
-   } else if (type == TYPE_SYMLINK) {
-   ep->type = 0x85;
-   SET16_A(ep->attr, ATTR_ARCHIVE | ATTR_SYMLINK);
}
 }
 
diff --git a/drivers/staging/exfat/exfat_super.c 
b/drivers/staging/exfat/exfat_super.c
index c7bc07e91c45..6f3b72eb999d 100644
--- a/drivers/staging/exfat/exfat_super.c
+++ b/drivers/staging/exfat/exfat_super.c
@@ -320,8 +320,6 @@ static inline mode_t exfat_make_mode(struct exfat_sb_info 
*sbi, u32 attr,
 
if (attr & ATTR_SUBDIR)
return (mode & ~sbi->options.fs_dmask) | S_IFDIR;
-   else if (attr & ATTR_SYMLINK)
-   return (mode & ~sbi->options.fs_dmask) | S_IFLNK;
else
return (mode & ~sbi->options.fs_fmask) | S_IFREG;
 }
@@ -2399,24 +2397,6 @@ static const struct inode_operations 
exfat_dir_inode_operations = {
 /*==*/
 /*  File Operations */
 /*==*/
-static const char *exfat_get_link(struct dentry *dentry, struct inode *inode,
- struct delayed_call *done)
-{
-   struct exfat_inode_info *ei = EXFAT_I(inode);
-
-   if (ei->target) {
-   char *cookie = ei->target;
-
-   if (cookie)
-   return (char *)(ei->target);
-   }
-   return NULL;
-}
-
-static const struct inode_operations exfat_symlink_inode_operations = {
-   .get_link = exfat_get_link,
-};
-
 static int exfat_file_release(struct inode *inode, struct file *filp)
 {
struct super_block *sb = inode->i_sb;
@@ -2688,13 +2668,6 @@ static int exfat_fill_inode(struct inode *inode, struct 
file_id_t *fid)
i_size_write(inode, info.Size);
EXFAT_I(inode)->mmu_private = i_size_read(inode);
set_nlink(inode, info.num_subdirs);
-   } else if (info.attr & ATTR_SYMLINK) { /* symbolic link */
-   inode->i_generation |= 1;
-   inode->i_mode = exfat_make_mode(sbi, info.attr, 0777);
-   inode->i_op = &exfat_symlink_inode_operations;
-
-   i_size_write(inode, info.Size);
-   EXFAT_I(inode)->mmu_private = i_size_read(inode);
} else { /* regular file */
inode->i_generation |= 1;
inode->i_mode = exfat_make_mode(sbi, info.attr, 0777);
-- 
2.25.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3] staging: exfat: remove symlink feature

2020-02-26 Thread Tetsuhiro Kohada
Completely remove symlink codes and definitions.
In the previous patch, it was not completely removed.

Reviewed-by: Takahiro Mori 
Signed-off-by: Tetsuhiro Kohada 
---
Changes in v3:
- fixed subject line
Changes in v2:
- previous patch didn't completely remove it

 drivers/staging/exfat/exfat.h   |  3 ---
 drivers/staging/exfat/exfat_core.c  |  3 ---
 drivers/staging/exfat/exfat_super.c | 27 ---
 3 files changed, 33 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index 4a0a481fe010..cd3479fc78ba 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -63,7 +63,6 @@
 #define TYPE_VOLUME0x0103
 #define TYPE_DIR   0x0104
 #define TYPE_FILE  0x011F
-#define TYPE_SYMLINK   0x015F
 #define TYPE_CRITICAL_SEC  0x0200
 #define TYPE_STREAM0x0201
 #define TYPE_EXTEND0x0202
@@ -198,13 +197,11 @@ static inline u16 get_row_index(u16 i)
 #define ATTR_VOLUME0x0008
 #define ATTR_SUBDIR0x0010
 #define ATTR_ARCHIVE   0x0020
-#define ATTR_SYMLINK   0x0040
 #define ATTR_EXTEND0x000F
 #define ATTR_RWMASK0x007E
 
 /* file creation modes */
 #define FM_REGULAR  0x00
-#define FM_SYMLINK  0x40
 
 #define NUM_UPCASE  2918
 
diff --git a/drivers/staging/exfat/exfat_core.c 
b/drivers/staging/exfat/exfat_core.c
index d30dc050411e..941094b08dd9 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -844,9 +844,6 @@ static void exfat_set_entry_type(struct dentry_t *p_entry, 
u32 type)
} else if (type == TYPE_FILE) {
ep->type = 0x85;
SET16_A(ep->attr, ATTR_ARCHIVE);
-   } else if (type == TYPE_SYMLINK) {
-   ep->type = 0x85;
-   SET16_A(ep->attr, ATTR_ARCHIVE | ATTR_SYMLINK);
}
 }
 
diff --git a/drivers/staging/exfat/exfat_super.c 
b/drivers/staging/exfat/exfat_super.c
index c7bc07e91c45..6f3b72eb999d 100644
--- a/drivers/staging/exfat/exfat_super.c
+++ b/drivers/staging/exfat/exfat_super.c
@@ -320,8 +320,6 @@ static inline mode_t exfat_make_mode(struct exfat_sb_info 
*sbi, u32 attr,
 
if (attr & ATTR_SUBDIR)
return (mode & ~sbi->options.fs_dmask) | S_IFDIR;
-   else if (attr & ATTR_SYMLINK)
-   return (mode & ~sbi->options.fs_dmask) | S_IFLNK;
else
return (mode & ~sbi->options.fs_fmask) | S_IFREG;
 }
@@ -2399,24 +2397,6 @@ static const struct inode_operations 
exfat_dir_inode_operations = {
 /*==*/
 /*  File Operations */
 /*==*/
-static const char *exfat_get_link(struct dentry *dentry, struct inode *inode,
- struct delayed_call *done)
-{
-   struct exfat_inode_info *ei = EXFAT_I(inode);
-
-   if (ei->target) {
-   char *cookie = ei->target;
-
-   if (cookie)
-   return (char *)(ei->target);
-   }
-   return NULL;
-}
-
-static const struct inode_operations exfat_symlink_inode_operations = {
-   .get_link = exfat_get_link,
-};
-
 static int exfat_file_release(struct inode *inode, struct file *filp)
 {
struct super_block *sb = inode->i_sb;
@@ -2688,13 +2668,6 @@ static int exfat_fill_inode(struct inode *inode, struct 
file_id_t *fid)
i_size_write(inode, info.Size);
EXFAT_I(inode)->mmu_private = i_size_read(inode);
set_nlink(inode, info.num_subdirs);
-   } else if (info.attr & ATTR_SYMLINK) { /* symbolic link */
-   inode->i_generation |= 1;
-   inode->i_mode = exfat_make_mode(sbi, info.attr, 0777);
-   inode->i_op = &exfat_symlink_inode_operations;
-
-   i_size_write(inode, info.Size);
-   EXFAT_I(inode)->mmu_private = i_size_read(inode);
} else { /* regular file */
inode->i_generation |= 1;
inode->i_mode = exfat_make_mode(sbi, info.attr, 0777);
-- 
2.25.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: exfat: rename buf_cache_t's 'flag' to 'locked'

2020-02-27 Thread Tetsuhiro Kohada
buf_cache_t.flag is used only for lock.
Change the variable name from 'flag' to 'locked' and remove unused definitions.

Reviewed-by: Takahiro Mori 
Signed-off-by: Tetsuhiro Kohada 
---
 drivers/staging/exfat/exfat.h   |  2 +-
 drivers/staging/exfat/exfat_cache.c | 27 ---
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index cd3479fc78ba..f588538c67a8 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -457,7 +457,7 @@ struct buf_cache_t {
struct buf_cache_t *hash_prev;
s32drv;
sector_t  sec;
-   u32   flag;
+   bool  locked;
struct buffer_head   *buf_bh;
 };
 
diff --git a/drivers/staging/exfat/exfat_cache.c 
b/drivers/staging/exfat/exfat_cache.c
index 87d019972050..b15203d4e0ae 100644
--- a/drivers/staging/exfat/exfat_cache.c
+++ b/drivers/staging/exfat/exfat_cache.c
@@ -8,9 +8,6 @@
 #include 
 #include "exfat.h"
 
-#define LOCKBIT0x01
-#define DIRTYBIT   0x02
-
 /* Local variables */
 static DEFINE_MUTEX(f_mutex);
 static DEFINE_MUTEX(b_mutex);
@@ -141,7 +138,7 @@ void exfat_buf_init(struct super_block *sb)
for (i = 0; i < FAT_CACHE_SIZE; i++) {
p_fs->FAT_cache_array[i].drv = -1;
p_fs->FAT_cache_array[i].sec = ~0;
-   p_fs->FAT_cache_array[i].flag = 0;
+   p_fs->FAT_cache_array[i].locked = false;
p_fs->FAT_cache_array[i].buf_bh = NULL;
p_fs->FAT_cache_array[i].prev = NULL;
p_fs->FAT_cache_array[i].next = NULL;
@@ -155,7 +152,7 @@ void exfat_buf_init(struct super_block *sb)
for (i = 0; i < BUF_CACHE_SIZE; i++) {
p_fs->buf_cache_array[i].drv = -1;
p_fs->buf_cache_array[i].sec = ~0;
-   p_fs->buf_cache_array[i].flag = 0;
+   p_fs->buf_cache_array[i].locked = false;
p_fs->buf_cache_array[i].buf_bh = NULL;
p_fs->buf_cache_array[i].prev = NULL;
p_fs->buf_cache_array[i].next = NULL;
@@ -289,7 +286,7 @@ u8 *exfat_fat_getblk(struct super_block *sb, sector_t sec)
 
bp->drv = p_fs->drv;
bp->sec = sec;
-   bp->flag = 0;
+   bp->locked = false;
 
FAT_cache_insert_hash(sb, bp);
 
@@ -297,7 +294,7 @@ u8 *exfat_fat_getblk(struct super_block *sb, sector_t sec)
FAT_cache_remove_hash(bp);
bp->drv = -1;
bp->sec = ~0;
-   bp->flag = 0;
+   bp->locked = false;
bp->buf_bh = NULL;
 
move_to_lru(bp, &p_fs->FAT_cache_lru_list);
@@ -328,7 +325,7 @@ void exfat_fat_release_all(struct super_block *sb)
if (bp->drv == p_fs->drv) {
bp->drv = -1;
bp->sec = ~0;
-   bp->flag = 0;
+   bp->locked = false;
 
if (bp->buf_bh) {
__brelse(bp->buf_bh);
@@ -366,7 +363,7 @@ static struct buf_cache_t *buf_cache_get(struct super_block 
*sb, sector_t sec)
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
 
bp = p_fs->buf_cache_lru_list.prev;
-   while (bp->flag & LOCKBIT)
+   while (bp->locked)
bp = bp->prev;
 
move_to_mru(bp, &p_fs->buf_cache_lru_list);
@@ -390,7 +387,7 @@ static u8 *__exfat_buf_getblk(struct super_block *sb, 
sector_t sec)
 
bp->drv = p_fs->drv;
bp->sec = sec;
-   bp->flag = 0;
+   bp->locked = false;
 
buf_cache_insert_hash(sb, bp);
 
@@ -398,7 +395,7 @@ static u8 *__exfat_buf_getblk(struct super_block *sb, 
sector_t sec)
buf_cache_remove_hash(bp);
bp->drv = -1;
bp->sec = ~0;
-   bp->flag = 0;
+   bp->locked = false;
bp->buf_bh = NULL;
 
move_to_lru(bp, &p_fs->buf_cache_lru_list);
@@ -443,7 +440,7 @@ void exfat_buf_lock(struct super_block *sb, sector_t sec)
 
bp = buf_cache_find(sb, sec);
if (likely(bp))
-   bp->flag |= LOCKBIT;
+   bp->locked = true;
 
WARN(!bp, "[EXFAT] failed to find buffer_cache(sector:%llu).\n",
 (unsigned long long)sec);
@@ -459,7 +456,7 @@ void exfat_buf_unlock(struct super_block *sb, sector_t sec)
 
bp = buf_cache_find(sb, sec);
if (likely(bp))
-   bp->flag &= ~(LOCKBIT);
+   bp->locked = false;
 
WARN(!bp, "[EXFAT] failed to find buffer_cache(sector:%llu).\n",
 (unsigned long long)sec);
@@ -478,7 +475,7 @@ voi

[PATCH] staging: exfat: remove 'file creation modes'

2020-02-28 Thread Tetsuhiro Kohada
The mode parameter in ffsCreateFile() and create_file() is redundant.
Remove it and definition.

Signed-off-by: Tetsuhiro Kohada 
---
 drivers/staging/exfat/exfat.h   | 5 +
 drivers/staging/exfat/exfat_core.c  | 6 +++---
 drivers/staging/exfat/exfat_super.c | 7 +++
 3 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index f588538c67a8..c863d7566b57 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -200,9 +200,6 @@ static inline u16 get_row_index(u16 i)
 #define ATTR_EXTEND0x000F
 #define ATTR_RWMASK0x007E
 
-/* file creation modes */
-#define FM_REGULAR  0x00
-
 #define NUM_UPCASE  2918
 
 #ifdef __LITTLE_ENDIAN
@@ -698,7 +695,7 @@ s32 exfat_mount(struct super_block *sb, struct pbr_sector_t 
*p_pbr);
 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,
-   struct uni_name_t *p_uniname, u8 mode, struct file_id_t *fid);
+   struct uni_name_t *p_uniname, struct file_id_t *fid);
 void remove_file(struct inode *inode, struct chain_t *p_dir, s32 entry);
 s32 exfat_rename_file(struct inode *inode, struct chain_t *p_dir, s32 
old_entry,
  struct uni_name_t *p_uniname, struct file_id_t *fid);
diff --git a/drivers/staging/exfat/exfat_core.c 
b/drivers/staging/exfat/exfat_core.c
index 941094b08dd9..ceaea1ba1a83 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -2172,7 +2172,7 @@ s32 create_dir(struct inode *inode, struct chain_t *p_dir,
 }
 
 s32 create_file(struct inode *inode, struct chain_t *p_dir,
-   struct uni_name_t *p_uniname, u8 mode, struct file_id_t *fid)
+   struct uni_name_t *p_uniname, struct file_id_t *fid)
 {
s32 ret, dentry, num_entries;
struct super_block *sb = inode->i_sb;
@@ -2190,7 +2190,7 @@ s32 create_file(struct inode *inode, struct chain_t 
*p_dir,
/* fill the directory entry information of the created file.
 * the first cluster is not determined yet. (0)
 */
-   ret = exfat_init_dir_entry(sb, p_dir, dentry, TYPE_FILE | mode,
+   ret = exfat_init_dir_entry(sb, p_dir, dentry, TYPE_FILE,
   CLUSTER_32(0), 0);
if (ret != 0)
return ret;
@@ -2204,7 +2204,7 @@ s32 create_file(struct inode *inode, struct chain_t 
*p_dir,
fid->dir.flags = p_dir->flags;
fid->entry = dentry;
 
-   fid->attr = ATTR_ARCHIVE | mode;
+   fid->attr = ATTR_ARCHIVE;
fid->flags = 0x03;
fid->size = 0;
fid->start_clu = CLUSTER_32(~0);
diff --git a/drivers/staging/exfat/exfat_super.c 
b/drivers/staging/exfat/exfat_super.c
index 6f3b72eb999d..708398265828 100644
--- a/drivers/staging/exfat/exfat_super.c
+++ b/drivers/staging/exfat/exfat_super.c
@@ -617,8 +617,7 @@ static int ffsLookupFile(struct inode *inode, char *path, 
struct file_id_t *fid)
return ret;
 }
 
-static int ffsCreateFile(struct inode *inode, char *path, u8 mode,
-struct file_id_t *fid)
+static int ffsCreateFile(struct inode *inode, char *path, struct file_id_t 
*fid)
 {
struct chain_t dir;
struct uni_name_t uni_name;
@@ -641,7 +640,7 @@ static int ffsCreateFile(struct inode *inode, char *path, 
u8 mode,
fs_set_vol_flags(sb, VOL_DIRTY);
 
/* create a new file */
-   ret = create_file(inode, &dir, &uni_name, mode, fid);
+   ret = create_file(inode, &dir, &uni_name, fid);
 
 #ifndef CONFIG_STAGING_EXFAT_DELAYED_SYNC
fs_sync(sb, true);
@@ -1834,7 +1833,7 @@ static int exfat_create(struct inode *dir, struct dentry 
*dentry, umode_t mode,
 
pr_debug("%s entered\n", __func__);
 
-   err = ffsCreateFile(dir, (u8 *)dentry->d_name.name, FM_REGULAR, &fid);
+   err = ffsCreateFile(dir, (u8 *)dentry->d_name.name, &fid);
if (err)
goto out;
 
-- 
2.25.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/2] staging: exfat: remove redundant if statements

2020-03-02 Thread Tetsuhiro Kohada
If statement does not affect results when updating directory entry in
ffsMapCluster().

Signed-off-by: Tetsuhiro Kohada 
---
 drivers/staging/exfat/exfat_super.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/exfat/exfat_super.c 
b/drivers/staging/exfat/exfat_super.c
index 708398265828..75813d0fe7a7 100644
--- a/drivers/staging/exfat/exfat_super.c
+++ b/drivers/staging/exfat/exfat_super.c
@@ -1361,11 +1361,8 @@ static int ffsMapCluster(struct inode *inode, s32 
clu_offset, u32 *clu)
 
/* (3) update directory entry */
if (modified) {
-   if (exfat_get_entry_flag(ep) != fid->flags)
-   exfat_set_entry_flag(ep, fid->flags);
-
-   if (exfat_get_entry_clu0(ep) != fid->start_clu)
-   exfat_set_entry_clu0(ep, fid->start_clu);
+   exfat_set_entry_flag(ep, fid->flags);
+   exfat_set_entry_clu0(ep, fid->start_clu);
}
 
update_dir_checksum_with_entry_set(sb, es);
-- 
2.25.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/2] staging: exfat: clean up d_entry rebuilding.

2020-03-02 Thread Tetsuhiro Kohada
Clean up d_entry rebuilding in exfat_rename_file() and move_file().

-Replace memcpy of d_entry with structure copy.
-Change to use the value already stored in fid.

Signed-off-by: Tetsuhiro Kohada 
---
 drivers/staging/exfat/exfat_core.c | 25 ++---
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/exfat/exfat_core.c 
b/drivers/staging/exfat/exfat_core.c
index ceaea1ba1a83..374a4fe183f5 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -2285,12 +2285,10 @@ s32 exfat_rename_file(struct inode *inode, struct 
chain_t *p_dir, s32 oldentry,
return -ENOENT;
}
 
-   memcpy((void *)epnew, (void *)epold, DENTRY_SIZE);
-   if (exfat_get_entry_type(epnew) == TYPE_FILE) {
-   exfat_set_entry_attr(epnew,
-exfat_get_entry_attr(epnew) |
-ATTR_ARCHIVE);
+   *epnew = *epold;
+   if (fid->type == TYPE_FILE) {
fid->attr |= ATTR_ARCHIVE;
+   exfat_set_entry_attr(epnew, fid->attr);
}
exfat_buf_modify(sb, sector_new);
exfat_buf_unlock(sb, sector_old);
@@ -2306,7 +2304,7 @@ s32 exfat_rename_file(struct inode *inode, struct chain_t 
*p_dir, s32 oldentry,
return -ENOENT;
}
 
-   memcpy((void *)epnew, (void *)epold, DENTRY_SIZE);
+   *epnew = *epold;
exfat_buf_modify(sb, sector_new);
exfat_buf_unlock(sb, sector_old);
 
@@ -2319,11 +2317,9 @@ s32 exfat_rename_file(struct inode *inode, struct 
chain_t *p_dir, s32 oldentry,
   num_old_entries);
fid->entry = newentry;
} else {
-   if (exfat_get_entry_type(epold) == TYPE_FILE) {
-   exfat_set_entry_attr(epold,
-exfat_get_entry_attr(epold) |
-ATTR_ARCHIVE);
+   if (fid->type == TYPE_FILE) {
fid->attr |= ATTR_ARCHIVE;
+   exfat_set_entry_attr(epold, fid->attr);
}
exfat_buf_modify(sb, sector_old);
exfat_buf_unlock(sb, sector_old);
@@ -2387,11 +2383,10 @@ s32 move_file(struct inode *inode, struct chain_t 
*p_olddir, s32 oldentry,
return -ENOENT;
}
 
-   memcpy((void *)epnew, (void *)epmov, DENTRY_SIZE);
-   if (exfat_get_entry_type(epnew) == TYPE_FILE) {
-   exfat_set_entry_attr(epnew, exfat_get_entry_attr(epnew) |
-ATTR_ARCHIVE);
+   *epnew = *epmov;
+   if (fid->type == TYPE_FILE) {
fid->attr |= ATTR_ARCHIVE;
+   exfat_set_entry_attr(epnew, fid->attr);
}
exfat_buf_modify(sb, sector_new);
exfat_buf_unlock(sb, sector_mov);
@@ -2406,7 +2401,7 @@ s32 move_file(struct inode *inode, struct chain_t 
*p_olddir, s32 oldentry,
return -ENOENT;
}
 
-   memcpy((void *)epnew, (void *)epmov, DENTRY_SIZE);
+   *epnew = *epmov;
exfat_buf_modify(sb, sector_new);
exfat_buf_unlock(sb, sector_mov);
 
-- 
2.25.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 4/5] staging: exfat: add boot region verification

2020-03-11 Thread Tetsuhiro Kohada
Add Boot-Regions verification specified in exFAT specification.

Reviewed-by: Takahiro Mori 
Signed-off-by: Tetsuhiro Kohada 
---
 drivers/staging/exfat/exfat_core.c | 69 ++
 1 file changed, 69 insertions(+)

diff --git a/drivers/staging/exfat/exfat_core.c 
b/drivers/staging/exfat/exfat_core.c
index 3faa7f35c77c..07c876bb1759 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -2017,7 +2017,20 @@ u16 calc_checksum_2byte(void *data, s32 len, u16 chksum, 
s32 type)
chksum = (((chksum & 1) << 15) |
  ((chksum & 0xFFFE) >> 1)) + (u16)*c;
}
+   return chksum;
+}
 
+u32 calc_checksum32(void *data, int len, u32 chksum, int type)
+{
+   int i;
+   u8 *c = (u8 *)data;
+
+   for (i = 0; i < len; i++, c++) {
+   if (unlikely(type == CS_BOOT_SECTOR &&
+(i == 106 || i == 107 || i == 112)))
+   continue;
+   chksum = ((chksum & 1) << 31 | chksum >> 1) + (u32)*c;
+   }
return chksum;
 }
 
@@ -2053,6 +2066,58 @@ s32 resolve_path(struct inode *inode, char *path, struct 
chain_t *p_dir,
return 0;
 }
 
+static int verify_boot_region(struct super_block *sb)
+{
+   struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
+   struct buffer_head *tmp_bh = NULL;
+   u32 chksum = 0, *p_signatue, *p_chksum;
+   int sn = 0, i, ret;
+
+   /* read boot sector sub-regions */
+   ret = sector_read(sb, sn++, &tmp_bh, 1);
+   if (ret)
+   goto out;
+
+   chksum = calc_checksum32(tmp_bh->b_data, p_bd->sector_size,
+chksum, CS_BOOT_SECTOR);
+
+   while (sn < 11) {
+   ret = sector_read(sb, sn++, &tmp_bh, 1);
+   if (ret)
+   goto out;
+
+   chksum = calc_checksum32(tmp_bh->b_data, p_bd->sector_size,
+chksum, CS_DEFAULT);
+
+   /* skip OEM Parameters & Reserved sub-regions */
+   if (sn >= 9)
+   continue;
+
+   /* extended boot sector sub-regions */
+   p_signatue = (u32 *)(tmp_bh->b_data + p_bd->sector_size - 4);
+   if (le32_to_cpu(*p_signatue) != EXBOOT_SIGNATURE) {
+   ret = -EFSCORRUPTED;
+   goto out;
+   }
+   }
+
+   /* boot checksum sub-regions */
+   ret = sector_read(sb, sn++, &tmp_bh, 1);
+   if (ret)
+   goto out;
+
+   p_chksum = (u32 *)tmp_bh->b_data;
+   for (i = 0; i < p_bd->sector_size / 4; i++) {
+   if (le32_to_cpu(*p_chksum) != chksum) {
+   ret = -EFSCORRUPTED;
+   goto out;
+   }
+   }
+out:
+   brelse(tmp_bh);
+   return ret;
+}
+
 static int read_boot_sector(struct super_block *sb)
 {
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
@@ -2129,6 +2194,10 @@ s32 exfat_mount(struct super_block *sb)
if (ret)
goto err_out;
 
+   ret = verify_boot_region(sb);
+   if (ret)
+   goto err_out;
+
ret = load_alloc_bitmap(sb);
if (ret)
goto err_out;
-- 
2.25.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 3/5] staging: exfat: consolidate boot sector analysis

2020-03-11 Thread Tetsuhiro Kohada
Consolidate boot sector analysis into read_boot_sector().

 - Move boot sector analysis from exfat_mount() to read_boot_sector().
 - Fix num_fats check in read_boot_sector().
 - Consolidate p_fs->boot_bh initialization/release into mount/umount.

This fixes vol_flags inconsistency at read failed in fs_set_vol_flags(),
and tmp_bh leak in exfat_mount(). :-)

Reviewed-by: Takahiro Mori 
Signed-off-by: Tetsuhiro Kohada 
---
 drivers/staging/exfat/exfat_core.c | 106 -
 1 file changed, 45 insertions(+), 61 deletions(-)

diff --git a/drivers/staging/exfat/exfat_core.c 
b/drivers/staging/exfat/exfat_core.c
index 2d88ce85217c..3faa7f35c77c 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -89,11 +89,6 @@ void fs_set_vol_flags(struct super_block *sb, u32 new_flag)
 
p_fs->vol_flag = new_flag;
 
-   if (!p_fs->boot_bh) {
-   if (sector_read(sb, 0, &p_fs->boot_bh, 1) != 0)
-   return;
-   }
-
p_boot = (struct boot_sector_t *)p_fs->boot_bh->b_data;
p_boot->vol_flags = cpu_to_le16(new_flag);
 
@@ -531,8 +526,6 @@ static s32 load_alloc_bitmap(struct super_block *sb)
return ret;
}
}
-
-   p_fs->boot_bh = NULL;
return 0;
}
}
@@ -549,9 +542,7 @@ static void free_alloc_bitmap(struct super_block *sb)
int i;
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
 
-   brelse(p_fs->boot_bh);
-
-   for (i = 0; i < p_fs->map_sectors; i++)
+   for (i = 0; i < p_fs->map_sectors && p_fs->vol_amap; i++)
__brelse(p_fs->vol_amap[i]);
 
kfree(p_fs->vol_amap);
@@ -763,7 +754,7 @@ static void free_upcase_table(struct super_block *sb)
u16 **upcase_table;
 
upcase_table = p_fs->vol_utbl;
-   for (i = 0; i < UTBL_COL_COUNT; i++)
+   for (i = 0; i < UTBL_COL_COUNT && upcase_table; i++)
kfree(upcase_table[i]);
 
kfree(p_fs->vol_utbl);
@@ -2062,15 +2053,31 @@ s32 resolve_path(struct inode *inode, char *path, 
struct chain_t *p_dir,
return 0;
 }
 
-static s32 read_boot_sector(struct super_block *sb,
-   struct boot_sector_t *p_boot)
+static int read_boot_sector(struct super_block *sb)
 {
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
+   struct boot_sector_t *p_boot;
+   int i;
+
+   p_boot = (struct boot_sector_t *)p_fs->boot_bh->b_data;
 
-   if (p_boot->num_fats == 0)
+   /* check the validity of BOOT sector */
+   if (le16_to_cpu(p_boot->boot_signature) != BOOT_SIGNATURE)
return -EFSCORRUPTED;
 
+   /* check the byte range consumed as BPB for FAT12/16/32 volumes */
+   for (i = 0; i < 53; i++) {
+   if (p_boot->must_be_zero[i]) {
+   pr_info("EXFAT: Attempted to mount VFAT filesystem\n");
+   return -EFSCORRUPTED;
+   }
+   }
+
+   if (p_boot->num_fats != 1 && p_boot->num_fats != 2)
+   return -EFSCORRUPTED;
+
+   /* fill fs_info */
p_fs->sectors_per_clu = 1 << p_boot->sectors_per_clu_shift;
p_fs->sectors_per_clu_bits = p_boot->sectors_per_clu_shift;
p_fs->cluster_size_bits = p_fs->sectors_per_clu_bits +
@@ -2080,11 +2087,9 @@ static s32 read_boot_sector(struct super_block *sb,
p_fs->num_FAT_sectors = le32_to_cpu(p_boot->fat_length);
 
p_fs->FAT1_start_sector = le32_to_cpu(p_boot->fat_offset);
-   if (p_boot->num_fats == 1)
-   p_fs->FAT2_start_sector = p_fs->FAT1_start_sector;
-   else
-   p_fs->FAT2_start_sector = p_fs->FAT1_start_sector +
- p_fs->num_FAT_sectors;
+   p_fs->FAT2_start_sector = p_fs->FAT1_start_sector;
+   if (p_boot->num_fats == 2)
+   p_fs->FAT2_start_sector += p_fs->num_FAT_sectors;
 
p_fs->root_start_sector = le32_to_cpu(p_boot->clu_offset);
p_fs->data_start_sector = p_fs->root_start_sector;
@@ -2109,71 +2114,50 @@ static s32 read_boot_sector(struct super_block *sb,
 
 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);
+   int ret;
 
-   /* read Sector 0 */
-   if (sector_read(sb, 0, &tmp_bh, 1) != 0) {
-   ret = -EIO;
-   goto out;
-   }
-
-   p_boot = (struct boot_sect

[PATCH 5/5] staging: exfat: standardize checksum calculation

2020-03-11 Thread Tetsuhiro Kohada
- Remove redundant code of calc_checksum_2byte() and rename to calc_checksum16.
- Replace checksum calculation in __load_upcase_table() with calc_checksum32().

Reviewed-by: Takahiro Mori 
Signed-off-by: Tetsuhiro Kohada 
---
 drivers/staging/exfat/exfat.h  |  3 ++-
 drivers/staging/exfat/exfat_core.c | 40 --
 drivers/staging/exfat/exfat_nls.c  |  3 +--
 3 files changed, 14 insertions(+), 32 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index 95c2a6ef0e71..4e6e6c4b20e5 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -601,7 +601,8 @@ bool is_dir_empty(struct super_block *sb, struct chain_t 
*p_dir);
 /* name conversion functions */
 s32 get_num_entries(struct super_block *sb, struct chain_t *p_dir,
struct uni_name_t *p_uniname, s32 *entries);
-u16 calc_checksum_2byte(void *data, s32 len, u16 chksum, s32 type);
+u16 calc_checksum16(void *data, int len, u16 chksum, int type);
+u32 calc_checksum32(void *data, int len, u32 chksum, int type);
 
 /* name resolution functions */
 s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir,
diff --git a/drivers/staging/exfat/exfat_core.c 
b/drivers/staging/exfat/exfat_core.c
index 07c876bb1759..d14e9b345903 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -588,14 +588,6 @@ static s32 __load_upcase_table(struct super_block *sb, 
sector_t sector,
 
for (i = 0; i < p_bd->sector_size && index <= 0x; i += 2) {
uni = GET16(((u8 *)tmp_bh->b_data) + i);
-
-   checksum = ((checksum & 1) ? 0x8000 : 0) +
-  (checksum >> 1) + *(((u8 *)tmp_bh->b_data) +
-  i);
-   checksum = ((checksum & 1) ? 0x8000 : 0) +
-  (checksum >> 1) + *(((u8 *)tmp_bh->b_data) +
-  (i + 1));
-
if (skip) {
pr_debug("skip from 0x%X ", index);
index += uni;
@@ -626,6 +618,8 @@ static s32 __load_upcase_table(struct super_block *sb, 
sector_t sector,
index++;
}
}
+   checksum = calc_checksum32(tmp_bh->b_data, i, checksum,
+  CS_DEFAULT);
}
if (index >= 0x && utbl_checksum == checksum) {
if (tmp_bh)
@@ -1096,8 +1090,7 @@ void update_dir_checksum(struct super_block *sb, struct 
chain_t *p_dir,
exfat_buf_lock(sb, sector);
 
num_entries = (s32)file_ep->num_ext + 1;
-   chksum = calc_checksum_2byte((void *)file_ep, DENTRY_SIZE, 0,
-CS_DIR_ENTRY);
+   chksum = calc_checksum16(file_ep, DENTRY_SIZE, 0, CS_DIR_ENTRY);
 
for (i = 1; i < num_entries; i++) {
ep = get_entry_in_dir(sb, p_dir, entry + i, NULL);
@@ -1106,8 +1099,7 @@ void update_dir_checksum(struct super_block *sb, struct 
chain_t *p_dir,
return;
}
 
-   chksum = calc_checksum_2byte((void *)ep, DENTRY_SIZE, chksum,
-CS_DEFAULT);
+   chksum = calc_checksum16(ep, DENTRY_SIZE, chksum, CS_DEFAULT);
}
 
SET16_A(file_ep->checksum, chksum);
@@ -1192,8 +1184,7 @@ void update_dir_checksum_with_entry_set(struct 
super_block *sb,
ep = (struct dentry_t *)&es->__buf;
for (i = 0; i < es->num_entries; i++) {
pr_debug("%s ep %p\n", __func__, ep);
-   chksum = calc_checksum_2byte((void *)ep, DENTRY_SIZE, chksum,
-chksum_type);
+   chksum = calc_checksum16(ep, DENTRY_SIZE, chksum, chksum_type);
ep++;
chksum_type = CS_DEFAULT;
}
@@ -1997,25 +1988,16 @@ s32 exfat_calc_num_entries(struct uni_name_t *p_uniname)
return (len - 1) / 15 + 3;
 }
 
-u16 calc_checksum_2byte(void *data, s32 len, u16 chksum, s32 type)
+u16 calc_checksum16(void *data, int len, u16 chksum, int type)
 {
int i;
u8 *c = (u8 *)data;
 
-   switch (type) {
-   case CS_DIR_ENTRY:
-   for (i = 0; i < len; i++, c++) {
-   if ((i == 2) || (i == 3))
-   continue;
-   chksum = (((chksum & 1) << 15) |
- ((chksum & 0xFFFE) >> 1)) + (u16)*c;
-   }
-   break;
-   default
-   :
-   for (i = 0; i < len; i++, c++)
-   chksum = (((chksum & 1) <<

[PATCH 1/5] staging: exfat: conform 'pbr_sector_t' definition to exFAT specification

2020-03-11 Thread Tetsuhiro Kohada
Redefine 'pbr_sector_t' as 'boot_sector_t' to comply with exFAT specification.
 - Redefine 'pbr_sector_t' as 'boot_sector_t'.
 - Rename variable names including 'pbr'.
 - Replace GET**()/SET**() macro with cpu_to_le**()/le**_ to_cpu().
 - Remove fs_info_t.PBR_sector (always 0).
 - Remove unused definitions.

Reviewed-by: Takahiro Mori 
Signed-off-by: Tetsuhiro Kohada 
---
 drivers/staging/exfat/exfat.h   | 139 +++-
 drivers/staging/exfat/exfat_core.c  |  62 ++---
 drivers/staging/exfat/exfat_super.c |  14 ++-
 3 files changed, 65 insertions(+), 150 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index c863d7566b57..0f730090cb30 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -35,17 +35,12 @@
 #define DENTRY_SIZE32  /* dir entry size */
 #define DENTRY_SIZE_BITS   5
 
-/* PBR entries */
-#define PBR_SIGNATURE  0xAA55
-#define EXT_SIGNATURE  0xAA55
-#define VOL_LABEL  "NO NAME"   /* size should be 11 */
-#define OEM_NAME   "MSWIN4.1"  /* size should be 8 */
-#define STR_FAT12  "FAT12   "  /* size should be 8 */
-#define STR_FAT16  "FAT16   "  /* size should be 8 */
-#define STR_FAT32  "FAT32   "  /* size should be 8 */
-#define STR_EXFAT  "EXFAT   "  /* size should be 8 */
-#define VOL_CLEAN  0x
-#define VOL_DIRTY  0x0002
+/* exFAT: 3 Main and Backup Boot Regions */
+#define BOOT_SIGNATURE 0xAA55
+#define EXBOOT_SIGNATURE   0xAA55
+#define STR_EXFAT  "EXFAT   "  /* size should be 8 */
+#define VOL_CLEAN  0x
+#define VOL_DIRTY  0x0002
 
 /* max number of clusters */
 #define FAT12_THRESHOLD4087/* 2^12 - 1 + 2 (clu 0 
& 1) */
@@ -81,7 +76,7 @@
 
 /* checksum types */
 #define CS_DIR_ENTRY   0
-#define CS_PBR_SECTOR  1
+#define CS_BOOT_SECTOR 1
 #define CS_DEFAULT 2
 
 #define CLUSTER_16(x)  ((u16)(x))
@@ -267,98 +262,29 @@ struct timestamp_t {
u16  year;   /* 0 ~ 127 (since 1980) */
 };
 
-/* MS_DOS FAT partition boot record (512 bytes) */
-struct pbr_sector_t {
-   u8   jmp_boot[3];
-   u8   oem_name[8];
-   u8   bpb[109];
-   u8   boot_code[390];
-   u8   signature[2];
-};
-
-/* MS-DOS FAT12/16 BIOS parameter block (51 bytes) */
-struct bpb16_t {
-   u8   sector_size[2];
-   u8   sectors_per_clu;
-   u8   num_reserved[2];
-   u8   num_fats;
-   u8   num_root_entries[2];
-   u8   num_sectors[2];
-   u8   media_type;
-   u8   num_fat_sectors[2];
-   u8   sectors_in_track[2];
-   u8   num_heads[2];
-   u8   num_hid_sectors[4];
-   u8   num_huge_sectors[4];
-
-   u8   phy_drv_no;
-   u8   reserved;
-   u8   ext_signature;
-   u8   vol_serial[4];
-   u8   vol_label[11];
-   u8   vol_type[8];
-};
-
-/* MS-DOS FAT32 BIOS parameter block (79 bytes) */
-struct bpb32_t {
-   u8   sector_size[2];
-   u8   sectors_per_clu;
-   u8   num_reserved[2];
-   u8   num_fats;
-   u8   num_root_entries[2];
-   u8   num_sectors[2];
-   u8   media_type;
-   u8   num_fat_sectors[2];
-   u8   sectors_in_track[2];
-   u8   num_heads[2];
-   u8   num_hid_sectors[4];
-   u8   num_huge_sectors[4];
-   u8   num_fat32_sectors[4];
-   u8   ext_flags[2];
-   u8   fs_version[2];
-   u8   root_cluster[4];
-   u8   fsinfo_sector[2];
-   u8   backup_sector[2];
-   u8   reserved[12];
-
-   u8   phy_drv_no;
-   u8   ext_reserved;
-   u8   ext_signature;
-   u8   vol_serial[4];
-   u8   vol_label[11];
-   u8   vol_type[8];
-};
-
-/* MS-DOS EXFAT BIOS parameter block (109 bytes) */
-struct bpbex_t {
-   u8   reserved1[53];
-   u8   vol_offset[8];
-   u8   vol_length[8];
-   u8   fat_offset[4];
-   u8   fat_length[4];
-   u8   clu_offset[4];
-   u8   clu_count[4];
-   u8   root_cluster[4];
-   u8   vol_serial[4];
-   u8   fs_version[2];
-   u8   vol_flags[2];
-   u8   sector_size_bits;
-   u8   sectors_per_clu_bits;
-   u8   num_fats;
-   u8   phy_drv_no;
-   u8   perc_in_use;
-   u8   reserved2[7];
-};
-
-/* MS-DOS FAT file system information sector (512 bytes) */
-struct fsi_sector_t {
-   u8   signature1[4];
-   u8   reserved1[480];
-   u8   signature2[4];
-   u8   free_cluster[4];
-   u8   next_cluster[4];
-   u8   re

[PATCH 2/5] staging: exfat: separate and move exFAT-mount core processing.

2020-03-11 Thread Tetsuhiro Kohada
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 
Signed-off-by: Tetsuhiro Kohada 
---
 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