From 4ef3ae920c696acf6fc8c1f2f177f454d8f3621a Mon Sep 17 00:00:00 2001 From: Bignaux Ronan Date: Sat, 30 Sep 2023 17:05:22 +0200 Subject: [PATCH] examples/lwnbd-server.c : fix conccurency issue --- .env | 1 + Makefile | 14 ++-- examples/Makefile | 2 +- examples/local-reader.c | 2 - examples/local-shell.c | 53 +++++++++++-- examples/lwnbd-server.c | 74 ++++++++++--------- include/config.h | 2 +- include/lwnbd-common.h | 56 ++++++++++++++ include/lwnbd-plugin.h | 31 +++++--- include/lwnbd-server.h | 2 +- include/lwnbd.h | 22 +++--- {servers/nbd => include/lwnbd}/nbd.h | 11 ++- {servers/sifrpc => include/lwnbd}/sifrpc.h | 0 plugins/atad/atad_d.c | 46 ++++++------ plugins/command/Makefile | 5 +- plugins/command/command.c | 3 +- plugins/command/command.h | 6 -- plugins/memory/memory.c | 29 +++----- plugins/memory/memory.h | 15 ---- plugins/pcmstream/pcmstream.c | 5 +- plugins/pcmstream/pcmstream.h | 18 ----- .../{iop => common}/include/endian.h | 0 ports/playstation2/ee/ee.mk | 3 +- ports/playstation2/iop/iop.mk | 13 ++-- ports/playstation2/iop/ioplib.h | 7 -- ports/playstation2/iop/irx_imports.h | 8 +- ports/playstation2/iop/lwnbd_irx.c | 3 - ports/playstation2/iop/tcp.c | 6 +- servers/nbd/nbd.c | 4 +- servers/nbd/protocol-handshake.c | 2 +- servers/nbd/protocol.c | 2 +- servers/sifrpc/sifrpc.c | 2 +- src/contexts_uri.c | 9 ++- src/plugins.c | 3 +- 34 files changed, 262 insertions(+), 197 deletions(-) create mode 100644 include/lwnbd-common.h rename {servers/nbd => include/lwnbd}/nbd.h (96%) rename {servers/sifrpc => include/lwnbd}/sifrpc.h (100%) delete mode 100644 plugins/command/command.h delete mode 100644 plugins/memory/memory.h delete mode 100644 plugins/pcmstream/pcmstream.h rename ports/playstation2/{iop => common}/include/endian.h (100%) diff --git a/.env b/.env index 1c709d7..1ade6e3 100644 --- a/.env +++ b/.env @@ -3,4 +3,5 @@ LWNBD_DEBUG=1 NBD_URI=1 TARGET_IP=192.168.1.10 MAKE_SILENT=1 +#MAKE_FATAL=1 WORKSPACE="../workspace/" diff --git a/Makefile b/Makefile index 158f377..a8807b2 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ CC ?= gcc # TODO: can't use -pedantic-errors yet due to LOG macros # -CFLAGS = -Iinclude -std=c99 -Wall -Wfatal-errors +CFLAGS = -Iinclude -std=c99 -Wall DEBUG ?= 0 APP_VERSION := $(shell git describe --always --tags) @@ -15,9 +15,6 @@ TARGET ?= unix RONN = ronn MANPAGE = lwnbd.3 -$(BIN): banner $(OBJ) - $(CC) $(CFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS) $(LIBS) - include .env include src/Makefile @@ -46,9 +43,16 @@ ifeq ($(MAKE_SILENT),1) .SILENT: $(OBJ) endif +ifeq ($(MAKE_FATAL),1) + CFLAGS += -Wfatal-errors +endif + $(MANPAGE): README.md $(RONN) -r --pipe $< > $@ +$(BIN): banner $(OBJ) + $(CC) $(CFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS) $(LIBS) + banner: @echo " _ _ _ __ _ ______ ______" @echo "| | | | | \\ | |_____] | \\" @@ -58,7 +62,7 @@ banner: clean: rm -f $(BIN) $(MANPAGE) $(OBJ) *~ core - find -iname "*.o" -or -iname "*.a" -exec rm {} \; + find -iname "*.o" -exec rm -f {} \; nbdcleanup: sudo lsof -t /dev/nbd* | sudo xargs -r kill -9 diff --git a/examples/Makefile b/examples/Makefile index 3f981eb..286d62e 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -2,7 +2,7 @@ BIN = local-reader \ local-shell \ lwnbd-server -CFLAGS = -I../include $(CFLAGS-$@) -g +CFLAGS = -I../include $(CFLAGS-$@) -DLWNBD_DEBUG LWNBD_LIB := ../lwnbd.a LDLIBS := $(LWNBD_LIB) LDFLAGS += $(LDFLAGS-$@) diff --git a/examples/local-reader.c b/examples/local-reader.c index 264fb1b..9e590c7 100644 --- a/examples/local-reader.c +++ b/examples/local-reader.c @@ -7,8 +7,6 @@ #include #include -extern struct lwnbd_plugin_t *file_plugin_init(void); - int main(int argc, const char **argv) { lwnbd_plugin_h fileplg; diff --git a/examples/local-shell.c b/examples/local-shell.c index 5892b4d..65f1418 100644 --- a/examples/local-shell.c +++ b/examples/local-shell.c @@ -1,6 +1,8 @@ /* * An interactive shell using command plugin * + * + * */ #define _GNU_SOURCE @@ -10,9 +12,6 @@ #include #include #include -#include - -extern struct lwnbd_plugin_t *command_plugin_init(void); char *exportname, *prompt, *base; @@ -37,13 +36,17 @@ static int set_exportname(int argc, char **argv, void *result, int64_t *size) int main(int argc, char **argv) { - lwnbd_plugin_h cmdplg; + lwnbd_plugin_h cmdplg, memplg; lwnbd_context_t *ctx; - char *p, *buf; + char *p, *buf, memtest[512]; int errno, r = 0; - ; uint64_t size = 0; + /* + * set base URI, default exportname to 'shell' and prompt + * + */ + if (-1 == asprintf(&exportname, "shell")) exit(EXIT_FAILURE); @@ -53,6 +56,34 @@ int main(int argc, char **argv) if (-1 == set_prompt(base, exportname)) exit(EXIT_FAILURE); + /* + * create a slice of memory to test memory query + * + */ + + memplg = lwnbd_plugin_init(memory_plugin_init); + + struct memory_config memh = { + .base = (uint64_t)memtest, + .name = "test", + .size = 512, + .desc = "", + }; + lwnbd_plugin_new(memplg, &memh); + + /* + * let's use query mechanism to set it + */ + + if (-1 == asprintf(&buf, "test?memcpy=Example of shared memory.\n")) /* create the request */ + exit(EXIT_FAILURE); + + ctx = lwnbd_get_context(buf); /* GET */ + + /* + * create a command to change export, to be able to switch to it + */ + cmdplg = lwnbd_plugin_init(command_plugin_init); struct lwnbd_command mycmd = { @@ -63,6 +94,10 @@ int main(int argc, char **argv) lwnbd_plugin_new(cmdplg, &mycmd); + /* + * main 'interactive' shell loop + */ + while (r == 0) { int n; @@ -84,6 +119,8 @@ int main(int argc, char **argv) } ctx = lwnbd_get_context(buf); + if (ctx == NULL) + continue; if (size < ctx->exportsize) { size = ctx->exportsize; @@ -94,5 +131,9 @@ int main(int argc, char **argv) printf("%s", buf); } + free(buf); + free(exportname); + free(prompt); + free(base); exit(EXIT_SUCCESS); } diff --git a/examples/lwnbd-server.c b/examples/lwnbd-server.c index cda6a27..e2d5cbf 100644 --- a/examples/lwnbd-server.c +++ b/examples/lwnbd-server.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -22,26 +23,24 @@ #include #include -#include "../plugins/memory/memory.h" -#include "../servers/nbd/nbd.h" +typedef enum { + CLIENT_FREE, + CLIENT_INUSE, +} worker_state_t; -/* static glue, could be generate : - * #define LIST_ENTRY(x) x, - * - * */ - -extern lwnbd_plugin_t *command_plugin_init(void); -extern lwnbd_plugin_t *memory_plugin_init(void); -extern lwnbd_plugin_t *file_plugin_init(void); -extern struct lwnbd_server *nbd_server_init(void); +struct nbd_worker +{ + uv_work_t req; + int client_id; + uv_stream_t *server; +}; -#define MAX_CLIENTS 10 -uv_work_t *client_reqs[MAX_CLIENTS]; +#define MAX_CLIENTS 3 +int gEnableWrite = 1; +int gHDDStartMode; -// plugin_init plugins_table[] = { -// file_plugin_init, -// NULL -// }; +static worker_state_t client_states[MAX_CLIENTS]; +struct nbd_worker *client_reqs[MAX_CLIENTS]; /* need to be accessible to signal handler */ void signal_handler(uv_signal_t *req, int signum) { @@ -66,17 +65,17 @@ int server_shutdown(int argc, char **argv, void *result, int64_t *size) return 0; } -int gEnableWrite = 1; -int gHDDStartMode; - -void on_close(uv_handle_t *handle) +void on_after_work(uv_work_t *req, int status) { - free(handle); + struct nbd_worker *client_reqs = (struct nbd_worker *)req; + client_states[client_reqs->client_id] = CLIENT_FREE; + free(req); } -void on_after_work(uv_work_t *req, int status) +void on_close(uv_handle_t *handle) { - free(req); + DEBUGLOG("on_close\n"); + free(handle); } /* @@ -86,7 +85,8 @@ void on_after_work(uv_work_t *req, int status) void on_work(uv_work_t *req) { /* a bit of headache but avoid a baton */ - uv_stream_t *server = (uv_stream_t *)req->data; + struct nbd_worker *client_reqs = (struct nbd_worker *)req; + uv_stream_t *server = (uv_stream_t *)client_reqs->server; lwnbd_server_t *s = (lwnbd_server_t *)server->data; uv_tcp_t *client = (uv_tcp_t *)malloc(sizeof(uv_tcp_t)); @@ -101,8 +101,10 @@ void on_work(uv_work_t *req) int sock; uv_fileno((const uv_handle_t *)client, &sock); + DEBUGLOG("/++++++++++++++++++++++++++++++++++++++++++++++++++\n"); DEBUGLOG("Worker %d: Accepted fd %d\n", getpid(), sock); lwnbd_server_run(*s, &sock); // the abstracted blocking loop + DEBUGLOG("+++++++++++++++++++++++++++++++++++++++++++++++++++/\n"); uv_close((uv_handle_t *)client, on_close); } @@ -116,19 +118,19 @@ void on_new_connection(uv_stream_t *server, int status) } for (i = 0; i < MAX_CLIENTS; i++) { - if (client_reqs[i] == NULL) { - client_reqs[i] = (uv_work_t *)malloc(sizeof(uv_work_t)); - break; + DEBUGLOG("client_reqs[%d] = %p\n", i, client_reqs[i]); + if (client_states[i] == CLIENT_FREE) { + client_reqs[i] = (struct nbd_worker *)malloc(sizeof(struct nbd_worker)); + client_states[i] = CLIENT_INUSE; + client_reqs[i]->client_id = i; + client_reqs[i]->server = server; + uv_queue_work(uv_default_loop(), (uv_work_t *)client_reqs[i], on_work, on_after_work); + return; } } - if (client_reqs[i] == NULL) { - LOG("New connection error : no slot available\n"); - return; - } - - client_reqs[i]->data = server; - uv_queue_work(uv_default_loop(), client_reqs[i], on_work, on_after_work); + LOG("New connection error : no slot available\n"); + return; } int main(int argc, const char **argv) @@ -234,5 +236,7 @@ int main(int argc, const char **argv) uv_signal_init(loop, &sig); uv_signal_start(&sig, signal_handler, SIGINT); + memset(client_states, CLIENT_FREE, sizeof(client_states)); + return uv_run(loop, UV_RUN_DEFAULT); } diff --git a/include/config.h b/include/config.h index 25af846..16c360a 100644 --- a/include/config.h +++ b/include/config.h @@ -36,7 +36,7 @@ extern "C" { /* plugins options - useless here ? */ -#define MAX_NUM_PLUGINS 5 +#define MAX_NUM_PLUGINS 10 #define MAX_CONTEXTS 10 #ifdef __cplusplus diff --git a/include/lwnbd-common.h b/include/lwnbd-common.h new file mode 100644 index 0000000..4c47d64 --- /dev/null +++ b/include/lwnbd-common.h @@ -0,0 +1,56 @@ +/* + * + */ + +#ifndef INCLUDE_LWNBD_COMMON_H_ +#define INCLUDE_LWNBD_COMMON_H_ + +#include "config.h" +#include + +/* + * + */ + +/* experimental */ +//#ifdef PLUGIN_COMMAND +extern struct lwnbd_plugin_t *command_plugin_init(void); +struct lwnbd_command +{ + char *name; + char *desc; + int (*cmd)(int argc, char **argv, void *result, int64_t *size); +}; +//#endif + +//#ifdef PLUGIN_MEMORY +extern struct lwnbd_plugin_t *memory_plugin_init(void); +struct memory_config +{ + intptr_t base; + intptr_t size; + char name[32]; + char desc[64]; /* export description */ + /* TODO readonly ? */ +}; +//#endif + +//#ifdef PLUGIN_PCMSTREAM + +struct pcmstream_config +{ + char name[32]; + char desc[64]; /* export description */ + // char format[32]; + int rate; /** output frequency in hz */ + int bits; /** bits per sample (8, 16) */ + int channels; /** output channels (1, 2) */ + char volume; + /* input => readonly or output => writeonly */ +}; +//#endif + +extern struct lwnbd_plugin_t *file_plugin_init(void); +extern struct lwnbd_server *nbd_server_init(void); + +#endif /* INCLUDE_LWNBD_COMMON_H_ */ diff --git a/include/lwnbd-plugin.h b/include/lwnbd-plugin.h index 9970153..04587c7 100644 --- a/include/lwnbd-plugin.h +++ b/include/lwnbd-plugin.h @@ -1,10 +1,8 @@ #ifndef LWNBD_PLUGIN_H #define LWNBD_PLUGIN_H -#include "config.h" -#include -//#include -#include +#include +//#include #ifdef __cplusplus extern "C" { @@ -20,14 +18,6 @@ typedef struct lwnbd_export_t } lwnbd_export_t; // int lwnbd_plugin_export(lwnbd_export_t *e); -/* experimental */ -struct lwnbd_command -{ - char *name; - char *desc; - int (*cmd)(int argc, char **argv, void *result, int64_t *size); -}; - /* A struct to hold the query string parameter values. */ struct query_t { @@ -96,6 +86,23 @@ typedef struct lwnbd_plugin_t return &(plugin); \ } +/* + * Default callback + * + */ + +static inline int func_no_error(void *handle, uint32_t flags) +{ + return 0; +} + +static inline int char_block_size(void *handle, + uint32_t *minimum, uint32_t *preferred, uint32_t *maximum) +{ + *minimum = *preferred = *maximum = 1; + return 0; +} + static inline int64_t stream_get_size(void *handle) { /** diff --git a/include/lwnbd-server.h b/include/lwnbd-server.h index 17bb522..f540e6f 100644 --- a/include/lwnbd-server.h +++ b/include/lwnbd-server.h @@ -1,7 +1,7 @@ #ifndef LWNBD_SERVER_H #define LWNBD_SERVER_H -#include +#include #include #ifdef __cplusplus diff --git a/include/lwnbd.h b/include/lwnbd.h index 4058bb8..be58d58 100644 --- a/include/lwnbd.h +++ b/include/lwnbd.h @@ -1,8 +1,7 @@ #ifndef LWNBD_H #define LWNBD_H -#include -#include "config.h" +#include #ifdef __cplusplus extern "C" { @@ -48,28 +47,33 @@ int lwnbd_trim(lwnbd_context_t const *const me, uint32_t count, uint64_t offset, int lwnbd_zero(lwnbd_context_t const *const me, uint32_t count, uint64_t offset, uint32_t flags); int lwnbd_update_size(lwnbd_context_t *me); -/* content plugins */ +/* + * content plugins + * + */ -typedef uint32_t lwnbd_plugin_h; typedef struct lwnbd_plugin_t *(*plugin_init)(void); +typedef uint32_t lwnbd_plugin_h; int lwnbd_plugin_config(lwnbd_plugin_h const plugin, const char *key, const char *value); int lwnbd_plugin_new(lwnbd_plugin_h const plugin, const void *pconfig); int lwnbd_plugin_news(lwnbd_plugin_h const plugin, const void *pconfig[]); lwnbd_plugin_h lwnbd_plugin_init(plugin_init init); -/* server plugins + +/* + * server plugins * */ -typedef uint32_t lwnbd_server_t; typedef struct lwnbd_server *(*server_init)(void); +typedef uint32_t lwnbd_server_t; int lwnbd_server_config(lwnbd_server_t const handle, const char *key, const char *value); +int lwnbd_server_dump(lwnbd_server_t const handle); int lwnbd_server_new(lwnbd_server_t const handle, const void *pconfig); -void lwnbd_server_start(lwnbd_server_t const handle); int lwnbd_server_stop(lwnbd_server_t const handle); -void lwnbd_server_run(lwnbd_server_t const handle, void *client); -int lwnbd_server_dump(lwnbd_server_t const handle); lwnbd_server_t lwnbd_server_init(server_init init); +void lwnbd_server_run(lwnbd_server_t const handle, void *client); +void lwnbd_server_start(lwnbd_server_t const handle); #ifdef __cplusplus } diff --git a/servers/nbd/nbd.h b/include/lwnbd/nbd.h similarity index 96% rename from servers/nbd/nbd.h rename to include/lwnbd/nbd.h index 56b8430..ca5403d 100644 --- a/servers/nbd/nbd.h +++ b/include/lwnbd/nbd.h @@ -1,17 +1,16 @@ #ifndef NBD_SERVER_H #define NBD_SERVER_H -#include + +#include /* context stuff */ #include -#include -#include "config.h" -#include -#include -#include #include +#include +#include #include #include +#include #ifdef __linux__ // TODO : manage endianess diff --git a/servers/sifrpc/sifrpc.h b/include/lwnbd/sifrpc.h similarity index 100% rename from servers/sifrpc/sifrpc.h rename to include/lwnbd/sifrpc.h diff --git a/plugins/atad/atad_d.c b/plugins/atad/atad_d.c index ec16c00..3114fa4 100644 --- a/plugins/atad/atad_d.c +++ b/plugins/atad/atad_d.c @@ -60,28 +60,28 @@ static int atad_ctor(const void *pconfig, lwnbd_export_t *e) } /* nbdcopy nbd://192.168.1.45/hdd0/identify - | hdparm --Istdin */ -int identify(int argc, char **argv, void *result, int64_t *size) -{ - return ata_device_sce_identify_drive(argc, result); -} -// int ata_device_idle(int device, int period); -// int ata_device_smart_get_status(int device); -// int ata_device_smart_save_attr(int device); - -static int atad_ctrl(void *handle, char *path, struct lwnbd_command *cmd) -{ - struct handle *h = handle; - - if (strcmp("identify", path)) { - cmd->cmd = identify; - cmd->argc = h->device; - cmd->size = 256; - return 0; - } - - else - return -1; -} +// int identify(int argc, char **argv, void *result, int64_t *size) +//{ +// return ata_device_sce_identify_drive(argc, result); +// } +// int ata_device_idle(int device, int period); +// int ata_device_smart_get_status(int device); +// int ata_device_smart_save_attr(int device); + +// static int atad_ctrl(void *handle, char *path, struct lwnbd_command *cmd) +//{ +// struct handle *h = handle; +// +// if (strcmp("identify", path)) { +// cmd->cmd = identify; +// cmd->argc = h->device; +// cmd->size = 256; +// return 0; +// } +// +// else +// return -1; +// } static int64_t atad_get_size(void *handle) { @@ -109,7 +109,7 @@ static lwnbd_plugin_t plugin = { .flush = atad_flush, .get_size = atad_get_size, .block_size = atad_block_size, - .ctrl = atad_ctrl, + // .ctrl = atad_ctrl, }; NBDKIT_REGISTER_PLUGIN(plugin) diff --git a/plugins/command/Makefile b/plugins/command/Makefile index dad6087..e49bbba 100644 --- a/plugins/command/Makefile +++ b/plugins/command/Makefile @@ -1,2 +1,3 @@ -OBJ += plugins/command/command.o -PLUGIN_COMMAND = 1 \ No newline at end of file +export PLUGIN_COMMAND = 1 +export +OBJ += plugins/command/command.o \ No newline at end of file diff --git a/plugins/command/command.c b/plugins/command/command.c index c9f4953..a327083 100644 --- a/plugins/command/command.c +++ b/plugins/command/command.c @@ -20,7 +20,6 @@ struct result_h static struct result_h pr; - static inline int command_pread(void *handle, void *buf, uint32_t count, uint64_t offset, uint32_t flags) { @@ -48,7 +47,7 @@ static int command_list(int argc, char **argv, void *result, int64_t *size) /* we could use size as result size*/ *size = 0; while (cnt < commands_cnt) { - *size += sprintf(result + *size, "%-32s: %s\n", commands[cnt].name, commands[cnt].desc); + *size += sprintf((char *)result + *size, "%-32s: %s\n", commands[cnt].name, commands[cnt].desc); cnt++; } // DEBUGLOG("%d : %s\n", *size, result); diff --git a/plugins/command/command.h b/plugins/command/command.h deleted file mode 100644 index ce1bb51..0000000 --- a/plugins/command/command.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef PLUGINS_COMMAND_COMMAND_H_ -#define PLUGINS_COMMAND_COMMAND_H_ - - - -#endif /* PLUGINS_COMMAND_COMMAND_H_ */ diff --git a/plugins/memory/memory.c b/plugins/memory/memory.c index c5db02c..bd5fad7 100644 --- a/plugins/memory/memory.c +++ b/plugins/memory/memory.c @@ -1,5 +1,4 @@ -#include "memory.h" -#include +#include #define PLUGIN_NAME memory #define MEM_DRIVER_MAX_DEVICES 10 @@ -32,11 +31,6 @@ static inline int memory_pwrite(void *handle, const void *buf, uint32_t count, return 0; } -static inline int memory_flush(void *handle, uint32_t flags) -{ - return 0; -} - static int memory_ctor(const void *pconfig, lwnbd_export_t *e) { uint32_t i; @@ -65,19 +59,16 @@ static int64_t memory_get_size(void *handle) return h->size; } -static int memory_block_size(void *handle, - uint32_t *minimum, uint32_t *preferred, uint32_t *maximum) -{ - *minimum = *preferred = *maximum = 1; - return 0; -} - +/* + * Here, queries are used as filters. + * if query is unknown, it's just ignored. + */ static int memory_query(void *handle, struct query_t *params, int nb_params) { struct memory_config *h = handle; while (nb_params-- > 0) { if (0 == strcmp(params[nb_params].key, "bzero")) { - bzero((char *)h->base, h->size); + memset((char *)h->base, '\0', h->size); } else if (0 == strcmp(params[nb_params].key, "memset")) { if (params[nb_params].val != NULL) { LOG("val = %s\n", params[nb_params].val); @@ -86,9 +77,11 @@ static int memory_query(void *handle, struct query_t *params, int nb_params) } else if (0 == strcmp(params[nb_params].key, "memcpy")) { if (params[nb_params].val != NULL) { LOG("val = %s\n", params[nb_params].val); - bzero((char *)h->base, h->size); + memset((char *)h->base, '\0', h->size); memcpy((char *)h->base, params[nb_params].val, strlen(params[nb_params].val)); } + } else { + DEBUGLOG("%s is not a known filter.\n", params[nb_params].key); } } return 0; @@ -101,9 +94,9 @@ static lwnbd_plugin_t plugin = { .ctor = memory_ctor, .pread = memory_pread, .pwrite = memory_pwrite, - .flush = memory_flush, + .flush = func_no_error, .get_size = memory_get_size, - .block_size = memory_block_size, + .block_size = char_block_size, .query = memory_query, }; diff --git a/plugins/memory/memory.h b/plugins/memory/memory.h deleted file mode 100644 index 88bcb8a..0000000 --- a/plugins/memory/memory.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef PLUGINS_MEMORY_H_ -#define PLUGINS_MEMORY_H_ - -#include - -struct memory_config -{ - intptr_t base; - intptr_t size; - char name[32]; - char desc[64]; /* export description */ - /* TODO readonly ? */ -}; - -#endif /* PLUGINS_MEMORY_H_ */ diff --git a/plugins/pcmstream/pcmstream.c b/plugins/pcmstream/pcmstream.c index 5448b88..96246d1 100644 --- a/plugins/pcmstream/pcmstream.c +++ b/plugins/pcmstream/pcmstream.c @@ -1,7 +1,6 @@ -#include -#include "pcmstream.h" - #include +#include +#include #define PLUGIN_NAME pcmstream #define PCM_DRIVER_MAX_DEVICES 1 diff --git a/plugins/pcmstream/pcmstream.h b/plugins/pcmstream/pcmstream.h deleted file mode 100644 index 43075b7..0000000 --- a/plugins/pcmstream/pcmstream.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef PLUGINS_PCMSTREAM_H_ -#define PLUGINS_PCMSTREAM_H_ - -#include - -struct pcmstream_config -{ - char name[32]; - char desc[64]; /* export description */ - // char format[32]; - int rate; /** output frequency in hz */ - int bits; /** bits per sample (8, 16) */ - int channels; /** output channels (1, 2) */ - char volume; - /* input => readonly or output => writeonly */ -}; - -#endif /* PLUGINS_PCMSTREAM_H_ */ diff --git a/ports/playstation2/iop/include/endian.h b/ports/playstation2/common/include/endian.h similarity index 100% rename from ports/playstation2/iop/include/endian.h rename to ports/playstation2/common/include/endian.h diff --git a/ports/playstation2/ee/ee.mk b/ports/playstation2/ee/ee.mk index ef8baa4..cd4c845 100644 --- a/ports/playstation2/ee/ee.mk +++ b/ports/playstation2/ee/ee.mk @@ -1,4 +1,5 @@ #PLUGINS +include plugins/command/Makefile include plugins/memory/Makefile include servers/nbd/Makefile @@ -6,7 +7,7 @@ PORT_DIR = ports/playstation2 EE_LIB = lwnbd.a EE_LIBS = -lc -lps2ips -EE_INCS += -I$(PORT_DIR)/include -DAPP_NAME=\"lwnbdsvr\" +EE_INCS += -I$(PORT_DIR)/common/include -DAPP_NAME=\"lwnbdsvr\" EE_OBJS += $(OBJ) EE_CFLAGS += $(CFLAGS) diff --git a/ports/playstation2/iop/iop.mk b/ports/playstation2/iop/iop.mk index e9467a3..0387622 100644 --- a/ports/playstation2/iop/iop.mk +++ b/ports/playstation2/iop/iop.mk @@ -1,8 +1,10 @@ +BIN = lwnbdsvr.irx #PLUGINS include servers/nbd/Makefile include servers/sifrpc/Makefile include plugins/atad/Makefile +include plugins/command/Makefile include plugins/memory/Makefile include plugins/mcman/Makefile include plugins/pcmstream/Makefile @@ -11,14 +13,9 @@ include plugins/pcmstream/Makefile #include plugins/file/Makefile CC = $(IOP_CC) - -BIN = lwnbdsvr.irx -PORT_DIR = ports/playstation2 +PORT_DIR = ports/playstation2/iop OBJ += $(PORT_DIR)/lwnbd_irx.o $(PORT_DIR)/exports.o $(PORT_DIR)/imports.o $(PORT_DIR)/ioplib.o $(PORT_DIR)/tcp.o -INCS += -I$(PORT_DIR)/include -include $(PORT_DIR)/ps2sdk-compat.h -DAPP_NAME=\"lwnbdsvr\" - -.SILENT: $(OBJ) -all: $(BIN) +INCS += -I$(PORT_DIR)/../common/include -I$(PORT_DIR)/include -include $(PORT_DIR)/ps2sdk-compat.h -DAPP_NAME=\"lwnbdsvr\" # only suitable for https://github.com/ps2dev/ps2sdk-ports/ #install: all @@ -32,6 +29,8 @@ all: $(BIN) include $(PS2SDK)/Defs.make include $(PORT_DIR)/iopglobal.mk +all: $(BIN) + DEST ?= $(PS2_WORKSPACE)/Open-PS2-Loader TARGET_IP ?= 192.168.1.45 DEV ?= /dev/nbd2 diff --git a/ports/playstation2/iop/ioplib.h b/ports/playstation2/iop/ioplib.h index 92f3b87..344ee6e 100644 --- a/ports/playstation2/iop/ioplib.h +++ b/ports/playstation2/iop/ioplib.h @@ -3,16 +3,9 @@ #include "irx_imports.h" -/* why did i do that here ? */ -#include "../../plugins/memory/memory.h" -#include "../../plugins/pcmstream/pcmstream.h" -#include "../../servers/nbd/nbd.h" - int GetSizeFromDelay(int device); void print_memorymap(); - - /* TODO: manage existence */ // struct memory_config bios = { // .base = 0x1FC00000, diff --git a/ports/playstation2/iop/irx_imports.h b/ports/playstation2/iop/irx_imports.h index 28c7c64..184b3c0 100644 --- a/ports/playstation2/iop/irx_imports.h +++ b/ports/playstation2/iop/irx_imports.h @@ -2,6 +2,7 @@ #define IOP_IRX_IMPORTS_H #include +#include #define PLUGIN_ATAD 1 //#define PLUGIN_BDM 1 @@ -19,7 +20,7 @@ extern struct lwnbd_plugin_t *atad_plugin_init(void); #ifdef PLUGIN_BDM #include -extern struct lwnbd_plugin_t *bdm_plugin_init(void); +// extern struct lwnbd_plugin_t *bdm_plugin_init(void); #endif #ifdef PLUGIN_MCMAN @@ -29,11 +30,12 @@ extern struct lwnbd_plugin_t *mcman_plugin_init(void); #ifdef PLUGIN_MEMORY #include -extern struct lwnbd_plugin_t *memory_plugin_init(void); +// extern struct lwnbd_plugin_t *memory_plugin_init(void); #endif #ifdef PLUGIN_NBD #include +#include extern struct lwnbd_server *nbd_server_init(void); #endif @@ -48,9 +50,9 @@ extern struct lwnbd_plugin_t *pcmstream_plugin_init(void); #endif #ifdef PLUGIN_SIFRPC +#include #include #include -#include "../../servers/sifrpc/sifrpc.h" extern struct lwnbd_server *sifrpc_server_init(void); #endif diff --git a/ports/playstation2/iop/lwnbd_irx.c b/ports/playstation2/iop/lwnbd_irx.c index 86bb329..cf2e1d8 100644 --- a/ports/playstation2/iop/lwnbd_irx.c +++ b/ports/playstation2/iop/lwnbd_irx.c @@ -14,9 +14,6 @@ */ #include "ioplib.h" -#include "irx_imports.h" -#include -#include /* tcp.c */ extern void listener(struct nbd_server *s); diff --git a/ports/playstation2/iop/tcp.c b/ports/playstation2/iop/tcp.c index f9a39bd..ab8d13a 100644 --- a/ports/playstation2/iop/tcp.c +++ b/ports/playstation2/iop/tcp.c @@ -1,5 +1,9 @@ -#include "../../servers/nbd/nbd.h" +//#include "../../servers/nbd/nbd.h" + #include +#include +#include +#include #ifdef __PS2SDK_SYS_SOCKET_H__ #define close(x) lwip_close(x) diff --git a/servers/nbd/nbd.c b/servers/nbd/nbd.c index 98fece1..a2d9e81 100644 --- a/servers/nbd/nbd.c +++ b/servers/nbd/nbd.c @@ -1,7 +1,7 @@ -#include "nbd.h" +#include #include #include -#include // temporary +//#include // temporary #define NAME nbd #define NBD_SERVER_MAX_DEVICES 1 /* TODO handles are bugged, fix it */ diff --git a/servers/nbd/protocol-handshake.c b/servers/nbd/protocol-handshake.c index 53a86b0..d6f0e5d 100644 --- a/servers/nbd/protocol-handshake.c +++ b/servers/nbd/protocol-handshake.c @@ -1,4 +1,4 @@ -#include "nbd.h" +#include /* * nbdkit alloc this size ... diff --git a/servers/nbd/protocol.c b/servers/nbd/protocol.c index 95ea063..c58f346 100644 --- a/servers/nbd/protocol.c +++ b/servers/nbd/protocol.c @@ -4,7 +4,7 @@ * */ -#include "nbd.h" +#include const char *nbd_commands_to_string(uint16_t f) { diff --git a/servers/sifrpc/sifrpc.c b/servers/sifrpc/sifrpc.c index 8408b10..d27a1c9 100644 --- a/servers/sifrpc/sifrpc.c +++ b/servers/sifrpc/sifrpc.c @@ -1,4 +1,4 @@ -#include "sifrpc.h" +#include #include #include #include diff --git a/src/contexts_uri.c b/src/contexts_uri.c index b6f90cc..7796f7e 100644 --- a/src/contexts_uri.c +++ b/src/contexts_uri.c @@ -24,8 +24,11 @@ lwnbd_context_t *lwnbd_get_context(char *uri) { lwnbd_context_t *c; lwnbd_plugin_t *p; - int ret; + // we don't have yet defaultexport mecanism in core + if (!uri) { + return NULL; + } DEBUGLOG("searched handler for %s.\n", uri); struct yuarel url; @@ -54,7 +57,7 @@ lwnbd_context_t *lwnbd_get_context(char *uri) */ c = lwnbd_get_context_string(url.path); - if (c == NULL) + if (!c) return NULL; p = c->p; @@ -64,7 +67,7 @@ lwnbd_context_t *lwnbd_get_context(char *uri) * */ if (p->query) { - ret = p->query(c->handle, (struct query_t *)params, pa2); + int ret = p->query(c->handle, (struct query_t *)params, pa2); if (ret) { LOG("query failed\n"); return NULL; diff --git a/src/plugins.c b/src/plugins.c index 75fb0bb..bcbe2d6 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -4,7 +4,7 @@ #include #include -#include +//#include // workaround extern int lwnbd_add_context(lwnbd_plugin_t *p, lwnbd_export_t *e); @@ -18,7 +18,6 @@ typedef enum { static lwnbd_plugin_t *plugins[MAX_NUM_PLUGINS]; static plugin_state_t plugins_status[MAX_NUM_PLUGINS]; - // int lwnbd_plugin_export(lwnbd_export_t *e) //{ // lwnbd_plugin_t *p = plugins[plugin];