-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add options to only run INQUIRY and to scan the bus to scsidump (#1092)…
… (#1261) * Add options to only run INQUIRY and to scan the bus to scsidump
- Loading branch information
Showing
8 changed files
with
324 additions
and
175 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,66 @@ | ||
|
||
//--------------------------------------------------------------------------- | ||
// | ||
// SCSI Target Emulator PiSCSI | ||
// for Raspberry Pi | ||
// | ||
// Copyright (C) 2022 akuker | ||
// Copyright (C) 2023 Uwe Seimet | ||
// | ||
//--------------------------------------------------------------------------- | ||
|
||
#include "mocks.h" | ||
#include <gtest/gtest.h> | ||
|
||
#include "scsidump/scsidump_core.h" | ||
#include "test/test_shared.h" | ||
#include <filesystem> | ||
#include <fstream> | ||
|
||
using namespace std; | ||
using namespace filesystem; | ||
|
||
class TestableScsidump : public ScsiDump | ||
{ | ||
public: | ||
static void PublicGeneratePropertiesFile(const string& filename, const inquiry_info_t& inq_info) | ||
{ | ||
ScsiDump::GeneratePropertiesFile(filename, inq_info); | ||
} | ||
}; | ||
|
||
TEST(ScsiDumpTest, GeneratePropertiesFile) | ||
{ | ||
// Basic test | ||
const string prop_file_name = "test.properties"; | ||
ScsiDump::inquiry_info_t test_data = { | ||
// Basic test | ||
auto filename = CreateTempFile(0); | ||
ScsiDump::inquiry_info_t test_data = { | ||
.vendor = "PISCSI", .product = "TEST PRODUCT", .revision = "REV1", .sector_size = 1000, .capacity = 100}; | ||
TestableScsidump::PublicGeneratePropertiesFile("test", test_data); | ||
test_data.GeneratePropertiesFile(filename); | ||
|
||
string expected_str = "{\n" | ||
" \"vendor\": \"PISCSI\",\n" | ||
" \"product\": \"TEST PRODUCT\",\n" | ||
" \"revision\": \"REV1\",\n" | ||
" \"block_size\": \"1000\",\n}" | ||
" \"block_size\": \"1000\"\n}" | ||
"\n"; | ||
EXPECT_EQ(ReadTempFileToString(prop_file_name), expected_str); | ||
EXPECT_EQ(expected_str, ReadTempFileToString(filename)); | ||
|
||
// Long string test | ||
filename = CreateTempFile(0); | ||
test_data = {.vendor = "01234567", | ||
.product = "0123456789ABCDEF", | ||
.revision = "0123", | ||
.sector_size = UINT32_MAX, | ||
.capacity = UINT64_MAX}; | ||
TestableScsidump::PublicGeneratePropertiesFile("test", test_data); | ||
test_data.GeneratePropertiesFile(filename); | ||
|
||
expected_str = "{\n" | ||
" \"vendor\": \"01234567\",\n" | ||
" \"product\": \"0123456789ABCDEF\",\n" | ||
" \"revision\": \"0123\",\n" | ||
" \"block_size\": \"4294967295\",\n" | ||
" \"block_size\": \"4294967295\"\n" | ||
"}\n"; | ||
EXPECT_EQ(ReadTempFileToString(prop_file_name), expected_str); | ||
EXPECT_EQ(expected_str, ReadTempFileToString(filename)); | ||
remove(filename); | ||
|
||
// Empty data test | ||
filename = CreateTempFile(0); | ||
test_data = {.vendor = "", .product = "", .revision = "", .sector_size = 0, .capacity = 0}; | ||
TestableScsidump::PublicGeneratePropertiesFile("test", test_data); | ||
test_data.GeneratePropertiesFile(filename); | ||
|
||
expected_str = "{\n" | ||
" \"vendor\": \"\",\n" | ||
" \"product\": \"\",\n" | ||
" \"revision\": \"\",\n" | ||
" \"block_size\": \"0\",\n" | ||
" \"block_size\": \"0\"\n" | ||
"}\n"; | ||
EXPECT_EQ(ReadTempFileToString(prop_file_name), expected_str); | ||
EXPECT_EQ(expected_str, ReadTempFileToString(filename)); | ||
remove(filename); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,83 @@ | ||
!! ------ THIS FILE IS AUTO_GENERATED! DO NOT MANUALLY UPDATE!!! | ||
!! ------ The native file is scsidump.1. Re-run 'make docs' after updating | ||
|
||
|
||
scsidump(1) General Commands Manual scsidump(1) | ||
!! ------ The native file is scsidump.1. Re-run 'make docs' after updating\n\n | ||
scsidump(1) General Commands Manual scsidump(1) | ||
|
||
NAME | ||
scsidump - SCSI disk dumping tool for PiSCSI | ||
|
||
SYNOPSIS | ||
scsidump -t ID[:LUN] [-i BID] -f FILE [-s BUFFER_SIZE] [-r] [-v] [-p] | ||
scsidump -t ID[:LUN] [-i BID] -f FILE [-s BUFFER_SIZE] [-r] [-v] [-p] | ||
[-I] ID[:LUN] [-S] | ||
|
||
DESCRIPTION | ||
scsidump has two modes of operation: dump and restore. These can be used with physical storage media, including hard drives and magneto optical drives. Dump mode can be used with read-only media such as CD/DVD drives. | ||
scsidump has two modes of operation: dump and restore. These can be | ||
used with physical storage media, including hard drives and magneto op‐ | ||
tical drives. Dump mode can be used with read-only media such as CD/DVD | ||
drives. | ||
|
||
When operating in dump mode, scsidump will copy all data from a remote SCSI drive to an image on the local filesystem. If enabled, it will also generate a .properties file that can be used to more closely emulate the source drive. | ||
When operating in dump mode, scsidump will copy all data from a remote | ||
SCSI drive to an image on the local filesystem. If enabled, it will | ||
also generate a .properties file that can be used to more closely emu‐ | ||
late the source drive. | ||
|
||
If you are operating in restore mode, scsidump will copy the data from a local binary image to a remote physical SCSI drive. The remote SCSI drive MUST be writable. | ||
If you are operating in restore mode, scsidump will copy the data from | ||
a local binary image to a remote physical SCSI drive. The remote SCSI | ||
drive MUST be writable. | ||
|
||
NOTES | ||
scsidump requires either a direct connection (one without transceivers) or a FULLSPEC PiSCSI/RaSCSI board. | ||
scsidump requires either a direct connection (one without transceivers) | ||
or a FULLSPEC PiSCSI/RaSCSI board. | ||
|
||
If the generated drive image is intended to be used with PiSCSI, the drive image should be moved to ~/images (or the location specified to the piscsi service). | ||
If the generated drive image is intended to be used with PiSCSI, the | ||
drive image should be moved by the user to ~/images (or the location | ||
specified to the piscsi service). | ||
|
||
OPTIONS | ||
-t ID[:LUN] | ||
SCSI ID and optional LUN of the remote SCSI device. The remote SCSI device will be functioning as the "Target" device. | ||
SCSI ID and optional LUN of the remote SCSI device. The remote | ||
SCSI device will be functioning as the "Target" device. | ||
|
||
-i BID SCSI ID of the PiSCSI device. If not specified, the PiSCSI device will use ID 7. The PiSCSI host will be functioning as the "Initiator" device. | ||
-i BID SCSI ID of the PiSCSI device. If not specified, the PiSCSI de‐ | ||
vice will use ID 7. The PiSCSI host will be functioning as the | ||
"Initiator" device. | ||
|
||
-f FILE | ||
Path to the dump file. | ||
|
||
-s BUFFER_SIZE | ||
The transfer buffer size, specified in bytes. Default is 1 MiB. This is specified in bytes with a minimum value of 65536 (64 KiB). | ||
The transfer buffer size, specified in bytes. Default is 1 MiB. | ||
This is specified in bytes with a minimum value of 65536 (64 | ||
KiB). | ||
|
||
-r Run in restore mode. Defaults to dump mode if not specified. | ||
|
||
-v Enable verbose logging. | ||
|
||
-p Generate a .properties file that is compatible with the PiSCSI web interface. The output filename will match the image filename with ".properties" appended. The generated file should be moved to ~/.config/piscsi. | ||
-p Generate a .properties file that is compatible with the PiSCSI | ||
web interface. The output filename will match the image filename | ||
with ".properties" appended. The generated file should be moved | ||
to ~/.config/piscsi. | ||
|
||
-I ID[:LUN] | ||
Display INQUIRY data of ID[:LUN]. | ||
|
||
-S Scan SCSI bus for devices. | ||
|
||
EXAMPLES | ||
Dump Mode: [SCSI Drive] ---> [PiSCSI host] Launch scsidump to dump an all data from SCSI ID 3 with block size 64 KiB, store it to the local filesystem as a drive image named outimage.hda, and generate the outimage.hda.properties file with the drive's INQUIRY | ||
information: | ||
Dump Mode: [SCSI Drive] ---> [PiSCSI host] Launch scsidump to dump an | ||
all data from SCSI ID 3 with block size 64 KiB, store it to the local | ||
filesystem as a drive image named outimage.hda, and generate the outim‐ | ||
age.hda.properties file with the drive's INQUIRY information: | ||
scsidump -t 3 -f ./outimage.hda -s 65536 -p | ||
|
||
Restore Mode: [PiSCSI host] ---> [SCSI Drive] Launch scsidump to restore/upload a drive image from the local file system to SCSI ID 0 with block size 1MiB: | ||
Restore Mode: [PiSCSI host] ---> [SCSI Drive] Launch scsidump to re‐ | ||
store/upload a drive image from the local file system to SCSI ID 0 with | ||
block size 1MiB: | ||
scsidump -r -t 0 -f ./outimage.hda -s 1048576 | ||
|
||
SEE ALSO | ||
scsictl(1), piscsi(1), scsimon(1) | ||
|
||
Full documentation is available at: <https://www.piscsi.com> | ||
|
||
scsidump(1) | ||
scsidump(1) |