You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/**
* @return disk size, in GB
*/
public long getTotalDisk() {
long total=0;
for(HWDiskStore d : info.getHardware().getDiskStores()){
total += d.getSize();
}
return Math.round((double)total/1024/1024/1024);
}
'info' is an instance of SystemInfo. It returns the correct size in GB on windows(windows 7), but on linux(centos 7) it needs to be divided by 1000 to get the correct size. Is that a hard driver vendor's problem? How do I convert disk size to GB correctly?
OSHI gets its disk size for Linux from the udev system, specifically: udev_device_get_sysattr_value(device, "size")
This returns the size in sectors, which is multiplied by a sector size constant of 512.
So if it's wrong, either udev is returning the value in 1000s of sectors, or the sector size is 512000. I'm not familiar with CentOS but if you can take a look at either of those outputs you can help us narrow this down.
Hi, my hard drive type is "WDC WD10EZEX". Here is my disk info using "fdisk -l":
I have a dual system. sda6~8 are centos partitions, formated as ext4. Others are windows ntfs partitions.
In the "getTotalDisk" method, total equals 1000204886016. If divided by 1000, it matches the disk size returned by fdisk.
Right now I don't know how to get the value returned by udev. I'll search for some udev cmd, or write some c code (which I'm not very familiar with) using the udev_device_get_sysattr_value method.
I'm a bit confused here. You said getTotalDisk returns 1000204886016 bytes. That is precisely the number shown in the fdisk -l printout above for /dev/sda.
Oh, I didn't see the bytes, I just focused on the "1000.2 GB". So oshi works correctly. Maybe that's a problem relating to fdisk? I just noticed that the size of sda1~11 added manually = 1000204886016/1024/1024/1024
Activity
dbwiddis commentedon Dec 18, 2017
OSHI gets its disk size for Linux from the
udevsystem, specifically:udev_device_get_sysattr_value(device, "size")This returns the size in sectors, which is multiplied by a sector size constant of 512.
So if it's wrong, either
udevis returning the value in 1000s of sectors, or the sector size is 512000. I'm not familiar with CentOS but if you can take a look at either of those outputs you can help us narrow this down.sify21 commentedon Dec 20, 2017
Hi, my hard drive type is "WDC WD10EZEX". Here is my disk info using "fdisk -l":


I have a dual system. sda6~8 are centos partitions, formated as ext4. Others are windows ntfs partitions.
In the "getTotalDisk" method, total equals 1000204886016. If divided by 1000, it matches the disk size returned by fdisk.
Right now I don't know how to get the value returned by udev. I'll search for some udev cmd, or write some c code (which I'm not very familiar with) using the udev_device_get_sysattr_value method.
dbwiddis commentedon Dec 20, 2017
I'm a bit confused here. You said
getTotalDiskreturns 1000204886016 bytes. That is precisely the number shown in thefdisk -lprintout above for/dev/sda.sify21 commentedon Dec 21, 2017
Oh, I didn't see the bytes, I just focused on the "1000.2 GB". So oshi works correctly. Maybe that's a problem relating to fdisk? I just noticed that the size of sda1~11 added manually = 1000204886016/1024/1024/1024