Skip to content

Commit ff9ddf7

Browse files
jankaratytso
authored andcommitted
ext4: copy i_flags to inode flags on write
Propagate flags such as S_APPEND, S_IMMUTABLE, etc. from i_flags into ext4-specific i_flags. Quota code changes these flags on quota files (to make it harder for sysadmin to screw himself) and these changes were not correctly propagated into the filesystem. (This is a forward port patch from ext3) Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Mingming Cao <cmm@us.ibm.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 1e2462f commit ff9ddf7

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

fs/ext4/inode.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,6 +2583,25 @@ void ext4_set_inode_flags(struct inode *inode)
25832583
inode->i_flags |= S_DIRSYNC;
25842584
}
25852585

2586+
/* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
2587+
void ext4_get_inode_flags(struct ext4_inode_info *ei)
2588+
{
2589+
unsigned int flags = ei->vfs_inode.i_flags;
2590+
2591+
ei->i_flags &= ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
2592+
EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|EXT4_DIRSYNC_FL);
2593+
if (flags & S_SYNC)
2594+
ei->i_flags |= EXT4_SYNC_FL;
2595+
if (flags & S_APPEND)
2596+
ei->i_flags |= EXT4_APPEND_FL;
2597+
if (flags & S_IMMUTABLE)
2598+
ei->i_flags |= EXT4_IMMUTABLE_FL;
2599+
if (flags & S_NOATIME)
2600+
ei->i_flags |= EXT4_NOATIME_FL;
2601+
if (flags & S_DIRSYNC)
2602+
ei->i_flags |= EXT4_DIRSYNC_FL;
2603+
}
2604+
25862605
void ext4_read_inode(struct inode * inode)
25872606
{
25882607
struct ext4_iloc iloc;
@@ -2744,6 +2763,7 @@ static int ext4_do_update_inode(handle_t *handle,
27442763
if (ei->i_state & EXT4_STATE_NEW)
27452764
memset(raw_inode, 0, EXT4_SB(inode->i_sb)->s_inode_size);
27462765

2766+
ext4_get_inode_flags(ei);
27472767
raw_inode->i_mode = cpu_to_le16(inode->i_mode);
27482768
if(!(test_opt(inode->i_sb, NO_UID32))) {
27492769
raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));

fs/ext4/ioctl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ int ext4_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
2828

2929
switch (cmd) {
3030
case EXT4_IOC_GETFLAGS:
31+
ext4_get_inode_flags(ei);
3132
flags = ei->i_flags & EXT4_FL_USER_VISIBLE;
3233
return put_user(flags, (int __user *) arg);
3334
case EXT4_IOC_SETFLAGS: {

include/linux/ext4_fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ extern int ext4_change_inode_journal_flag(struct inode *, int);
868868
extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *);
869869
extern void ext4_truncate (struct inode *);
870870
extern void ext4_set_inode_flags(struct inode *);
871+
extern void ext4_get_inode_flags(struct ext4_inode_info *);
871872
extern void ext4_set_aops(struct inode *inode);
872873
extern int ext4_writepage_trans_blocks(struct inode *);
873874
extern int ext4_block_truncate_page(handle_t *handle, struct page *page,

0 commit comments

Comments
 (0)