Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag/colour for directory which is a btrfs subvolume #434

Open
daviessm opened this issue Oct 29, 2018 · 7 comments
Open

Flag/colour for directory which is a btrfs subvolume #434

daviessm opened this issue Oct 29, 2018 · 7 comments
Labels
feature request New features to add to exa

Comments

@daviessm
Copy link
Contributor

Would it be possible to flag a directory which is a subvolume in the btrfs filesystem? These directories have an inode type of 2 or 256 when the filesystem type is btrfs: https://stackoverflow.com/a/32865333/5293556

I wouldn't mind whether a character other than d or a different colour was used for these, it would just be nice to see them.

@daviessm
Copy link
Contributor Author

Upon further investigation, it's the inode number which signifies a subvolume, so I can see them by using -i and looking for 2 or 256. It would still be nice to highlight those without having to look through inode numbers though.

@daviessm
Copy link
Contributor Author

I have started work on this in https://github.com/daviessm/exa/tree/issue_434_subvolumes - it correctly detects subvolumes by ino as described above, but needs to also check that the filesystem type is btrfs.

This can be done with getmntent() from libc as described here: https://stackoverflow.com/questions/40659638/how-can-i-determine-the-mount-path-of-a-given-file-on-linux-in-c but that will need to be cached as there could be thousands of calls per run of exa.

@ogham
Copy link
Owner

ogham commented Dec 7, 2018

Hi there, and sorry for not leaving a reply until now.

I've looked at your code, and it all looks good. If detecting a subvolume really is as easy as checking the inode, then I'll be happy to merge it in.

@ogham ogham added the feature request New features to add to exa label Dec 7, 2018
@daviessm
Copy link
Contributor Author

daviessm commented Dec 7, 2018

No worries, yes it is that simple - but obviously this will only apply if the volume the directory is on is actually btrfs - otherwise there's a remote possibility of false positives (where the inode number of a directory just happens to be 2 or 256). I haven't figured out yet how to check that.

@ogham
Copy link
Owner

ogham commented Dec 7, 2018

Aaah, you’re right, I missed that bit. Running find / -type d -inum 2 on my machine actually did produce results in /dev, /run, and /net. One option would be to ignore those three directories, but that feels like a hack.

What about if it checked the inode first, and then only ran getmntent if the inode matches?

@daviessm
Copy link
Contributor Author

daviessm commented Dec 7, 2018

I think that's what I'd do, yeah. However it's beyond my Rust skills at the moment so I'll do it when I get around to it later unless you want to pick it up first.

I was also thinking about caching all the getmntents somewhere once they've been looked up, because there might be lots of directories within directories, all of which are subvolumes, and that would result in a lot of lookups. Could they be used for anything else (like highlighting mount points themselves...)?

@daviessm
Copy link
Contributor Author

New PR: #941

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New features to add to exa
Projects
None yet
Development

No branches or pull requests

2 participants