Skip to content

Conversation

shirou
Copy link
Owner

@shirou shirou commented May 24, 2025

This fixes #1858.

On disk.Parition() When we can not read /proc/1/mountinfo because version <2.6.26, fallback to read /proc/1/mounts. However, mount options are not splitted.

Here is a example line of mounts,

tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=1285356k,nr_inodes=321339,mode=700,uid=1000,gid=1000 0 0

and this is parsed like this, opts is just one long line.

{"device":"tmpfs","mountpoint":"/run/user/1000","fstype":"tmpfs","opts":["rw,nosuid,nodev,relatime,size=1285356k,nr_inodes=321339,mode=700,uid=1000,gid=1000"]}

This PR fixes this issue.

Add tests

This PR also split parse to parseFieldsOnMounts and parseFieldsOnMountinfo. These functions are used according to which file is used. And also introduce tests for those functions.

Opts: strings.Fields(fields[3]),
Opts: strings.Split(fields[3], ","),
Copy link
Contributor

Choose a reason for hiding this comment

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

No test to update/add for the issue you describe?

@shirou shirou force-pushed the feat/fix_paritions_opts_split branch from 7b5356f to d63507d Compare May 29, 2025 14:58
@shirou shirou requested review from ccoVeille and Copilot and removed request for ccoVeille June 1, 2025 05:51
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.

Pull Request Overview

This PR fixes an issue where mount options were incorrectly parsed when falling back to reading /proc/1/mounts, and it adds tests for the parsing functions.

  • Fixes mount option parsing by splitting comma-separated options.
  • Introduces dedicated functions parseFieldsOnMounts and parseFieldsOnMountinfo along with corresponding tests.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
disk/disk_linux_test.go Added tests for both mountinfo and mounts parsing logic.
disk/disk_linux.go Updated the parsing logic and error handling in PartitionsWithContext.

@shirou shirou force-pushed the feat/fix_paritions_opts_split branch from 8224b2a to 9896b27 Compare June 1, 2025 06:02
@shirou shirou force-pushed the feat/fix_paritions_opts_split branch from 451e4cf to 0e773f1 Compare June 7, 2025 11:28
Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
@shirou shirou force-pushed the feat/fix_paritions_opts_split branch from 0e773f1 to d3578cf Compare June 7, 2025 11:35
@shirou shirou merged commit afdd6f1 into master Jun 7, 2025
52 checks passed
@shirou shirou deleted the feat/fix_paritions_opts_split branch June 7, 2025 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mount options does not split by comma
2 participants