Extended Attributes in Ext4

In ext4, we are now able to create arbitrary "file attributes", much as NTFS offers.

First, let's create a test directory and a test file:

langley@sophie ~ $ mkdir xsetfattr-test
langley@sophie ~ $ cd xsetfattr-test
langley@sophie ~/xsetfattr-test $ touch file1

And check to see if any attributes are already set:

langley@sophie ~/xsetfattr-test $ getfattr -d file1

No, we don't have any currently. Let's add one:

langley@sophie ~/xsetfattr-test $ setfattr -n user.name1 -v val1 file1
langley@sophie ~/xsetfattr-test $ getfattr -d file1
# file: file1
user.name1="val1"

Okay, let's add ten more:

langley@sophie ~/xsetfattr-test $ for((i=0;i<10;i++))
> do
> setfattr -n user.name$i -v val$i file1
> done
langley@sophie ~/xsetfattr-test $ getfattr -d file1
# file: file1
user.name0="val0"
user.name1="val1"
user.name2="val2"
user.name3="val3"
user.name4="val4"
user.name5="val5"
user.name6="val6"
user.name7="val7"
user.name8="val8"
user.name9="val9"

And, finally, remove them all:

langley@sophie ~/xsetfattr-test $ for name in `getfattr -d file1 | sed s/=.*//`
> do
> setfattr -x $name file1
> done
setfattr: file1: Operation not supported
setfattr: file1: Operation not supported
setfattr: file1: Operation not supported
langley@sophie ~/xsetfattr-test $ getfattr -d file1
langley@sophie ~/xsetfattr-test $