gitee.com/mirrors_u-root/u-root@v7.0.0+incompatible/pkg/mount/scuzz/control.go (about)

     1  // Copyright 2019 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package scuzz
     6  
     7  import (
     8  	"encoding/json"
     9  	"fmt"
    10  	"time"
    11  )
    12  
    13  // DefaultTimeout is the default timeout for disk operations.
    14  const DefaultTimeout time.Duration = 15 * time.Second
    15  
    16  // Info is information about a SCSI disk device.
    17  type Info struct {
    18  	NumberSectors           uint64
    19  	ECCBytes                uint
    20  	MasterPasswordRev       uint16
    21  	SecurityStatus          uint16
    22  	TrustedComputingSupport uint16
    23  
    24  	Serial           string
    25  	Model            string
    26  	FirmwareRevision string
    27  
    28  	// These are the pair-byte-swapped space-padded versions of serial,
    29  	// model, and firmware revision as originally returned by the SCSI
    30  	// device.
    31  	OrigSerial           string
    32  	OrigModel            string
    33  	OrigFirmwareRevision string
    34  }
    35  
    36  // Disk is the interface to a disk, with operations to create packets and
    37  // operate on them.
    38  type Disk interface {
    39  	// Unlock unlocks the drive, given a password and an indication of
    40  	// whether it is the admin (true) or user (false) password.
    41  	Unlock(password string, admin bool) error
    42  
    43  	// Identify returns drive identity information
    44  	Identify() (*Info, error)
    45  }
    46  
    47  // String prints a nice JSON-formatted info.
    48  func (i *Info) String() string {
    49  	s, err := json.MarshalIndent(i, "", "\t")
    50  	if err != nil {
    51  		return fmt.Sprintf("%v", err)
    52  	}
    53  	return string(s)
    54  }