Skip to content

Match the BSD df partition fallback by exact device name and fixed units - #3833

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:disklabel-df-fallback
Oct 18, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:disklabel-df-fallback

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

When disklabel cannot be read without root, HWDiskStore.getPartitions() on OpenBSD and NetBSD lists a disk's partitions from df instead. That fallback, Disklabel.parseDfFallback, had three faults, all fixed here.

Changes

  • Prefix match. Every row starting with /dev/<disk> was taken, so sd1 also claimed sd10's partitions. A row now belongs to the disk only when its device is the disk name plus one partition letter (a-p).
  • Block size. The code assumed 512-byte blocks, but plain df follows the BLOCKSIZE environment variable, so sizes were halved with BLOCKSIZE=1k. It now runs df -k and multiplies by 1024. -k reports 1K blocks whatever BLOCKSIZE is, on both OpenBSD 7.9 (cfarm220) and NetBSD 10.1 (cfarm428). df -P would not do, because it still follows BLOCKSIZE on NetBSD.
  • Spaces. The row was split on whitespace, which cut a mount point at its first space. It is now split into at most six fields, so the mount point keeps the rest of the row.
  • Tests. Two new ones, for disks sharing a prefix and for a mount point with spaces. The existing size test now expects 1K units.

Verification

  • Checked how df handles BLOCKSIZE by hand on both systems. The test fixtures follow cfarm220's real df -k output.
  • Not run end to end: cfarm220 has no JDK, and cfarm428's disks are wedges, which take a different path.
  • The full gate with -Paggregate-coverage passes, and so does the -Perror-prone build.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed disk partition reporting on OpenBSD and NetBSD when elevated permissions are unavailable. Disk sizes now use consistent 1-KiB units regardless of the BLOCKSIZE setting, similarly named disks are distinguished correctly, and mount points containing spaces are preserved.

When disklabel cannot be read without root, OpenBSD and NetBSD list a
disk's partitions from df. That fallback had three faults:

- It took every row starting with /dev/<disk>, so sd1 also claimed
  sd10's partitions. A row now belongs to the disk only when its device
  is the disk name plus one partition letter (a-p).
- It assumed 512-byte blocks, but plain df follows BLOCKSIZE, so sizes
  were halved with BLOCKSIZE=1k. It now runs df -k, which reports 1K
  blocks regardless of BLOCKSIZE on both OpenBSD 7.9 (cfarm220) and
  NetBSD 10.1 (cfarm428); df -P still follows BLOCKSIZE on NetBSD.
- It split the whole row on whitespace, cutting a mount point at its
  first space. The row is now split into at most six fields.
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3b55418c-38dc-49ec-b969-47ee6a795cb5
📥 Commits

Reviewing files that changed from the base of the PR and between 80d06cd and 53b9e88.

📒 Files selected for processing: 3
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/unix/bsd/disk/Disklabel.java
  • oshi-common/src/test/java/oshi/driver/common/unix/bsd/disk/DisklabelTest.java

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout: 8
  • GitHub Check: Test JDK 25, FreeBSD
  • GitHub Check: Test JDK 25, NetBSD
  • GitHub Check: Test JDK 25, OpenBSD
  • GitHub Check: Test JDK 25, OpenIndiana
  • GitHub Check: Error Prone
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Test JDK 25, windows-latest
🧰 Additional context used
📚 Code guidelines: 2
AGENTS.md — auto-discovered
CONTRIBUTING.md — auto-discovered
📓 Path-based instructions: 2
Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `oshi-common` may not reference `com.sun.jna.**`, `java.lang.foreign.**`, or any `System.load`/`loadLibrary`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-common/src/main/java/oshi/driver/common/unix/bsd/disk/Disklabel.java
  • oshi-common/src/test/java/oshi/driver/common/unix/bsd/disk/DisklabelTest.java
Applicability reference: AGENTS.md: # AGENTS.md Instructions for AI coding agents working in the OSHI repository.

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Files:

  • CHANGELOG.md
🪛 ast-grep (0.45.3)
oshi-common/src/main/java/oshi/driver/common/unix/bsd/disk/Disklabel.java

[warning] 126-126: Regular expression is compiled from a non-literal, possibly user-controlled value. A crafted regex (or input matched against one) can trigger catastrophic backtracking and hang the thread (ReDoS). Use a hardcoded literal pattern, wrap untrusted text with Pattern.quote(...), or validate/length-limit the input and enforce a matching timeout before passing it to Pattern.compile / String.matches / String.replaceAll / String.replaceFirst.
Context: Pattern.compile("/dev/" + Pattern.quote(diskName) + "([a-p])")
Note: [CWE-1333] Inefficient Regular Expression Complexity.

(redos-non-literal-regex-java)

🔇 Additional comments: 3
oshi-common/src/main/java/oshi/driver/common/unix/bsd/disk/Disklabel.java: 1

10-11: LGTM!

Also applies to: 53-53, 109-115, 118-118, 126-126, 129-137

oshi-common/src/test/java/oshi/driver/common/unix/bsd/disk/DisklabelTest.java: 1

160-160: LGTM!

Also applies to: 179-179, 184-184, 205-228

CHANGELOG.md: 1

38-38: LGTM!

📝 Walkthrough

The BSD df fallback now uses df -k and parses 1-KiB block sizes. It matches partition device names exactly and preserves mount points containing spaces. Tests cover block-size conversion, device matching, and mount-point parsing.

Changes: BSD disklabel fallback

Layer / File(s) Summary
Run and parse the df fallback
oshi-common/src/main/java/oshi/driver/common/unix/bsd/disk/Disklabel.java, oshi-common/src/test/java/oshi/driver/common/unix/bsd/disk/DisklabelTest.java, CHANGELOG.md
The fallback runs df -k, accepts device paths with the disk name and one partition letter from a through p, preserves spaces in mount points, and converts 1-KiB blocks to bytes. Tests cover these parsing rules. The changelog records the fallback changes.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 53b9e

The fallback preserves the intended partition and mount-point parsing, and the examined NetBSD orphan-wedge case does not reveal an inventory defect. No actionable merge risk remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly summarizes the main changes: exact BSD device-name matching and fixed-size units for the df partition fallback. It is concise and specific.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the disklabel rows,
Then counts each block in 1K flows.
It finds the partition by its name,
And keeps the spaces just the same.
“df -k,” it says, and hops away.

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.04%. Comparing base (80d06cd) to head (53b9e88).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...va/oshi/driver/common/unix/bsd/disk/Disklabel.java 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3833      +/-   ##
============================================
- Coverage     81.09%   81.04%   -0.05%     
  Complexity      773      773              
============================================
  Files           726      726              
  Lines         26320    26320              
  Branches       4472     4471       -1     
============================================
- Hits          21344    21332      -12     
- Misses         2767     2779      +12     
  Partials       2209     2209              
Flag Coverage Δ
freebsd 37.81% <77.77%> (-0.02%) ⬇️
linux 41.77% <77.77%> (-0.02%) ⬇️
macos 42.70% <77.77%> (-0.04%) ⬇️
netbsd 37.11% <88.88%> (+<0.01%) ⬆️
openbsd 37.68% <88.88%> (+<0.01%) ⬆️
solaris 38.96% <77.77%> (+<0.01%) ⬆️
windows 49.07% <77.77%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbwiddis
dbwiddis merged commit d0956e4 into oshi:master Oct 18, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the disklabel-df-fallback branch October 18, 2026 22:40
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.

1 participant