Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add free/total inode counts #659

Merged
merged 19 commits into from
Oct 23, 2018
Merged

Add free/total inode counts #659

merged 19 commits into from
Oct 23, 2018

Conversation

Space2Man
Copy link
Contributor

Hi,

initial pull request ... not sure about the variable names ... in LibC I have called them (free|total)InodeCounts because that's what it is (at least on Linux) ... not sure if it's called like that for all the other OS as well. In FreeBSD it's called

file serial numbers (i.e., inodes)

But in LinuxFileSystem I have called them file counts ... let me know what you prefer. Furthermore I had issues using the "new" JNA stuff ... if you convert the existing Sysinfo I can adapt Statvfs as well.

Furthermore I have set it to -1 for all other OS except of Linux ... not sure how to implement it for FreeBSD, Solaris, MacOS, ...

@dbwiddis
Copy link
Member

dbwiddis commented Oct 20, 2018

I think "inode" is fine; it seems standard terminology/POSIX standard on all the *nix-based systems including mac, and there's no windows equivalent.

Check out here for the "new" JNA way to do Sysinfo.

totalSpace = vfsStat.fsSizeInBlocks.longValue() * vfsStat.fsBlockSize.longValue();
usableSpace = vfsStat.fsBlocksFree.longValue() * vfsStat.fsBlockSize.longValue();
} else {
totalSpace = new File(path).getTotalSpace();
Copy link
Member

Choose a reason for hiding this comment

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

don't create a new File object twice.

LOG.error("Failed to get file counts from statvfs. {}", e);
}

OSFileStore osStore = new OSFileStore(name, volume, path, description, type, uuid, usableSpace, totalSpace, usableFiles, totalFiles);
Copy link
Member

Choose a reason for hiding this comment

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

Use a no-argument constructor and setters.

*
* @return Usable files / free inodes on the drive (count)
*/
public long getUsableFiles() {
Copy link
Member

Choose a reason for hiding this comment

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

per comments, let's go with freeInodes()

@dbwiddis dbwiddis force-pushed the master branch 2 times, most recently from 96afac1 to a8cd334 Compare October 21, 2018 02:08
jogi added 3 commits October 21, 2018 18:24
- Avoid calling new File() twice
- use Constructor + setters
@oshi oshi deleted a comment Oct 21, 2018
@dbwiddis
Copy link
Member

Looking good so far....

For Solaris you should be able to do something similar to Linux with the Statvfs structure. For Mac and FreeBSD you're going to have to parse the output of df -i. And for Windows just leave as default/unimplemented.

@dbwiddis
Copy link
Member

Also travis-ci can no longer test on oraclejdk10 so for the time being you can just delete that in your .travis.yml file so the PR build tests don't show red. I can't seem to get it to work with oraclejdk11 yet due to some issue with surefire plugin and writing to the console. Hopefully I'll get it figured out soon...

@Space2Man
Copy link
Contributor Author

Is someone able to help with Solaris / Mac / FreeBSD? I have no such system at hand ...

@dbwiddis
Copy link
Member

I can help with those. Can you get rid of the “-1, -1” add ones to those constructors though? Stick with the original constructors or switch to no-arg with the -1 as the initialization.

@Space2Man
Copy link
Contributor Author

I pushed a new version ... Switched back to the original constructors and added a copy constructor for json instead ...

@dbwiddis
Copy link
Member

Looks good. I'll see if I can check out your branch and send commits to it for the other OS's.

@dbwiddis
Copy link
Member

dbwiddis commented Oct 22, 2018

Heh. Mac was trivial, the needed values were already in the Statfs structure we already had.

Macintosh HD (Volume) [apfs] 86.4 GiB of 465.7 GiB free (18.6%), 9223372036852193649 of 9223372036854775807 files free (100.0%) is /dev/disk1s1 [/] and is mounted at null

I've committed implementations for Mac, Solaris, and FreeBSD to your master branch.

@oshi oshi deleted a comment Oct 22, 2018
@oshi oshi deleted a comment Oct 22, 2018
if (split.length > 7) {
inodeFreeMap.put(split[0], ParseUtil.parseLongOrDefault(split[6], 0L));
// total is actually used + free
if (inodeFreeMap.get(split[0]) >= 0) {
Copy link
Member

Choose a reason for hiding this comment

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

This conditional should be removed since I changed the default from -1.

* @return On success, zero is returned. On error, -1 is returned, and errno
* is set appropriately.
*/
int statvfs(String path, Statvfs buf);
Copy link
Member

Choose a reason for hiding this comment

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

Need to write a test method for this.

if (split.length > 7) {
inodeFreeMap.put(split[0], ParseUtil.parseLongOrDefault(split[6], 0L));
// total is actually used + free
if (inodeFreeMap.get(split[0]) >= 0) {
Copy link
Member

Choose a reason for hiding this comment

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

need to remove this conditional left over from earlier logic.

@codecov-io
Copy link

codecov-io commented Oct 22, 2018

Codecov Report

Merging #659 into master will decrease coverage by 0.25%.
The diff coverage is 81.81%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #659      +/-   ##
============================================
- Coverage      83.9%   83.64%   -0.26%     
- Complexity      197      198       +1     
============================================
  Files            28       28              
  Lines          1460     1480      +20     
  Branches        211      213       +2     
============================================
+ Hits           1225     1238      +13     
- Misses          112      117       +5     
- Partials        123      125       +2
Impacted Files Coverage Δ Complexity Δ
...re/src/main/java/oshi/software/os/OSFileStore.java 100% <100%> (+5%) 0 <0> (ø) ⬇️
...c/main/java/oshi/json/software/os/OSFileStore.java 71.18% <50%> (-10.45%) 20 <2> (+1)
...n/src/main/java/oshi/json/util/PropertiesUtil.java 76.92% <0%> (-3.85%) 9% <0%> (ø)
...hi-core/src/main/java/oshi/hardware/NetworkIF.java 81.42% <0%> (-0.27%) 0% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 696a208...44fdbff. Read the comment docs.

@dbwiddis dbwiddis changed the title - Initial version of fileCount Add free/total inode counts Oct 23, 2018
@dbwiddis dbwiddis merged commit 5ef8bb2 into oshi:master Oct 23, 2018
Copy link
Contributor Author

@Space2Man Space2Man left a comment

Choose a reason for hiding this comment

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

Hi,

looks like for Windows now OSFileStore.mount is not set any more ... previously it was the drive (strMount) which is now stored in OSFileStore.logicalVolume ... is this wanted?

@dbwiddis
Copy link
Member

No... that error was everywhere and I backed it out the other 4 OS's but since we weren't adding the new fields to Windows I didn't even bother looking! Whoops. Can you fix?

@Space2Man
Copy link
Contributor Author

see #664

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.

3 participants