Skip to content

Commit b522412

Browse files
author
Al Viro
committed
Sanitize ->fsync() for FAT
* mark directory data blocks as assoc. metadata * add new inode to deal with FAT, mark FAT blocks as assoc. metadata of that * now ->fsync() is trivial both for files and directories Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 964f536 commit b522412

7 files changed

Lines changed: 49 additions & 19 deletions

File tree

‎fs/fat/dir.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ const struct file_operations fat_dir_operations = {
840840
#ifdef CONFIG_COMPAT
841841
.compat_ioctl = fat_compat_dir_ioctl,
842842
#endif
843-
.fsync = file_fsync,
843+
.fsync = fat_file_fsync,
844844
};
845845

846846
static int fat_get_short_entry(struct inode *dir, loff_t *pos,
@@ -967,7 +967,7 @@ static int __fat_remove_entries(struct inode *dir, loff_t pos, int nr_slots)
967967
de++;
968968
nr_slots--;
969969
}
970-
mark_buffer_dirty(bh);
970+
mark_buffer_dirty_inode(bh, dir);
971971
if (IS_DIRSYNC(dir))
972972
err = sync_dirty_buffer(bh);
973973
brelse(bh);
@@ -1001,7 +1001,7 @@ int fat_remove_entries(struct inode *dir, struct fat_slot_info *sinfo)
10011001
de--;
10021002
nr_slots--;
10031003
}
1004-
mark_buffer_dirty(bh);
1004+
mark_buffer_dirty_inode(bh, dir);
10051005
if (IS_DIRSYNC(dir))
10061006
err = sync_dirty_buffer(bh);
10071007
brelse(bh);
@@ -1051,7 +1051,7 @@ static int fat_zeroed_cluster(struct inode *dir, sector_t blknr, int nr_used,
10511051
}
10521052
memset(bhs[n]->b_data, 0, sb->s_blocksize);
10531053
set_buffer_uptodate(bhs[n]);
1054-
mark_buffer_dirty(bhs[n]);
1054+
mark_buffer_dirty_inode(bhs[n], dir);
10551055

10561056
n++;
10571057
blknr++;
@@ -1131,7 +1131,7 @@ int fat_alloc_new_dir(struct inode *dir, struct timespec *ts)
11311131
de[0].size = de[1].size = 0;
11321132
memset(de + 2, 0, sb->s_blocksize - 2 * sizeof(*de));
11331133
set_buffer_uptodate(bhs[0]);
1134-
mark_buffer_dirty(bhs[0]);
1134+
mark_buffer_dirty_inode(bhs[0], dir);
11351135

11361136
err = fat_zeroed_cluster(dir, blknr, 1, bhs, MAX_BUF_PER_PAGE);
11371137
if (err)
@@ -1193,7 +1193,7 @@ static int fat_add_new_entries(struct inode *dir, void *slots, int nr_slots,
11931193
slots += copy;
11941194
size -= copy;
11951195
set_buffer_uptodate(bhs[n]);
1196-
mark_buffer_dirty(bhs[n]);
1196+
mark_buffer_dirty_inode(bhs[n], dir);
11971197
if (!size)
11981198
break;
11991199
n++;
@@ -1293,7 +1293,7 @@ int fat_add_entries(struct inode *dir, void *slots, int nr_slots,
12931293
for (i = 0; i < long_bhs; i++) {
12941294
int copy = min_t(int, sb->s_blocksize - offset, size);
12951295
memcpy(bhs[i]->b_data + offset, slots, copy);
1296-
mark_buffer_dirty(bhs[i]);
1296+
mark_buffer_dirty_inode(bhs[i], dir);
12971297
offset = 0;
12981298
slots += copy;
12991299
size -= copy;
@@ -1304,7 +1304,7 @@ int fat_add_entries(struct inode *dir, void *slots, int nr_slots,
13041304
/* Fill the short name slot. */
13051305
int copy = min_t(int, sb->s_blocksize - offset, size);
13061306
memcpy(bhs[i]->b_data + offset, slots, copy);
1307-
mark_buffer_dirty(bhs[i]);
1307+
mark_buffer_dirty_inode(bhs[i], dir);
13081308
if (IS_DIRSYNC(dir))
13091309
err = sync_dirty_buffer(bhs[i]);
13101310
}

‎fs/fat/fat.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct msdos_sb_info {
7474

7575
int fatent_shift;
7676
struct fatent_operations *fatent_ops;
77+
struct inode *fat_inode;
7778

7879
spinlock_t inode_hash_lock;
7980
struct hlist_head inode_hashtable[FAT_HASH_SIZE];
@@ -251,6 +252,7 @@ struct fat_entry {
251252
} u;
252253
int nr_bhs;
253254
struct buffer_head *bhs[2];
255+
struct inode *fat_inode;
254256
};
255257

256258
static inline void fatent_init(struct fat_entry *fatent)
@@ -259,6 +261,7 @@ static inline void fatent_init(struct fat_entry *fatent)
259261
fatent->entry = 0;
260262
fatent->u.ent32_p = NULL;
261263
fatent->bhs[0] = fatent->bhs[1] = NULL;
264+
fatent->fat_inode = NULL;
262265
}
263266

264267
static inline void fatent_set_entry(struct fat_entry *fatent, int entry)
@@ -275,6 +278,7 @@ static inline void fatent_brelse(struct fat_entry *fatent)
275278
brelse(fatent->bhs[i]);
276279
fatent->nr_bhs = 0;
277280
fatent->bhs[0] = fatent->bhs[1] = NULL;
281+
fatent->fat_inode = NULL;
278282
}
279283

280284
extern void fat_ent_access_init(struct super_block *sb);
@@ -296,6 +300,8 @@ extern int fat_setattr(struct dentry * dentry, struct iattr * attr);
296300
extern void fat_truncate(struct inode *inode);
297301
extern int fat_getattr(struct vfsmount *mnt, struct dentry *dentry,
298302
struct kstat *stat);
303+
extern int fat_file_fsync(struct file *file, struct dentry *dentry,
304+
int datasync);
299305

300306
/* fat/inode.c */
301307
extern void fat_attach(struct inode *inode, loff_t i_pos);

‎fs/fat/fatent.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ static int fat12_ent_bread(struct super_block *sb, struct fat_entry *fatent,
7373
struct buffer_head **bhs = fatent->bhs;
7474

7575
WARN_ON(blocknr < MSDOS_SB(sb)->fat_start);
76+
fatent->fat_inode = MSDOS_SB(sb)->fat_inode;
77+
7678
bhs[0] = sb_bread(sb, blocknr);
7779
if (!bhs[0])
7880
goto err;
@@ -103,6 +105,7 @@ static int fat_ent_bread(struct super_block *sb, struct fat_entry *fatent,
103105
struct fatent_operations *ops = MSDOS_SB(sb)->fatent_ops;
104106

105107
WARN_ON(blocknr < MSDOS_SB(sb)->fat_start);
108+
fatent->fat_inode = MSDOS_SB(sb)->fat_inode;
106109
fatent->bhs[0] = sb_bread(sb, blocknr);
107110
if (!fatent->bhs[0]) {
108111
printk(KERN_ERR "FAT: FAT read failed (blocknr %llu)\n",
@@ -167,9 +170,9 @@ static void fat12_ent_put(struct fat_entry *fatent, int new)
167170
}
168171
spin_unlock(&fat12_entry_lock);
169172

170-
mark_buffer_dirty(fatent->bhs[0]);
173+
mark_buffer_dirty_inode(fatent->bhs[0], fatent->fat_inode);
171174
if (fatent->nr_bhs == 2)
172-
mark_buffer_dirty(fatent->bhs[1]);
175+
mark_buffer_dirty_inode(fatent->bhs[1], fatent->fat_inode);
173176
}
174177

175178
static void fat16_ent_put(struct fat_entry *fatent, int new)
@@ -178,7 +181,7 @@ static void fat16_ent_put(struct fat_entry *fatent, int new)
178181
new = EOF_FAT16;
179182

180183
*fatent->u.ent16_p = cpu_to_le16(new);
181-
mark_buffer_dirty(fatent->bhs[0]);
184+
mark_buffer_dirty_inode(fatent->bhs[0], fatent->fat_inode);
182185
}
183186

184187
static void fat32_ent_put(struct fat_entry *fatent, int new)
@@ -189,7 +192,7 @@ static void fat32_ent_put(struct fat_entry *fatent, int new)
189192
WARN_ON(new & 0xf0000000);
190193
new |= le32_to_cpu(*fatent->u.ent32_p) & ~0x0fffffff;
191194
*fatent->u.ent32_p = cpu_to_le32(new);
192-
mark_buffer_dirty(fatent->bhs[0]);
195+
mark_buffer_dirty_inode(fatent->bhs[0], fatent->fat_inode);
193196
}
194197

195198
static int fat12_ent_next(struct fat_entry *fatent)
@@ -381,7 +384,7 @@ static int fat_mirror_bhs(struct super_block *sb, struct buffer_head **bhs,
381384
}
382385
memcpy(c_bh->b_data, bhs[n]->b_data, sb->s_blocksize);
383386
set_buffer_uptodate(c_bh);
384-
mark_buffer_dirty(c_bh);
387+
mark_buffer_dirty_inode(c_bh, sbi->fat_inode);
385388
if (sb->s_flags & MS_SYNCHRONOUS)
386389
err = sync_dirty_buffer(c_bh);
387390
brelse(c_bh);

‎fs/fat/file.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ static int fat_file_release(struct inode *inode, struct file *filp)
133133
return 0;
134134
}
135135

136+
int fat_file_fsync(struct file *filp, struct dentry *dentry, int datasync)
137+
{
138+
struct inode *inode = dentry->d_inode;
139+
int res, err;
140+
141+
res = simple_fsync(filp, dentry, datasync);
142+
err = sync_mapping_buffers(MSDOS_SB(inode->i_sb)->fat_inode->i_mapping);
143+
144+
return res ? res : err;
145+
}
146+
147+
136148
const struct file_operations fat_file_operations = {
137149
.llseek = generic_file_llseek,
138150
.read = do_sync_read,
@@ -142,7 +154,7 @@ const struct file_operations fat_file_operations = {
142154
.mmap = generic_file_mmap,
143155
.release = fat_file_release,
144156
.ioctl = fat_generic_ioctl,
145-
.fsync = file_fsync,
157+
.fsync = fat_file_fsync,
146158
.splice_read = generic_file_splice_read,
147159
};
148160

‎fs/fat/inode.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ static void fat_put_super(struct super_block *sb)
458458
if (sb->s_dirt)
459459
fat_write_super(sb);
460460

461+
iput(sbi->fat_inode);
462+
461463
if (sbi->nls_disk) {
462464
unload_nls(sbi->nls_disk);
463465
sbi->nls_disk = NULL;
@@ -1183,7 +1185,7 @@ static int fat_read_root(struct inode *inode)
11831185
int fat_fill_super(struct super_block *sb, void *data, int silent,
11841186
const struct inode_operations *fs_dir_inode_ops, int isvfat)
11851187
{
1186-
struct inode *root_inode = NULL;
1188+
struct inode *root_inode = NULL, *fat_inode = NULL;
11871189
struct buffer_head *bh;
11881190
struct fat_boot_sector *b;
11891191
struct msdos_sb_info *sbi;
@@ -1423,6 +1425,11 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
14231425
}
14241426

14251427
error = -ENOMEM;
1428+
fat_inode = new_inode(sb);
1429+
if (!fat_inode)
1430+
goto out_fail;
1431+
MSDOS_I(fat_inode)->i_pos = 0;
1432+
sbi->fat_inode = fat_inode;
14261433
root_inode = new_inode(sb);
14271434
if (!root_inode)
14281435
goto out_fail;
@@ -1448,6 +1455,8 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
14481455
" on dev %s.\n", sb->s_id);
14491456

14501457
out_fail:
1458+
if (fat_inode)
1459+
iput(fat_inode);
14511460
if (root_inode)
14521461
iput(root_inode);
14531462
if (sbi->nls_io)

‎fs/fat/namei_msdos.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
544544
int start = MSDOS_I(new_dir)->i_logstart;
545545
dotdot_de->start = cpu_to_le16(start);
546546
dotdot_de->starthi = cpu_to_le16(start >> 16);
547-
mark_buffer_dirty(dotdot_bh);
547+
mark_buffer_dirty_inode(dotdot_bh, old_inode);
548548
if (IS_DIRSYNC(new_dir)) {
549549
err = sync_dirty_buffer(dotdot_bh);
550550
if (err)
@@ -586,7 +586,7 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
586586
int start = MSDOS_I(old_dir)->i_logstart;
587587
dotdot_de->start = cpu_to_le16(start);
588588
dotdot_de->starthi = cpu_to_le16(start >> 16);
589-
mark_buffer_dirty(dotdot_bh);
589+
mark_buffer_dirty_inode(dotdot_bh, old_inode);
590590
corrupt |= sync_dirty_buffer(dotdot_bh);
591591
}
592592
error_inode:

‎fs/fat/namei_vfat.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
965965
int start = MSDOS_I(new_dir)->i_logstart;
966966
dotdot_de->start = cpu_to_le16(start);
967967
dotdot_de->starthi = cpu_to_le16(start >> 16);
968-
mark_buffer_dirty(dotdot_bh);
968+
mark_buffer_dirty_inode(dotdot_bh, old_inode);
969969
if (IS_DIRSYNC(new_dir)) {
970970
err = sync_dirty_buffer(dotdot_bh);
971971
if (err)
@@ -1009,7 +1009,7 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
10091009
int start = MSDOS_I(old_dir)->i_logstart;
10101010
dotdot_de->start = cpu_to_le16(start);
10111011
dotdot_de->starthi = cpu_to_le16(start >> 16);
1012-
mark_buffer_dirty(dotdot_bh);
1012+
mark_buffer_dirty_inode(dotdot_bh, old_inode);
10131013
corrupt |= sync_dirty_buffer(dotdot_bh);
10141014
}
10151015
error_inode:

0 commit comments

Comments
 (0)