public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] let fat handle MS_SYNCHRONOUS flag
@ 2004-11-18 18:49 Colin Leroy
  2004-11-18 18:51 ` [PATCH] let vfat " Colin Leroy
                   ` (4 more replies)
  0 siblings, 5 replies; 27+ messages in thread
From: Colin Leroy @ 2004-11-18 18:49 UTC (permalink / raw)
  To: linux-kernel; +Cc: hirofumi

Hi,

this patch is an RFC patch not to be applied.
It adds MS_SYNCHRONOUS support to FAT filesystem, so that less
filesystem breakage happen when disconnecting an USB key, for 
example. I'd like to have comments about it, because as it 
seems to work fine here, I'm not used to fs drivers and could
have made mistakes.
Thanks,

Signed-off-by: Colin Leroy <colin@colino.net>
--- a/fs/fat/dir.c	2004-11-18 19:42:41.704777744 +0100
+++ b/fs/fat/dir.c	2004-11-18 14:36:44.000000000 +0100
@@ -736,6 +736,7 @@
 {
 	struct buffer_head *bh;
 	struct msdos_dir_entry *de;
+	struct super_block *sb;
 	__le16 date, time;
 
 	bh = fat_extend_dir(dir);
@@ -764,6 +765,11 @@
 	dir->i_atime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
 	mark_inode_dirty(dir);
 
+	sb = dir->i_sb;
+
+	if (sb->s_flags & MS_SYNCHRONOUS)
+		sync_dirty_buffer(bh);
+
 	return 0;
 }
 
--- a/fs/fat/file.c	2004-10-18 23:53:44.000000000 +0200
+++ b/fs/fat/file.c	2004-11-18 14:57:03.000000000 +0100
@@ -74,21 +74,34 @@
 {
 	struct inode *inode = filp->f_dentry->d_inode;
 	int retval;
+	struct super_block *sb = inode->i_sb;
+	struct buffer_head *bh = NULL;
 
 	retval = generic_file_write(filp, buf, count, ppos);
 	if (retval > 0) {
 		inode->i_mtime = inode->i_ctime = CURRENT_TIME;
 		MSDOS_I(inode)->i_attrs |= ATTR_ARCH;
 		mark_inode_dirty(inode);
+		if (sb->s_flags & MS_SYNCHRONOUS) {
+			bh = sb_bread(sb, MSDOS_SB(sb)->fsinfo_sector);
+			if (bh != NULL) {
+				sync_dirty_buffer(bh);
+				brelse(bh);
+			} else {
+				BUG_ON(1);
+			}
+		}
 	}
 	return retval;
 }
 
 void fat_truncate(struct inode *inode)
 {
+	struct super_block *sb = inode->i_sb;
 	struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
 	const unsigned int cluster_size = sbi->cluster_size;
 	int nr_clusters;
+	struct buffer_head *bh = NULL;
 
 	/* 
 	 * This protects against truncating a file bigger than it was then
@@ -105,4 +118,8 @@
 	unlock_kernel();
 	inode->i_ctime = inode->i_mtime = CURRENT_TIME;
 	mark_inode_dirty(inode);
+	if (sb->s_flags & MS_SYNCHRONOUS) {
+		bh = sb_bread(sb, sbi->fsinfo_sector);
+		sync_dirty_buffer(bh);
+	}
 }
--- a/fs/fat/inode.c	2004-11-18 19:42:41.710776832 +0100
+++ b/fs/fat/inode.c	2004-11-18 15:00:55.000000000 +0100
@@ -1273,8 +1273,12 @@
 	}
 	spin_unlock(&sbi->inode_hash_lock);
 	mark_buffer_dirty(bh);
-	brelse(bh);
 	unlock_kernel();
+
+	if (sb->s_flags & MS_SYNCHRONOUS)
+		sync_dirty_buffer(bh);
+	brelse(bh);
+
 	return 0;
 }
 

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2004-12-30  3:05 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-18 18:49 [PATCH] let fat handle MS_SYNCHRONOUS flag Colin Leroy
2004-11-18 18:51 ` [PATCH] let vfat " Colin Leroy
2004-11-23 19:32 ` [PATCH] let fat " Colin Leroy
2004-11-23 20:24 ` OGAWA Hirofumi
2004-11-24  3:20   ` Matt Mackall
2004-11-24  5:00     ` OGAWA Hirofumi
2004-11-24  5:35       ` Matt Mackall
2004-11-24  6:26         ` OGAWA Hirofumi
2004-11-24  6:40           ` Andrew Morton
2004-11-24  6:49             ` Matt Mackall
2004-11-24  6:57               ` Andrew Morton
2004-11-24 13:26             ` OGAWA Hirofumi
2004-11-24  5:41       ` Bernd Eckenfels
2004-11-24  7:30         ` Colin Leroy
2004-11-24  3:17 ` Matt Mackall
2004-11-24  7:34   ` Colin Leroy
2004-11-24  7:50     ` Matt Mackall
2004-11-24  8:40       ` Colin Leroy
2004-11-24 14:02 ` OGAWA Hirofumi
2004-11-24 14:25   ` Colin Leroy
2004-11-24 15:02   ` Colin Leroy
2004-11-24 18:10     ` OGAWA Hirofumi
2004-11-24 20:28       ` Colin Leroy
     [not found]         ` <87k6saunwl.fsf@devron.myhome.or.jp>
2004-11-25 12:47           ` Colin Leroy
     [not found]             ` <87act6ulc5.fsf@devron.myhome.or.jp>
2004-11-25 13:11               ` Colin Leroy
2004-12-29 19:33                 ` Robert Hardy
2004-12-30  3:02                   ` OGAWA Hirofumi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox