Ubuntu: Where are file properties stored on the actual file system?


I am creating a program that takes a hexdump of a file, so that I can then transmit that somewhere, and have the file reconstructed, however the hexdump is only of the file contents, I also need to get the file properties, so where do I get the properties of that file, and then apply them to the new file that I create from that hexdump? I am using bash for this, but it's not really about the code, but more about where to find it, although you could it's about the code because obviously I am going to need some commands. I am running Ubuntu GNOME 15.04, with GNOME Shell, and GNOME 3.16.


File attributes are stored in inodes. The attributes that each inode stores are listed in POSIX Inode Specification. When we use ls -l or stat or any other program that get us the file attribute uses the stat(2) system call underneath.

Now inodes are filesystem dependent property, they are created as fixed numbers when the filesystem is created. There is a program dumpe2fs to read the superblock of a ext* filesystem so that we can get some idea e.g. :

sudo dumpe2fs -h /dev/sda1  

Now let's check the inode related properties:

$ sudo dumpe2fs -h /dev/sda1 | grep -i 'inode.*:'    Inode count:              9379840  Free inodes:              9297243  Inodes per group:         8192  Inode blocks per group:   512  First inode:              11  Inode size:               256  Journal inode:            8  

As you can see you get enough info like first inode, inode size, inode count etc. If you do a multiplication of Inode count and Inode size you get how much is reserved for the inodes.

File copying programs such as cp or rsync have the -a (archive) option to copy the attributes stored on the inode for a file, so you need to look for those or similar options available in the program you are likely to use.

For preserving attributes of files and then use it later you can check this answer from mighty Gilles.


This may not be a complete answer, but this is what I was able to find from my research.

File attributes are stored in inodes and the 'inode tables' are generally scattered throughout the file-system. In general, to find where you have the inode tables (at least in ext3 filesystem), you can run:

sudo dumpe2fs /dev/<device> | fgrep 'Inode table'  

and you can do a hexdump of the raw data at the block where the inodes resides (Note I've not tried this command!):

sudo dd if=/dev/<device> ibs=4096 skip=<inode block> count=1 | hexdump  

Replace the <device> and the <inode block> with the block offset to the inode table you want to look at.

source: LinuxQuestions, SO question

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »