kdave / btrfs-progs

Development of userspace BTRFS tools
GNU General Public License v2.0
527 stars 239 forks source link

Inodes of subvolumes #728

Closed korpe1 closed 6 months ago

korpe1 commented 6 months ago

What this exactly means "A subvolume has always inode number 256."? Is it really mandatory that a subvolume has at least file with inode 256?

I have noticed that after 5 other subvolumes ids start count from 256. Would that be what the quote try to say?

https://btrfs.readthedocs.io/en/latest/Subvolumes.html

Zygo commented 6 months ago

256 is the root directory inode number for all subvolumes on btrfs.

When you want to tell whether a directory is the root of a subvolume on a btrfs filesystem, you can compare the inode number. If the inode number is 256, the directory is the root of a subvolume.

korpe1 commented 6 months ago

Okay, so would it be better say "The first inode of any subvolume is always 256."

korpe1 commented 6 months ago

256 is the root directory inode number for all subvolumes on btrfs.

When you want to tell whether a directory is the root of a subvolume on a btrfs filesystem, you can compare the inode number. If the inode number is 256, the directory is the root of a subvolume.

Another question, are subvolume ids and inodes completely separate things? The both start count from 256 (execpt the root subvolume with id 5), but them seems separate, look:

sudo btrfs subvolume list /
ID 256 gen 00000 top level 5 path @home
ID 257 gen 00000 top level 5 path @
ID 258 gen 00000 top level 257 path var/lib/machines
...
ls  -lai /btrfs-root
total 16
256 drwxr-xr-x. 1 root root  12 Jan  7 13:22 .
256 dr-xr-xr-x. 1 root root 270 Jan  7 13:21 ..
256 dr-xr-xr-x. 1 root root 270 Jan  7 13:21 @
256 drwxr-xr-x. 1 root root  12 Jan  6 15:27 @home
...

As you can see id and inode of the @ are different (257 vs 256).

Another question, if 256 is always inode of the root directory of a subvolume, why and how both @ and @home have inode 256???

adam900710 commented 6 months ago

Another question, are subvolume ids and inodes completely separate things? The both start count from 256 (execpt the root subvolume with id 5), but them seems separate, look:

They are different. The subvolumeid is recorded inside the subvolume root key (<SUBVOLID> ROOT_ITEM <SNAPSHOT SOURCE SUBVOLID>), of root tree. Meanwhile the inode value is stored inside the inode key (<INODE NUMBER> INODE_ITEM 0), of a subvolume tree.

Thus they are indeed in different address space.

Another question, if 256 is always inode of the root directory of a subvolume, why and how both @ and @home have inode 256???

@/home is the subvolume top inode, thus it's 256 (of that subvolume) .. in your case means @, another subvolume top inode, thus it's also 256 (of that toplevel subvolume).

korpe1 commented 6 months ago

Another question, if 256 is always inode of the root directory of a subvolume, why and how both @ and @home have inode 256???

@/home is the subvolume top inode, thus it's 256 (of that subvolume) .. in your case means @, another subvolume top inode, thus it's also 256 (of that toplevel subvolume).

That explains, thank you! In fact, thank you for all devs behind BTRFS. I'm so exciting about BTRFS and its subvolumes, quotas etc. :heart: