Code clean-up.

This commit is contained in:
2020-10-24 04:23:01 +01:00
parent ac3b7f19c7
commit 3c6906afe9
22 changed files with 75 additions and 65 deletions

View File

@@ -18,17 +18,12 @@
#ifndef AARUREMOTE__AARUREMOTE_H_ #ifndef AARUREMOTE__AARUREMOTE_H_
#define AARUREMOTE__AARUREMOTE_H_ #define AARUREMOTE__AARUREMOTE_H_
#include <stddef.h>
#include <stdint.h>
#ifdef GEKKO #ifdef GEKKO
#include <network.h> #include <network.h>
#ifndef MSG_PEEK #ifndef MSG_PEEK
#define MSG_PEEK 0x02 // TODO: Untested, may not work #define MSG_PEEK 0x02 // TODO: Untested, may not work
#endif #endif
#elif _WIN32 #elif !defined(_WIN32)
#include <ws2tcpip.h>
#else
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/socket.h> #include <sys/socket.h>
#endif #endif

View File

@@ -15,10 +15,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "linux.h"
#include <string.h> #include <string.h>
#include "../aaruremote.h"
#include "linux.h"
int32_t AtaProtocolToScsiDirection(uint8_t protocol) int32_t AtaProtocolToScsiDirection(uint8_t protocol)
{ {
switch(protocol) switch(protocol)

View File

@@ -15,8 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "linux.h"
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
@@ -28,6 +26,9 @@
#include <libudev.h> #include <libudev.h>
#endif #endif
#include "../aaruremote.h"
#include "linux.h"
void* DeviceOpen(const char* device_path) void* DeviceOpen(const char* device_path)
{ {
DeviceContext* ctx; DeviceContext* ctx;
@@ -135,9 +136,7 @@ int32_t GetDeviceType(void* device_ctx)
{ {
if(strncmp(tmp_string, "cd", 2) == 0 || strncmp(tmp_string, "disk", 4) == 0 || if(strncmp(tmp_string, "cd", 2) == 0 || strncmp(tmp_string, "disk", 4) == 0 ||
strncmp(tmp_string, "optical", 7) == 0) strncmp(tmp_string, "optical", 7) == 0)
{
device_type = AARUREMOTE_DEVICE_TYPE_SCSI; device_type = AARUREMOTE_DEVICE_TYPE_SCSI;
}
free((void*)tmp_string); free((void*)tmp_string);
} }

View File

@@ -15,14 +15,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "linux.h"
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include "../aaruremote.h"
#include "linux.h"
uint8_t GetFireWireData(void* device_ctx, uint8_t GetFireWireData(void* device_ctx,
uint32_t* id_model, uint32_t* id_model,
uint32_t* id_vendor, uint32_t* id_vendor,

View File

@@ -18,8 +18,6 @@
#ifndef AARUREMOTE_LINUX_LINUX_H_ #ifndef AARUREMOTE_LINUX_LINUX_H_
#define AARUREMOTE_LINUX_LINUX_H_ #define AARUREMOTE_LINUX_LINUX_H_
#include "../aaruremote.h"
#define PATH_SYS_DEVBLOCK "/sys/block" #define PATH_SYS_DEVBLOCK "/sys/block"
typedef struct typedef struct

View File

@@ -15,8 +15,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../aaruremote.h" #ifdef HAS_UDEV
#include "linux.h" #include <libudev.h>
#endif
#include <ctype.h> #include <ctype.h>
#include <dirent.h> #include <dirent.h>
@@ -27,9 +28,8 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#ifdef HAS_UDEV #include "../aaruremote.h"
#include <libudev.h> #include "linux.h"
#endif
DeviceInfoList* ListDevices() DeviceInfoList* ListDevices()
{ {

View File

@@ -7,8 +7,6 @@
#include <linux/major.h> #include <linux/major.h>
#include <linux/mmc/ioctl.h> #include <linux/mmc/ioctl.h>
#else #else
#include <stdint.h>
#ifndef MMC_BLOCK_MAJOR #ifndef MMC_BLOCK_MAJOR
#define MMC_BLOCK_MAJOR 179 #define MMC_BLOCK_MAJOR 179
#endif #endif

View File

@@ -15,8 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "linux.h"
#include <dirent.h> #include <dirent.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@@ -24,6 +22,9 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include "../aaruremote.h"
#include "linux.h"
uint8_t GetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis) uint8_t GetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis)
{ {
DeviceContext* ctx = device_ctx; DeviceContext* ctx = device_ctx;
@@ -78,8 +79,7 @@ uint8_t GetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis)
dir = opendir(tmp_path); dir = opendir(tmp_path);
if(!dir) continue; if(!dir) continue;
do do {
{
dent = readdir(dir); dent = readdir(dir);
if(!dent) break; if(!dent) break;

View File

@@ -15,15 +15,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../aaruremote.h"
#include "linux.h"
#include <malloc.h> #include <malloc.h>
#include <scsi/sg.h> #include <scsi/sg.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include "../aaruremote.h"
#include "linux.h"
int32_t SendScsiCommand(void* device_ctx, int32_t SendScsiCommand(void* device_ctx,
char* cdb, char* cdb,
char* buffer, char* buffer,

View File

@@ -15,9 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "linux.h"
#include "mmc/ioctl.h"
#include <errno.h> #include <errno.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@@ -26,6 +23,10 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <unistd.h> #include <unistd.h>
#include "../aaruremote.h"
#include "linux.h"
#include "mmc/ioctl.h"
int32_t SendSdhciCommand(void* device_ctx, int32_t SendSdhciCommand(void* device_ctx,
uint8_t command, uint8_t command,
uint8_t write, uint8_t write,

View File

@@ -15,14 +15,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "linux.h"
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include "../aaruremote.h"
#include "linux.h"
uint8_t GetUsbData(void* device_ctx, uint8_t GetUsbData(void* device_ctx,
uint16_t* desc_len, uint16_t* desc_len,
char* descriptors, char* descriptors,

View File

@@ -15,10 +15,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "aaruremote.h"
#include <stdlib.h> #include <stdlib.h>
#ifdef _WIN32
#include <windows.h>
#include "win32/win32.h"
#else
#include <stdint.h>
#endif
#include "aaruremote.h"
void FreeDeviceInfoList(DeviceInfoList* start) void FreeDeviceInfoList(DeviceInfoList* start)
{ {
DeviceInfoList* current; DeviceInfoList* current;

11
main.c
View File

@@ -15,11 +15,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "aaruremote.h"
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <windows.h>
#include "win32/win32.h"
#endif
#include "aaruremote.h"
int main() int main()
{ {

View File

@@ -15,12 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../aaruremote.h"
#include <malloc.h> #include <malloc.h>
#include <string.h> #include <string.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include "../aaruremote.h"
AaruPacketHello* GetHello() AaruPacketHello* GetHello()
{ {
struct utsname utsname; struct utsname utsname;

View File

@@ -15,9 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../aaruremote.h"
#include "../unix/unix.h"
#include <arpa/inet.h> #include <arpa/inet.h>
#include <ifaddrs.h> #include <ifaddrs.h>
#include <stddef.h> #include <stddef.h>
@@ -25,6 +22,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "../aaruremote.h"
#include "unix.h"
int PrintNetworkAddresses() int PrintNetworkAddresses()
{ {
int ret; int ret;

View File

@@ -15,10 +15,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../aaruremote.h"
#include <unistd.h> #include <unistd.h>
#include "../aaruremote.h"
void Initialize() void Initialize()
{ {
// Do nothing // Do nothing

View File

@@ -15,14 +15,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../aaruremote.h"
#include "../endian.h"
#include <gccore.h> #include <gccore.h>
#include <malloc.h> #include <malloc.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "../aaruremote.h"
#include "../endian.h"
AaruPacketHello* GetHello() AaruPacketHello* GetHello()
{ {
AaruPacketHello* pkt_server_hello; AaruPacketHello* pkt_server_hello;

View File

@@ -15,9 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../aaruremote.h"
#include "wii.h"
#include <gccore.h> #include <gccore.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
@@ -25,6 +22,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../aaruremote.h"
#include "wii.h"
DeviceInfoList* ListDevices() DeviceInfoList* ListDevices()
{ {
DeviceInfoList *list_start = NULL, *list_current = NULL, *list_next = NULL; DeviceInfoList *list_start = NULL, *list_current = NULL, *list_next = NULL;

View File

@@ -15,13 +15,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../aaruremote.h"
#include "wii.h"
#include <network.h> #include <network.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "../aaruremote.h"
#include "wii.h"
int PrintNetworkAddresses() int PrintNetworkAddresses()
{ {
int ret; int ret;

View File

@@ -15,13 +15,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../aaruremote.h"
#include <debug.h> #include <debug.h>
#include <errno.h> #include <errno.h>
#include <gccore.h> #include <gccore.h>
#include <wiiuse/wpad.h> #include <wiiuse/wpad.h>
#include "../aaruremote.h"
void Initialize() void Initialize()
{ {
void* framebuffer; void* framebuffer;

View File

@@ -18,8 +18,6 @@
#ifndef AARUREMOTE_WII_WII_H_ #ifndef AARUREMOTE_WII_WII_H_
#define AARUREMOTE_WII_WII_H_ #define AARUREMOTE_WII_WII_H_
#include "../aaruremote.h"
#define AARUREMOTE_WII_DEVICE_FD_NAND 1 #define AARUREMOTE_WII_DEVICE_FD_NAND 1
#define AARUREMOTE_WII_DEVICE_FD_DVD 2 #define AARUREMOTE_WII_DEVICE_FD_DVD 2
#define AARUREMOTE_WII_DEVICE_FD_SD 3 #define AARUREMOTE_WII_DEVICE_FD_SD 3

View File

@@ -15,18 +15,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "aaruremote.h"
#include "endian.h"
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef WIN32 #ifdef _WIN32
#define ssize_t int #define ssize_t int
#include <windows.h>
#include "win32/win32.h"
#include <winsock.h>
#endif #endif
#include "aaruremote.h"
#include "endian.h"
void* WorkingLoop(void* arguments) void* WorkingLoop(void* arguments)
{ {
AtaErrorRegistersChs ata_chs_error_regs; AtaErrorRegistersChs ata_chs_error_regs;
@@ -392,7 +397,7 @@ void* WorkingLoop(void* arguments)
pkt_nop->reason_code = device_ctx == NULL ? AARUREMOTE_PACKET_NOP_REASON_OPEN_ERROR pkt_nop->reason_code = device_ctx == NULL ? AARUREMOTE_PACKET_NOP_REASON_OPEN_ERROR
: AARUREMOTE_PACKET_NOP_REASON_OPEN_OK; : AARUREMOTE_PACKET_NOP_REASON_OPEN_OK;
pkt_nop->error_no = errno; pkt_nop->error_no = errno;
memset(&pkt_nop->reason, 0, 256); memset(&pkt_nop->reason, 0, 256);
NetWrite(cli_ctx, pkt_nop, sizeof(AaruPacketNop)); NetWrite(cli_ctx, pkt_nop, sizeof(AaruPacketNop));