-
Notifications
You must be signed in to change notification settings - Fork 37
Add support for findmnt
#210
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ feat_common_core = [ | |
| "renice", | ||
| "rev", | ||
| "setsid", | ||
| "findmnt", | ||
| ] | ||
|
|
||
| [workspace.dependencies] | ||
|
|
@@ -94,6 +95,7 @@ mountpoint = { optional = true, version = "0.0.1", package = "uu_mountpoint", pa | |
| renice = { optional = true, version = "0.0.1", package = "uu_renice", path = "src/uu/renice" } | ||
| rev = { optional = true, version = "0.0.1", package = "uu_rev", path = "src/uu/rev" } | ||
| setsid = { optional = true, version = "0.0.1", package = "uu_setsid", path ="src/uu/setsid" } | ||
| findmnt = { optional = true, version = "0.0.1", package = "uu_findmnt", path = "src/uu/findmnt" } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also should be alphabetical |
||
|
|
||
| [dev-dependencies] | ||
| # dmesg test require fixed-boot-time feature turned on. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| [package] | ||
| name = "uu_findmnt" | ||
| version = "0.0.1" | ||
| edition = "2021" | ||
|
|
||
| [lib] | ||
| path = "src/findmnt.rs" | ||
|
|
||
| [[bin]] | ||
| name = "findmnt" | ||
| path = "src/main.rs" | ||
|
|
||
| [dependencies] | ||
| tabled = { workspace = true } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We recently removed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Harshit933 I had started working on a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the pointer, I'll take a look. |
||
| uucore = { workspace = true } | ||
| clap = { workspace = true } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # findmnt | ||
|
|
||
| ``` | ||
| findmnt [options] | ||
| ``` | ||
|
|
||
| findmnt will list all mounted filesytems or search for a filesystem. The findmnt command is able to search in /etc/fstab, /etc/fstab.d, /etc/mtab or /proc/self/mountinfo. If device or mountpoint is not given, all filesystems are shown. |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,189 @@ | ||||||||||
| use core::fmt; | ||||||||||
| use std::fs; | ||||||||||
|
|
||||||||||
| use clap::{crate_version, Command}; | ||||||||||
| use tabled::{settings::Style, Table, Tabled}; | ||||||||||
| use uucore::{error::UResult, help_about}; | ||||||||||
|
|
||||||||||
| #[uucore::main] | ||||||||||
| pub fn uumain(args: impl uucore::Args) -> UResult<()> { | ||||||||||
| let _matches: clap::ArgMatches = uu_app().try_get_matches_from(args)?; | ||||||||||
|
|
||||||||||
| // By default findmnt reads /proc/self/mountinfo | ||||||||||
| let mut res = Findmnt::new(MOUNTINFO_DIR); | ||||||||||
| res.form_nodes(); | ||||||||||
| res.print_table(); | ||||||||||
| Ok(()) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| pub static MOUNTINFO_DIR: &str = "/proc/self/mountinfo"; | ||||||||||
| pub static ABOUT: &str = help_about!("findmnt.md"); | ||||||||||
|
|
||||||||||
| pub fn uu_app() -> Command { | ||||||||||
| Command::new(uucore::util_name()) | ||||||||||
| .version(crate_version!()) | ||||||||||
| .about(ABOUT) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| #[derive(Debug, Clone)] | ||||||||||
| pub struct Findmnt<'a> { | ||||||||||
| pub nodes_vec: Vec<Node>, | ||||||||||
| file_name: &'a str, | ||||||||||
| } | ||||||||||
|
|
||||||||||
| impl Findmnt<'_> { | ||||||||||
| pub fn new(file_name: &str) -> Findmnt { | ||||||||||
| Findmnt { | ||||||||||
| file_name, | ||||||||||
| nodes_vec: Vec::<Node>::new(), | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| pub fn form_nodes(&mut self) { | ||||||||||
| let res = fs::read_to_string(self.file_name).unwrap(); | ||||||||||
|
Comment on lines
+42
to
+43
|
||||||||||
| pub fn form_nodes(&mut self) { | |
| let res = fs::read_to_string(self.file_name).unwrap(); | |
| pub fn form_nodes(&mut self) -> Result<(), Box<dyn std::error::Error>> { | |
| let res = fs::read_to_string(self.file_name)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some niche cases, /proc might not be mounted - I agree with Copilot here - but use UError instead.
Copilot
AI
Mar 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current logic splitting on "rw" may be unreliable if the options string unexpectedly contains this substring; consider a more robust parsing strategy or document the assumptions clearly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot is correct here - I have a ro mounted partition and I'm unable to see it. This document specifies the exact format of the file.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #[cfg(target_os = "linux")] | ||
| uucore::bin!(uu_findmnt); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| use crate::common::util::TestScenario; | ||
|
|
||
| #[cfg(target_os = "linux")] | ||
| #[test] | ||
| fn test_findmnt() { | ||
| new_ucmd!().succeeds().stdout_contains("/proc"); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in alphabetical order :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the project should consider adding cargo sort to the CI.