Skip to contentSkip to conversation

ext2/3/4: enable "undeletable" file attribute.

PATCH In review James Hunt 1 participant 1 message Nov 21, 2006 ext4 file system

lore
Share & tools
lore

James Hunt

author
#0 lore raw

PATCH 3/3 ext2/3/4: enable "undeletable" file attribute.

Currently, although you can mark a file as undeletable with 'chattr'...

Quoted 2 lines

touch /tmp/wibble
ls -l /tmp/wibble

-rw-rw-r-- 1 james james 0 Nov 16 20:00 /tmp/wibble

Quoted 2 lines

chattr +u /tmp/wibble # mark file as undeletable
lsattr /tmp/wibble

-u----------- /tmp/wibble

... it's not honoured by the kernel:

Quoted 1 line

rm /tmp/wibble # yikes! this should fail!!

This patch makes ext4 aware of the undeletable attribute such that attempting to delete a file marked as undeltable works as expected:

Quoted 2 lines

chattr +u /tmp/wibble # mark file as undeletable
lsattr /tmp/wibble

-u----------- /tmp/wibble

Quoted 1 line

rm /tmp/wibble

rm: cannot remove `/tmp/wibble': Operation not permitted

Quoted 2 lines

chattr -u /tmp/wibble # remove undeletable attribute
lsattr /tmp/wibble

------------- /tmp/wibble

Quoted 1 line

rm /tmp/wibble # works as expected this time

Tested with e2fsprogs-1.38-12 (FC5).

---
 fs/ext4/inode.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
fs/ext4/inode.c +3 -1
index 0a60ec5..8115b64 100644
@@ -2571,11 +2571,13 @@ void ext4_set_inode_flags(struct inode *
 {
 	unsigned int flags = EXT4_I(inode)->i_flags;
 
-	inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
+	inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_UNRM);
 	if (flags & EXT4_SYNC_FL)
 		inode->i_flags |= S_SYNC;
 	if (flags & EXT4_APPEND_FL)
 		inode->i_flags |= S_APPEND;
+	if (flags & EXT4_UNRM_FL)
+		inode->i_flags |= S_UNRM;
 	if (flags & EXT4_IMMUTABLE_FL)
 		inode->i_flags |= S_IMMUTABLE;
 	if (flags & EXT4_NOATIME_FL)
Signature · 4 lines
1.4.1

-- 
JaMeS