more use new fat_get_cluster (9/11)
OGAWA Hirofumi
maintainerPATCH 1/1 more use new fat_get_cluster (9/11)
This uses new fat_get_cluster() in fat_free(), fat_calc_dir_size() and fat_add_cluster().
fs/fat/cache.c | 50 +++++++++++++++++++++++----------------- fs/fat/inode.c | 27 ++++----------------- fs/fat/misc.c | 71 +++++++++++++++++++++------------------------------------ 3 files changed, 62 insertions(+), 86 deletions(-)
fs/fat/cache.c renamed from fs/fat/cache.c~fat_use-get_cluster2 +29 -21
@@ -232,6 +232,8 @@ void fat_cache_add(struct inode *inode,struct fat_cache *walk, *last;int first, prev_f_clu, prev_d_clu; +if (f_clu ==0 ) +return ; first =MSDOS_I (inode)->i_start;if (!first)return ;
@@ -380,41 +382,47 @@ int fat_bmap(struct inode *inode, sectorreturn 0 ; } - -/* Free all clusters after the skip'th cluster. Doesn't use the cache, -because this way we get an additional sanity check. */ - -int fat_free (struct inode *inode,int skip) +/* Free all clusters after the skip'th cluster. */ +int fat_free (struct inode *inode,int skip) {struct super_block *sb = inode->i_sb; -int nr,last; +int nr, ret, fclus, dclus; -if (!(nr =MSDOS_I (inode)->i_start))return 0 ; - last =0 ; -while (skip--) { - last = nr; - nr =fat_access (sb, nr,-1 ); +if (MSDOS_I (inode)->i_start ==0 ) +return 0 ; + +if (skip) { + ret =fat_get_cluster (inode, skip -1 , &fclus, &dclus); +if (ret <0 ) +return ret; +else if (ret ==FAT_ENT_EOF ) +return 0 ; + + nr =fat_access (sb, dclus,-1 );if (nr ==FAT_ENT_EOF )return 0 ; -else if (nr ==FAT_ENT_FREE ) { -fat_fs_panic (sb,"%s: invalid cluster chain (ino %lu)" , - __FUNCTION__, inode->i_ino); -return -EIO ; - }else if (nr <0 ) +else if (nr >0 ) { +/* +* write a new EOF, and get the remaining cluster +* chain for freeing. +*/ + nr =fat_access (sb, dclus,FAT_ENT_EOF ); + } +if (nr <0 )return nr; - } -if (last) { -fat_access (sb, last,FAT_ENT_EOF ); +fat_cache_inval_inode (inode); }else {fat_cache_inval_inode (inode); + + nr =MSDOS_I (inode)->i_start;MSDOS_I (inode)->i_start =0 ;MSDOS_I (inode)->i_logstart =0 ;mark_inode_dirty (inode); }lock_fat (sb); -while (nr !=FAT_ENT_EOF ) { + do { nr = fat_access(sb, nr, FAT_ENT_FREE); if (nr < 0) goto error;
@@ -427,7 +435,7 @@ int fat_free(struct inode *inode,int skiif (MSDOS_SB (sb)->free_clusters !=-1 )MSDOS_SB (sb)->free_clusters++; inode->i_blocks -= (1 <<MSDOS_SB (sb)->cluster_bits) >>9 ; - } + }while (nr !=FAT_ENT_EOF );fat_clusters_flush (sb); nr =0 ; error:
fs/fat/inode.c renamed from fs/fat/inode.c~fat_use-get_cluster2 +6 -21
@@ -465,32 +465,17 @@ out:static int fat_calc_dir_size (struct inode *inode) { -struct super_block *sb = inode->i_sb; -int nr; +struct msdos_sb_info *sbi =MSDOS_SB (inode->i_sb); +int ret, fclus, dclus; inode->i_size =0 ;if (MSDOS_I (inode)->i_start ==0 )return 0 ; - nr =MSDOS_I (inode)->i_start; -do { - inode->i_size +=1 <<MSDOS_SB (sb)->cluster_bits; - nr =fat_access (sb, nr,-1 ); -if (nr <0 ) -return nr; -else if (nr ==FAT_ENT_FREE ) { -fat_fs_panic (sb,"Directory %lu: invalid cluster chain" , - inode->i_ino); -return -EIO ; - } -if (inode->i_size >FAT_MAX_DIR_SIZE ) { -fat_fs_panic (sb,"Directory %lu: " -"exceeded the maximum size of directory" , - inode->i_ino); - inode->i_size =FAT_MAX_DIR_SIZE ; -break ; - } - }while (nr !=FAT_ENT_EOF ); + ret =fat_get_cluster (inode,FAT_ENT_EOF , &fclus, &dclus); +if (ret <0 ) +return ret; + inode->i_size = (fclus +1 ) << sbi->cluster_bits;return 0 ; }
fs/fat/misc.c renamed from fs/fat/misc.c~fat_use-get_cluster2 +27 -44
111 lines not on this page · raw message
_
Signature · 1 line
OGAWA Hirofumi <[email protected]>