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,107 +202,22 @@ static int __FAT_read(struct super_block *sb, u32 loc, u32 *content)
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_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;
sec = p_fs->FAT1_start_sector +
(loc >> (p_bd->sector_size_bits - 2));
off = (loc << 2) & p_bd->sector_size_mask;
fat_entry = &fat_sector[off];
fat_sector = FAT_getblk(sb, sec);
if (!fat_sector)
return -1;
_content = GET32_A(fat_entry);
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 +
(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);
if (_content >= CLUSTER_32(0xFFFFFFF8)) {
*content = CLUSTER_32(~0);
return 0;
}
*content = CLUSTER_32(_content);
if (_content >= CLUSTER_32(0xFFFFFFF8)) {
*content = CLUSTER_32(~0);
return 0;
}
/* Unknown volume type, throw in the towel and go home */
*content = CLUSTER_32(~0);
*content = CLUSTER_32(_content);
return 0;
}
......@@ -330,101 +245,17 @@ static s32 __FAT_write(struct super_block *sb, u32 loc, u32 content)
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_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 >>
(p_bd->sector_size_bits - 2));
off = (loc << 2) & p_bd->sector_size_mask;
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;
fat_sector = FAT_getblk(sb, sec);
if (!fat_sector)
return -1;
fat_entry = &fat_sector[off];
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 >>
(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) & 0xF0000000;
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);
}
SET32_A(fat_entry, content);
FAT_modify(sb, sec);
return 0;
......
......@@ -20,15 +20,6 @@ static void __set_sb_dirty(struct super_block *sb)
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[] = {
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 */
......@@ -99,25 +90,23 @@ void fs_set_vol_flags(struct super_block *sb, u32 new_flag)
p_fs->vol_flag = new_flag;
if (p_fs->vol_type == EXFAT) {
if (!p_fs->pbr_bh) {
if (sector_read(sb, p_fs->PBR_sector,
&p_fs->pbr_bh, 1) != 0)
return;
}
if (!p_fs->pbr_bh) {
if (sector_read(sb, p_fs->PBR_sector,
&p_fs->pbr_bh, 1) != 0)
return;
}
p_pbr = (struct pbr_sector_t *)p_fs->pbr_bh->b_data;
p_bpb = (struct bpbex_t *)p_pbr->bpb;
SET16(p_bpb->vol_flags, (u16)new_flag);
p_pbr = (struct pbr_sector_t *)p_fs->pbr_bh->b_data;
p_bpb = (struct bpbex_t *)p_pbr->bpb;
SET16(p_bpb->vol_flags, (u16)new_flag);
/* XXX duyoung
* what can we do here? (cuz fs_set_vol_flags() is void)
*/
if ((new_flag == VOL_DIRTY) && (!buffer_dirty(p_fs->pbr_bh)))
sector_write(sb, p_fs->PBR_sector, p_fs->pbr_bh, 1);
else
sector_write(sb, p_fs->PBR_sector, p_fs->pbr_bh, 0);
}
/* XXX duyoung
* what can we do here? (cuz fs_set_vol_flags() is void)
*/
if ((new_flag == VOL_DIRTY) && (!buffer_dirty(p_fs->pbr_bh)))
sector_write(sb, p_fs->PBR_sector, p_fs->pbr_bh, 1);
else
sector_write(sb, p_fs->PBR_sector, p_fs->pbr_bh, 0);
}
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
if (p_fs->dev_ejected)
break;
if (p_fs->vol_type == EXFAT) {
if (p_dir->dir != p_fs->root_dir)
size = i_size_read(inode);
}
if (p_dir->dir != p_fs->root_dir)
size = i_size_read(inode);
last_clu = find_last_cluster(sb, p_dir);
clu.dir = last_clu + 1;
......@@ -1653,21 +1640,19 @@ s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir, s32 num_entries
p_dir->size++;
/* (3) update the directory entry */
if (p_fs->vol_type == EXFAT) {
if (p_dir->dir != p_fs->root_dir) {
size += p_fs->cluster_size;
ep = get_entry_in_dir(sb, &fid->dir,
fid->entry + 1, &sector);
if (!ep)
return -ENOENT;
p_fs->fs_func->set_entry_size(ep, size);
p_fs->fs_func->set_entry_flag(ep, p_dir->flags);
buf_modify(sb, sector);
update_dir_checksum(sb, &fid->dir,
fid->entry);
}
if (p_dir->dir != p_fs->root_dir) {
size += p_fs->cluster_size;
ep = get_entry_in_dir(sb, &fid->dir,
fid->entry + 1, &sector);
if (!ep)
return -ENOENT;
p_fs->fs_func->set_entry_size(ep, size);
p_fs->fs_func->set_entry_flag(ep, p_dir->flags);
buf_modify(sb, sector);
update_dir_checksum(sb, &fid->dir,
fid->entry);
}
i_size_write(inode, i_size_read(inode) + p_fs->cluster_size);
......@@ -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 dos_name_t *p_dosname)
{
s32 ret, num_entries;
bool lossy = false;
char **r;
s32 num_entries;
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
num_entries = p_fs->fs_func->calc_num_entries(p_uniname);
if (num_entries == 0)
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;
return 0;
......@@ -2392,7 +2354,7 @@ s32 create_dir(struct inode *inode, struct chain_t *p_dir,
s32 ret, dentry, num_entries;
u64 size;
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 fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
struct fs_func *fs_func = p_fs->fs_func;
......@@ -2422,45 +2384,7 @@ s32 create_dir(struct inode *inode, struct chain_t *p_dir,
if (ret != 0)
return ret;
if (p_fs->vol_type == EXFAT) {
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;
}
size = p_fs->cluster_size;
/* (2) update the directory entry */
/* make sub-dir entry in parent directory */
......@@ -2626,23 +2550,21 @@ s32 rename_file(struct inode *inode, struct chain_t *p_dir, s32 oldentry,
buf_modify(sb, sector_new);
buf_unlock(sb, sector_old);
if (p_fs->vol_type == EXFAT) {
epold = get_entry_in_dir(sb, p_dir, oldentry + 1,
&sector_old);
buf_lock(sb, sector_old);
epnew = get_entry_in_dir(sb, p_dir, newentry + 1,
&sector_new);
if (!epold || !epnew) {
buf_unlock(sb, sector_old);
return -ENOENT;
}
epold = get_entry_in_dir(sb, p_dir, oldentry + 1,
&sector_old);
buf_lock(sb, sector_old);
epnew = get_entry_in_dir(sb, p_dir, newentry + 1,
&sector_new);
memcpy((void *)epnew, (void *)epold, DENTRY_SIZE);
buf_modify(sb, sector_new);
if (!epold || !epnew) {
buf_unlock(sb, sector_old);
return -ENOENT;
}
memcpy((void *)epnew, (void *)epold, DENTRY_SIZE);
buf_modify(sb, sector_new);
buf_unlock(sb, sector_old);
ret = fs_func->init_ext_entry(sb, p_dir, newentry,
num_new_entries, p_uniname,
&dos_name);
......@@ -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;
sector_t sector_mov, sector_new;
struct chain_t clu;
struct dos_name_t dos_name;
struct dentry_t *epmov, *epnew;
struct super_block *sb = inode->i_sb;
......@@ -2736,36 +2657,20 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry,
buf_modify(sb, sector_new);
buf_unlock(sb, sector_mov);
if (p_fs->vol_type == EXFAT) {
epmov = get_entry_in_dir(sb, p_olddir, oldentry + 1,
&sector_mov);
buf_lock(sb, sector_mov);
epnew = get_entry_in_dir(sb, p_newdir, newentry + 1,
&sector_new);
if (!epmov || !epnew) {
buf_unlock(sb, sector_mov);
return -ENOENT;
}
memcpy((void *)epnew, (void *)epmov, DENTRY_SIZE);
buf_modify(sb, sector_new);
epmov = get_entry_in_dir(sb, p_olddir, oldentry + 1,
&sector_mov);
buf_lock(sb, sector_mov);
epnew = get_entry_in_dir(sb, p_newdir, newentry + 1,
&sector_new);
if (!epmov || !epnew) {
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);
return -ENOENT;
}
memcpy((void *)epnew, (void *)epmov, DENTRY_SIZE);
buf_modify(sb, sector_new);
buf_unlock(sb, sector_mov);
ret = fs_func->init_ext_entry(sb, p_newdir, newentry, num_new_entries,
p_uniname, &dos_name);
if (ret != 0)
......
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