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

Can I get the disk model number? #1456

Open
Teeoo opened this issue Apr 28, 2023 · 2 comments
Open

Can I get the disk model number? #1456

Teeoo opened this issue Apr 28, 2023 · 2 comments

Comments

@Teeoo
Copy link

Teeoo commented Apr 28, 2023

Is your feature request related to a problem? Please describe.
[A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]]

Describe the solution you'd like
[A clear and concise description of what you want to happen.]

Describe alternatives you've considered
This is currently how it gets the job done

    var cmd *exec.Cmd
    if runtime.GOOS == "windows" {
        cmd = exec.Command("wmic", "diskdrive", "get", "model")
    } else if runtime.GOOS == "linux" {
        cmd = exec.Command("sh", "-c", "lsblk -d -o name,model | grep '^sd' | awk '{print $2}'")
    } else if runtime.GOOS == "darwin" {
        cmd = exec.Command("sh", "-c", "system_profiler SPSerialATADataType | awk '/Revision/ {print $3}'")
    } else {
        fmt.Println("Unsupported OS")
        return
    }
    out, err := cmd.Output()
    if err != nil {
        fmt.Println("Error:", err)
        return
    }
    model := strings.TrimSpace(string(out))
    fmt.Println("Disk Model:", model)

Additional context
[Add any other context or screenshots about the feature request here.]

@shirou
Copy link
Owner

shirou commented May 13, 2023

Thank you for your suggestion. I've given it some thought.

  1. This function can be obtained on 3 different operating systems: windows, linux, darwin
  2. There is no model number in psutil.
  3. However, there are already functions SerialNumber and Label in disk package.

As for No. 1, it MUST be done, but it is accomplished. As for No. 2, it is a negative point. However, for the reason of No. 3, adding ModelNumber() here seems to be OK.

Therefore, if there are no objections, I will try to implement it in the near future. However, I am not sure how much time I will have, so the completion schedule is unknown (PR is always welcome).

The function signature should be like this.

func Model(name string) (string, error)

@stevenparkerco3
Copy link

stevenparkerco3 commented Aug 28, 2023

On an M2 Mac, with OSX 13.4.1 and an NVMe HDD, you'll have to modify the command to:

me@mymac ~ % system_profiler -detaillevel mini SPNVMeDataType      
NVMExpress:

    Apple SSD Controller:

        APPLE SSD AP0512Z:

          Capacity: 500.28 GB (500,277,792,768 bytes)
          TRIM Support: Yes
          Model: APPLE SSD AP0512Z
          Revision: 874.120.
          Detachable Drive: No
          BSD Name: disk0
          Partition Map Type: GPT (GUID Partition Table)
          Removable Media: No
          S.M.A.R.T. status: Verified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants