Repository navigation
Add fast path to OSFileStore.updateAttributes() for all platforms - #3195
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📋 Issue PlannerBuilt with CodeRabbit's Coding Plans for faster development and fewer bugs. View plan used: ✨ Finishing Touches✨ Simplify 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (4)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java (1)
84-117: Fast path mirrorsLinuxFileSystem.getFileStoreMatchingcorrectly; small de-dup opportunity.Index mapping (
vfs[0..4]→ totalInodes/freeInodes/totalSpace/usableSpace/freeSpace) and thetotalSpace == 0LJVM fallback both match the enumeration code inLinuxFileSystem.getFileStoreMatching, so behavior is consistent. Returningtrueonce the fast path succeeds is correct sincelogicalVolume/description/fsTypedon'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 aprotected void updateFrom(OSFileStore)helper onLinuxOSFileStore(matching the pattern already used byMacOSFileStoreandWindowsOSFileStore) 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_BAVAILare added but not yet read anywhere in this PR.
MacOSFileStoreFFM.updateAttributes()only consumesF_FFREEandF_FILES; space values are taken fromjava.io.File. Two options to consider:
- Use these new accessors in the macOS FFM fast path to avoid a redundant second
statvfs-equivalent syscall (java.io.File.getTotalSpace()ultimately callsstatvfsagain). The struct is already populated when we reach this point.- If the design choice is intentionally to defer to
java.io.File(e.g., to match the enumeration code path's behavior ontotalSpace == 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,STATFSbuffer, UTF-8 path viaallocateFrom, and aThrowablecatch 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
STATFSis already populated on success, you could computetotalSpace/freeSpace/usableSpacedirectly fromf_blocks * f_bsize,f_bfree * f_bsize, andf_bavail * f_bsize(using the newF_BSIZE/F_BLOCKS/F_BFREE/F_BAVAILPathElements inMacSystem.java). That avoids the extrastatvfs-equivalent syscall thatjava.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.Fileroute to mirror the existingMacFileSystemenumeration 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 theStatfsstruct to keep the fast path truly O(1) syscalls.The fast path currently issues
statfs64plus threejava.io.Filecalls (getFreeSpace,getUsableSpace,getTotalSpace), each of which performs its own underlyingstatvfson Unix-like JVMs. Since you already have a populatedStatfsin hand, you can compute all three fromf_bsize,f_blocks,f_bfree, andf_bavailand 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
📒 Files selected for processing (10)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.javaoshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.javaoshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.javaoshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.javaoshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.javaoshi-core/src/main/java/oshi/jna/platform/mac/SystemB.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.javaoshi-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.javaoshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.javaoshi-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.javaoshi-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
updateSpacemethod is appropriately scoped (protected) so only the JNA/FFM Windows subclasses can call it, and the Javadoc clearly documents its narrower contract versusupdateFrom. 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.
updateSpaceAndInodesis the right shape for the macOS fast path: it covers everythingstatfs64can refresh (space + inodes) without touchinglogicalVolume/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 matchesint statfs64(const char *, struct statfs *).
FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS)and the wrapper signature line up with the existing style forgetfsstat64/statfs64neighbors.oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.java (1)
34-47: LGTM — argument order maps correctly toGetDiskFreeSpaceEx.Verified the mapping:
userFreeBytesBuf↔lpFreeBytesAvailableToCaller→usableSpacetotalBytesBuf↔lpTotalNumberOfBytes→totalSpacesystemFreeBytesBuf↔lpTotalNumberOfFreeBytes→freeSpaceThis matches the JNA counterpart exactly, and the
result.isPresent() && result.getAsInt() != 0check correctly handles both the FFM-internalThrowable-swallow case and the nativeBOOL FALSEfailure 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 forGetDiskFreeSpaceEx), and the fallback togetLocalVolumes/getWmiVolumesis 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 plainnew WinNT.LARGE_INTEGER()since the value is overwritten byGetDiskFreeSpaceExon 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 forstatfs64.Signature, javadoc, and return-code semantics all match the macOS man page, and using
Stringfor 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 Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
acb85a5 to
3bafdb5
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java (1)
85-101: Fast path looks correct and mirrorsgetFileStoreMatching()validation.The
totalSpace == 0Lguard correctly handles the documented case wherequeryStatvfssucceeds but returns untrustworthy zeros (consistent withLinuxFileSystem.getFileStoreMatching()). Whenstatvfs()outright fails (e.g., the mount was removed),queryStatvfsreturnsnullper the JNA implementation, so the full-enumeration fallback below is reached as intended.One small consistency note vs. the macOS counterpart:
MacOSFileStorefactors space/inode assignments into anupdateSpaceAndInodes(...)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_bsizeis correct. One small consistency concern: the FFM sibling (MacOSFileStoreFFM, ~lines 40–66) wraps itsstatfs64fast path intry { ... } catch (Throwable e) { LOG.debug(...) }so any unexpected native/runtime error still falls through to the enumeration fallback. Here, ifSystemB.INSTANCE.statfs64ever throws (e.g., a JNA mapping problem or anUnsatisfiedLinkErroron an unusual system), the fallbackfor-loop is bypassed and the caller sees an exception instead offalse/the enumerated result — which contradicts the PR objective of always preserving a fallback.Returning
-1on 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
📒 Files selected for processing (10)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.javaoshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.javaoshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.javaoshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.javaoshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.javaoshi-core/src/main/java/oshi/jna/platform/mac/SystemB.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.javaoshi-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.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.javaoshi-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 ofupdateFrom(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
statfs64declaration matches the macOS prototype, the javadoc is clear, and reusing the existingcom.sun.jna.platform.mac.SystemB.Statfskeeps 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
volumeandmount, so behavior on fast-path failure (e.g., a removed mount returning -1 fromstatfs64) 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
statfs64MethodHandleand wrapper mirror the existinggetfsstat64binding pattern (function descriptor(JAVA_INT, ADDRESS, ADDRESS)matches the nativeint statfs64(const char *path, struct statfs *buf)signature), and noCAPTURE_CALL_STATEis used — consistent with other neighboring bindings that don't readerrno. 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
Throwableis required here because ofinvokeExact, 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 usestatfs64to 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.
3bafdb5 to
97a31d2
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java (1)
111-118: Parameter order differs fromMacOSFileStore.updateSpaceAndInodes(...)— easy to mis-call later.
MacOSFileStore.updateSpaceAndInodesis(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
📒 Files selected for processing (10)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.javaoshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.javaoshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.javaoshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.javaoshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.javaoshi-core/src/main/java/oshi/jna/platform/mac/SystemB.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.javaoshi-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.javaoshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.javaoshi-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.javaoshi-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.
updateSpacecorrectly 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 toupdateSpace(free, usable, total)looks correct.For anyone reading later:
GetDiskFreeSpaceEx's 2nd/3rd/4th out-params arelpFreeBytesAvailable(per-caller/quota = usable),lpTotalNumberOfBytes(total),lpTotalNumberOfFreeBytes(system-wide free). Your call toupdateSpace(systemFreeBytes, userFreeBytes, totalBytes)lines up with(freeSpace, usableSpace, totalSpace). 👍One small thing worth confirming:
GetDiskFreeSpaceExrequires the root path to end in a backslash.getVolume()for the local-volume path here is typically populated asX:\fromgetLocalVolumes, so this should be fine — but if a caller ever constructs aWindowsOSFileStoreJNAdirectly 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.Filefor space whenvfs[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: Thevfs[]index ordering is correct — the array layout matches the documented return value inLinuxFileSystem.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 theupdateSpaceAndInodes()parameter order.The
frsvariable 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)matchesint 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 treatf_bsizeas unsigned 32-bit. ✓- Parameter order to
updateSpaceAndInodes(freeSpace, usableSpace, totalSpace, freeInodes, totalInodes)lines up correctly. ✓- The confined
Arenais properly try-with-resources scoped, so the off-heapbuf/pathSegare 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 & 0xFFFFFFFFLand the call toupdateSpaceAndInodes(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
queryStatvfsreturnsnull, whereas the Mac FFM/JNA paths log a DEBUG breadcrumb onThrowable. Both are defensible —queryStatvfsalready handles its own errors internally, while a rawstatfs64JNA call can throw. Worth being aware of if a future refactor consolidates the patterns.
97a31d2 to
fb776bd
Compare
There was a problem hiding this comment.
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 importingjava.io.File.The rest of the file uses imports rather than fully-qualified class names, so importing
java.io.Filewould 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 thevfs[]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 whenqueryStatvfsreturnsnull. 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-referenceLinuxFileSystem.queryStatvfsto know thatvfs[0]is total inodes andvfs[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. Passingeas 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
📒 Files selected for processing (10)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.javaoshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.javaoshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.javaoshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.javaoshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.javaoshi-core/src/main/java/oshi/jna/platform/mac/SystemB.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.javaoshi-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.javaoshi-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.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.javaoshi-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 toupdateFrom()and slots in nicely with the fast-path callers inWindowsOSFileStoreJNAandWindowsOSFileStoreFFM. LeavingfreeInodes/totalInodesuntouched is correct here since they're not applicable on Windows, and skippinglogicalVolume/description/fsTypeis 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.
updateSpaceAndInodesandupdateFromcleanly separate the two refresh paths and are reused symmetrically across platforms per the PR description. Identity fields fromAbstractOSFileStore(name, volume, mount, etc.) are correctly left untouched byupdateFromsince 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
statfs64binding follows the same pattern as the other System library handles in this file, and the descriptor(JAVA_INT, ADDRESS, ADDRESS)matches the native signatureint 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
STATFSlayout andupdateSpaceAndInodes(freeSpace, usableSpace, totalSpace, freeInodes, totalInodes):
bfree * bsize→ freeSpace ✓bavail * bsize→ usableSpace ✓blocks * bsize→ totalSpace ✓ffree→ freeInodes,files→ totalInodes ✓
f_bsizeisuint32_tnatively, andInteger.toUnsignedLong(...)correctly preserves that on Line 50. The confinedArenacleans up the path/struct buffers deterministically, and the fallback toMacFileSystemFFM.getFileStoreMatching(...)preserves the previous semantics if the syscall path fails. Thecatch (Throwable)pattern is consistent with prior conventions forupdateAttributes()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 +errnocontract, andStatfsis already exposed via the parentcom.sun.jna.platform.mac.SystemB. Nice and tidy alongside the existinggetfsstat64binding.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
#3185asked for, and thef_bsize & 0xFFFFFFFFLunsigned widening is correct for theuint32_tfield. Thecatch (Throwable) → debug log → fallbackflow keeps the publicupdateAttributes()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]>
fb776bd to
e807006
Compare
There was a problem hiding this comment.
🧹 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.Filefor space, and a graceful fallback to full enumeration on failure. The earlier feedback about sourcing space values fromjava.io.Filehas 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 thestatfs64call and theFile.getTotalSpace()call, theFilemethods will silently return0, and the fast path will still returntruewith 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
📒 Files selected for processing (10)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.javaoshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.javaoshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.javaoshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystem.javaoshi-core-ffm/src/main/java/oshi/ffm/mac/MacSystemFunctions.javaoshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSFileStoreFFM.javaoshi-core/src/main/java/oshi/jna/platform/mac/SystemB.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.javaoshi-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.javaoshi-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, namedSTATFSpath elements, and a graceful fallback all look good. The same optional "treat zero total space as a fallback trigger" suggestion I left onMacOSFileStoreJNAapplies 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/errnosemantics. 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/fsTypestable across fast-path refreshes — exactly what the platform-specific fast paths need. JavaDoc matches the parameter order, which always makes future-me happy.
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
queryStatvfs()directly on the mount pathLinuxOSFileStoreis inoshi-commonandqueryStatvfs()is resolved polymorphicallyjava.io.Filemethods if native call returns zero total spacemacOS
statfs64()per-path binding in both JNA (SystemB) and FFM (MacSystemFunctions)f_files,f_ffree) from the struct; usesjava.io.Filefor space values (matching existing pattern ingetFileStoreMatching)updateSpaceAndInodes()helper toMacOSFileStorebase classWindows
GetDiskFreeSpaceExdirectly on the known volume path (bindings already exist in both JNA and FFM)updateSpace()helper toWindowsOSFileStorebase 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 storeVerification
spotless:apply— no formatting changes neededcheckstyle:check— 0 violationsforbiddenapis:check— 0 errorsjavadoc:javadoc— builds successfullyCloses #3185
Summary by CodeRabbit
Performance Improvements
Bug Fixes / Reliability
Compatibility