Commit 2a17b09f authored by Valdis Kletnieks's avatar Valdis Kletnieks Committed by Greg Kroah-Hartman

staging: exfat: Remove FAT/VFAT mount support, part 3

In this patch, we straighten out most of the cases where the
code was testing 'p_fs->vol_type == EXFAT' and '!= EXFAT'

There's still some ?: ops and a few places where the code
is doing checks for '.' and '..' that require looking at,
but those are future patches
Signed-off-by: default avatarValdis Kletnieks <Valdis.Kletnieks@vt.edu>
Link: https://lore.kernel.org/r/20191112211238.156490-4-Valdis.Kletnieks@vt.eduSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7c6d78eb
...@@ -202,86 +202,6 @@ static int __FAT_read(struct super_block *sb, u32 loc, u32 *content) ...@@ -202,86 +202,6 @@ static int __FAT_read(struct super_block *sb, u32 loc, u32 *content)
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
if (p_fs->vol_type == FAT12) {
sec = p_fs->FAT1_start_sector +
((loc + (loc >> 1)) >> p_bd->sector_size_bits);
off = (loc + (loc >> 1)) & p_bd->sector_size_mask;
if (off == (p_bd->sector_size - 1)) {
fat_sector = FAT_getblk(sb, sec);
if (!fat_sector)
return -1;
_content = (u32)fat_sector[off];
fat_sector = FAT_getblk(sb, ++sec);
if (!fat_sector)
return -1;
_content |= (u32)fat_sector[0] << 8;
} else {
fat_sector = FAT_getblk(sb, sec);
if (!fat_sector)
return -1;
fat_entry = &fat_sector[off];
_content = GET16(fat_entry);
}
if (loc & 1)
_content >>= 4;
_content &= 0x00000FFF;
if (_content >= CLUSTER_16(0x0FF8)) {
*content = CLUSTER_32(~0);
return 0;
}
*content = CLUSTER_32(_content);
return 0;
} else if (p_fs->vol_type == FAT16) {
sec = p_fs->FAT1_start_sector +
(loc >> (p_bd->sector_size_bits - 1));
off = (loc << 1) & p_bd->sector_size_mask;
fat_sector = FAT_getblk(sb, sec);
if (!fat_sector)
return -1;
fat_entry = &fat_sector[off];
_content = GET16_A(fat_entry);
_content &= 0x0000FFFF;
if (_content >= CLUSTER_16(0xFFF8)) {
*content = CLUSTER_32(~0);
return 0;
}
*content = CLUSTER_32(_content);
return 0;
} else if (p_fs->vol_type == FAT32) {
sec = p_fs->FAT1_start_sector +
(loc >> (p_bd->sector_size_bits - 2));
off = (loc << 2) & p_bd->sector_size_mask;
fat_sector = FAT_getblk(sb, sec);
if (!fat_sector)
return -1;
fat_entry = &fat_sector[off];
_content = GET32_A(fat_entry);
_content &= 0x0FFFFFFF;
if (_content >= CLUSTER_32(0x0FFFFFF8)) {
*content = CLUSTER_32(~0);
return 0;
}
*content = CLUSTER_32(_content);
return 0;
} else if (p_fs->vol_type == EXFAT) {
sec = p_fs->FAT1_start_sector + sec = p_fs->FAT1_start_sector +
(loc >> (p_bd->sector_size_bits - 2)); (loc >> (p_bd->sector_size_bits - 2));
off = (loc << 2) & p_bd->sector_size_mask; off = (loc << 2) & p_bd->sector_size_mask;
...@@ -299,11 +219,6 @@ static int __FAT_read(struct super_block *sb, u32 loc, u32 *content) ...@@ -299,11 +219,6 @@ static int __FAT_read(struct super_block *sb, u32 loc, u32 *content)
} }
*content = CLUSTER_32(_content); *content = CLUSTER_32(_content);
return 0; return 0;
}
/* Unknown volume type, throw in the towel and go home */
*content = CLUSTER_32(~0);
return 0;
} }
/* in : sb, loc /* in : sb, loc
...@@ -330,75 +245,6 @@ static s32 __FAT_write(struct super_block *sb, u32 loc, u32 content) ...@@ -330,75 +245,6 @@ static s32 __FAT_write(struct super_block *sb, u32 loc, u32 content)
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
if (p_fs->vol_type == FAT12) {
content &= 0x00000FFF;
sec = p_fs->FAT1_start_sector +
((loc + (loc >> 1)) >> p_bd->sector_size_bits);
off = (loc + (loc >> 1)) & p_bd->sector_size_mask;
fat_sector = FAT_getblk(sb, sec);
if (!fat_sector)
return -1;
if (loc & 1) { /* odd */
content <<= 4;
if (off == (p_bd->sector_size - 1)) {
fat_sector[off] = (u8)(content |
(fat_sector[off] &
0x0F));
FAT_modify(sb, sec);
fat_sector = FAT_getblk(sb, ++sec);
if (!fat_sector)
return -1;
fat_sector[0] = (u8)(content >> 8);
} else {
fat_entry = &fat_sector[off];
content |= GET16(fat_entry) & 0x000F;
SET16(fat_entry, content);
}
} else { /* even */
fat_sector[off] = (u8)(content);
if (off == (p_bd->sector_size - 1)) {
fat_sector[off] = (u8)(content);
FAT_modify(sb, sec);
fat_sector = FAT_getblk(sb, ++sec);
if (!fat_sector)
return -1;
fat_sector[0] = (u8)((fat_sector[0] & 0xF0) |
(content >> 8));
} else {
fat_entry = &fat_sector[off];
content |= GET16(fat_entry) & 0xF000;
SET16(fat_entry, content);
}
}
}
else if (p_fs->vol_type == FAT16) {
content &= 0x0000FFFF;
sec = p_fs->FAT1_start_sector + (loc >>
(p_bd->sector_size_bits - 1));
off = (loc << 1) & p_bd->sector_size_mask;
fat_sector = FAT_getblk(sb, sec);
if (!fat_sector)
return -1;
fat_entry = &fat_sector[off];
SET16_A(fat_entry, content);
} else if (p_fs->vol_type == FAT32) {
content &= 0x0FFFFFFF;
sec = p_fs->FAT1_start_sector + (loc >> sec = p_fs->FAT1_start_sector + (loc >>
(p_bd->sector_size_bits - 2)); (p_bd->sector_size_bits - 2));
off = (loc << 2) & p_bd->sector_size_mask; off = (loc << 2) & p_bd->sector_size_mask;
...@@ -409,22 +255,7 @@ static s32 __FAT_write(struct super_block *sb, u32 loc, u32 content) ...@@ -409,22 +255,7 @@ static s32 __FAT_write(struct super_block *sb, u32 loc, u32 content)
fat_entry = &fat_sector[off]; fat_entry = &fat_sector[off];
content |= GET32_A(fat_entry) & 0xF0000000;
SET32_A(fat_entry, content); SET32_A(fat_entry, content);
} else { /* p_fs->vol_type == EXFAT */
sec = p_fs->FAT1_start_sector + (loc >>
(p_bd->sector_size_bits - 2));
off = (loc << 2) & p_bd->sector_size_mask;
fat_sector = FAT_getblk(sb, sec);
if (!fat_sector)
return -1;
fat_entry = &fat_sector[off];
SET32_A(fat_entry, content);
}
FAT_modify(sb, sec); FAT_modify(sb, sec);
return 0; return 0;
......
...@@ -20,15 +20,6 @@ static void __set_sb_dirty(struct super_block *sb) ...@@ -20,15 +20,6 @@ static void __set_sb_dirty(struct super_block *sb)
static u8 name_buf[MAX_PATH_LENGTH * MAX_CHARSET_SIZE]; static u8 name_buf[MAX_PATH_LENGTH * MAX_CHARSET_SIZE];
static char *reserved_names[] = {
"AUX ", "CON ", "NUL ", "PRN ",
"COM1 ", "COM2 ", "COM3 ", "COM4 ",
"COM5 ", "COM6 ", "COM7 ", "COM8 ", "COM9 ",
"LPT1 ", "LPT2 ", "LPT3 ", "LPT4 ",
"LPT5 ", "LPT6 ", "LPT7 ", "LPT8 ", "LPT9 ",
NULL
};
static u8 free_bit[] = { static u8 free_bit[] = {
0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, /* 0 ~ 19 */ 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, /* 0 ~ 19 */
0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, /* 20 ~ 39 */ 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, /* 20 ~ 39 */
...@@ -99,7 +90,6 @@ void fs_set_vol_flags(struct super_block *sb, u32 new_flag) ...@@ -99,7 +90,6 @@ void fs_set_vol_flags(struct super_block *sb, u32 new_flag)
p_fs->vol_flag = new_flag; p_fs->vol_flag = new_flag;
if (p_fs->vol_type == EXFAT) {
if (!p_fs->pbr_bh) { if (!p_fs->pbr_bh) {
if (sector_read(sb, p_fs->PBR_sector, if (sector_read(sb, p_fs->PBR_sector,
&p_fs->pbr_bh, 1) != 0) &p_fs->pbr_bh, 1) != 0)
...@@ -117,7 +107,6 @@ void fs_set_vol_flags(struct super_block *sb, u32 new_flag) ...@@ -117,7 +107,6 @@ void fs_set_vol_flags(struct super_block *sb, u32 new_flag)
sector_write(sb, p_fs->PBR_sector, p_fs->pbr_bh, 1); sector_write(sb, p_fs->PBR_sector, p_fs->pbr_bh, 1);
else else
sector_write(sb, p_fs->PBR_sector, p_fs->pbr_bh, 0); sector_write(sb, p_fs->PBR_sector, p_fs->pbr_bh, 0);
}
} }
void fs_error(struct super_block *sb) void fs_error(struct super_block *sb)
...@@ -1613,10 +1602,8 @@ s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir, s32 num_entries ...@@ -1613,10 +1602,8 @@ s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir, s32 num_entries
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
break; break;
if (p_fs->vol_type == EXFAT) {
if (p_dir->dir != p_fs->root_dir) if (p_dir->dir != p_fs->root_dir)
size = i_size_read(inode); size = i_size_read(inode);
}
last_clu = find_last_cluster(sb, p_dir); last_clu = find_last_cluster(sb, p_dir);
clu.dir = last_clu + 1; clu.dir = last_clu + 1;
...@@ -1653,7 +1640,6 @@ s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir, s32 num_entries ...@@ -1653,7 +1640,6 @@ s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir, s32 num_entries
p_dir->size++; p_dir->size++;
/* (3) update the directory entry */ /* (3) update the directory entry */
if (p_fs->vol_type == EXFAT) {
if (p_dir->dir != p_fs->root_dir) { if (p_dir->dir != p_fs->root_dir) {
size += p_fs->cluster_size; size += p_fs->cluster_size;
...@@ -1668,7 +1654,6 @@ s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir, s32 num_entries ...@@ -1668,7 +1654,6 @@ s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir, s32 num_entries
update_dir_checksum(sb, &fid->dir, update_dir_checksum(sb, &fid->dir,
fid->entry); fid->entry);
} }
}
i_size_write(inode, i_size_read(inode) + p_fs->cluster_size); i_size_write(inode, i_size_read(inode) + p_fs->cluster_size);
EXFAT_I(inode)->mmu_private += p_fs->cluster_size; EXFAT_I(inode)->mmu_private += p_fs->cluster_size;
...@@ -1979,36 +1964,13 @@ s32 get_num_entries_and_dos_name(struct super_block *sb, struct chain_t *p_dir, ...@@ -1979,36 +1964,13 @@ 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 uni_name_t *p_uniname, s32 *entries,
struct dos_name_t *p_dosname) struct dos_name_t *p_dosname)
{ {
s32 ret, num_entries; s32 num_entries;
bool lossy = false;
char **r;
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
num_entries = p_fs->fs_func->calc_num_entries(p_uniname); num_entries = p_fs->fs_func->calc_num_entries(p_uniname);
if (num_entries == 0) if (num_entries == 0)
return -EINVAL; return -EINVAL;
if (p_fs->vol_type != EXFAT) {
nls_uniname_to_dosname(sb, p_dosname, p_uniname, &lossy);
if (lossy) {
ret = fat_generate_dos_name(sb, p_dir, p_dosname);
if (ret)
return ret;
} else {
for (r = reserved_names; *r; r++) {
if (!strncmp((void *)p_dosname->name, *r, 8))
return -EINVAL;
}
if (p_dosname->name_case != 0xFF)
num_entries = 1;
}
if (num_entries > 1)
p_dosname->name_case = 0x0;
}
*entries = num_entries; *entries = num_entries;
return 0; return 0;
...@@ -2392,7 +2354,7 @@ s32 create_dir(struct inode *inode, struct chain_t *p_dir, ...@@ -2392,7 +2354,7 @@ s32 create_dir(struct inode *inode, struct chain_t *p_dir,
s32 ret, dentry, num_entries; s32 ret, dentry, num_entries;
u64 size; u64 size;
struct chain_t clu; struct chain_t clu;
struct dos_name_t dos_name, dot_name; struct dos_name_t dos_name;
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
struct fs_func *fs_func = p_fs->fs_func; struct fs_func *fs_func = p_fs->fs_func;
...@@ -2422,45 +2384,7 @@ s32 create_dir(struct inode *inode, struct chain_t *p_dir, ...@@ -2422,45 +2384,7 @@ s32 create_dir(struct inode *inode, struct chain_t *p_dir,
if (ret != 0) if (ret != 0)
return ret; return ret;
if (p_fs->vol_type == EXFAT) {
size = p_fs->cluster_size; size = p_fs->cluster_size;
} else {
size = 0;
/* initialize the . and .. entry
* Information for . points to itself
* Information for .. points to parent dir
*/
dot_name.name_case = 0x0;
memcpy(dot_name.name, DOS_CUR_DIR_NAME, DOS_NAME_LENGTH);
ret = fs_func->init_dir_entry(sb, &clu, 0, TYPE_DIR, clu.dir,
0);
if (ret != 0)
return ret;
ret = fs_func->init_ext_entry(sb, &clu, 0, 1, NULL, &dot_name);
if (ret != 0)
return ret;
memcpy(dot_name.name, DOS_PAR_DIR_NAME, DOS_NAME_LENGTH);
if (p_dir->dir == p_fs->root_dir)
ret = fs_func->init_dir_entry(sb, &clu, 1, TYPE_DIR,
CLUSTER_32(0), 0);
else
ret = fs_func->init_dir_entry(sb, &clu, 1, TYPE_DIR,
p_dir->dir, 0);
if (ret != 0)
return ret;
ret = p_fs->fs_func->init_ext_entry(sb, &clu, 1, 1, NULL,
&dot_name);
if (ret != 0)
return ret;
}
/* (2) update the directory entry */ /* (2) update the directory entry */
/* make sub-dir entry in parent directory */ /* make sub-dir entry in parent directory */
...@@ -2626,7 +2550,6 @@ s32 rename_file(struct inode *inode, struct chain_t *p_dir, s32 oldentry, ...@@ -2626,7 +2550,6 @@ s32 rename_file(struct inode *inode, struct chain_t *p_dir, s32 oldentry,
buf_modify(sb, sector_new); buf_modify(sb, sector_new);
buf_unlock(sb, sector_old); buf_unlock(sb, sector_old);
if (p_fs->vol_type == EXFAT) {
epold = get_entry_in_dir(sb, p_dir, oldentry + 1, epold = get_entry_in_dir(sb, p_dir, oldentry + 1,
&sector_old); &sector_old);
buf_lock(sb, sector_old); buf_lock(sb, sector_old);
...@@ -2641,7 +2564,6 @@ s32 rename_file(struct inode *inode, struct chain_t *p_dir, s32 oldentry, ...@@ -2641,7 +2564,6 @@ s32 rename_file(struct inode *inode, struct chain_t *p_dir, s32 oldentry,
memcpy((void *)epnew, (void *)epold, DENTRY_SIZE); memcpy((void *)epnew, (void *)epold, DENTRY_SIZE);
buf_modify(sb, sector_new); buf_modify(sb, sector_new);
buf_unlock(sb, sector_old); buf_unlock(sb, sector_old);
}
ret = fs_func->init_ext_entry(sb, p_dir, newentry, ret = fs_func->init_ext_entry(sb, p_dir, newentry,
num_new_entries, p_uniname, num_new_entries, p_uniname,
...@@ -2681,7 +2603,6 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry, ...@@ -2681,7 +2603,6 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry,
{ {
s32 ret, newentry, num_new_entries, num_old_entries; s32 ret, newentry, num_new_entries, num_old_entries;
sector_t sector_mov, sector_new; sector_t sector_mov, sector_new;
struct chain_t clu;
struct dos_name_t dos_name; struct dos_name_t dos_name;
struct dentry_t *epmov, *epnew; struct dentry_t *epmov, *epnew;
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
...@@ -2736,7 +2657,6 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry, ...@@ -2736,7 +2657,6 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry,
buf_modify(sb, sector_new); buf_modify(sb, sector_new);
buf_unlock(sb, sector_mov); buf_unlock(sb, sector_mov);
if (p_fs->vol_type == EXFAT) {
epmov = get_entry_in_dir(sb, p_olddir, oldentry + 1, epmov = get_entry_in_dir(sb, p_olddir, oldentry + 1,
&sector_mov); &sector_mov);
buf_lock(sb, sector_mov); buf_lock(sb, sector_mov);
...@@ -2750,21 +2670,6 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry, ...@@ -2750,21 +2670,6 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry,
memcpy((void *)epnew, (void *)epmov, DENTRY_SIZE); memcpy((void *)epnew, (void *)epmov, DENTRY_SIZE);
buf_modify(sb, sector_new); buf_modify(sb, sector_new);
buf_unlock(sb, sector_mov); buf_unlock(sb, sector_mov);
} else if (fs_func->get_entry_type(epnew) == TYPE_DIR) {
/* change ".." pointer to new parent dir */
clu.dir = fs_func->get_entry_clu0(epnew);
clu.flags = 0x01;
epnew = get_entry_in_dir(sb, &clu, 1, &sector_new);
if (!epnew)
return -ENOENT;
if (p_newdir->dir == p_fs->root_dir)
fs_func->set_entry_clu0(epnew, CLUSTER_32(0));
else
fs_func->set_entry_clu0(epnew, p_newdir->dir);
buf_modify(sb, sector_new);
}
ret = fs_func->init_ext_entry(sb, p_newdir, newentry, num_new_entries, ret = fs_func->init_ext_entry(sb, p_newdir, newentry, num_new_entries,
p_uniname, &dos_name); p_uniname, &dos_name);
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment