Commit 5b85212c authored by Hirofumi Ogawa's avatar Hirofumi Ogawa Committed by Linus Torvalds

[PATCH] FAT: Fix fat_truncate()

Instead of
	mark_inode_dirty(inode);
	if (IS_SYNC(inode))
		fat_sync_inode(inode);

use this
	if (IS_SYNC(inode))
		fat_sync_inode(inode);
	else
		mark_inode_dirty(inode);

And if occurs a error, restore the ->i_start and ->i_logstart.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>-
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent d127375a
...@@ -212,7 +212,7 @@ EXPORT_SYMBOL(fat_notify_change); ...@@ -212,7 +212,7 @@ EXPORT_SYMBOL(fat_notify_change);
static int fat_free(struct inode *inode, int skip) static int fat_free(struct inode *inode, int skip)
{ {
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
int ret, wait; int err, wait, free_start, i_start, i_logstart;
if (MSDOS_I(inode)->i_start == 0) if (MSDOS_I(inode)->i_start == 0)
return 0; return 0;
...@@ -223,7 +223,7 @@ static int fat_free(struct inode *inode, int skip) ...@@ -223,7 +223,7 @@ static int fat_free(struct inode *inode, int skip)
wait = IS_DIRSYNC(inode); wait = IS_DIRSYNC(inode);
if (skip) { if (skip) {
struct fat_entry fatent; struct fat_entry fatent;
int fclus, dclus; int ret, fclus, dclus;
ret = fat_get_cluster(inode, skip - 1, &fclus, &dclus); ret = fat_get_cluster(inode, skip - 1, &fclus, &dclus);
if (ret < 0) if (ret < 0)
...@@ -242,8 +242,7 @@ static int fat_free(struct inode *inode, int skip) ...@@ -242,8 +242,7 @@ static int fat_free(struct inode *inode, int skip)
__FUNCTION__, MSDOS_I(inode)->i_pos); __FUNCTION__, MSDOS_I(inode)->i_pos);
ret = -EIO; ret = -EIO;
} else if (ret > 0) { } else if (ret > 0) {
int err = fat_ent_write(inode, &fatent, FAT_ENT_EOF, err = fat_ent_write(inode, &fatent, FAT_ENT_EOF, wait);
wait);
if (err) if (err)
ret = err; ret = err;
} }
...@@ -251,24 +250,36 @@ static int fat_free(struct inode *inode, int skip) ...@@ -251,24 +250,36 @@ static int fat_free(struct inode *inode, int skip)
if (ret < 0) if (ret < 0)
return ret; return ret;
free_start = ret;
i_start = i_logstart = 0;
fat_cache_inval_inode(inode); fat_cache_inval_inode(inode);
} else { } else {
fat_cache_inval_inode(inode); fat_cache_inval_inode(inode);
ret = MSDOS_I(inode)->i_start; i_start = free_start = MSDOS_I(inode)->i_start;
i_logstart = MSDOS_I(inode)->i_logstart;
MSDOS_I(inode)->i_start = 0; MSDOS_I(inode)->i_start = 0;
MSDOS_I(inode)->i_logstart = 0; MSDOS_I(inode)->i_logstart = 0;
}
MSDOS_I(inode)->i_attrs |= ATTR_ARCH;
inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC;
if (wait) { if (wait) {
int err = fat_sync_inode(inode); err = fat_sync_inode(inode);
if (err) if (err)
return err; goto error;
} else } else
mark_inode_dirty(inode); mark_inode_dirty(inode);
}
inode->i_blocks = skip << (MSDOS_SB(sb)->cluster_bits - 9); inode->i_blocks = skip << (MSDOS_SB(sb)->cluster_bits - 9);
/* Freeing the remained cluster chain */ /* Freeing the remained cluster chain */
return fat_free_clusters(inode, ret); return fat_free_clusters(inode, free_start);
error:
if (i_start) {
MSDOS_I(inode)->i_start = i_start;
MSDOS_I(inode)->i_logstart = i_logstart;
}
return err;
} }
void fat_truncate(struct inode *inode) void fat_truncate(struct inode *inode)
...@@ -288,12 +299,7 @@ void fat_truncate(struct inode *inode) ...@@ -288,12 +299,7 @@ void fat_truncate(struct inode *inode)
lock_kernel(); lock_kernel();
fat_free(inode, nr_clusters); fat_free(inode, nr_clusters);
MSDOS_I(inode)->i_attrs |= ATTR_ARCH;
unlock_kernel(); unlock_kernel();
inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC;
mark_inode_dirty(inode);
if (IS_SYNC(inode))
fat_sync_inode(inode);
} }
struct inode_operations fat_file_inode_operations = { struct inode_operations fat_file_inode_operations = {
......
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