Skip to content

Commit 4583ce7

Browse files
committed
Add the supportedvpdpages example
1 parent e9ae23b commit 4583ce7

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "supportedvpdpages",
3+
"description": "Getting the supported VPD pages",
4+
"copyright": "Copyright © 2015, Lucas Burson",
5+
"authors": ["Lucas Burson"],
6+
"dependencies": {
7+
"sgio-d": {"version": "~master", "path": "../../"}
8+
},
9+
"targetType": "executable"
10+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import std.stdio : writeln;
2+
3+
import sgio.inquiry.inquiry;
4+
import sgio.SCSIDevice;
5+
import sgio.utility;
6+
import sgio.exceptions;
7+
import sgio.SCSICommand;
8+
9+
int main(string[] args)
10+
{
11+
if (args.length <= 1)
12+
{
13+
writeln("app <device>");
14+
return 1;
15+
}
16+
17+
auto deviceName = args[1];
18+
19+
// TODO: this should be generalized somehow. nasty os-specific.
20+
version (Windows)
21+
{
22+
wchar* thefile = std.utf.toUTFz!(wchar*)(deviceName);
23+
auto file = CreateFileW(thefile,
24+
GENERIC_WRITE|GENERIC_READ,
25+
FILE_SHARE_WRITE|FILE_SHARE_READ,
26+
null, OPEN_EXISTING,
27+
FILE_ATTRIBUTE_NORMAL, null);
28+
29+
if (file == INVALID_HANDLE_VALUE)
30+
{
31+
writeln("failed to open device");
32+
return 1;
33+
}
34+
auto dev = new SCSIDeviceBS(cast(uint)(file));
35+
}
36+
version (Posix)
37+
{
38+
auto file = File(deviceName, "rb");
39+
auto dev = new SCSIDeviceBS(file.fileno());
40+
}
41+
42+
try
43+
{
44+
auto vpdpages = new SupportedVPDPagesInquiry(dev);
45+
writeln("Here are the suppored VPD pages for " ~ deviceName);
46+
writeln(writeBuffer(vpdpages.supported_pages, vpdpages.supported_pages.length));
47+
}
48+
catch (SCSIException err)
49+
{
50+
writeln("SCSIException... Message: ", err.msg);
51+
return 1;
52+
}
53+
finally
54+
{
55+
version (Posix)
56+
{
57+
file.close();
58+
}
59+
version (Windows)
60+
{
61+
CloseHandle(file);
62+
}
63+
}
64+
return 0;
65+
}

0 commit comments

Comments
 (0)