This is a simple question but I've done some research and can't find any answers... So does anyone know if when we define extended attributes through xattr, those attributes are stored within - as a part of - the file'contents(in the biggining, in the end?), or if the inode has a special region to store these?
And by the way, i've read that in ext4 "each extended attribute is limited to a filesystem block (e.g. 4 KiB)". I can't tell if this is enough if I wanted to store 7 extended attributes to each file in the file system. Is this reallistic?
My last question is if those extended attributes are portable in the sense that if the files move to other machines with different file systems what happens to this attributes?
If you look at the inode spec, you'll discover that there is a small amount of space at the end of the inode to accommodate extended attributes. If you overflow that area, ext4 allows to you allocate another block (basically like a resource fork) for additional extended attributes. That 4KB restriction is per attribute, per file, so you can certainly store 7 extended attributes per file, unless the attribute is a BLOB larger than 4KB. However, if you overrun the space at the end of the inode, you'll be allocating blocks to metadata instead of data, reducing the usable size of your file system.
Source: https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Extended_Attributes
To answer your question about portability, extended attributes are not copied by default, even within a single file system, and are not portable between file systems.
See: https://unix.stackexchange.com/questions/44253/how-to-clone-copy-all-file-directory-attributes-onto-different-file-directory for some further discussion on this. Rysnc can do a lot for copying extended attributes, but if the target file system doesn't support xattrs, you're out of luck.