GuillaumeGomez / sysinfo

Cross-platform library to fetch system information
MIT License
2.06k stars 306 forks source link

get disk space info incorrect on windows #426

Closed rustbomber closed 3 years ago

rustbomber commented 3 years ago

on some machine, my disk total space is 5TB and use code, some partition total space is incorrect

let total_space = disk.get_total_space();
let available_space = disk.get_available_space();
let used_space = (disk.get_total_space() - disk.get_available_space());

WeChatWorkScreenshot_23dc209c-dc23-4c19-b813-1b5199e8e42f

but D/E/F partition total is 5785851133440.

[
    {
      "total_space": 214745610240,
      "available_space": 127209074688,
      "used_space": 87536535552,
      "usage": 40.762897,
      "file_system": "NTFS",
      "name": "未指定" //C
    },
    {
      "total_space": 5785851133440,    //here
      "available_space": 80036704256,
      "used_space": 5705814429184,
      "usage": 98.616684,
      "file_system": "NTFS",
      "name": "软件" //D
    },
    {
      "total_space": 5785851133440,  //here
      "available_space": 1524733210624,
      "used_space": 4261117922816,
      "usage": 73.64722,
      "file_system": "NTFS",
      "name": "数据" //E
    },
    {
      "total_space": 5785851133440,  //here
      "available_space": 877719977984,
      "used_space": 4908131155456,
      "usage": 84.82989,
      "file_system": "NTFS",
      "name": "测试" //F
    }
  ]

I also use golang test, with package github.com/shirou/gopsutil/v3, is report correct:

[{
    "path": "C:",
    "fstype": "",
    "total": 214379261952,
    "free": 134845419520,
    "used": 79533842432,
    "usedPercent": 37.09959709153575,
    "inodesTotal": 0,
    "inodesUsed": 0,
    "inodesFree": 0,
    "inodesUsedPercent": 0
}, {
    "path": "D:",
    "fstype": "",
    "total": 214748360704,
    "free": 79829192704,
    "used": 134919168000,
    "usedPercent": 62.82663465169209,
    "inodesTotal": 0,
    "inodesUsed": 0,
    "inodesFree": 0,
    "inodesUsedPercent": 0
}, {
    "path": "E:",
    "fstype": "",
    "total": 4497230262272,
    "free": 1521829142528,
    "used": 2975401119744,
    "usedPercent": 66.16074664233065,
    "inodesTotal": 0,
    "inodesUsed": 0,
    "inodesFree": 0,
    "inodesUsedPercent": 0
}, {
    "path": "F:",
    "fstype": "",
    "total": 1073740771328,
    "free": 877156130816,
    "used": 196584640512,
    "usedPercent": 18.308389302276805,
    "inodesTotal": 0,
    "inodesUsed": 0,
    "inodesFree": 0,
    "inodesUsedPercent": 0
}]
GuillaumeGomez commented 3 years ago

Thanks for reporting the issue! Maybe @mjarkk would be interested into taking a look? :smiley:

mjarkk commented 3 years ago

I'll check it out.
@akaylh Is it true D, E and F are one disk with 3 partitions because the partitions seem to fit into 5785851133440?

GuillaumeGomez commented 3 years ago

Awesome! Thanks a lot!

rustbomber commented 3 years ago

I'll check it out. @akaylh Is it true D, E and F are one disk with 3 partitions because the partitions seem to fit into 5785851133440?

yes, my server have two disk in fact:

image

mjarkk commented 3 years ago

Ah this also explains then why your C disk in this library is bigger than gopsutil.

rustbomber commented 3 years ago

Ah this also explains then why your C disk in this library is bigger than gopsutil.

I think the problem should not be here, mainly because the total space of D/E/F is incorrect 。

BTW:My English is a weak!

mjarkk commented 3 years ago

I've created a pr to fix this #431