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

Add support for findmnt #210

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add support for findmnt #210

wants to merge 2 commits into from

Conversation

Harshit933
Copy link
Contributor

@Harshit933 Harshit933 commented Feb 2, 2025

For now the output of findmnt is:

[harshit:~/dev/util-linux (findmnt|✔)] target/debug/util-linux findmnt
 target                                     source          fstype       options                                                                                               
 /                                          /dev/nvme0n1p7  ext4         rw,relatime                                                                                           
 /proc                                      proc            proc         rw,nosuid,nodev,noexec,relatime                                                                       
 /proc/sys/fs/binfmt_misc                   systemd-1       autofs       rw,relatime,fd=41,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=6207                         
 /proc/sys/fs/binfmt_misc                   binfmt_misc     binfmt_misc  rw,nosuid,nodev,noexec,relatime                                                                       
 /sys                                       sys             sysfs        rw,nosuid,nodev,noexec,relatime                                                                       
 /sys/firmware/efi/efivars                  efivarfs        efivarfs     rw,nosuid,nodev,noexec,relatime                                                                       
 /sys/kernel/security                       securityfs      securityfs   rw,nosuid,nodev,noexec,relatime                                                                       
 /sys/fs/cgroup                             cgroup2         cgroup2      rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot                                       
 /sys/fs/pstore                             pstore          pstore       rw,nosuid,nodev,noexec,relatime                                                                       
 /sys/fs/bpf                                bpf             bpf          rw,nosuid,nodev,noexec,relatime,mode=700                                                              
 /sys/kernel/tracing                        tracefs         tracefs      rw,nosuid,nodev,noexec,relatime                                                                       
 /sys/kernel/debug                          debugfs         debugfs      rw,nosuid,nodev,noexec,relatime                                                                       
 /sys/fs/fuse/connections                   fusectl         fusectl      rw,nosuid,nodev,noexec,relatime                                                                       
 /sys/kernel/config                         configfs        configfs     rw,nosuid,nodev,noexec,relatime                                                                       
 /dev                                       dev             devtmpfs     rw,nosuid,relatime,size=8027368k,nr_inodes=2006842,mode=755,inode64                                   
 /dev/shm                                   tmpfs           tmpfs        rw,nosuid,nodev,inode64                                                                               
 /dev/pts                                   devpts          devpts       rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000                                                 
 /dev/hugepages                             hugetlbfs       hugetlbfs    rw,nosuid,nodev,relatime,pagesize=2M                                                                  
 /dev/mqueue                                mqueue          mqueue       rw,nosuid,nodev,noexec,relatime                                                                       
 /run                                       run             tmpfs        rw,nosuid,nodev,relatime,mode=755,inode64                                                             
 /run/credentials/systemd-journald.service  tmpfs           tmpfs        ro,nosuid,nodev,noexec,relatime,nosymfollow,size=1024k,nr_inodes=1024,mode=700,inode64,noswap         
 /run/user/1000                             tmpfs           tmpfs        rw,nosuid,nodev,relatime,size=1612004k,nr_inodes=403001,mode=700,uid=1000,gid=1000,inode64            
 /run/user/1000/doc                         portal          fuse.portal  rw,nosuid,nodev,relatime,user_id=1000,group_id=1000                                                   
 /tmp                                       tmpfs           tmpfs        rw,nosuid,nodev,nr_inodes=1048576,inode64                                                             
 /boot                                      /dev/nvme0n1p6  vfat         rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro

Potential fix #23

@cakebaker
Copy link
Contributor

Can you please run cargo clippy? The CI shows some clippy errors. Plus the test fails on macOS because there's no /proc on macOS as far as I know.

@Harshit933 Harshit933 force-pushed the findmnt branch 2 times, most recently from 01071f2 to 2977baa Compare February 8, 2025 06:39
@Harshit933
Copy link
Contributor Author

Harshit933 commented Feb 8, 2025

Plus the test fails on macOS because there's no /proc on macOS as far as I know.

Yup. I guess that is the case. I'll feature gate this on linux only

error: test failed, to rerun pass `--test tests`
run: /Users/runner/work/util-linux/util-linux/target/debug/util-linux findmnt
thread 'test_findmnt::test_findmnt' panicked at tests/by-util/test_findmnt.rs:5:17:
Command was expected to succeed. Exit code: 101.
stdout = 
 stderr = thread 'main' panicked at src/uu/findmnt/src/findmnt.rs:43:54:
called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@sylvestre
Copy link
Contributor

Yup. I guess that is the case. I'll feature gate this on linux only

there might be crate or equivalent for mac/unix. Maybe have a look before making this linux specific

@Harshit933
Copy link
Contributor Author

@sylvestre I see there are some alternatives present inside macOS like the mount and diskutil commands. But shouldn't they be implemented differently from the findmnt one? I am a bit confused here on what do I need to do further.

@cakebaker cakebaker mentioned this pull request Feb 16, 2025
path = "src/main.rs"

[dependencies]
tabled = { workspace = true }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recently removed tabled and so this will no longer work. And as the output currently looks quite different from the output of the original findmnt, I think it is probably easier to do the output manually than trying to figure out how to do it with tabled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Harshit933 I had started working on a findmnt implementation as well before realizing you had this PR open, feel free to take the output code from here, that version doesn't use tabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pointer, I'll take a look.

@sylvestre sylvestre requested a review from Copilot March 8, 2025 12:42
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR adds support for the findmnt utility by introducing its own Rust package, command-line interface, and associated tests.

  • Added a new package (uu_findmnt) with implementation and CLI entry point.
  • Updated workspace configuration to include findmnt as a dependency.
  • Added tests and documentation for the new utility.

Reviewed Changes

File Description
src/uu/findmnt/Cargo.toml New package manifest for the findmnt utility
src/uu/findmnt/src/findmnt.rs Core implementation including parsing and table formatting
src/uu/findmnt/src/main.rs CLI entry point for findmnt
src/uu/findmnt/findmnt.md Documentation for findmnt
tests/by-util/test_findmnt.rs Test validating the findmnt output on Linux
Cargo.toml Workspace dependencies updated to include findmnt
tests/tests.rs Integration of findmnt tests into the overall test suite

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment on lines +42 to +43
pub fn form_nodes(&mut self) {
let res = fs::read_to_string(self.file_name).unwrap();
Copy link
Preview

Copilot AI Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using unwrap() here can lead to a panic if the mountinfo file cannot be read; consider handling the error gracefully with proper error messaging.

Suggested change
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)?;

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
let (_, rest) = rest.trim().split_once("-").unwrap();
let (fstype, rest) = rest.trim().split_once(" ").unwrap();
let (source, rest) = rest.trim().split_once(" ").unwrap();
let options_added = if rest.split_once("rw").is_some() {
Copy link
Preview

Copilot AI Mar 8, 2025

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.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement program findmnt
4 participants