0

I'm not very experienced in Linux kernel so I don't have idea how to do this.

What I have to do is to modify ext4 file system to add custom attributes in files (e.g. to add original location when file was created). So, not to add custom attribute to a particular file, but to all files when they are being created, automatically.

Any idea, or some link for deeper investigation?

Thanks

Milan
  • 41
  • 7
  • `Any idea, or some link for deeper investigation?` - Start with writting kernel modules, continue with knowledge about files and filesystems in the kernel space, end with `ext4` filesystem implementation, of course. Actually, the question is **too broad** for Stack Overflow format. – Tsyvarev Jun 08 '17 at 16:32
  • @Tsyvarev I know that it is too broad but I am totally new to the linux kernel so every trace is significant. Thanks for advice! – Milan Jun 09 '17 at 11:10

1 Answers1

1

You will need something like extended attributes 'attr':

$ man attr
...
OVERVIEW
       Extended  attributes  implement  the  ability  for a user to attach name:value pairs to objects within the XFS
       filesystem.
...

Install the command if it is not present in your system:

$ sudo apt install attr

I've used it within an ext4 file system:

$ echo "testing attr command" > test.txt
$ setfattr -n user.new_attr -v "attribute value" test.txt
$ getfattr -n user.new_attr test.txt
# file: test.txt
user.new_attr="attribute value"

Now you just need to intercept the creation of a file. You can use incron, as explained in:

Executing a bash script upon file creation

For more information, you can take a look at their respective man pages.

hector
  • 907
  • 1
  • 9
  • 23