Skip to content

Add fast path to OSFileStore.updateAttributes() for all platforms - #3195

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:fix/fast-path-updateAttributes
Apr 25, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:fix/fast-path-updateAttributes

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 25, 2026 •

Copy link
Copy Markdown
Member

Summary

OSFileStore.updateAttributes() re-enumerates every mounted filesystem just to update space/inode numbers for a single known mount point. When called in a monitoring loop for N file stores, this results in O(N²) work.

This PR adds platform-specific fast paths that call stat syscalls directly on the known mount point instead of re-enumerating all filesystems:

Linux

  • Calls the existing queryStatvfs() directly on the mount path
  • Works for both JNA and FFM since LinuxOSFileStore is in oshi-common and queryStatvfs() is resolved polymorphically
  • Falls back to java.io.File methods if native call returns zero total space

macOS

  • Adds new statfs64() per-path binding in both JNA (SystemB) and FFM (MacSystemFunctions)
  • Extracts inode counts (f_files, f_ffree) from the struct; uses java.io.File for space values (matching existing pattern in getFileStoreMatching)
  • Adds updateSpaceAndInodes() helper to MacOSFileStore base class

Windows

  • Calls GetDiskFreeSpaceEx directly on the known volume path (bindings already exist in both JNA and FFM)
  • Adds updateSpace() helper to WindowsOSFileStore base class (Windows inode fields are always -1)

All platforms fall back to the existing full-enumeration path if the direct syscall fails (e.g., mount was removed), ensuring backward compatibility.

Complexity reduction

  • updateAttributes(): O(N) enumeration → O(1) per store
  • Monitoring loop over N stores: O(N²) → O(N)

Verification

  • spotless:apply — no formatting changes needed
  • checkstyle:check — 0 violations
  • forbiddenapis:check — 0 errors
  • javadoc:javadoc — builds successfully

Closes #3185

Summary by CodeRabbit

  • Performance Improvements

    • Faster filesystem info retrieval on Linux, macOS, and Windows via new native fast-paths that directly read space and inode metrics for known mounts/volumes.
  • Bug Fixes / Reliability

    • Safer fallbacks preserve accurate storage and inode metrics when fast-path calls fail or return incomplete data.
  • Compatibility

    • Expanded native bindings on macOS and Windows for more reliable metric collection.

@coderabbitai

coderabbitai Bot commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds per-file-store fast-paths: updateAttributes() first queries the mount/volume directly (statvfs/statfs64/GetDiskFreeSpaceEx) to update only space/inode fields; on failure it falls back to full enumeration and updateFrom(...).

Changes

Cohort / File(s) Summary
Linux Common
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java
Fast-path uses fs.queryStatvfs(getMount()) to compute free/usable/total space and free/total inodes; falls back to enumeration and updateFrom(...).
macOS Common & FFM
oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java, oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.java, oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.java, oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
Added updateSpaceAndInodes(...) helper; exposed STATFS PathElements; added FFM statfs64 binding and FFM fast-path calling statfs64(getMount()) with debug logging and fallback to enumeration + updateFrom(...).
macOS JNA
oshi-core/src/main/java/oshi/jna/platform/mac/SystemB.java, oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
Added JNA statfs64 method; JNA fast-path calls statfs64(getMount()) to derive inode counts and uses File space values, else logs and falls back to enumeration + updateFrom(...).
Windows Common & FFM
oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java, oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.java
Added updateSpace(...) helper; FFM fast-path calls GetDiskFreeSpaceEx on getVolume() using confined Arena and updates space via updateSpace(...), else falls back to enumeration + updateFrom(...).
Windows JNA
oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
JNA fast-path calls Kernel32.GetDiskFreeSpaceEx with WinNT.LARGE_INTEGER outputs and updates space via updateSpace(...); falls back to enumeration + updateFrom(...).
Core JNA (macOS)
oshi-core/src/main/java/oshi/jna/platform/mac/SystemB.java
Added native statfs64(String, Statfs) declaration returning 0 on success / -1 on failure.

Sequence Diagram(s)

sequenceDiagram
  participant FS as FileStore.updateAttributes()
  participant Native as Native (FFM / JNA / syscall)
  participant Enum as Enumerator (getFileStores() / Volumes)
  participant Match as OSFileStore (matched)

  FS->>Native: fast-path stat/GetDiskFreeSpace on mount/volume
  alt native returns success
    Native-->>FS: space & inode values
    FS->>FS: call updateSpace/updateSpaceAndInodes(...)
    FS-->>FS: return true
  else native fails / returns non-zero / null
    Native-->>FS: failure
    FS->>Enum: enumerate file stores / volumes
    Enum-->>FS: list of OSFileStore
    FS->>Match: find matching (volume, mount)
    alt match found
      Match-->>FS: matched store
      FS->>FS: call updateFrom(matched)
      FS-->>FS: return true
    else no match
      FS-->>FS: return false
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

A mount once polled by every loop,
Now one stat wakes its bytes and inodes,
Fast paths skip the costly scoop,
Fallbacks linger where mounts have strode.
Cheers — lighter loops and happier nodes! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 accurately describes the main change: adding fast paths to OSFileStore.updateAttributes() across all platforms, which is the core objective of this PR.
Linked Issues check ✅ Passed The PR implements all coding requirements from issue #3185: fast paths using platform-specific syscalls (statvfs/statfs64/GetDiskFreeSpaceEx), fallback to full enumeration on failure, and helper methods for updating space/inode values.
Out of Scope Changes check ✅ Passed All changes directly support the objective of adding fast paths to updateAttributes(). Helper methods (updateSpaceAndInodes, updateSpace) and FFM bindings (statfs64 constants, MacSystemFunctions wrapper) are necessary supporting changes within scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📋 Issue Planner

Built with CodeRabbit's Coding Plans for faster development and fewer bugs.

View plan used: #3185

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code

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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (4)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java (1)

84-117: Fast path mirrors LinuxFileSystem.getFileStoreMatching correctly; small de-dup opportunity.

Index mapping (vfs[0..4] → totalInodes/freeInodes/totalSpace/usableSpace/freeSpace) and the totalSpace == 0L JVM fallback both match the enumeration code in LinuxFileSystem.getFileStoreMatching, so behavior is consistent. Returning true once the fast path succeeds is correct since logicalVolume/description/fsType don't change for an existing mount.

Optional cleanup: the field-copy block in the fallback (lines 105–112) is essentially updateFrom(fileStore). You could introduce a protected void updateFrom(OSFileStore) helper on LinuxOSFileStore (matching the pattern already used by MacOSFileStore and WindowsOSFileStore) to keep the three platforms structurally symmetric. Not a blocker.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java`
around lines 84 - 117, The fast-path duplication in updateAttributes can be
DRYed: add a protected void updateFrom(OSFileStore) method on LinuxOSFileStore
(matching MacOSFileStore/WindowsOSFileStore) that copies logicalVolume,
description, fsType, freeSpace, usableSpace, totalSpace, freeInodes, totalInodes
from the passed OSFileStore; then replace the fallback block that copies fields
from the matched fileStore (inside updateAttributes) with a call to
updateFrom(fileStore). Keep LinuxFileSystem.getFileStoreMatching usage
unchanged.
oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.java (1)

259-262: F_BSIZE/F_BLOCKS/F_BFREE/F_BAVAIL are added but not yet read anywhere in this PR.

MacOSFileStoreFFM.updateAttributes() only consumes F_FFREE and F_FILES; space values are taken from java.io.File. Two options to consider:

  1. Use these new accessors in the macOS FFM fast path to avoid a redundant second statvfs-equivalent syscall (java.io.File.getTotalSpace() ultimately calls statvfs again). The struct is already populated when we reach this point.
  2. If the design choice is intentionally to defer to java.io.File (e.g., to match the enumeration code path's behavior on totalSpace == 0), then dropping the unused constants from this PR keeps the patch surface tight and avoids confusing future readers.

Either way is fine — flagging because adding public interface fields that have no current consumer is a small wart.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.java` around lines 259 -
262, The new PathElement constants F_BSIZE, F_BLOCKS, F_BFREE and F_BAVAIL are
declared but never consumed; update MacOSFileStoreFFM.updateAttributes() to use
these populated fields to compute total/free/usable space (replacing the
java.io.File.getTotalSpace()/getUsableSpace() path and avoiding a second
statvfs), or if you intentionally want to keep delegating to java.io.File,
remove these unused public constants to avoid exposing dead API surface; locate
references to F_BSIZE/F_BLOCKS/F_BFREE/F_BAVAIL and
MacOSFileStoreFFM.updateAttributes() to implement the chosen change.
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java (1)

41-54: Fast path looks correct; one optional optimization to consider.

The flow is clean: confined Arena, STATFS buffer, UTF-8 path via allocateFrom, and a Throwable catch that logs at debug and falls through to the existing enumeration — consistent with the project's "return false on overall failure, but stay silent on transparent fallbacks" pattern.

Optional refactor: since STATFS is already populated on success, you could compute totalSpace/freeSpace/usableSpace directly from f_blocks * f_bsize, f_bfree * f_bsize, and f_bavail * f_bsize (using the new F_BSIZE/F_BLOCKS/F_BFREE/F_BAVAIL PathElements in MacSystem.java). That avoids the extra statvfs-equivalent syscall that java.io.File.getTotalSpace()/getUsableSpace()/getFreeSpace() performs on macOS, which slightly undercuts the O(1) goal of this PR.

♻️ Sketch
-            if (MacSystemFunctions.statfs64(pathSeg, buf) == 0) {
-                long ffree = buf.get(JAVA_LONG, STATFS.byteOffset(F_FFREE));
-                long files = buf.get(JAVA_LONG, STATFS.byteOffset(F_FILES));
-                File f = new File(getMount());
-                updateSpaceAndInodes(f.getFreeSpace(), f.getUsableSpace(), f.getTotalSpace(), ffree, files);
-                return true;
-            }
+            if (MacSystemFunctions.statfs64(pathSeg, buf) == 0) {
+                long bsize  = buf.get(JAVA_INT,  STATFS.byteOffset(F_BSIZE)) & 0xFFFFFFFFL;
+                long blocks = buf.get(JAVA_LONG, STATFS.byteOffset(F_BLOCKS));
+                long bfree  = buf.get(JAVA_LONG, STATFS.byteOffset(F_BFREE));
+                long bavail = buf.get(JAVA_LONG, STATFS.byteOffset(F_BAVAIL));
+                long ffree  = buf.get(JAVA_LONG, STATFS.byteOffset(F_FFREE));
+                long files  = buf.get(JAVA_LONG, STATFS.byteOffset(F_FILES));
+                updateSpaceAndInodes(bfree * bsize, bavail * bsize, blocks * bsize, ffree, files);
+                return true;
+            }

(If you prefer to keep the java.io.File route to mirror the existing MacFileSystem enumeration behavior, that's also defensible — flagging only because the constants were added presumably with this in mind.)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java`
around lines 41 - 54, The fast-path should compute total/free/usable bytes
directly from the populated STATFS buffer instead of calling java.io.File:
inside the try block where MacSystemFunctions.statfs64(pathSeg, buf) succeeds in
MacOSFileStoreFFM, read the block size and block counts using the new MacSystem
PathElements (F_BSIZE, F_BLOCKS, F_BFREE, F_BAVAIL) from the STATFS
MemorySegment, compute totalSpace = f_blocks * f_bsize, freeSpace = f_bfree *
f_bsize, usableSpace = f_bavail * f_bsize, and then call
updateSpaceAndInodes(totalSpace, usableSpace, totalSpace, ffree, files) (or the
correct order expected by updateSpaceAndInodes) instead of constructing
java.io.File and calling getFreeSpace/getUsableSpace/getTotalSpace; keep the
existing inode reads (F_FFREE/F_FILES) and the catch logging unchanged.
oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java (1)

31-37: Consider deriving space values from the Statfs struct to keep the fast path truly O(1) syscalls.

The fast path currently issues statfs64 plus three java.io.File calls (getFreeSpace, getUsableSpace, getTotalSpace), each of which performs its own underlying statvfs on Unix-like JVMs. Since you already have a populated Statfs in hand, you can compute all three from f_bsize, f_blocks, f_bfree, and f_bavail and avoid 3 extra syscalls per store on every refresh—which compounds across monitoring loops.

The Linux code already does this (see LinuxFileSystemJNA.java:28-32), so the pattern is proven in your codebase. That said, this is a deliberate design choice per the PR description ("uses java.io.File for space values"), so feel free to ignore if there's a reason (e.g., quota/APFS container nuances) the JDK values are preferred. If so, a one-line comment explaining why would help future readers.

♻️ Sketch of the alternative
-        if (SystemB.INSTANCE.statfs64(getMount(), stat) == 0) {
-            File f = new File(getMount());
-            updateSpaceAndInodes(f.getFreeSpace(), f.getUsableSpace(), f.getTotalSpace(), stat.f_ffree, stat.f_files);
-            return true;
-        }
+        if (SystemB.INSTANCE.statfs64(getMount(), stat) == 0) {
+            long bsize = stat.f_bsize;
+            long total = stat.f_blocks * bsize;
+            long free = stat.f_bfree * bsize;
+            long usable = stat.f_bavail * bsize;
+            updateSpaceAndInodes(free, usable, total, stat.f_ffree, stat.f_files);
+            return true;
+        }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java` around
lines 31 - 37, The fast path currently calls
SystemB.INSTANCE.statfs64(getMount(), stat) but then uses java.io.File
(getFreeSpace/getUsableSpace/getTotalSpace) causing extra syscalls; replace
these File calls by computing sizes from the populated Statfs struct (use
stat.f_bsize, stat.f_blocks, stat.f_bfree, stat.f_bavail) and pass those
computed free/usable/total values into updateSpaceAndInodes along with
stat.f_ffree and stat.f_files so the fast path remains O(1) (i.e., compute total
= f_bsize * f_blocks, free = f_bsize * f_bfree, usable = f_bsize * f_bavail
before calling updateSpaceAndInodes in the block that follows
SystemB.INSTANCE.statfs64).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java`:
- Around line 84-117: The fast-path duplication in updateAttributes can be
DRYed: add a protected void updateFrom(OSFileStore) method on LinuxOSFileStore
(matching MacOSFileStore/WindowsOSFileStore) that copies logicalVolume,
description, fsType, freeSpace, usableSpace, totalSpace, freeInodes, totalInodes
from the passed OSFileStore; then replace the fallback block that copies fields
from the matched fileStore (inside updateAttributes) with a call to
updateFrom(fileStore). Keep LinuxFileSystem.getFileStoreMatching usage
unchanged.

In `@oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.java`:
- Around line 259-262: The new PathElement constants F_BSIZE, F_BLOCKS, F_BFREE
and F_BAVAIL are declared but never consumed; update
MacOSFileStoreFFM.updateAttributes() to use these populated fields to compute
total/free/usable space (replacing the
java.io.File.getTotalSpace()/getUsableSpace() path and avoiding a second
statvfs), or if you intentionally want to keep delegating to java.io.File,
remove these unused public constants to avoid exposing dead API surface; locate
references to F_BSIZE/F_BLOCKS/F_BFREE/F_BAVAIL and
MacOSFileStoreFFM.updateAttributes() to implement the chosen change.

In `@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java`:
- Around line 41-54: The fast-path should compute total/free/usable bytes
directly from the populated STATFS buffer instead of calling java.io.File:
inside the try block where MacSystemFunctions.statfs64(pathSeg, buf) succeeds in
MacOSFileStoreFFM, read the block size and block counts using the new MacSystem
PathElements (F_BSIZE, F_BLOCKS, F_BFREE, F_BAVAIL) from the STATFS
MemorySegment, compute totalSpace = f_blocks * f_bsize, freeSpace = f_bfree *
f_bsize, usableSpace = f_bavail * f_bsize, and then call
updateSpaceAndInodes(totalSpace, usableSpace, totalSpace, ffree, files) (or the
correct order expected by updateSpaceAndInodes) instead of constructing
java.io.File and calling getFreeSpace/getUsableSpace/getTotalSpace; keep the
existing inode reads (F_FFREE/F_FILES) and the catch logging unchanged.

In `@oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java`:
- Around line 31-37: The fast path currently calls
SystemB.INSTANCE.statfs64(getMount(), stat) but then uses java.io.File
(getFreeSpace/getUsableSpace/getTotalSpace) causing extra syscalls; replace
these File calls by computing sizes from the populated Statfs struct (use
stat.f_bsize, stat.f_blocks, stat.f_bfree, stat.f_bavail) and pass those
computed free/usable/total values into updateSpaceAndInodes along with
stat.f_ffree and stat.f_files so the fast path remains O(1) (i.e., compute total
= f_bsize * f_blocks, free = f_bsize * f_bfree, usable = f_bsize * f_bavail
before calling updateSpaceAndInodes in the block that follows
SystemB.INSTANCE.statfs64).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 82cf6b6c-55c0-4ba5-944e-c381849e2b0f

📥 Commits

Reviewing files that changed from the base of the PR and between 529e5e4 and acb85a5.

📒 Files selected for processing (10)
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.java
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.java
  • oshi-core/src/main/java/oshi/jna/platform/mac/SystemB.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java
📚 Learning: 2026-04-03T02:07:49.467Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:49.467Z
Learning: In `oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java` (and similar FFM/API implementations in OSHI), the `updateAttributes()` method intentionally uses `catch (Throwable e) { return false; }` without logging. This is by design: `updateAttributes()` is a public API method whose contract is to return `false` on failure; callers consume the boolean and would never see log output, so adding a log statement is not desired.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
📚 Learning: 2026-04-17T23:43:35.860Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:35.860Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
🔇 Additional comments (7)
oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java (1)

96-108: LGTM — clean, single-responsibility helper.

The new updateSpace method is appropriately scoped (protected) so only the JNA/FFM Windows subclasses can call it, and the Javadoc clearly documents its narrower contract versus updateFrom. Inode fields correctly stay untouched on Windows, where they remain -1.

oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java (1)

96-113: LGTM — symmetric counterpart of the Windows helper.

updateSpaceAndInodes is the right shape for the macOS fast path: it covers everything statfs64 can refresh (space + inodes) without touching logicalVolume/description/fsType, which don't change for an existing mount. Visibility and Javadoc look good.

oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.java (1)

156-163: LGTM — binding matches int statfs64(const char *, struct statfs *).

FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS) and the wrapper signature line up with the existing style for getfsstat64/statfs64 neighbors.

oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.java (1)

34-47: LGTM — argument order maps correctly to GetDiskFreeSpaceEx.

Verified the mapping:

  • userFreeBytesBuf ↔ lpFreeBytesAvailableToCaller → usableSpace
  • totalBytesBuf ↔ lpTotalNumberOfBytes → totalSpace
  • systemFreeBytesBuf ↔ lpTotalNumberOfFreeBytes → freeSpace

This matches the JNA counterpart exactly, and the result.isPresent() && result.getAsInt() != 0 check correctly handles both the FFM-internal Throwable-swallow case and the native BOOL FALSE failure case before falling back to enumeration.

oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java (1)

30-38: LGTM — consistent with the FFM Windows implementation.

The JNA fast path mirrors WindowsOSFileStoreFFM (same arg→field mapping for GetDiskFreeSpaceEx), and the fallback to getLocalVolumes/getWmiVolumes is preserved unchanged. LARGE_INTEGER.getValue() correctly returns the 64-bit long for direct assignment.

Minor nit (non-blocking): the explicit new WinNT.LARGE_INTEGER(0L) initializers can be plain new WinNT.LARGE_INTEGER() since the value is overwritten by GetDiskFreeSpaceEx on success and discarded on failure — but the current form is arguably clearer about the initial state.

oshi-core/src/main/java/oshi/jna/platform/mac/SystemB.java (1)

175-186: LGTM — clean JNA binding for statfs64.

Signature, javadoc, and return-code semantics all match the macOS man page, and using String for the path parameter aligns with how other path-taking calls in this interface are declared. Nice addition.

oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java (1)

38-46: LGTM — fallback preserves prior behavior.

Nice that the existing enumeration path is retained verbatim for the unmounted/removed-mount case; this keeps the contract of updateAttributes() intact while still letting the fast path do its job in the common case.

@codecov

codecov Bot commented Apr 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 2.53165% with 77 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.98%. Comparing base (529e5e4) to head (fb776bd).

Files with missing lines Patch % Lines
...shi/software/common/os/linux/LinuxOSFileStore.java 0.00% 28 Missing ⚠️
...n/java/oshi/software/os/mac/MacOSFileStoreFFM.java 6.25% 15 Missing ⚠️
...shi/software/os/windows/WindowsOSFileStoreFFM.java 0.00% 10 Missing ⚠️
...n/java/oshi/software/os/mac/MacOSFileStoreJNA.java 11.11% 8 Missing ⚠️
...va/oshi/software/common/os/mac/MacOSFileStore.java 0.00% 6 Missing ⚠️
...shi/software/os/windows/WindowsOSFileStoreJNA.java 0.00% 6 Missing ⚠️
...software/common/os/windows/WindowsOSFileStore.java 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3195      +/-   ##
==========================================
- Coverage   58.16%   57.98%   -0.18%     
==========================================
  Files         421      421              
  Lines       20264    20335      +71     
  Branches     3563     3576      +13     
==========================================
+ Hits        11786    11792       +6     
- Misses       6715     6781      +66     
+ Partials     1763     1762       -1     
Flag Coverage Δ
linux 23.66% <0.00%> (-0.08%) ⬇️
macos 26.69% <2.53%> (-0.08%) ⬇️
windows 35.54% <0.00%> (-0.12%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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 force-pushed the fix/fast-path-updateAttributes branch from acb85a5 to 3bafdb5 Compare April 25, 2026 22:51

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java (1)

85-101: Fast path looks correct and mirrors getFileStoreMatching() validation.

The totalSpace == 0L guard correctly handles the documented case where queryStatvfs succeeds but returns untrustworthy zeros (consistent with LinuxFileSystem.getFileStoreMatching()). When statvfs() outright fails (e.g., the mount was removed), queryStatvfs returns null per the JNA implementation, so the full-enumeration fallback below is reached as intended.

One small consistency note vs. the macOS counterpart: MacOSFileStore factors space/inode assignments into an updateSpaceAndInodes(...) helper, while here the assignments are inlined. Not a blocker — just worth considering if you want symmetry across platforms.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java`
around lines 85 - 101, Refactor the inlined space/inode assignment in
LinuxOSFileStore where queryStatvfs(...) sets totalInodes, freeInodes,
totalSpace, usableSpace and freeSpace into a shared helper (e.g.,
updateSpaceAndInodes(long[] vfs) or updateSpaceAndInodes(long totalInodes, long
freeInodes, long totalSpace, long usableSpace, long freeSpace) ), then call that
helper from the fast path and from any other code paths that set these fields
(mirroring MacOSFileStore's updateSpaceAndInodes usage) and preserve the
existing totalSpace == 0L JVM-fallback behavior by invoking the helper after
determining final values.
oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java (1)

29-36: Consider guarding the fast path with try/catch for parity with the FFM implementation.

Thanks for the contribution — the fast path looks good and the unsigned masking on f_bsize is correct. One small consistency concern: the FFM sibling (MacOSFileStoreFFM, ~lines 40–66) wraps its statfs64 fast path in try { ... } catch (Throwable e) { LOG.debug(...) } so any unexpected native/runtime error still falls through to the enumeration fallback. Here, if SystemB.INSTANCE.statfs64 ever throws (e.g., a JNA mapping problem or an UnsatisfiedLinkError on an unusual system), the fallback for-loop is bypassed and the caller sees an exception instead of false/the enumerated result — which contradicts the PR objective of always preserving a fallback.

Returning -1 on a normal syscall failure is already handled correctly; this is purely about defensive parity for the unexpected-throw case.

🛡️ Suggested defensive wrapping (mirrors the FFM version)
     `@Override`
     public boolean updateAttributes() {
         // Fast path: call statfs64 directly on the known mount point
-        Statfs stat = new Statfs();
-        if (SystemB.INSTANCE.statfs64(getMount(), stat) == 0) {
-            long bsize = stat.f_bsize & 0xFFFFFFFFL;
-            updateSpaceAndInodes(stat.f_bfree * bsize, stat.f_bavail * bsize, stat.f_blocks * bsize, stat.f_ffree,
-                    stat.f_files);
-            return true;
+        try {
+            Statfs stat = new Statfs();
+            if (SystemB.INSTANCE.statfs64(getMount(), stat) == 0) {
+                long bsize = stat.f_bsize & 0xFFFFFFFFL;
+                updateSpaceAndInodes(stat.f_bfree * bsize, stat.f_bavail * bsize, stat.f_blocks * bsize,
+                        stat.f_ffree, stat.f_files);
+                return true;
+            }
+        } catch (Throwable e) {
+            // Fall through to full enumeration below
         }
         // Fall back to full enumeration
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java` around
lines 29 - 36, Wrap the fast-path call in MacOSFileStoreJNA that invokes
SystemB.INSTANCE.statfs64 with a try/catch to mirror MacOSFileStoreFFM: catch
Throwable around the Statfs allocation and statfs64 invocation, log the
exception with LOG.debug including context (e.g., mount point and the throwable)
and let execution fall through to the enumeration fallback by returning false
only on normal syscall failure (when statfs64 returns non-zero) — ensure you
still compute bsize and call updateSpaceAndInodes(stat.f_bfree * bsize,
stat.f_bavail * bsize, stat.f_blocks * bsize, stat.f_ffree, stat.f_files) when
statfs64 returns 0.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java`:
- Around line 85-101: Refactor the inlined space/inode assignment in
LinuxOSFileStore where queryStatvfs(...) sets totalInodes, freeInodes,
totalSpace, usableSpace and freeSpace into a shared helper (e.g.,
updateSpaceAndInodes(long[] vfs) or updateSpaceAndInodes(long totalInodes, long
freeInodes, long totalSpace, long usableSpace, long freeSpace) ), then call that
helper from the fast path and from any other code paths that set these fields
(mirroring MacOSFileStore's updateSpaceAndInodes usage) and preserve the
existing totalSpace == 0L JVM-fallback behavior by invoking the helper after
determining final values.

In `@oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java`:
- Around line 29-36: Wrap the fast-path call in MacOSFileStoreJNA that invokes
SystemB.INSTANCE.statfs64 with a try/catch to mirror MacOSFileStoreFFM: catch
Throwable around the Statfs allocation and statfs64 invocation, log the
exception with LOG.debug including context (e.g., mount point and the throwable)
and let execution fall through to the enumeration fallback by returning false
only on normal syscall failure (when statfs64 returns non-zero) — ensure you
still compute bsize and call updateSpaceAndInodes(stat.f_bfree * bsize,
stat.f_bavail * bsize, stat.f_blocks * bsize, stat.f_ffree, stat.f_files) when
statfs64 returns 0.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cb96ae26-82cb-44a8-ba5b-26d0ebc5ed54

📥 Commits

Reviewing files that changed from the base of the PR and between acb85a5 and 3bafdb5.

📒 Files selected for processing (10)
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.java
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.java
  • oshi-core/src/main/java/oshi/jna/platform/mac/SystemB.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
✅ Files skipped from review due to trivial changes (2)
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2026-04-03T02:07:49.467Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:49.467Z
Learning: In `oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java` (and similar FFM/API implementations in OSHI), the `updateAttributes()` method intentionally uses `catch (Throwable e) { return false; }` without logging. This is by design: `updateAttributes()` is a public API method whose contract is to return `false` on failure; callers consume the boolean and would never see log output, so adding a log statement is not desired.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java
🔇 Additional comments (6)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java (1)

112-121: Nice extraction of updateFrom(OSFileStore).

Centralizing the field copy makes the fallback path easier to read and matches the pattern used in the Mac/Windows file store classes in this PR.

oshi-core/src/main/java/oshi/jna/platform/mac/SystemB.java (1)

175-186: Welcome and nice clean binding!

The statfs64 declaration matches the macOS prototype, the javadoc is clear, and reusing the existing com.sun.jna.platform.mac.SystemB.Statfs keeps things tidy. 👍

oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java (1)

38-44: Fallback enumeration preserved — looks good.

The fallback loop is unchanged and still matches on both volume and mount, so behavior on fast-path failure (e.g., a removed mount returning -1 from statfs64) is preserved as intended. 🎉

oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.java (1)

156-164: LGTM — clean addition that matches the surrounding style.

The statfs64 MethodHandle and wrapper mirror the existing getfsstat64 binding pattern (function descriptor (JAVA_INT, ADDRESS, ADDRESS) matches the native int statfs64(const char *path, struct statfs *buf) signature), and no CAPTURE_CALL_STATE is used — consistent with other neighboring bindings that don't read errno. Welcome aboard, and thanks for the contribution! 🐇

oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java (2)

59-69: Fallback structure looks great.

Catching Throwable is required here because of invokeExact, the debug log is appropriate (this isn't the same as the "return false silently" pattern — you're falling through to a recovery path, so a breadcrumb is genuinely useful), and the existing enumeration/match path is preserved verbatim, which keeps backward-compatibility for the "mount removed/replaced" case called out in the PR objectives. Nice job preserving the contract while still getting the O(1) win. 🎉


49-58: No action needed — the FFM implementation correctly aligns with the JNA implementation. Both use statfs64 to derive space values from the block fields (f_bsize × f_blocks, f_bfree × bsize, f_bavail × bsize), and both extract inode counts directly from the struct (f_files, f_ffree). No divergence exists between the two backends.

			> Likely an incorrect or invalid review comment.

@dbwiddis
dbwiddis force-pushed the fix/fast-path-updateAttributes branch from 3bafdb5 to 97a31d2 Compare April 25, 2026 23:12

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java (1)

111-118: Parameter order differs from MacOSFileStore.updateSpaceAndInodes(...) — easy to mis-call later.

MacOSFileStore.updateSpaceAndInodes is (freeSpace, usableSpace, totalSpace, freeInodes, totalInodes), but this private helper here is (totalSpace, usableSpace, freeSpace, totalInodes, freeInodes) — both space and inode pairs are swapped. Each implementation is internally correct today, but if anyone later promotes this to a shared helper or copies the call site between platforms, it's a foot-gun.

Consider aligning to the Mac signature for consistency:

♻️ Proposed alignment
-            updateSpaceAndInodes(ts, us, frs, vfs[0], vfs[1]);
+            updateSpaceAndInodes(frs, us, ts, vfs[1], vfs[0]);
-    private void updateSpaceAndInodes(long totalSpace, long usableSpace, long freeSpace, long totalInodes,
-            long freeInodes) {
+    private void updateSpaceAndInodes(long freeSpace, long usableSpace, long totalSpace, long freeInodes,
+            long totalInodes) {
         this.totalSpace = totalSpace;
         this.usableSpace = usableSpace;
         this.freeSpace = freeSpace;
         this.totalInodes = totalInodes;
         this.freeInodes = freeInodes;
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java`
around lines 111 - 118, The private method LinuxOSFileStore.updateSpaceAndInodes
has a different parameter order than MacOSFileStore.updateSpaceAndInodes which
is error-prone; change LinuxOSFileStore.updateSpaceAndInodes signature to match
MacOSFileStore (freeSpace, usableSpace, totalSpace, freeInodes, totalInodes),
then update the body to assign this.freeSpace, this.usableSpace,
this.totalSpace, this.freeInodes, this.totalInodes in that order and adjust any
internal callers in LinuxOSFileStore to pass arguments in the new order so field
assignments remain correct.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java`:
- Around line 111-118: The private method LinuxOSFileStore.updateSpaceAndInodes
has a different parameter order than MacOSFileStore.updateSpaceAndInodes which
is error-prone; change LinuxOSFileStore.updateSpaceAndInodes signature to match
MacOSFileStore (freeSpace, usableSpace, totalSpace, freeInodes, totalInodes),
then update the body to assign this.freeSpace, this.usableSpace,
this.totalSpace, this.freeInodes, this.totalInodes in that order and adjust any
internal callers in LinuxOSFileStore to pass arguments in the new order so field
assignments remain correct.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d17a6aac-374d-4e7d-9013-8748513910c6

📥 Commits

Reviewing files that changed from the base of the PR and between 3bafdb5 and 97a31d2.

📒 Files selected for processing (10)
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.java
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.java
  • oshi-core/src/main/java/oshi/jna/platform/mac/SystemB.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
✅ Files skipped from review due to trivial changes (1)
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • oshi-core/src/main/java/oshi/jna/platform/mac/SystemB.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2026-04-03T02:07:49.467Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:49.467Z
Learning: In `oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java` (and similar FFM/API implementations in OSHI), the `updateAttributes()` method intentionally uses `catch (Throwable e) { return false; }` without logging. This is by design: `updateAttributes()` is a public API method whose contract is to return `false` on failure; callers consume the boolean and would never see log output, so adding a log statement is not desired.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
🔇 Additional comments (8)
oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java (1)

96-108: LGTM — clean, minimal helper.

updateSpace correctly avoids touching identity/description/inode fields, which is exactly what the Windows fast path needs (Windows leaves inodes at -1). Welcome to the project, and thanks for keeping the API surface small here. 🎉

oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java (1)

31-38: Mapping to updateSpace(free, usable, total) looks correct.

For anyone reading later: GetDiskFreeSpaceEx's 2nd/3rd/4th out-params are lpFreeBytesAvailable (per-caller/quota = usable), lpTotalNumberOfBytes (total), lpTotalNumberOfFreeBytes (system-wide free). Your call to updateSpace(systemFreeBytes, userFreeBytes, totalBytes) lines up with (freeSpace, usableSpace, totalSpace). 👍

One small thing worth confirming: GetDiskFreeSpaceEx requires the root path to end in a backslash. getVolume() for the local-volume path here is typically populated as X:\ from getLocalVolumes, so this should be fine — but if a caller ever constructs a WindowsOSFileStoreJNA directly with a non-rooted volume string, the fast path will simply fail and fall back, which is the intended behavior.

oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java (2)

92-97: Nice handling of statvfs-reports-zero filesystems.

Falling back to java.io.File for space when vfs[2] == 0 (procfs/sysfs/overlayfs quirks) while still trusting the inode counts from the native call is a sensible compromise and preserves the pre-PR behavior. 👍


86-100: The vfs[] index ordering is correct — the array layout matches the documented return value in LinuxFileSystem.queryStatvfs(): [totalInodes, freeInodes, totalSpace, usableSpace, freeSpace]. The indices you're using (vfs[0]/vfs[1] for inodes, vfs[2]/vfs[3]/vfs[4] for space) align perfectly with the producer and the updateSpaceAndInodes() parameter order.

The frs variable name is a minor readability note if you'd like to consider it, but nothing blocks this as-is.

oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.java (1)

156-163: LGTM — binding is consistent with the surrounding style.

FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS) matches int statfs64(const char *path, struct statfs *buf), and the wrapper mirrors the other downcall patterns in this class. Good neighbor.

oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java (1)

44-61: LGTM — fast path looks correct.

A few things checked while reading:

  • Integer.toUnsignedLong(f_bsize) matches the JNA path's & 0xFFFFFFFFL — both treat f_bsize as unsigned 32-bit. ✓
  • Parameter order to updateSpaceAndInodes(freeSpace, usableSpace, totalSpace, freeInodes, totalInodes) lines up correctly. ✓
  • The confined Arena is properly try-with-resources scoped, so the off-heap buf/pathSeg are released after the call. ✓
  • arena.allocateFrom(getMount()) produces a UTF-8 C-string, which is what macOS expects for path arguments. ✓

Logging at DEBUG before falling back (rather than swallowing silently) is fine here since this is a fast-path-failure breadcrumb, not the outer "method returned false" case.

oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java (1)

96-113: LGTM — symmetrical with the JNA/FFM call sites.

Helper is nicely scoped to just space/inodes and leaves identity fields alone, which is exactly what the fast path needs. (Heads-up: the Linux private helper of the same name uses a different parameter order — I've left a comment over there suggesting alignment to this signature.)

oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java (1)

33-45: LGTM — JNA fast path matches the FFM variant.

f_bsize & 0xFFFFFFFFL and the call to updateSpaceAndInodes(stat.f_bfree * bsize, stat.f_bavail * bsize, stat.f_blocks * bsize, stat.f_ffree, stat.f_files) map cleanly onto the base helper's (freeSpace, usableSpace, totalSpace, freeInodes, totalInodes) signature. ✓

Minor consistency note (non-blocking): the Linux fast path silently falls back when queryStatvfs returns null, whereas the Mac FFM/JNA paths log a DEBUG breadcrumb on Throwable. Both are defensible — queryStatvfs already handles its own errors internally, while a raw statfs64 JNA call can throw. Worth being aware of if a future refactor consolidates the patterns.

@dbwiddis
dbwiddis force-pushed the fix/fast-path-updateAttributes branch from 97a31d2 to fb776bd Compare April 25, 2026 23:21

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java (2)

93-93: Tiny style nit: prefer importing java.io.File.

The rest of the file uses imports rather than fully-qualified class names, so importing java.io.File would be more consistent. Purely cosmetic — feel free to ignore if you'd rather keep the diff small.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java`
at line 93, Replace the fully-qualified java.io.File usage with an imported File
to match the file's existing style: add the import statement `import
java.io.File;` at the top of the file and change the instantiation in
LinuxOSFileStore (the variable `f` created from `getMount()`) from `java.io.File
f = new java.io.File(getMount());` to use `File f = new File(getMount());`.

84-109: Nice fast-path; consider naming the vfs[] slots for readability.

The logic looks correct: native syscall first, JVM-File fallback when total space is reported as 0L (which neatly handles filesystems where statvfs returns zeros for space without losing the inode values), and a final fallback to full enumeration when queryStatvfs returns null. Welcome change for the O(N²) → O(N) reduction.

One minor readability nit: the meaning of vfs[0], vfs[1], vfs[2..4] is implicit — a reader has to cross-reference LinuxFileSystem.queryStatvfs to know that vfs[0] is total inodes and vfs[1] is free inodes. Naming them at the call site (or a brief comment) would make this self-documenting and protect against accidental index swaps if the array layout ever changes.

♻️ Optional: name the slots locally
         // Fast path: query space/inode stats directly on the known mount point
         long[] vfs = fs.queryStatvfs(getMount());
         if (vfs != null) {
-            long ts = vfs[2];
-            long us = vfs[3];
-            long frs = vfs[4];
+            long totalInodes = vfs[0];
+            long freeInodes = vfs[1];
+            long ts = vfs[2];
+            long us = vfs[3];
+            long frs = vfs[4];
             // If native methods failed use JVM methods
             if (ts == 0L) {
                 java.io.File f = new java.io.File(getMount());
                 ts = f.getTotalSpace();
                 us = f.getUsableSpace();
                 frs = f.getFreeSpace();
             }
-            updateSpaceAndInodes(frs, us, ts, vfs[1], vfs[0]);
+            updateSpaceAndInodes(frs, us, ts, freeInodes, totalInodes);
             return true;
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java`
around lines 84 - 109, In updateAttributes(), the meaning of vfs[] indexes is
implicit; replace or supplement the raw array indexing from
fs.queryStatvfs(getMount()) with named local variables (e.g., totalInodes,
freeInodes, totalSpace, usableSpace, freeSpace) derived from vfs[0], vfs[1],
vfs[2], vfs[3], vfs[4] (or add a concise comment) before calling
updateSpaceAndInodes(...) so the call site and the fallback JVM-file logic
(java.io.File getMount()) clearly show which slot maps to which value; reference
LinuxFileSystem.queryStatvfs and updateSpaceAndInodes to ensure the local names
match the native layout.
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java (1)

60-60: Optional: pass the throwable to SLF4J for a stack trace. 🪵

Tiny nit — when this fast path fails unexpectedly, only e.getMessage() is captured. Passing e as the last argument lets SLF4J render the full stack trace at DEBUG, which can save time when diagnosing layout/linker mismatches. Totally optional; ignore if you prefer the terser line.

♻️ Optional refactor
-        } catch (Throwable e) {
-            LOG.debug("statfs64 fast path failed for {}: {}", getMount(), e.getMessage());
-        }
+        } catch (Throwable e) {
+            LOG.debug("statfs64 fast path failed for {}", getMount(), e);
+        }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java` at
line 60, The DEBUG log in MacOSFileStoreFFM currently logs only e.getMessage()
for the statfs64 fast path failure; update the LOG.debug call (in the statfs64
fast path handling within class MacOSFileStoreFFM, referencing getMount() and
variable e) to pass the throwable e as the final argument so SLF4J can render
the full stack trace (i.e., keep the existing message and placeholders but add e
as an extra parameter).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java`:
- Around line 36-45: The fast-path in MacOSFileStoreJNA currently uses
statfs64-derived byte counts for space; change it to obtain space values from
java.io.File instead while still using inode counts from the Statfs result:
create a File f = new File(getMount()) and call f.getFreeSpace(),
f.getUsableSpace(), and f.getTotalSpace() to pass to updateSpaceAndInodes,
keeping stat.f_ffree and stat.f_files for inode arguments; also add/import
java.io.File if missing and keep the Statfs/statfs64 call for inodes as now.

---

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java`:
- Line 93: Replace the fully-qualified java.io.File usage with an imported File
to match the file's existing style: add the import statement `import
java.io.File;` at the top of the file and change the instantiation in
LinuxOSFileStore (the variable `f` created from `getMount()`) from `java.io.File
f = new java.io.File(getMount());` to use `File f = new File(getMount());`.
- Around line 84-109: In updateAttributes(), the meaning of vfs[] indexes is
implicit; replace or supplement the raw array indexing from
fs.queryStatvfs(getMount()) with named local variables (e.g., totalInodes,
freeInodes, totalSpace, usableSpace, freeSpace) derived from vfs[0], vfs[1],
vfs[2], vfs[3], vfs[4] (or add a concise comment) before calling
updateSpaceAndInodes(...) so the call site and the fallback JVM-file logic
(java.io.File getMount()) clearly show which slot maps to which value; reference
LinuxFileSystem.queryStatvfs and updateSpaceAndInodes to ensure the local names
match the native layout.

In `@oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java`:
- Line 60: The DEBUG log in MacOSFileStoreFFM currently logs only e.getMessage()
for the statfs64 fast path failure; update the LOG.debug call (in the statfs64
fast path handling within class MacOSFileStoreFFM, referencing getMount() and
variable e) to pass the throwable e as the final argument so SLF4J can render
the full stack trace (i.e., keep the existing message and placeholders but add e
as an extra parameter).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 779c6884-3d76-440c-9102-6c0248a1b774

📥 Commits

Reviewing files that changed from the base of the PR and between 97a31d2 and fb776bd.

📒 Files selected for processing (10)
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.java
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.java
  • oshi-core/src/main/java/oshi/jna/platform/mac/SystemB.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
✅ Files skipped from review due to trivial changes (1)
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java
📚 Learning: 2026-04-03T02:07:49.467Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:49.467Z
Learning: In `oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java` (and similar FFM/API implementations in OSHI), the `updateAttributes()` method intentionally uses `catch (Throwable e) { return false; }` without logging. This is by design: `updateAttributes()` is a public API method whose contract is to return `false` on failure; callers consume the boolean and would never see log output, so adding a log statement is not desired.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
🔇 Additional comments (6)
oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java (1)

96-108: LGTM — clean, minimal helper for the Windows fast path! 🎉

The new updateSpace() helper is a tidy counterpart to updateFrom() and slots in nicely with the fast-path callers in WindowsOSFileStoreJNA and WindowsOSFileStoreFFM. Leaving freeInodes/totalInodes untouched is correct here since they're not applicable on Windows, and skipping logicalVolume/description/fsType is reasonable given those are effectively static for a given volume after construction.

Welcome contribution to the O(N²) → O(N) effort — thanks for keeping the surface area small and focused! 🙌

oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java (1)

111-129: Helper extraction LGTM.

updateSpaceAndInodes and updateFrom cleanly separate the two refresh paths and are reused symmetrically across platforms per the PR description. Identity fields from AbstractOSFileStore (name, volume, mount, etc.) are correctly left untouched by updateFrom since they don't change for an existing store.

oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.java (1)

156-163: LGTM! 🎉

The new statfs64 binding follows the same pattern as the other System library handles in this file, and the descriptor (JAVA_INT, ADDRESS, ADDRESS) matches the native signature int statfs64(const char *path, struct statfs *buf). Welcome change — clean, consistent, and minimal.

oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java (1)

44-70: Fast path looks correct — nice O(1) win. ✅

Spot-checked the math against the STATFS layout and updateSpaceAndInodes(freeSpace, usableSpace, totalSpace, freeInodes, totalInodes):

  • bfree * bsize → freeSpace ✓
  • bavail * bsize → usableSpace ✓
  • blocks * bsize → totalSpace ✓
  • ffree → freeInodes, files → totalInodes ✓

f_bsize is uint32_t natively, and Integer.toUnsignedLong(...) correctly preserves that on Line 50. The confined Arena cleans up the path/struct buffers deterministically, and the fallback to MacFileSystemFFM.getFileStoreMatching(...) preserves the previous semantics if the syscall path fails. The catch (Throwable) pattern is consistent with prior conventions for updateAttributes() in this codebase, and debug-level logging is fine here since a real fallback follows.

oshi-core/src/main/java/oshi/jna/platform/mac/SystemB.java (1)

175-186: Clean binding addition — LGTM!

The signature mirrors the macOS statfs64(2) prototype, the javadoc captures the 0 / -1 + errno contract, and Statfs is already exposed via the parent com.sun.jna.platform.mac.SystemB. Nice and tidy alongside the existing getfsstat64 binding.

oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java (1)

32-54: Fast-path structure looks great overall.

The O(1) shortcut with a graceful fall-through to the existing enumeration is exactly what issue #3185 asked for, and the f_bsize & 0xFFFFFFFFL unsigned widening is correct for the uint32_t field. The catch (Throwable) → debug log → fallback flow keeps the public updateAttributes() contract intact even if JNA throws on an unexpected platform quirk. 👍

… Windows

Instead of re-enumerating all mounted filesystems, updateAttributes() now
calls the stat syscall directly on the known mount point:
- Linux: queryStatvfs() on the mount path (works for both JNA and FFM)
- macOS: new statfs64() binding (JNA and FFM) for per-path inode stats,
  java.io.File for space values
- Windows: GetDiskFreeSpaceEx() on the known volume (JNA and FFM)

Each platform falls back to the existing full-enumeration path if the
direct call fails (e.g., mount was removed).

This reduces updateAttributes() from O(N) enumeration to O(1) per store,
and a monitoring loop over N stores from O(N²) to O(N).

Closes #3185

Signed-off-by: Dan Widdis <[email protected]>
@dbwiddis
dbwiddis force-pushed the fix/fast-path-updateAttributes branch from fb776bd to e807006 Compare April 25, 2026 23:39

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java (1)

36-47: Welcome and nice work on the fast path! 🎉

The shape is exactly right: statfs64 for inodes, java.io.File for space, and a graceful fallback to full enumeration on failure. The earlier feedback about sourcing space values from java.io.File has been incorporated cleanly.

One small, optional thought (from the PR description, the Linux fast path apparently falls back when the native call yields zero total space): if getMount() becomes briefly unavailable between the statfs64 call and the File.getTotalSpace() call, the File methods will silently return 0, and the fast path will still return true with zeroed space. Mirroring Linux's "fallback if total space is 0" guard would make the macOS path consistent and self-healing in that narrow race:

♻️ Optional consistency tweak
             if (SystemB.INSTANCE.statfs64(getMount(), stat) == 0) {
                 File f = new File(getMount());
-                updateSpaceAndInodes(f.getFreeSpace(), f.getUsableSpace(), f.getTotalSpace(), stat.f_ffree,
-                        stat.f_files);
-                return true;
+                long total = f.getTotalSpace();
+                if (total > 0) {
+                    updateSpaceAndInodes(f.getFreeSpace(), f.getUsableSpace(), total, stat.f_ffree, stat.f_files);
+                    return true;
+                }
             }

Totally fine to defer — the existing fallback path will still recover on the next refresh.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java` around
lines 36 - 47, The fast-path returns true even if java.io.File reports zero
total space after calling SystemB.INSTANCE.statfs64(getMount(), stat); add a
guard after creating File f = new File(getMount()) to check f.getTotalSpace() >
0 and if it is zero, do not call updateSpaceAndInodes and instead allow the
method to fall through to the full enumeration fallback; keep existing behavior
of using stat.f_ffree and stat.f_files when total space is non-zero so
updateSpaceAndInodes(...) is only invoked on a non-zero total.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java`:
- Around line 36-47: The fast-path returns true even if java.io.File reports
zero total space after calling SystemB.INSTANCE.statfs64(getMount(), stat); add
a guard after creating File f = new File(getMount()) to check f.getTotalSpace()
> 0 and if it is zero, do not call updateSpaceAndInodes and instead allow the
method to fall through to the full enumeration fallback; keep existing behavior
of using stat.f_ffree and stat.f_files when total space is non-zero so
updateSpaceAndInodes(...) is only invoked on a non-zero total.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: feff4b24-ea35-4383-9282-7c7cd1659be3

📥 Commits

Reviewing files that changed from the base of the PR and between fb776bd and e807006.

📒 Files selected for processing (10)
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.java
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.java
  • oshi-core/src/main/java/oshi/jna/platform/mac/SystemB.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
✅ Files skipped from review due to trivial changes (2)
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.java
🚧 Files skipped from review as they are similar to previous changes (4)
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (6)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
📚 Learning: 2026-04-03T02:07:49.467Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:49.467Z
Learning: In `oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java` (and similar FFM/API implementations in OSHI), the `updateAttributes()` method intentionally uses `catch (Throwable e) { return false; }` without logging. This is by design: `updateAttributes()` is a public API method whose contract is to return `false` on failure; callers consume the boolean and would never see log output, so adding a log statement is not desired.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
📚 Learning: 2026-04-18T22:53:56.149Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:56.149Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
📚 Learning: 2026-04-10T22:44:36.786Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:36.786Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
🔇 Additional comments (3)
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java (1)

41-54: Clean FFM mirror of the JNA fast path — nicely done!

Arena.ofConfined() with try-with-resources, named STATFS path elements, and a graceful fallback all look good. The same optional "treat zero total space as a fallback trigger" suggestion I left on MacOSFileStoreJNA applies here too, for parity with the Linux fast path described in the PR summary. No need to address it now if you'd rather keep the change minimal.

oshi-core/src/main/java/oshi/jna/platform/mac/SystemB.java (1)

175-185: Clean JNA binding — looks great!

The signature mirrors macOS's int statfs64(const char *path, struct statfs *buf) cleanly, and the JavaDoc captures the success/errno semantics. Nothing to add here.

oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java (1)

96-113: Nice focused helper.

Surgical update of just the space/inode fields keeps logicalVolume/description/fsType stable across fast-path refreshes — exactly what the platform-specific fast paths need. JavaDoc matches the parameter order, which always makes future-me happy.

@dbwiddis
dbwiddis merged commit 48fbcf2 into oshi:master Apr 25, 2026
13 of 15 checks passed
@dbwiddis
dbwiddis deleted the fix/fast-path-updateAttributes branch April 25, 2026 23:46
dbwiddis added a commit that referenced this pull request May 9, 2026
- Add native-free Linux SystemInfoProvider and Apple Silicon fix to 7.2.0
- Fix issue links to point to implementing PRs (#3230, #3232, #3227)
- Add macOS disk type (#3231) and OSFileStore fast path (#3195)
- Mention native-free Linux option in README Usage section
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.

OSFileStore.updateAttributes() re-enumerates all mounts instead of querying the known path

1 participant