Changed system call to use fork/wait. Moved some disk functions out of the header

This commit is contained in:
Tony Kuker 2021-01-30 12:36:18 -06:00
parent 788b2a3b46
commit bc561d65dd
13 changed files with 109 additions and 25 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
venv
*.pyc
core

View File

@ -8,13 +8,15 @@
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/rascsi",
"program": "${workspaceFolder}/bin/fullspec/rascsi",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"targetArchitecture": "arm",
"miDebuggerPath": "${workspaceFolder}/launch_sudo.sh",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",

View File

@ -5,7 +5,7 @@
"type": "shell",
"label": "g++ build active file",
"command": "make",
"args": ["all", "DEBUG=1"],
"args": ["all", "DEBUG=1", "-j4"],
"options": {
"cwd": "${workspaceFolder}/"
},

View File

@ -75,6 +75,7 @@ SRC_RASCSI = \
gpiobus.cpp \
filepath.cpp \
fileio.cpp\
os.cpp\
rascsi_version.cpp
# os.cpp
# rasctl_command.cpp

View File

@ -559,7 +559,7 @@ void FASTCALL SCSIDEV::CmdInquiry()
if (disk) {
major = (DWORD)(RASCSI >> 8);
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.unit[lun]->Inquiry(ctrl.cmd, ctrl.buffer, major, minor);
} else {

View File

@ -48,35 +48,44 @@ BOOL FASTCALL CTapDriver::Init()
ASSERT(this);
LOGTRACE("Opening Tap device");
// TAP device initilization
if ((m_hTAP = open("/dev/net/tun", O_RDWR)) < 0) {
LOGERROR("Error: can't open tun. Errno: %d %s", errno, strerror(errno));
return FALSE;
}
LOGTRACE("Opened tap device %d",m_hTAP);
// IFF_NO_PI for no extra packet information
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
LOGTRACE("Going to open %s", ifr.ifr_name);
if ((ret = ioctl(m_hTAP, TUNSETIFF, (void *)&ifr)) < 0) {
LOGERROR("Error: can't ioctl TUNSETIFF. Errno: %d %s", errno, strerror(errno));
close(m_hTAP);
return FALSE;
}
LOGTRACE("return code from ioctl was %d", ret);
// Force the tap interface 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");
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
LOGTRACE("Getting the MAC address");
ifr.ifr_addr.sa_family = AF_INET;
if ((ret = ioctl(m_hTAP, SIOCGIFHWADDR, &ifr)) < 0) {
LOGERROR("Error: can't ioctl SIOCGIFHWADDR. Errno: %d %s", errno, strerror(errno));
close(m_hTAP);
return FALSE;
}
LOGTRACE("got the mac");
// Save MAC address
memcpy(m_MacAddr, ifr.ifr_hwaddr.sa_data, sizeof(m_MacAddr));
@ -141,20 +150,20 @@ BOOL FASTCALL CTapDriver::Init()
void FASTCALL CTapDriver::Cleanup()
{
ASSERT(this);
int result;
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 device
// Release TAP defice
if (m_hTAP != -1) {
close(m_hTAP);
m_hTAP = -1;
}
}
//---------------------------------------------------------------------------

View File

@ -974,6 +974,7 @@ BOOL FASTCALL Disk::IsNULL() const
}
return FALSE;
}
//---------------------------------------------------------------------------
//
// Retrieve the disk's ID
@ -984,6 +985,37 @@ DWORD FASTCALL Disk::GetID() const
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

View File

@ -328,13 +328,13 @@ public:
// PLAY AUDIO MSF command
virtual BOOL FASTCALL PlayAudioTrack(const DWORD *cdb);
// PLAY AUDIO TRACK command
void FASTCALL InvalidCmd() { disk.code = DISK_INVALIDCMD; }
void FASTCALL InvalidCmd();
// Unsupported command
// Other
BOOL IsCacheWB() { return cache_wb; }
BOOL FASTCALL IsCacheWB();
// Get cache writeback mode
void SetCacheWB(BOOL enable) { cache_wb = enable; }
void FASTCALL SetCacheWB(BOOL enable);
// Set cache writeback mode
protected:

View File

@ -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_apple_talk_addr[6] = { 0x09, 0x00, 0x07, 0xff, 0xff, 0xff };
#ifndef NDEBUG
static DWORD file_counter = 0;
#endif
//---------------------------------------------------------------------------
//
// Constructor
@ -63,11 +59,13 @@ SCSIDaynaPort::SCSIDaynaPort() : Disk()
LOGINFO("Tap interface created")
}
LOGTRACE("%s this->reset()", __PRETTY_FUNCTION__);
this->Reset();
disk.ready = true;
disk.reset = false;
// Generate MAC Address
LOGTRACE("%s memset(m_mac_addr, 0x00, 6);", __PRETTY_FUNCTION__);
memset(m_mac_addr, 0x00, 6);
// 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!
// TODO: Remove this hard-coded address
LOGTRACE("%s m_mac_addr[0]=0x00;", __PRETTY_FUNCTION__);
m_mac_addr[0]=0x00;
m_mac_addr[1]=0x80;
m_mac_addr[2]=0x19;
@ -299,8 +298,6 @@ int FASTCALL SCSIDaynaPort::Read(const DWORD *cdb, BYTE *buf, DWORD block)
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
// The CRC was already appended by the ctapdriver
return rx_packet_size + m_read_header_size;

35
src/raspberrypi/os.cpp Normal file
View 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;
}

View File

@ -155,4 +155,7 @@ typedef const char *LPCSTR;
#define xstrcasecmp strcasecmp
#define xstrncasecmp strncasecmp
// Run system command and wait for it to finish
extern int run_system_cmd(const char* command);
#endif // os_h

View File

@ -9,7 +9,7 @@ ExecStart=/usr/local/bin/rascsi
# Example: If you want to automatically attach a hard disk at startup, change
# the ExecStart line to:
# 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
StandardError=syslog
SyslogIdentifier=RASCSI

View File

@ -297,6 +297,8 @@ void ListDevice(FILE *fp)
// mount status output
if (pUnit->GetID() == MAKEID('S', 'C', 'B', 'R')) {
FPRT(fp, "%s", "HOST BRIDGE");
} else if (pUnit->GetID() == MAKEID('S', 'C', 'D', 'P')) {
FPRT(fp, "%s", "DaynaPort SCSI/Link");
} else {
pUnit->GetPath(filepath);
FPRT(fp, "%s",
@ -526,6 +528,7 @@ BOOL ProcessCmd(FILE *fp, int id, int un, int cmd, int type, char *file)
// break;
case rasctl_dev_daynaport: // DaynaPort SCSI Link
pUnit = new SCSIDaynaPort();
LOGTRACE("Done creating SCSIDayanPort");
break;
default:
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
if (type <= 1 || (type <= 3 && xstrcasecmp(file, "-") != 0)) {
if (type <= rasctl_dev_scsi_hd || (type <= rasctl_dev_cd && xstrcasecmp(file, "-") != 0)) {
// Set the Path
filepath.SetPath(file);