mirror of
https://github.com/akuker/RASCSI.git
synced 2025-08-15 08:27:34 +00:00
Changed system call to use fork/wait. Moved some disk functions out of the header
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
|||||||
venv
|
venv
|
||||||
|
*.pyc
|
||||||
|
core
|
||||||
|
4
src/raspberrypi/.vscode/launch.json
vendored
4
src/raspberrypi/.vscode/launch.json
vendored
@@ -8,13 +8,15 @@
|
|||||||
"name": "(gdb) Launch",
|
"name": "(gdb) Launch",
|
||||||
"type": "cppdbg",
|
"type": "cppdbg",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/bin/rascsi",
|
"program": "${workspaceFolder}/bin/fullspec/rascsi",
|
||||||
"args": [],
|
"args": [],
|
||||||
"stopAtEntry": true,
|
"stopAtEntry": true,
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
"environment": [],
|
"environment": [],
|
||||||
"externalConsole": false,
|
"externalConsole": false,
|
||||||
"MIMode": "gdb",
|
"MIMode": "gdb",
|
||||||
|
"targetArchitecture": "arm",
|
||||||
|
"miDebuggerPath": "${workspaceFolder}/launch_sudo.sh",
|
||||||
"setupCommands": [
|
"setupCommands": [
|
||||||
{
|
{
|
||||||
"description": "Enable pretty-printing for gdb",
|
"description": "Enable pretty-printing for gdb",
|
||||||
|
2
src/raspberrypi/.vscode/tasks.json
vendored
2
src/raspberrypi/.vscode/tasks.json
vendored
@@ -5,7 +5,7 @@
|
|||||||
"type": "shell",
|
"type": "shell",
|
||||||
"label": "g++ build active file",
|
"label": "g++ build active file",
|
||||||
"command": "make",
|
"command": "make",
|
||||||
"args": ["all", "DEBUG=1"],
|
"args": ["all", "DEBUG=1", "-j4"],
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceFolder}/"
|
"cwd": "${workspaceFolder}/"
|
||||||
},
|
},
|
||||||
|
@@ -75,6 +75,7 @@ SRC_RASCSI = \
|
|||||||
gpiobus.cpp \
|
gpiobus.cpp \
|
||||||
filepath.cpp \
|
filepath.cpp \
|
||||||
fileio.cpp\
|
fileio.cpp\
|
||||||
|
os.cpp\
|
||||||
rascsi_version.cpp
|
rascsi_version.cpp
|
||||||
# os.cpp
|
# os.cpp
|
||||||
# rasctl_command.cpp
|
# rasctl_command.cpp
|
||||||
|
@@ -559,7 +559,7 @@ void FASTCALL SCSIDEV::CmdInquiry()
|
|||||||
if (disk) {
|
if (disk) {
|
||||||
major = (DWORD)(RASCSI >> 8);
|
major = (DWORD)(RASCSI >> 8);
|
||||||
minor = (DWORD)(RASCSI & 0xff);
|
minor = (DWORD)(RASCSI & 0xff);
|
||||||
LOGINFO("%s Buffer size is %d",__PRETTY_FUNCTION__, ctrl.bufsize);
|
LOGTRACE("%s Buffer size is %d",__PRETTY_FUNCTION__, ctrl.bufsize);
|
||||||
ctrl.length =
|
ctrl.length =
|
||||||
ctrl.unit[lun]->Inquiry(ctrl.cmd, ctrl.buffer, major, minor);
|
ctrl.unit[lun]->Inquiry(ctrl.cmd, ctrl.buffer, major, minor);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -48,35 +48,44 @@ BOOL FASTCALL CTapDriver::Init()
|
|||||||
|
|
||||||
ASSERT(this);
|
ASSERT(this);
|
||||||
|
|
||||||
|
LOGTRACE("Opening Tap device");
|
||||||
// TAP device initilization
|
// TAP device initilization
|
||||||
if ((m_hTAP = open("/dev/net/tun", O_RDWR)) < 0) {
|
if ((m_hTAP = open("/dev/net/tun", O_RDWR)) < 0) {
|
||||||
LOGERROR("Error: can't open tun. Errno: %d %s", errno, strerror(errno));
|
LOGERROR("Error: can't open tun. Errno: %d %s", errno, strerror(errno));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
LOGTRACE("Opened tap device %d",m_hTAP);
|
||||||
|
|
||||||
|
|
||||||
// IFF_NO_PI for no extra packet information
|
// IFF_NO_PI for no extra packet information
|
||||||
memset(&ifr, 0, sizeof(ifr));
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
|
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
|
||||||
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
|
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
|
||||||
|
LOGTRACE("Going to open %s", ifr.ifr_name);
|
||||||
if ((ret = ioctl(m_hTAP, TUNSETIFF, (void *)&ifr)) < 0) {
|
if ((ret = ioctl(m_hTAP, TUNSETIFF, (void *)&ifr)) < 0) {
|
||||||
LOGERROR("Error: can't ioctl TUNSETIFF. Errno: %d %s", errno, strerror(errno));
|
LOGERROR("Error: can't ioctl TUNSETIFF. Errno: %d %s", errno, strerror(errno));
|
||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
LOGTRACE("return code from ioctl was %d", ret);
|
||||||
|
|
||||||
// Force the tap interface up
|
|
||||||
LOGDEBUG("ip link set ras0 up");
|
LOGDEBUG("ip link set ras0 up");
|
||||||
system("ip link set ras0 up");
|
ret = run_system_cmd("ip link set ras0 up");
|
||||||
|
LOGTRACE("return code from ip link set ras0 up was %d", ret);
|
||||||
|
|
||||||
LOGDEBUG("brctl addif rascsi_bridge ras0");
|
LOGDEBUG("brctl addif rascsi_bridge ras0");
|
||||||
system("brctl addif rascsi_bridge ras0");
|
ret = run_system_cmd("brctl addif rascsi_bridge ras0");
|
||||||
|
LOGTRACE("return code from brctl addif rascsi_bridge ras0 was %d", ret);
|
||||||
|
|
||||||
// Get MAC address
|
// Get MAC address
|
||||||
|
LOGTRACE("Getting the MAC address");
|
||||||
ifr.ifr_addr.sa_family = AF_INET;
|
ifr.ifr_addr.sa_family = AF_INET;
|
||||||
if ((ret = ioctl(m_hTAP, SIOCGIFHWADDR, &ifr)) < 0) {
|
if ((ret = ioctl(m_hTAP, SIOCGIFHWADDR, &ifr)) < 0) {
|
||||||
LOGERROR("Error: can't ioctl SIOCGIFHWADDR. Errno: %d %s", errno, strerror(errno));
|
LOGERROR("Error: can't ioctl SIOCGIFHWADDR. Errno: %d %s", errno, strerror(errno));
|
||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
LOGTRACE("got the mac");
|
||||||
|
|
||||||
// Save MAC address
|
// Save MAC address
|
||||||
memcpy(m_MacAddr, ifr.ifr_hwaddr.sa_data, sizeof(m_MacAddr));
|
memcpy(m_MacAddr, ifr.ifr_hwaddr.sa_data, sizeof(m_MacAddr));
|
||||||
@@ -141,20 +150,20 @@ BOOL FASTCALL CTapDriver::Init()
|
|||||||
void FASTCALL CTapDriver::Cleanup()
|
void FASTCALL CTapDriver::Cleanup()
|
||||||
{
|
{
|
||||||
ASSERT(this);
|
ASSERT(this);
|
||||||
|
int result;
|
||||||
|
|
||||||
LOGDEBUG("brctl delif rascsi_bridge ras0");
|
LOGDEBUG("brctl delif rascsi_bridge ras0");
|
||||||
system("brctl delif rascsi_bridge ras0");
|
result = run_system_cmd("brctl delif rascsi_bridge ras0");
|
||||||
|
if(result != EXIT_SUCCESS){
|
||||||
|
LOGWARN("Warning: The brctl delif command failed.");
|
||||||
|
LOGWARN("You may need to manually remove the ras0 tap device from the bridge");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release TAP defice
|
||||||
// Release TAP device
|
|
||||||
if (m_hTAP != -1) {
|
if (m_hTAP != -1) {
|
||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
m_hTAP = -1;
|
m_hTAP = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@@ -974,6 +974,7 @@ BOOL FASTCALL Disk::IsNULL() const
|
|||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Retrieve the disk's ID
|
// Retrieve the disk's ID
|
||||||
@@ -984,6 +985,37 @@ DWORD FASTCALL Disk::GetID() const
|
|||||||
return disk.id;
|
return disk.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Get cache writeback mode
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
BOOL FASTCALL Disk::IsCacheWB()
|
||||||
|
{
|
||||||
|
return cache_wb;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set cache writeback mode
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
void FASTCALL Disk::SetCacheWB(BOOL enable)
|
||||||
|
{
|
||||||
|
cache_wb = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set unsupported command
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
void FASTCALL Disk::InvalidCmd()
|
||||||
|
{
|
||||||
|
disk.code = DISK_INVALIDCMD;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// SASI Check
|
// SASI Check
|
||||||
|
@@ -328,13 +328,13 @@ public:
|
|||||||
// PLAY AUDIO MSF command
|
// PLAY AUDIO MSF command
|
||||||
virtual BOOL FASTCALL PlayAudioTrack(const DWORD *cdb);
|
virtual BOOL FASTCALL PlayAudioTrack(const DWORD *cdb);
|
||||||
// PLAY AUDIO TRACK command
|
// PLAY AUDIO TRACK command
|
||||||
void FASTCALL InvalidCmd() { disk.code = DISK_INVALIDCMD; }
|
void FASTCALL InvalidCmd();
|
||||||
// Unsupported command
|
// Unsupported command
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
BOOL IsCacheWB() { return cache_wb; }
|
BOOL FASTCALL IsCacheWB();
|
||||||
// Get cache writeback mode
|
// Get cache writeback mode
|
||||||
void SetCacheWB(BOOL enable) { cache_wb = enable; }
|
void FASTCALL SetCacheWB(BOOL enable);
|
||||||
// Set cache writeback mode
|
// Set cache writeback mode
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@@ -38,10 +38,6 @@ const char* SCSIDaynaPort::m_firmware_version = "01.00.00";
|
|||||||
const BYTE SCSIDaynaPort::m_bcast_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
const BYTE SCSIDaynaPort::m_bcast_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||||
const BYTE SCSIDaynaPort::m_apple_talk_addr[6] = { 0x09, 0x00, 0x07, 0xff, 0xff, 0xff };
|
const BYTE SCSIDaynaPort::m_apple_talk_addr[6] = { 0x09, 0x00, 0x07, 0xff, 0xff, 0xff };
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
static DWORD file_counter = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -63,11 +59,13 @@ SCSIDaynaPort::SCSIDaynaPort() : Disk()
|
|||||||
LOGINFO("Tap interface created")
|
LOGINFO("Tap interface created")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGTRACE("%s this->reset()", __PRETTY_FUNCTION__);
|
||||||
this->Reset();
|
this->Reset();
|
||||||
disk.ready = true;
|
disk.ready = true;
|
||||||
disk.reset = false;
|
disk.reset = false;
|
||||||
|
|
||||||
// Generate MAC Address
|
// Generate MAC Address
|
||||||
|
LOGTRACE("%s memset(m_mac_addr, 0x00, 6);", __PRETTY_FUNCTION__);
|
||||||
memset(m_mac_addr, 0x00, 6);
|
memset(m_mac_addr, 0x00, 6);
|
||||||
|
|
||||||
// if (m_bTapEnable) {
|
// if (m_bTapEnable) {
|
||||||
@@ -76,6 +74,7 @@ SCSIDaynaPort::SCSIDaynaPort() : Disk()
|
|||||||
// }
|
// }
|
||||||
// !!!!!!!!!!!!!!!!! For now, hard code the MAC address. Its annoying when it keeps changing during development!
|
// !!!!!!!!!!!!!!!!! For now, hard code the MAC address. Its annoying when it keeps changing during development!
|
||||||
// TODO: Remove this hard-coded address
|
// TODO: Remove this hard-coded address
|
||||||
|
LOGTRACE("%s m_mac_addr[0]=0x00;", __PRETTY_FUNCTION__);
|
||||||
m_mac_addr[0]=0x00;
|
m_mac_addr[0]=0x00;
|
||||||
m_mac_addr[1]=0x80;
|
m_mac_addr[1]=0x80;
|
||||||
m_mac_addr[2]=0x19;
|
m_mac_addr[2]=0x19;
|
||||||
@@ -299,8 +298,6 @@ int FASTCALL SCSIDaynaPort::Read(const DWORD *cdb, BYTE *buf, DWORD block)
|
|||||||
buf[5] = 0;
|
buf[5] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGTRACE("%s Packet of size %d received [Counter: %d]", __PRETTY_FUNCTION__, (int)rx_packet_size, (int)file_counter);
|
|
||||||
|
|
||||||
// Return the packet size + 2 for the length + 4 for the flag field
|
// Return the packet size + 2 for the length + 4 for the flag field
|
||||||
// The CRC was already appended by the ctapdriver
|
// The CRC was already appended by the ctapdriver
|
||||||
return rx_packet_size + m_read_header_size;
|
return rx_packet_size + m_read_header_size;
|
||||||
|
35
src/raspberrypi/os.cpp
Normal file
35
src/raspberrypi/os.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// SCSI Target Emulator RaSCSI (*^..^*)
|
||||||
|
// for Raspberry Pi
|
||||||
|
//
|
||||||
|
// Powered by XM6 TypeG Technology.
|
||||||
|
// Copyright (C) 2016-2020 GIMONS
|
||||||
|
// Copyright (C) 2020-2021 akuker
|
||||||
|
//
|
||||||
|
// [ OS related definitions ]
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Run system command and wait for it to finish
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
int run_system_cmd(const char* command)
|
||||||
|
{
|
||||||
|
pid_t pid;
|
||||||
|
int result;
|
||||||
|
int status = 0;
|
||||||
|
pid=fork();
|
||||||
|
if(pid == 0){
|
||||||
|
result = system(command);
|
||||||
|
exit(result);
|
||||||
|
}
|
||||||
|
waitpid(pid, &status, 0);
|
||||||
|
return status;
|
||||||
|
}
|
@@ -155,4 +155,7 @@ typedef const char *LPCSTR;
|
|||||||
#define xstrcasecmp strcasecmp
|
#define xstrcasecmp strcasecmp
|
||||||
#define xstrncasecmp strncasecmp
|
#define xstrncasecmp strncasecmp
|
||||||
|
|
||||||
|
// Run system command and wait for it to finish
|
||||||
|
extern int run_system_cmd(const char* command);
|
||||||
|
|
||||||
#endif // os_h
|
#endif // os_h
|
||||||
|
@@ -9,7 +9,7 @@ ExecStart=/usr/local/bin/rascsi
|
|||||||
# Example: If you want to automatically attach a hard disk at startup, change
|
# Example: If you want to automatically attach a hard disk at startup, change
|
||||||
# the ExecStart line to:
|
# the ExecStart line to:
|
||||||
# ExecStart=/usr/local/bin/rascsi -ID1 /home/pi/images/harddisk.hda
|
# ExecStart=/usr/local/bin/rascsi -ID1 /home/pi/images/harddisk.hda
|
||||||
ExecStop=/usr/local/bin/rasctl -stop
|
# This functionality isn't implmented yet: ExecStop=/usr/local/bin/rasctl -stop
|
||||||
StandardOutput=syslog
|
StandardOutput=syslog
|
||||||
StandardError=syslog
|
StandardError=syslog
|
||||||
SyslogIdentifier=RASCSI
|
SyslogIdentifier=RASCSI
|
||||||
|
@@ -297,6 +297,8 @@ void ListDevice(FILE *fp)
|
|||||||
// mount status output
|
// mount status output
|
||||||
if (pUnit->GetID() == MAKEID('S', 'C', 'B', 'R')) {
|
if (pUnit->GetID() == MAKEID('S', 'C', 'B', 'R')) {
|
||||||
FPRT(fp, "%s", "HOST BRIDGE");
|
FPRT(fp, "%s", "HOST BRIDGE");
|
||||||
|
} else if (pUnit->GetID() == MAKEID('S', 'C', 'D', 'P')) {
|
||||||
|
FPRT(fp, "%s", "DaynaPort SCSI/Link");
|
||||||
} else {
|
} else {
|
||||||
pUnit->GetPath(filepath);
|
pUnit->GetPath(filepath);
|
||||||
FPRT(fp, "%s",
|
FPRT(fp, "%s",
|
||||||
@@ -526,6 +528,7 @@ BOOL ProcessCmd(FILE *fp, int id, int un, int cmd, int type, char *file)
|
|||||||
// break;
|
// break;
|
||||||
case rasctl_dev_daynaport: // DaynaPort SCSI Link
|
case rasctl_dev_daynaport: // DaynaPort SCSI Link
|
||||||
pUnit = new SCSIDaynaPort();
|
pUnit = new SCSIDaynaPort();
|
||||||
|
LOGTRACE("Done creating SCSIDayanPort");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
FPRT(fp, "Error : Invalid device type\n");
|
FPRT(fp, "Error : Invalid device type\n");
|
||||||
@@ -533,7 +536,7 @@ BOOL ProcessCmd(FILE *fp, int id, int un, int cmd, int type, char *file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// drive checks files
|
// drive checks files
|
||||||
if (type <= 1 || (type <= 3 && xstrcasecmp(file, "-") != 0)) {
|
if (type <= rasctl_dev_scsi_hd || (type <= rasctl_dev_cd && xstrcasecmp(file, "-") != 0)) {
|
||||||
// Set the Path
|
// Set the Path
|
||||||
filepath.SetPath(file);
|
filepath.SetPath(file);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user