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

staging: exfat: Clean up return codes - FFS_MEDIAERR

Convert FFS_MEDIAERR to (mostly) -ENOENT and -EIO.  Some additional code surgery
needed to propogate correct error codes upwards.
Signed-off-by: default avatarValdis Kletnieks <Valdis.Kletnieks@vt.edu>
Link: https://lore.kernel.org/r/20191112021000.42091-3-Valdis.Kletnieks@vt.eduSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 133c8874
...@@ -210,7 +210,6 @@ static inline u16 get_row_index(u16 i) ...@@ -210,7 +210,6 @@ static inline u16 get_row_index(u16 i)
/* return values */ /* return values */
#define FFS_SUCCESS 0 #define FFS_SUCCESS 0
#define FFS_MEDIAERR 1
#define FFS_MOUNTED 3 #define FFS_MOUNTED 3
#define FFS_NOTMOUNTED 4 #define FFS_NOTMOUNTED 4
#define FFS_ALIGNMENTERR 5 #define FFS_ALIGNMENTERR 5
......
...@@ -40,11 +40,11 @@ int bdev_read(struct super_block *sb, sector_t secno, struct buffer_head **bh, ...@@ -40,11 +40,11 @@ int bdev_read(struct super_block *sb, sector_t secno, struct buffer_head **bh,
long flags = sbi->debug_flags; long flags = sbi->debug_flags;
if (flags & EXFAT_DEBUGFLAGS_ERROR_RW) if (flags & EXFAT_DEBUGFLAGS_ERROR_RW)
return FFS_MEDIAERR; return -EIO;
#endif /* CONFIG_EXFAT_KERNEL_DEBUG */ #endif /* CONFIG_EXFAT_KERNEL_DEBUG */
if (!p_bd->opened) if (!p_bd->opened)
return FFS_MEDIAERR; return -ENODEV;
if (*bh) if (*bh)
__brelse(*bh); __brelse(*bh);
...@@ -62,7 +62,7 @@ int bdev_read(struct super_block *sb, sector_t secno, struct buffer_head **bh, ...@@ -62,7 +62,7 @@ int bdev_read(struct super_block *sb, sector_t secno, struct buffer_head **bh,
WARN(!p_fs->dev_ejected, WARN(!p_fs->dev_ejected,
"[EXFAT] No bh, device seems wrong or to be ejected.\n"); "[EXFAT] No bh, device seems wrong or to be ejected.\n");
return FFS_MEDIAERR; return -EIO;
} }
int bdev_write(struct super_block *sb, sector_t secno, struct buffer_head *bh, int bdev_write(struct super_block *sb, sector_t secno, struct buffer_head *bh,
...@@ -77,11 +77,11 @@ int bdev_write(struct super_block *sb, sector_t secno, struct buffer_head *bh, ...@@ -77,11 +77,11 @@ int bdev_write(struct super_block *sb, sector_t secno, struct buffer_head *bh,
long flags = sbi->debug_flags; long flags = sbi->debug_flags;
if (flags & EXFAT_DEBUGFLAGS_ERROR_RW) if (flags & EXFAT_DEBUGFLAGS_ERROR_RW)
return FFS_MEDIAERR; return -EIO;
#endif /* CONFIG_EXFAT_KERNEL_DEBUG */ #endif /* CONFIG_EXFAT_KERNEL_DEBUG */
if (!p_bd->opened) if (!p_bd->opened)
return FFS_MEDIAERR; return -ENODEV;
if (secno == bh->b_blocknr) { if (secno == bh->b_blocknr) {
lock_buffer(bh); lock_buffer(bh);
...@@ -89,7 +89,7 @@ int bdev_write(struct super_block *sb, sector_t secno, struct buffer_head *bh, ...@@ -89,7 +89,7 @@ int bdev_write(struct super_block *sb, sector_t secno, struct buffer_head *bh,
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
unlock_buffer(bh); unlock_buffer(bh);
if (sync && (sync_dirty_buffer(bh) != 0)) if (sync && (sync_dirty_buffer(bh) != 0))
return FFS_MEDIAERR; return -EIO;
} else { } else {
count = num_secs << p_bd->sector_size_bits; count = num_secs << p_bd->sector_size_bits;
...@@ -115,7 +115,7 @@ int bdev_write(struct super_block *sb, sector_t secno, struct buffer_head *bh, ...@@ -115,7 +115,7 @@ int bdev_write(struct super_block *sb, sector_t secno, struct buffer_head *bh,
WARN(!p_fs->dev_ejected, WARN(!p_fs->dev_ejected,
"[EXFAT] No bh, device seems wrong or to be ejected.\n"); "[EXFAT] No bh, device seems wrong or to be ejected.\n");
return FFS_MEDIAERR; return -EIO;
} }
int bdev_sync(struct super_block *sb) int bdev_sync(struct super_block *sb)
...@@ -126,11 +126,11 @@ int bdev_sync(struct super_block *sb) ...@@ -126,11 +126,11 @@ int bdev_sync(struct super_block *sb)
long flags = sbi->debug_flags; long flags = sbi->debug_flags;
if (flags & EXFAT_DEBUGFLAGS_ERROR_RW) if (flags & EXFAT_DEBUGFLAGS_ERROR_RW)
return FFS_MEDIAERR; return -EIO;
#endif /* CONFIG_EXFAT_KERNEL_DEBUG */ #endif /* CONFIG_EXFAT_KERNEL_DEBUG */
if (!p_bd->opened) if (!p_bd->opened)
return FFS_MEDIAERR; return -ENODEV;
return sync_blockdev(sb->s_bdev); return sync_blockdev(sb->s_bdev);
} }
...@@ -252,13 +252,13 @@ s32 exfat_alloc_cluster(struct super_block *sb, s32 num_alloc, ...@@ -252,13 +252,13 @@ s32 exfat_alloc_cluster(struct super_block *sb, s32 num_alloc,
} }
if (set_alloc_bitmap(sb, new_clu - 2) != FFS_SUCCESS) if (set_alloc_bitmap(sb, new_clu - 2) != FFS_SUCCESS)
return -1; return -EIO;
num_clusters++; num_clusters++;
if (p_chain->flags == 0x01) { if (p_chain->flags == 0x01) {
if (FAT_write(sb, new_clu, CLUSTER_32(~0)) < 0) if (FAT_write(sb, new_clu, CLUSTER_32(~0)) < 0)
return -1; return -EIO;
} }
if (p_chain->dir == CLUSTER_32(~0)) { if (p_chain->dir == CLUSTER_32(~0)) {
...@@ -266,7 +266,7 @@ s32 exfat_alloc_cluster(struct super_block *sb, s32 num_alloc, ...@@ -266,7 +266,7 @@ s32 exfat_alloc_cluster(struct super_block *sb, s32 num_alloc,
} else { } else {
if (p_chain->flags == 0x01) { if (p_chain->flags == 0x01) {
if (FAT_write(sb, last_clu, new_clu) < 0) if (FAT_write(sb, last_clu, new_clu) < 0)
return -1; return -EIO;
} }
} }
last_clu = new_clu; last_clu = new_clu;
...@@ -526,7 +526,7 @@ s32 load_alloc_bitmap(struct super_block *sb) ...@@ -526,7 +526,7 @@ s32 load_alloc_bitmap(struct super_block *sb)
ep = (struct bmap_dentry_t *)get_entry_in_dir(sb, &clu, ep = (struct bmap_dentry_t *)get_entry_in_dir(sb, &clu,
i, NULL); i, NULL);
if (!ep) if (!ep)
return FFS_MEDIAERR; return -ENOENT;
type = p_fs->fs_func->get_entry_type((struct dentry_t *)ep); type = p_fs->fs_func->get_entry_type((struct dentry_t *)ep);
...@@ -570,7 +570,7 @@ s32 load_alloc_bitmap(struct super_block *sb) ...@@ -570,7 +570,7 @@ s32 load_alloc_bitmap(struct super_block *sb)
} }
if (FAT_read(sb, clu.dir, &clu.dir) != 0) if (FAT_read(sb, clu.dir, &clu.dir) != 0)
return FFS_MEDIAERR; return -EIO;
} }
return -EFSCORRUPTED; return -EFSCORRUPTED;
...@@ -856,14 +856,14 @@ s32 load_upcase_table(struct super_block *sb) ...@@ -856,14 +856,14 @@ s32 load_upcase_table(struct super_block *sb)
clu.flags = 0x01; clu.flags = 0x01;
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
return FFS_MEDIAERR; return -EIO;
while (clu.dir != CLUSTER_32(~0)) { while (clu.dir != CLUSTER_32(~0)) {
for (i = 0; i < p_fs->dentries_per_clu; i++) { for (i = 0; i < p_fs->dentries_per_clu; i++) {
ep = (struct case_dentry_t *)get_entry_in_dir(sb, &clu, ep = (struct case_dentry_t *)get_entry_in_dir(sb, &clu,
i, NULL); i, NULL);
if (!ep) if (!ep)
return FFS_MEDIAERR; return -ENOENT;
type = p_fs->fs_func->get_entry_type((struct dentry_t *)ep); type = p_fs->fs_func->get_entry_type((struct dentry_t *)ep);
...@@ -883,7 +883,7 @@ s32 load_upcase_table(struct super_block *sb) ...@@ -883,7 +883,7 @@ s32 load_upcase_table(struct super_block *sb)
return FFS_SUCCESS; return FFS_SUCCESS;
} }
if (FAT_read(sb, clu.dir, &clu.dir) != 0) if (FAT_read(sb, clu.dir, &clu.dir) != 0)
return FFS_MEDIAERR; return -EIO;
} }
/* load default upcase table */ /* load default upcase table */
return __load_default_upcase_table(sb); return __load_default_upcase_table(sb);
...@@ -1246,7 +1246,7 @@ s32 fat_init_dir_entry(struct super_block *sb, struct chain_t *p_dir, s32 entry, ...@@ -1246,7 +1246,7 @@ s32 fat_init_dir_entry(struct super_block *sb, struct chain_t *p_dir, s32 entry,
dos_ep = (struct dos_dentry_t *)get_entry_in_dir(sb, p_dir, entry, dos_ep = (struct dos_dentry_t *)get_entry_in_dir(sb, p_dir, entry,
&sector); &sector);
if (!dos_ep) if (!dos_ep)
return FFS_MEDIAERR; return -EIO;
init_dos_entry(dos_ep, type, start_clu); init_dos_entry(dos_ep, type, start_clu);
buf_modify(sb, sector); buf_modify(sb, sector);
...@@ -1268,12 +1268,12 @@ s32 exfat_init_dir_entry(struct super_block *sb, struct chain_t *p_dir, ...@@ -1268,12 +1268,12 @@ s32 exfat_init_dir_entry(struct super_block *sb, struct chain_t *p_dir,
file_ep = (struct file_dentry_t *)get_entry_in_dir(sb, p_dir, entry, file_ep = (struct file_dentry_t *)get_entry_in_dir(sb, p_dir, entry,
&sector); &sector);
if (!file_ep) if (!file_ep)
return FFS_MEDIAERR; return -ENOENT;
strm_ep = (struct strm_dentry_t *)get_entry_in_dir(sb, p_dir, entry + 1, strm_ep = (struct strm_dentry_t *)get_entry_in_dir(sb, p_dir, entry + 1,
&sector); &sector);
if (!strm_ep) if (!strm_ep)
return FFS_MEDIAERR; return -ENOENT;
init_file_entry(file_ep, type); init_file_entry(file_ep, type);
buf_modify(sb, sector); buf_modify(sb, sector);
...@@ -1299,7 +1299,7 @@ static s32 fat_init_ext_entry(struct super_block *sb, struct chain_t *p_dir, ...@@ -1299,7 +1299,7 @@ static s32 fat_init_ext_entry(struct super_block *sb, struct chain_t *p_dir,
dos_ep = (struct dos_dentry_t *)get_entry_in_dir(sb, p_dir, entry, dos_ep = (struct dos_dentry_t *)get_entry_in_dir(sb, p_dir, entry,
&sector); &sector);
if (!dos_ep) if (!dos_ep)
return FFS_MEDIAERR; return -EIO;
dos_ep->lcase = p_dosname->name_case; dos_ep->lcase = p_dosname->name_case;
memcpy(dos_ep->name, p_dosname->name, DOS_NAME_LENGTH); memcpy(dos_ep->name, p_dosname->name, DOS_NAME_LENGTH);
...@@ -1315,7 +1315,7 @@ static s32 fat_init_ext_entry(struct super_block *sb, struct chain_t *p_dir, ...@@ -1315,7 +1315,7 @@ static s32 fat_init_ext_entry(struct super_block *sb, struct chain_t *p_dir,
entry - i, entry - i,
&sector); &sector);
if (!ext_ep) if (!ext_ep)
return FFS_MEDIAERR; return -EIO;
init_ext_entry(ext_ep, i, chksum, uniname); init_ext_entry(ext_ep, i, chksum, uniname);
buf_modify(sb, sector); buf_modify(sb, sector);
...@@ -1326,7 +1326,7 @@ static s32 fat_init_ext_entry(struct super_block *sb, struct chain_t *p_dir, ...@@ -1326,7 +1326,7 @@ static s32 fat_init_ext_entry(struct super_block *sb, struct chain_t *p_dir,
entry - i, entry - i,
&sector); &sector);
if (!ext_ep) if (!ext_ep)
return FFS_MEDIAERR; return -EIO;
init_ext_entry(ext_ep, i + 0x40, chksum, uniname); init_ext_entry(ext_ep, i + 0x40, chksum, uniname);
buf_modify(sb, sector); buf_modify(sb, sector);
...@@ -1350,7 +1350,7 @@ static s32 exfat_init_ext_entry(struct super_block *sb, struct chain_t *p_dir, ...@@ -1350,7 +1350,7 @@ static s32 exfat_init_ext_entry(struct super_block *sb, struct chain_t *p_dir,
file_ep = (struct file_dentry_t *)get_entry_in_dir(sb, p_dir, entry, file_ep = (struct file_dentry_t *)get_entry_in_dir(sb, p_dir, entry,
&sector); &sector);
if (!file_ep) if (!file_ep)
return FFS_MEDIAERR; return -ENOENT;
file_ep->num_ext = (u8)(num_entries - 1); file_ep->num_ext = (u8)(num_entries - 1);
buf_modify(sb, sector); buf_modify(sb, sector);
...@@ -1358,7 +1358,7 @@ static s32 exfat_init_ext_entry(struct super_block *sb, struct chain_t *p_dir, ...@@ -1358,7 +1358,7 @@ static s32 exfat_init_ext_entry(struct super_block *sb, struct chain_t *p_dir,
strm_ep = (struct strm_dentry_t *)get_entry_in_dir(sb, p_dir, entry + 1, strm_ep = (struct strm_dentry_t *)get_entry_in_dir(sb, p_dir, entry + 1,
&sector); &sector);
if (!strm_ep) if (!strm_ep)
return FFS_MEDIAERR; return -ENOENT;
strm_ep->name_len = p_uniname->name_len; strm_ep->name_len = p_uniname->name_len;
SET16_A(strm_ep->name_hash, p_uniname->name_hash); SET16_A(strm_ep->name_hash, p_uniname->name_hash);
...@@ -1369,7 +1369,7 @@ static s32 exfat_init_ext_entry(struct super_block *sb, struct chain_t *p_dir, ...@@ -1369,7 +1369,7 @@ static s32 exfat_init_ext_entry(struct super_block *sb, struct chain_t *p_dir,
entry + i, entry + i,
&sector); &sector);
if (!name_ep) if (!name_ep)
return FFS_MEDIAERR; return -ENOENT;
init_name_entry(name_ep, uniname); init_name_entry(name_ep, uniname);
buf_modify(sb, sector); buf_modify(sb, sector);
...@@ -1592,7 +1592,7 @@ static s32 _walk_fat_chain(struct super_block *sb, struct chain_t *p_dir, ...@@ -1592,7 +1592,7 @@ static s32 _walk_fat_chain(struct super_block *sb, struct chain_t *p_dir,
} else { } else {
while (clu_offset > 0) { while (clu_offset > 0) {
if (FAT_read(sb, cur_clu, &cur_clu) == -1) if (FAT_read(sb, cur_clu, &cur_clu) == -1)
return FFS_MEDIAERR; return -EIO;
clu_offset--; clu_offset--;
} }
} }
...@@ -2084,10 +2084,10 @@ s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir, s32 num_entries ...@@ -2084,10 +2084,10 @@ s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir, s32 num_entries
/* (1) allocate a cluster */ /* (1) allocate a cluster */
ret = p_fs->fs_func->alloc_cluster(sb, 1, &clu); ret = p_fs->fs_func->alloc_cluster(sb, 1, &clu);
if (ret < 1) if (ret < 1)
return -1; return -EIO;
if (clear_cluster(sb, clu.dir) != FFS_SUCCESS) if (clear_cluster(sb, clu.dir) != FFS_SUCCESS)
return -1; return -EIO;
/* (2) append to the FAT chain */ /* (2) append to the FAT chain */
if (clu.flags != p_dir->flags) { if (clu.flags != p_dir->flags) {
...@@ -2097,7 +2097,7 @@ s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir, s32 num_entries ...@@ -2097,7 +2097,7 @@ s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir, s32 num_entries
} }
if (clu.flags == 0x01) if (clu.flags == 0x01)
if (FAT_write(sb, last_clu, clu.dir) < 0) if (FAT_write(sb, last_clu, clu.dir) < 0)
return -1; return -EIO;
if (p_fs->hint_uentry.entry == -1) { if (p_fs->hint_uentry.entry == -1) {
p_fs->hint_uentry.dir = p_dir->dir; p_fs->hint_uentry.dir = p_dir->dir;
...@@ -2118,7 +2118,7 @@ s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir, s32 num_entries ...@@ -2118,7 +2118,7 @@ s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir, s32 num_entries
ep = get_entry_in_dir(sb, &fid->dir, ep = get_entry_in_dir(sb, &fid->dir,
fid->entry + 1, &sector); fid->entry + 1, &sector);
if (!ep) if (!ep)
return -1; return -ENOENT;
p_fs->fs_func->set_entry_size(ep, size); p_fs->fs_func->set_entry_size(ep, size);
p_fs->fs_func->set_entry_flag(ep, p_dir->flags); p_fs->fs_func->set_entry_flag(ep, p_dir->flags);
buf_modify(sb, sector); buf_modify(sb, sector);
...@@ -2464,7 +2464,7 @@ s32 count_dos_name_entries(struct super_block *sb, struct chain_t *p_dir, ...@@ -2464,7 +2464,7 @@ s32 count_dos_name_entries(struct super_block *sb, struct chain_t *p_dir,
for (i = 0; i < dentries_per_clu; i++) { for (i = 0; i < dentries_per_clu; i++) {
ep = get_entry_in_dir(sb, &clu, i, NULL); ep = get_entry_in_dir(sb, &clu, i, NULL);
if (!ep) if (!ep)
return -1; return -ENOENT;
entry_type = p_fs->fs_func->get_entry_type(ep); entry_type = p_fs->fs_func->get_entry_type(ep);
...@@ -2488,7 +2488,7 @@ s32 count_dos_name_entries(struct super_block *sb, struct chain_t *p_dir, ...@@ -2488,7 +2488,7 @@ s32 count_dos_name_entries(struct super_block *sb, struct chain_t *p_dir,
clu.dir = CLUSTER_32(~0); clu.dir = CLUSTER_32(~0);
} else { } else {
if (FAT_read(sb, clu.dir, &clu.dir) != 0) if (FAT_read(sb, clu.dir, &clu.dir) != 0)
return -1; return -EIO;
} }
} }
...@@ -2772,7 +2772,7 @@ s32 fat_generate_dos_name(struct super_block *sb, struct chain_t *p_dir, ...@@ -2772,7 +2772,7 @@ s32 fat_generate_dos_name(struct super_block *sb, struct chain_t *p_dir,
ep = (struct dos_dentry_t *)get_entry_in_dir(sb, &clu, ep = (struct dos_dentry_t *)get_entry_in_dir(sb, &clu,
i, NULL); i, NULL);
if (!ep) if (!ep)
return FFS_MEDIAERR; return -ENOENT;
type = p_fs->fs_func->get_entry_type((struct dentry_t *) type = p_fs->fs_func->get_entry_type((struct dentry_t *)
ep); ep);
...@@ -2811,7 +2811,7 @@ s32 fat_generate_dos_name(struct super_block *sb, struct chain_t *p_dir, ...@@ -2811,7 +2811,7 @@ s32 fat_generate_dos_name(struct super_block *sb, struct chain_t *p_dir,
break; /* FAT16 root_dir */ break; /* FAT16 root_dir */
if (FAT_read(sb, clu.dir, &clu.dir) != 0) if (FAT_read(sb, clu.dir, &clu.dir) != 0)
return FFS_MEDIAERR; return -EIO;
} }
count = 0; count = 0;
...@@ -3226,7 +3226,7 @@ s32 create_dir(struct inode *inode, struct chain_t *p_dir, ...@@ -3226,7 +3226,7 @@ s32 create_dir(struct inode *inode, struct chain_t *p_dir,
/* (1) allocate a cluster */ /* (1) allocate a cluster */
ret = fs_func->alloc_cluster(sb, 1, &clu); ret = fs_func->alloc_cluster(sb, 1, &clu);
if (ret < 0) if (ret < 0)
return FFS_MEDIAERR; return ret;
else if (ret == 0) else if (ret == 0)
return -ENOSPC; return -ENOSPC;
...@@ -3395,7 +3395,7 @@ s32 rename_file(struct inode *inode, struct chain_t *p_dir, s32 oldentry, ...@@ -3395,7 +3395,7 @@ s32 rename_file(struct inode *inode, struct chain_t *p_dir, s32 oldentry,
epold = get_entry_in_dir(sb, p_dir, oldentry, &sector_old); epold = get_entry_in_dir(sb, p_dir, oldentry, &sector_old);
if (!epold) if (!epold)
return FFS_MEDIAERR; return -ENOENT;
buf_lock(sb, sector_old); buf_lock(sb, sector_old);
...@@ -3404,7 +3404,7 @@ s32 rename_file(struct inode *inode, struct chain_t *p_dir, s32 oldentry, ...@@ -3404,7 +3404,7 @@ s32 rename_file(struct inode *inode, struct chain_t *p_dir, s32 oldentry,
epold); epold);
if (num_old_entries < 0) { if (num_old_entries < 0) {
buf_unlock(sb, sector_old); buf_unlock(sb, sector_old);
return FFS_MEDIAERR; return -ENOENT;
} }
num_old_entries++; num_old_entries++;
...@@ -3425,7 +3425,7 @@ s32 rename_file(struct inode *inode, struct chain_t *p_dir, s32 oldentry, ...@@ -3425,7 +3425,7 @@ s32 rename_file(struct inode *inode, struct chain_t *p_dir, s32 oldentry,
epnew = get_entry_in_dir(sb, p_dir, newentry, &sector_new); epnew = get_entry_in_dir(sb, p_dir, newentry, &sector_new);
if (!epnew) { if (!epnew) {
buf_unlock(sb, sector_old); buf_unlock(sb, sector_old);
return FFS_MEDIAERR; return -ENOENT;
} }
memcpy((void *)epnew, (void *)epold, DENTRY_SIZE); memcpy((void *)epnew, (void *)epold, DENTRY_SIZE);
...@@ -3447,7 +3447,7 @@ s32 rename_file(struct inode *inode, struct chain_t *p_dir, s32 oldentry, ...@@ -3447,7 +3447,7 @@ s32 rename_file(struct inode *inode, struct chain_t *p_dir, s32 oldentry,
if (!epold || !epnew) { if (!epold || !epnew) {
buf_unlock(sb, sector_old); buf_unlock(sb, sector_old);
return FFS_MEDIAERR; return -ENOENT;
} }
memcpy((void *)epnew, (void *)epold, DENTRY_SIZE); memcpy((void *)epnew, (void *)epold, DENTRY_SIZE);
...@@ -3502,7 +3502,7 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry, ...@@ -3502,7 +3502,7 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry,
epmov = get_entry_in_dir(sb, p_olddir, oldentry, &sector_mov); epmov = get_entry_in_dir(sb, p_olddir, oldentry, &sector_mov);
if (!epmov) if (!epmov)
return FFS_MEDIAERR; return -ENOENT;
/* check if the source and target directory is the same */ /* check if the source and target directory is the same */
if (fs_func->get_entry_type(epmov) == TYPE_DIR && if (fs_func->get_entry_type(epmov) == TYPE_DIR &&
...@@ -3516,7 +3516,7 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry, ...@@ -3516,7 +3516,7 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry,
epmov); epmov);
if (num_old_entries < 0) { if (num_old_entries < 0) {
buf_unlock(sb, sector_mov); buf_unlock(sb, sector_mov);
return FFS_MEDIAERR; return -ENOENT;
} }
num_old_entries++; num_old_entries++;
...@@ -3536,7 +3536,7 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry, ...@@ -3536,7 +3536,7 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry,
epnew = get_entry_in_dir(sb, p_newdir, newentry, &sector_new); epnew = get_entry_in_dir(sb, p_newdir, newentry, &sector_new);
if (!epnew) { if (!epnew) {
buf_unlock(sb, sector_mov); buf_unlock(sb, sector_mov);
return FFS_MEDIAERR; return -ENOENT;
} }
memcpy((void *)epnew, (void *)epmov, DENTRY_SIZE); memcpy((void *)epnew, (void *)epmov, DENTRY_SIZE);
...@@ -3556,7 +3556,7 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry, ...@@ -3556,7 +3556,7 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry,
&sector_new); &sector_new);
if (!epmov || !epnew) { if (!epmov || !epnew) {
buf_unlock(sb, sector_mov); buf_unlock(sb, sector_mov);
return FFS_MEDIAERR; return -ENOENT;
} }
memcpy((void *)epnew, (void *)epmov, DENTRY_SIZE); memcpy((void *)epnew, (void *)epmov, DENTRY_SIZE);
...@@ -3569,7 +3569,7 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry, ...@@ -3569,7 +3569,7 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry,
epnew = get_entry_in_dir(sb, &clu, 1, &sector_new); epnew = get_entry_in_dir(sb, &clu, 1, &sector_new);
if (!epnew) if (!epnew)
return FFS_MEDIAERR; return -ENOENT;
if (p_newdir->dir == p_fs->root_dir) if (p_newdir->dir == p_fs->root_dir)
fs_func->set_entry_clu0(epnew, CLUSTER_32(0)); fs_func->set_entry_clu0(epnew, CLUSTER_32(0));
...@@ -3601,7 +3601,7 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry, ...@@ -3601,7 +3601,7 @@ s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry,
int sector_read(struct super_block *sb, sector_t sec, struct buffer_head **bh, int sector_read(struct super_block *sb, sector_t sec, struct buffer_head **bh,
bool read) bool read)
{ {
s32 ret = FFS_MEDIAERR; s32 ret = -EIO;
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
if ((sec >= (p_fs->PBR_sector + p_fs->num_sectors)) && if ((sec >= (p_fs->PBR_sector + p_fs->num_sectors)) &&
...@@ -3624,7 +3624,7 @@ int sector_read(struct super_block *sb, sector_t sec, struct buffer_head **bh, ...@@ -3624,7 +3624,7 @@ int sector_read(struct super_block *sb, sector_t sec, struct buffer_head **bh,
int sector_write(struct super_block *sb, sector_t sec, struct buffer_head *bh, int sector_write(struct super_block *sb, sector_t sec, struct buffer_head *bh,
bool sync) bool sync)
{ {
s32 ret = FFS_MEDIAERR; s32 ret = -EIO;
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
if (sec >= (p_fs->PBR_sector + p_fs->num_sectors) && if (sec >= (p_fs->PBR_sector + p_fs->num_sectors) &&
...@@ -3653,7 +3653,7 @@ int sector_write(struct super_block *sb, sector_t sec, struct buffer_head *bh, ...@@ -3653,7 +3653,7 @@ int sector_write(struct super_block *sb, sector_t sec, struct buffer_head *bh,
int multi_sector_read(struct super_block *sb, sector_t sec, int multi_sector_read(struct super_block *sb, sector_t sec,
struct buffer_head **bh, s32 num_secs, bool read) struct buffer_head **bh, s32 num_secs, bool read)
{ {
s32 ret = FFS_MEDIAERR; s32 ret = -EIO;
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
if (((sec + num_secs) > (p_fs->PBR_sector + p_fs->num_sectors)) && if (((sec + num_secs) > (p_fs->PBR_sector + p_fs->num_sectors)) &&
...@@ -3676,7 +3676,7 @@ int multi_sector_read(struct super_block *sb, sector_t sec, ...@@ -3676,7 +3676,7 @@ int multi_sector_read(struct super_block *sb, sector_t sec,
int multi_sector_write(struct super_block *sb, sector_t sec, int multi_sector_write(struct super_block *sb, sector_t sec,
struct buffer_head *bh, s32 num_secs, bool sync) struct buffer_head *bh, s32 num_secs, bool sync)
{ {
s32 ret = FFS_MEDIAERR; s32 ret = -EIO;
struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
if ((sec + num_secs) > (p_fs->PBR_sector + p_fs->num_sectors) && if ((sec + num_secs) > (p_fs->PBR_sector + p_fs->num_sectors) &&
......
...@@ -364,7 +364,9 @@ static int ffsMountVol(struct super_block *sb) ...@@ -364,7 +364,9 @@ static int ffsMountVol(struct super_block *sb)
bdev_open(sb); bdev_open(sb);
if (p_bd->sector_size < sb->s_blocksize) { if (p_bd->sector_size < sb->s_blocksize) {
ret = FFS_MEDIAERR; printk(KERN_INFO "EXFAT: maont failed - sector size %d less than blocksize %ld\n",
p_bd->sector_size, sb->s_blocksize);
ret = -EINVAL;
goto out; goto out;
} }
if (p_bd->sector_size > sb->s_blocksize) if (p_bd->sector_size > sb->s_blocksize)
...@@ -372,7 +374,7 @@ static int ffsMountVol(struct super_block *sb) ...@@ -372,7 +374,7 @@ static int ffsMountVol(struct super_block *sb)
/* read Sector 0 */ /* read Sector 0 */
if (sector_read(sb, 0, &tmp_bh, 1) != FFS_SUCCESS) { if (sector_read(sb, 0, &tmp_bh, 1) != FFS_SUCCESS) {
ret = FFS_MEDIAERR; ret = -EIO;
goto out; goto out;
} }
...@@ -435,7 +437,7 @@ static int ffsMountVol(struct super_block *sb) ...@@ -435,7 +437,7 @@ static int ffsMountVol(struct super_block *sb)
free_alloc_bitmap(sb); free_alloc_bitmap(sb);
} }
bdev_close(sb); bdev_close(sb);
ret = FFS_MEDIAERR; ret = -EIO;
goto out; goto out;
} }
...@@ -475,7 +477,7 @@ static int ffsUmountVol(struct super_block *sb) ...@@ -475,7 +477,7 @@ static int ffsUmountVol(struct super_block *sb)
if (p_fs->dev_ejected) { if (p_fs->dev_ejected) {
pr_info("[EXFAT] unmounted with media errors. Device is already ejected.\n"); pr_info("[EXFAT] unmounted with media errors. Device is already ejected.\n");
err = FFS_MEDIAERR; err = -EIO;
} }
buf_shutdown(sb); buf_shutdown(sb);
...@@ -511,7 +513,7 @@ static int ffsGetVolInfo(struct super_block *sb, struct vol_info_t *info) ...@@ -511,7 +513,7 @@ static int ffsGetVolInfo(struct super_block *sb, struct vol_info_t *info)
info->FreeClusters = info->NumClusters - info->UsedClusters; info->FreeClusters = info->NumClusters - info->UsedClusters;
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
err = FFS_MEDIAERR; err = -EIO;
/* release the lock for file system critical section */ /* release the lock for file system critical section */
mutex_unlock(&p_fs->v_mutex); mutex_unlock(&p_fs->v_mutex);
...@@ -532,7 +534,7 @@ static int ffsSyncVol(struct super_block *sb, bool do_sync) ...@@ -532,7 +534,7 @@ static int ffsSyncVol(struct super_block *sb, bool do_sync)
fs_set_vol_flags(sb, VOL_CLEAN); fs_set_vol_flags(sb, VOL_CLEAN);
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
err = FFS_MEDIAERR; err = -EIO;
/* release the lock for file system critical section */ /* release the lock for file system critical section */
mutex_unlock(&p_fs->v_mutex); mutex_unlock(&p_fs->v_mutex);
...@@ -601,14 +603,14 @@ static int ffsLookupFile(struct inode *inode, char *path, struct file_id_t *fid) ...@@ -601,14 +603,14 @@ static int ffsLookupFile(struct inode *inode, char *path, struct file_id_t *fid)
es = get_entry_set_in_dir(sb, &dir, dentry, es = get_entry_set_in_dir(sb, &dir, dentry,
ES_2_ENTRIES, &ep); ES_2_ENTRIES, &ep);
if (!es) { if (!es) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out; goto out;
} }
ep2 = ep + 1; ep2 = ep + 1;
} else { } else {
ep = get_entry_in_dir(sb, &dir, dentry, NULL); ep = get_entry_in_dir(sb, &dir, dentry, NULL);
if (!ep) { if (!ep) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out; goto out;
} }
ep2 = ep; ep2 = ep;
...@@ -633,7 +635,7 @@ static int ffsLookupFile(struct inode *inode, char *path, struct file_id_t *fid) ...@@ -633,7 +635,7 @@ static int ffsLookupFile(struct inode *inode, char *path, struct file_id_t *fid)
} }
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
out: out:
/* release the lock for file system critical section */ /* release the lock for file system critical section */
mutex_unlock(&p_fs->v_mutex); mutex_unlock(&p_fs->v_mutex);
...@@ -673,7 +675,7 @@ static int ffsCreateFile(struct inode *inode, char *path, u8 mode, ...@@ -673,7 +675,7 @@ static int ffsCreateFile(struct inode *inode, char *path, u8 mode,
#endif #endif
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
out: out:
/* release the lock for file system critical section */ /* release the lock for file system critical section */
...@@ -744,7 +746,7 @@ static int ffsReadFile(struct inode *inode, struct file_id_t *fid, void *buffer, ...@@ -744,7 +746,7 @@ static int ffsReadFile(struct inode *inode, struct file_id_t *fid, void *buffer,
while (clu_offset > 0) { while (clu_offset > 0) {
/* clu = FAT_read(sb, clu); */ /* clu = FAT_read(sb, clu); */
if (FAT_read(sb, clu, &clu) == -1) { if (FAT_read(sb, clu, &clu) == -1) {
ret = FFS_MEDIAERR; ret = -EIO;
goto out; goto out;
} }
...@@ -799,7 +801,7 @@ static int ffsReadFile(struct inode *inode, struct file_id_t *fid, void *buffer, ...@@ -799,7 +801,7 @@ static int ffsReadFile(struct inode *inode, struct file_id_t *fid, void *buffer,
*rcount = read_bytes; *rcount = read_bytes;
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
out: out:
/* release the lock for file system critical section */ /* release the lock for file system critical section */
...@@ -890,7 +892,7 @@ static int ffsWriteFile(struct inode *inode, struct file_id_t *fid, ...@@ -890,7 +892,7 @@ static int ffsWriteFile(struct inode *inode, struct file_id_t *fid,
last_clu = clu; last_clu = clu;
/* clu = FAT_read(sb, clu); */ /* clu = FAT_read(sb, clu); */
if (FAT_read(sb, clu, &clu) == -1) { if (FAT_read(sb, clu, &clu) == -1) {
ret = FFS_MEDIAERR; ret = -EIO;
goto out; goto out;
} }
clu_offset--; clu_offset--;
...@@ -912,7 +914,7 @@ static int ffsWriteFile(struct inode *inode, struct file_id_t *fid, ...@@ -912,7 +914,7 @@ static int ffsWriteFile(struct inode *inode, struct file_id_t *fid,
if (num_alloced == 0) if (num_alloced == 0)
break; break;
if (num_alloced < 0) { if (num_alloced < 0) {
ret = FFS_MEDIAERR; ret = num_alloced;
goto out; goto out;
} }
...@@ -1057,7 +1059,7 @@ static int ffsWriteFile(struct inode *inode, struct file_id_t *fid, ...@@ -1057,7 +1059,7 @@ static int ffsWriteFile(struct inode *inode, struct file_id_t *fid,
ret = -ENOSPC; ret = -ENOSPC;
else if (p_fs->dev_ejected) else if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
out: out:
/* release the lock for file system critical section */ /* release the lock for file system critical section */
...@@ -1118,7 +1120,7 @@ static int ffsTruncateFile(struct inode *inode, u64 old_size, u64 new_size) ...@@ -1118,7 +1120,7 @@ static int ffsTruncateFile(struct inode *inode, u64 old_size, u64 new_size)
while (num_clusters > 0) { while (num_clusters > 0) {
last_clu = clu.dir; last_clu = clu.dir;
if (FAT_read(sb, clu.dir, &clu.dir) == -1) { if (FAT_read(sb, clu.dir, &clu.dir) == -1) {
ret = FFS_MEDIAERR; ret = -EIO;
goto out; goto out;
} }
num_clusters--; num_clusters--;
...@@ -1140,14 +1142,14 @@ static int ffsTruncateFile(struct inode *inode, u64 old_size, u64 new_size) ...@@ -1140,14 +1142,14 @@ static int ffsTruncateFile(struct inode *inode, u64 old_size, u64 new_size)
es = get_entry_set_in_dir(sb, &fid->dir, fid->entry, es = get_entry_set_in_dir(sb, &fid->dir, fid->entry,
ES_ALL_ENTRIES, &ep); ES_ALL_ENTRIES, &ep);
if (!es) { if (!es) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out; goto out;
} }
ep2 = ep + 1; ep2 = ep + 1;
} else { } else {
ep = get_entry_in_dir(sb, &fid->dir, fid->entry, &sector); ep = get_entry_in_dir(sb, &fid->dir, fid->entry, &sector);
if (!ep) { if (!ep) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out; goto out;
} }
ep2 = ep; ep2 = ep;
...@@ -1189,7 +1191,7 @@ static int ffsTruncateFile(struct inode *inode, u64 old_size, u64 new_size) ...@@ -1189,7 +1191,7 @@ static int ffsTruncateFile(struct inode *inode, u64 old_size, u64 new_size)
#endif #endif
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
out: out:
pr_debug("%s exited (%d)\n", __func__, ret); pr_debug("%s exited (%d)\n", __func__, ret);
...@@ -1262,7 +1264,7 @@ static int ffsMoveFile(struct inode *old_parent_inode, struct file_id_t *fid, ...@@ -1262,7 +1264,7 @@ static int ffsMoveFile(struct inode *old_parent_inode, struct file_id_t *fid,
ep = get_entry_in_dir(sb, &olddir, dentry, NULL); ep = get_entry_in_dir(sb, &olddir, dentry, NULL);
if (!ep) { if (!ep) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out2; goto out2;
} }
...@@ -1275,7 +1277,7 @@ static int ffsMoveFile(struct inode *old_parent_inode, struct file_id_t *fid, ...@@ -1275,7 +1277,7 @@ static int ffsMoveFile(struct inode *old_parent_inode, struct file_id_t *fid,
if (new_inode) { if (new_inode) {
u32 entry_type; u32 entry_type;
ret = FFS_MEDIAERR; ret = -ENOENT;
new_fid = &EXFAT_I(new_inode)->fid; new_fid = &EXFAT_I(new_inode)->fid;
update_parent_info(new_fid, new_parent_inode); update_parent_info(new_fid, new_parent_inode);
...@@ -1337,7 +1339,7 @@ static int ffsMoveFile(struct inode *old_parent_inode, struct file_id_t *fid, ...@@ -1337,7 +1339,7 @@ static int ffsMoveFile(struct inode *old_parent_inode, struct file_id_t *fid,
#endif #endif
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
out2: out2:
/* release the lock for file system critical section */ /* release the lock for file system critical section */
mutex_unlock(&p_fs->v_mutex); mutex_unlock(&p_fs->v_mutex);
...@@ -1369,7 +1371,7 @@ static int ffsRemoveFile(struct inode *inode, struct file_id_t *fid) ...@@ -1369,7 +1371,7 @@ static int ffsRemoveFile(struct inode *inode, struct file_id_t *fid)
ep = get_entry_in_dir(sb, &dir, dentry, NULL); ep = get_entry_in_dir(sb, &dir, dentry, NULL);
if (!ep) { if (!ep) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out; goto out;
} }
...@@ -1399,7 +1401,7 @@ static int ffsRemoveFile(struct inode *inode, struct file_id_t *fid) ...@@ -1399,7 +1401,7 @@ static int ffsRemoveFile(struct inode *inode, struct file_id_t *fid)
#endif #endif
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
out: out:
/* release the lock for file system critical section */ /* release the lock for file system critical section */
mutex_unlock(&p_fs->v_mutex); mutex_unlock(&p_fs->v_mutex);
...@@ -1423,7 +1425,7 @@ static int ffsSetAttr(struct inode *inode, u32 attr) ...@@ -1423,7 +1425,7 @@ static int ffsSetAttr(struct inode *inode, u32 attr)
if (fid->attr == attr) { if (fid->attr == attr) {
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
return FFS_MEDIAERR; return -EIO;
return FFS_SUCCESS; return FFS_SUCCESS;
} }
...@@ -1431,7 +1433,7 @@ static int ffsSetAttr(struct inode *inode, u32 attr) ...@@ -1431,7 +1433,7 @@ static int ffsSetAttr(struct inode *inode, u32 attr)
if ((fid->dir.dir == p_fs->root_dir) && if ((fid->dir.dir == p_fs->root_dir) &&
(fid->entry == -1)) { (fid->entry == -1)) {
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
return FFS_MEDIAERR; return -EIO;
return FFS_SUCCESS; return FFS_SUCCESS;
} }
} }
...@@ -1444,13 +1446,13 @@ static int ffsSetAttr(struct inode *inode, u32 attr) ...@@ -1444,13 +1446,13 @@ static int ffsSetAttr(struct inode *inode, u32 attr)
es = get_entry_set_in_dir(sb, &fid->dir, fid->entry, es = get_entry_set_in_dir(sb, &fid->dir, fid->entry,
ES_ALL_ENTRIES, &ep); ES_ALL_ENTRIES, &ep);
if (!es) { if (!es) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out; goto out;
} }
} else { } else {
ep = get_entry_in_dir(sb, &fid->dir, fid->entry, &sector); ep = get_entry_in_dir(sb, &fid->dir, fid->entry, &sector);
if (!ep) { if (!ep) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out; goto out;
} }
} }
...@@ -1460,7 +1462,7 @@ static int ffsSetAttr(struct inode *inode, u32 attr) ...@@ -1460,7 +1462,7 @@ static int ffsSetAttr(struct inode *inode, u32 attr)
if (((type == TYPE_FILE) && (attr & ATTR_SUBDIR)) || if (((type == TYPE_FILE) && (attr & ATTR_SUBDIR)) ||
((type == TYPE_DIR) && (!(attr & ATTR_SUBDIR)))) { ((type == TYPE_DIR) && (!(attr & ATTR_SUBDIR)))) {
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
else else
ret = FFS_ERROR; ret = FFS_ERROR;
...@@ -1488,7 +1490,7 @@ static int ffsSetAttr(struct inode *inode, u32 attr) ...@@ -1488,7 +1490,7 @@ static int ffsSetAttr(struct inode *inode, u32 attr)
#endif #endif
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
out: out:
/* release the lock for file system critical section */ /* release the lock for file system critical section */
mutex_unlock(&p_fs->v_mutex); mutex_unlock(&p_fs->v_mutex);
...@@ -1544,13 +1546,13 @@ static int ffsReadStat(struct inode *inode, struct dir_entry_t *info) ...@@ -1544,13 +1546,13 @@ static int ffsReadStat(struct inode *inode, struct dir_entry_t *info)
count = count_dos_name_entries(sb, &dir, TYPE_DIR); count = count_dos_name_entries(sb, &dir, TYPE_DIR);
if (count < 0) { if (count < 0) {
ret = FFS_MEDIAERR; ret = count; /* propogate error upward */
goto out; goto out;
} }
info->NumSubdirs = count; info->NumSubdirs = count;
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
goto out; goto out;
} }
} }
...@@ -1560,14 +1562,14 @@ static int ffsReadStat(struct inode *inode, struct dir_entry_t *info) ...@@ -1560,14 +1562,14 @@ static int ffsReadStat(struct inode *inode, struct dir_entry_t *info)
es = get_entry_set_in_dir(sb, &fid->dir, fid->entry, es = get_entry_set_in_dir(sb, &fid->dir, fid->entry,
ES_2_ENTRIES, &ep); ES_2_ENTRIES, &ep);
if (!es) { if (!es) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out; goto out;
} }
ep2 = ep + 1; ep2 = ep + 1;
} else { } else {
ep = get_entry_in_dir(sb, &fid->dir, fid->entry, &sector); ep = get_entry_in_dir(sb, &fid->dir, fid->entry, &sector);
if (!ep) { if (!ep) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out; goto out;
} }
ep2 = ep; ep2 = ep;
...@@ -1633,14 +1635,14 @@ static int ffsReadStat(struct inode *inode, struct dir_entry_t *info) ...@@ -1633,14 +1635,14 @@ static int ffsReadStat(struct inode *inode, struct dir_entry_t *info)
count = count_dos_name_entries(sb, &dir, TYPE_DIR); count = count_dos_name_entries(sb, &dir, TYPE_DIR);
if (count < 0) { if (count < 0) {
ret = FFS_MEDIAERR; ret = count; /* propogate error upward */
goto out; goto out;
} }
info->NumSubdirs += count; info->NumSubdirs += count;
} }
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
out: out:
/* release the lock for file system critical section */ /* release the lock for file system critical section */
...@@ -1671,7 +1673,7 @@ static int ffsWriteStat(struct inode *inode, struct dir_entry_t *info) ...@@ -1671,7 +1673,7 @@ static int ffsWriteStat(struct inode *inode, struct dir_entry_t *info)
if ((fid->dir.dir == p_fs->root_dir) && if ((fid->dir.dir == p_fs->root_dir) &&
(fid->entry == -1)) { (fid->entry == -1)) {
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
ret = FFS_SUCCESS; ret = FFS_SUCCESS;
goto out; goto out;
} }
...@@ -1684,7 +1686,7 @@ static int ffsWriteStat(struct inode *inode, struct dir_entry_t *info) ...@@ -1684,7 +1686,7 @@ static int ffsWriteStat(struct inode *inode, struct dir_entry_t *info)
es = get_entry_set_in_dir(sb, &fid->dir, fid->entry, es = get_entry_set_in_dir(sb, &fid->dir, fid->entry,
ES_ALL_ENTRIES, &ep); ES_ALL_ENTRIES, &ep);
if (!es) { if (!es) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out; goto out;
} }
ep2 = ep + 1; ep2 = ep + 1;
...@@ -1692,7 +1694,7 @@ static int ffsWriteStat(struct inode *inode, struct dir_entry_t *info) ...@@ -1692,7 +1694,7 @@ static int ffsWriteStat(struct inode *inode, struct dir_entry_t *info)
/* for other than exfat */ /* for other than exfat */
ep = get_entry_in_dir(sb, &fid->dir, fid->entry, &sector); ep = get_entry_in_dir(sb, &fid->dir, fid->entry, &sector);
if (!ep) { if (!ep) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out; goto out;
} }
ep2 = ep; ep2 = ep;
...@@ -1727,7 +1729,7 @@ static int ffsWriteStat(struct inode *inode, struct dir_entry_t *info) ...@@ -1727,7 +1729,7 @@ static int ffsWriteStat(struct inode *inode, struct dir_entry_t *info)
} }
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
out: out:
/* release the lock for file system critical section */ /* release the lock for file system critical section */
...@@ -1789,7 +1791,7 @@ static int ffsMapCluster(struct inode *inode, s32 clu_offset, u32 *clu) ...@@ -1789,7 +1791,7 @@ static int ffsMapCluster(struct inode *inode, s32 clu_offset, u32 *clu)
while ((clu_offset > 0) && (*clu != CLUSTER_32(~0))) { while ((clu_offset > 0) && (*clu != CLUSTER_32(~0))) {
last_clu = *clu; last_clu = *clu;
if (FAT_read(sb, *clu, clu) == -1) { if (FAT_read(sb, *clu, clu) == -1) {
ret = FFS_MEDIAERR; ret = -EIO;
goto out; goto out;
} }
clu_offset--; clu_offset--;
...@@ -1807,7 +1809,7 @@ static int ffsMapCluster(struct inode *inode, s32 clu_offset, u32 *clu) ...@@ -1807,7 +1809,7 @@ static int ffsMapCluster(struct inode *inode, s32 clu_offset, u32 *clu)
/* (1) allocate a cluster */ /* (1) allocate a cluster */
num_alloced = p_fs->fs_func->alloc_cluster(sb, 1, &new_clu); num_alloced = p_fs->fs_func->alloc_cluster(sb, 1, &new_clu);
if (num_alloced < 0) { if (num_alloced < 0) {
ret = FFS_MEDIAERR; ret = -EIO;
goto out; goto out;
} else if (num_alloced == 0) { } else if (num_alloced == 0) {
ret = -ENOSPC; ret = -ENOSPC;
...@@ -1838,7 +1840,7 @@ static int ffsMapCluster(struct inode *inode, s32 clu_offset, u32 *clu) ...@@ -1838,7 +1840,7 @@ static int ffsMapCluster(struct inode *inode, s32 clu_offset, u32 *clu)
es = get_entry_set_in_dir(sb, &fid->dir, fid->entry, es = get_entry_set_in_dir(sb, &fid->dir, fid->entry,
ES_ALL_ENTRIES, &ep); ES_ALL_ENTRIES, &ep);
if (!es) { if (!es) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out; goto out;
} }
/* get stream entry */ /* get stream entry */
...@@ -1851,7 +1853,7 @@ static int ffsMapCluster(struct inode *inode, s32 clu_offset, u32 *clu) ...@@ -1851,7 +1853,7 @@ static int ffsMapCluster(struct inode *inode, s32 clu_offset, u32 *clu)
ep = get_entry_in_dir(sb, &fid->dir, ep = get_entry_in_dir(sb, &fid->dir,
fid->entry, &sector); fid->entry, &sector);
if (!ep) { if (!ep) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out; goto out;
} }
} }
...@@ -1881,7 +1883,7 @@ static int ffsMapCluster(struct inode *inode, s32 clu_offset, u32 *clu) ...@@ -1881,7 +1883,7 @@ static int ffsMapCluster(struct inode *inode, s32 clu_offset, u32 *clu)
fid->hint_last_clu = *clu; fid->hint_last_clu = *clu;
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
out: out:
/* release the lock for file system critical section */ /* release the lock for file system critical section */
...@@ -1926,7 +1928,7 @@ static int ffsCreateDir(struct inode *inode, char *path, struct file_id_t *fid) ...@@ -1926,7 +1928,7 @@ static int ffsCreateDir(struct inode *inode, char *path, struct file_id_t *fid)
#endif #endif
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
out: out:
/* release the lock for file system critical section */ /* release the lock for file system critical section */
mutex_unlock(&p_fs->v_mutex); mutex_unlock(&p_fs->v_mutex);
...@@ -1956,7 +1958,7 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry) ...@@ -1956,7 +1958,7 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry)
/* check if the given file ID is opened */ /* check if the given file ID is opened */
if (fid->type != TYPE_DIR) if (fid->type != TYPE_DIR)
return -EPERM; return -ENOTDIR;
/* acquire the lock for file system critical section */ /* acquire the lock for file system critical section */
mutex_lock(&p_fs->v_mutex); mutex_lock(&p_fs->v_mutex);
...@@ -2006,7 +2008,7 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry) ...@@ -2006,7 +2008,7 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry)
while (clu_offset > 0) { while (clu_offset > 0) {
/* clu.dir = FAT_read(sb, clu.dir); */ /* clu.dir = FAT_read(sb, clu.dir); */
if (FAT_read(sb, clu.dir, &clu.dir) == -1) { if (FAT_read(sb, clu.dir, &clu.dir) == -1) {
ret = FFS_MEDIAERR; ret = -EIO;
goto out; goto out;
} }
clu_offset--; clu_offset--;
...@@ -2026,7 +2028,7 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry) ...@@ -2026,7 +2028,7 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry)
for ( ; i < dentries_per_clu; i++, dentry++) { for ( ; i < dentries_per_clu; i++, dentry++) {
ep = get_entry_in_dir(sb, &clu, i, &sector); ep = get_entry_in_dir(sb, &clu, i, &sector);
if (!ep) { if (!ep) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out; goto out;
} }
type = fs_func->get_entry_type(ep); type = fs_func->get_entry_type(ep);
...@@ -2074,7 +2076,7 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry) ...@@ -2074,7 +2076,7 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry)
if (p_fs->vol_type == EXFAT) { if (p_fs->vol_type == EXFAT) {
ep = get_entry_in_dir(sb, &clu, i + 1, NULL); ep = get_entry_in_dir(sb, &clu, i + 1, NULL);
if (!ep) { if (!ep) {
ret = FFS_MEDIAERR; ret = -ENOENT;
goto out; goto out;
} }
} else { } else {
...@@ -2098,7 +2100,7 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry) ...@@ -2098,7 +2100,7 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry)
fid->rwoffset = (s64)(++dentry); fid->rwoffset = (s64)(++dentry);
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
goto out; goto out;
} }
...@@ -2113,7 +2115,7 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry) ...@@ -2113,7 +2115,7 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry)
} else { } else {
/* clu.dir = FAT_read(sb, clu.dir); */ /* clu.dir = FAT_read(sb, clu.dir); */
if (FAT_read(sb, clu.dir, &clu.dir) == -1) { if (FAT_read(sb, clu.dir, &clu.dir) == -1) {
ret = FFS_MEDIAERR; ret = -EIO;
goto out; goto out;
} }
} }
...@@ -2124,7 +2126,7 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry) ...@@ -2124,7 +2126,7 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry)
fid->rwoffset = (s64)(++dentry); fid->rwoffset = (s64)(++dentry);
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
out: out:
/* release the lock for file system critical section */ /* release the lock for file system critical section */
...@@ -2187,7 +2189,7 @@ static int ffsRemoveDir(struct inode *inode, struct file_id_t *fid) ...@@ -2187,7 +2189,7 @@ static int ffsRemoveDir(struct inode *inode, struct file_id_t *fid)
#endif #endif
if (p_fs->dev_ejected) if (p_fs->dev_ejected)
ret = FFS_MEDIAERR; ret = -EIO;
out: out:
/* release the lock for file system critical section */ /* release the lock for file system critical section */
...@@ -2247,12 +2249,11 @@ static int exfat_readdir(struct file *filp, struct dir_context *ctx) ...@@ -2247,12 +2249,11 @@ static int exfat_readdir(struct file *filp, struct dir_context *ctx)
/* at least we tried to read a sector /* at least we tried to read a sector
* move cpos to next sector position (should be aligned) * move cpos to next sector position (should be aligned)
*/ */
if (err == FFS_MEDIAERR) { if (err == -EIO) {
cpos += 1 << p_bd->sector_size_bits; cpos += 1 << p_bd->sector_size_bits;
cpos &= ~((1 << p_bd->sector_size_bits) - 1); cpos &= ~((1 << p_bd->sector_size_bits) - 1);
} }
err = -EIO;
goto end_of_dir; goto end_of_dir;
} }
...@@ -3550,7 +3551,7 @@ static int exfat_statfs(struct dentry *dentry, struct kstatfs *buf) ...@@ -3550,7 +3551,7 @@ static int exfat_statfs(struct dentry *dentry, struct kstatfs *buf)
struct vol_info_t info; struct vol_info_t info;
if (p_fs->used_clusters == UINT_MAX) { if (p_fs->used_clusters == UINT_MAX) {
if (ffsGetVolInfo(sb, &info) == FFS_MEDIAERR) if (ffsGetVolInfo(sb, &info) == -EIO)
return -EIO; return -EIO;
} else { } else {
......
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