-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
117 lines (100 loc) · 2.48 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
// vim: ts=4:sts=4
import (
"encoding/json"
"errors"
"fmt"
flags "github.com/jessevdk/go-flags"
"os"
"time"
)
type OptionsStruct struct {
Device string `short:"f" long:"device" value-name:"DEV" description:"Tape device (default: /dev/nst0, or TAPE envvar)"`
Mock bool `long:"mock" description:"Use a mocked tape drive (for tests only)"`
Debug bool `short:"d" long:"debug" description:"Print debug information"`
Dump string `long:"dump" value-name:"FILE" description:"Dump SCSI raw data to a file"`
Man bool `hidden:"1" long:"man"`
}
func main() {
var err error
options := &OptionsStruct{}
parser := flags.NewParser(options, flags.Default)
_, err = parser.Parse()
if err != nil {
os.Exit(1)
}
if options.Man {
fmt.Println("man")
parser.WriteManPage(os.Stdout)
return
}
// err = attrSet0803(dev, "Cartouche de Test YaY! 3 spaces: ")
// fmt.Println("Set:",err)
var drive *TapeDrive
syncerr := make(chan error)
go func() {
if options.Mock {
drive, err = TapeDriveNewFake()
} else {
drive, err = TapeDriveNew(options.Device)
}
syncerr <- err
}()
openerr := errors.New("timeout")
started := time.Now()
waitupto := started.Add(time.Second * 20)
lastprint := started
waitfor:
for waitupto.After(time.Now()) && openerr != nil {
select {
case openerr = <-syncerr:
if openerr != nil {
fmt.Println("Failed")
os.Exit(1)
} else {
// openerr
break waitfor
}
default:
if time.Since(lastprint) > time.Second {
fmt.Printf("Still trying to open the device, aborting in %s...\n", time.Until(waitupto).Round(time.Second))
lastprint = time.Now()
}
}
time.Sleep(10 * time.Millisecond)
}
if openerr != nil {
fmt.Println("Timed out opening device, is a tape inserted?")
os.Exit(1)
} else {
fmt.Printf("Device %s opened\n", drive.DeviceName)
}
if options.Dump != "" {
drive.SetDumpFile(options.Dump)
}
/*
poh := &LogSenseType{0x3C, 0x0008}
err = scsiLogSense(dev, poh)
if err != nil {
fmt.Println("logtest:",err)
/ }
*/
//fmt.Println("Inquiry")
/*err =*/
drive.ScsiInquiry()
//fmt.Println("Inquiry err:")
//fmt.Println(err)
drive.GetStatus()
for i, a := range attributes {
fmt.Printf("\rReading attribute %02d/%02d...", i+1, len(attributes))
drive.GetAttribute(a)
if options.Debug {
j, _ := json.MarshalIndent(a, "", " ")
fmt.Println(string(j))
}
}
fmt.Println("")
//fmt.Printf("\r \r")
//drive.CmList.Print()
fmt.Println(drive)
}