Skip to content

Commit

Permalink
lwNBDsvr: Small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Bignaux Ronan committed Aug 24, 2021
1 parent 399ec25 commit 3f06d4b
Show file tree
Hide file tree
Showing 12 changed files with 549 additions and 404 deletions.
2 changes: 1 addition & 1 deletion modules/network/lwnbdsvr/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IOP_BIN = lwnbdsvr.irx
IOP_OBJS = lwnbdsvr.o imports.o exports.o drivers/atad.o lwNBD/nbd_server.o
IOP_OBJS = lwnbdsvr.o imports.o exports.o drivers/atad.o lwNBD/nbd_server.o lwNBD/nbd_protocol.o

IOP_CFLAGS += -DPS2SDK
IOP_INCS += -I../../iopcore/common -I../../../include/
Expand Down
8 changes: 4 additions & 4 deletions modules/network/lwnbdsvr/drivers/atad.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "atad.h"

int hdd_atad_init(struct nbd_context *me)
int atad_init(struct nbd_context *me)
{
ata_devinfo_t *dev_info = ata_get_devinfo(0);
if (dev_info != NULL && dev_info->exists) {
Expand All @@ -10,17 +10,17 @@ int hdd_atad_init(struct nbd_context *me)
return 1;
}

int hdd_atad_read(struct nbd_context *me, void *buffer, uint64_t offset, uint32_t length)
int atad_read(struct nbd_context *me, void *buffer, uint64_t offset, uint32_t length)
{
return ata_device_sector_io(0, buffer, (uint32_t)offset, length, ATA_DIR_READ);
}

int hdd_atad_write(struct nbd_context *me, void *buffer, uint64_t offset, uint32_t length)
int atad_write(struct nbd_context *me, void *buffer, uint64_t offset, uint32_t length)
{
return ata_device_sector_io(0, buffer, (uint32_t)offset, length, ATA_DIR_WRITE);
}

int hdd_atad_flush(struct nbd_context *me)
int atad_flush(struct nbd_context *me)
{
return ata_device_flush_cache(0);
}
10 changes: 4 additions & 6 deletions modules/network/lwnbdsvr/drivers/atad.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef ATAD_DRIVERS_NBD_H
#define ATAD_DRIVERS_NBD_H

Expand All @@ -10,10 +8,10 @@
extern "C" {
#endif

int hdd_atad_init(struct nbd_context *me);
int hdd_atad_read(struct nbd_context *me, void *buffer, uint64_t offset, uint32_t length);
int hdd_atad_write(struct nbd_context *me, void *buffer, uint64_t offset, uint32_t length);
int hdd_atad_flush(struct nbd_context *me);
int atad_init(struct nbd_context *me);
int atad_read(struct nbd_context *me, void *buffer, uint64_t offset, uint32_t length);
int atad_write(struct nbd_context *me, void *buffer, uint64_t offset, uint32_t length);
int atad_flush(struct nbd_context *me);

#ifdef __cplusplus
}
Expand Down
13 changes: 6 additions & 7 deletions modules/network/lwnbdsvr/drivers/drivers.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef DRIVERS_NBD_H
#define DRIVERS_NBD_H

Expand All @@ -13,18 +11,19 @@ extern "C" {

static struct nbd_context hdd_atad =
{
.export_name = "hdd",
.export_desc = "PlayStation 2 HDD via ATAD",
.export_name = "hdd0",
.blockshift = 9,
.buffer = nbd_buffer,
.export_init = hdd_atad_init,
.read = hdd_atad_read,
.write = hdd_atad_write,
.flush = hdd_atad_flush,
.export_init = atad_init,
.read = atad_read,
.write = atad_write,
.flush = atad_flush,
};

struct nbd_context *nbd_contexts[] = {
&hdd_atad,
NULL,
};

#ifdef __cplusplus
Expand Down
35 changes: 21 additions & 14 deletions modules/network/lwnbdsvr/lwNBD/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
#lwNBD
# lwNBD

* Description : A Lightweight NBD server based on lwIP stack
* Official repository : https://github.com/bignaux/lwNBD
* Author : Ronan Bignaux
* Licence : BSD
* lwIP 2.0.0 Socket API
* Description : A Lightweight NBD server based on lwIP stack
* Official repository : <https://github.com/bignaux/lwNBD>
* Author : Ronan Bignaux
* Licence : BSD
* lwIP 2.0.0 Socket API

#History
## History

On Playstation 2, there is no standardised central partition table like GPT for hard disk partitioning, nor is there a standard file system but PFS and HDLoader. In fact, there are few tools capable of handling hard disks, especially under Linux, and the servers developed in the past to handle these disks via the network did not use a standard protocol, which required each software wishing to handle the disks to include a specific client part, which were broken when the toolchain was updated. The same goes for the memory cards and other block devices on this console, which is why I decided to implement NBD on this target first.
On Playstation 2, there is no standardized central partition table like GPT for hard disk partitioning, nor is there a standard file system but PFS and HDLoader. In fact, there are few tools capable of handling hard disks, especially under Linux, and the servers developed in the past to handle these disks via the network did not use a standard protocol, which required each software wishing to handle the disks to include a specific client part, which were broken when the toolchain was updated. The same goes for the memory cards and other block devices on this console, which is why I decided to implement NBD on this target first.

lwNBD is developed on MIPS R3000 IOP in [my OPL nbd branch](https://github.com/bignaux/Open-PS2-Loader/tree/nbd/modules/network/lwnbdsvr), that provides a good uptodate use case.
lwNBD is developed on MIPS R3000 IOP in [my OPL nbd branch](https://github.com/bignaux/Open-PS2-Loader/tree/nbd/modules/network/lwnbdsvr), that provides a good uptodate use case. Currently, the support for HDD is merged in OPL.

#Status
## Status

Although this server is not yet complete in respect of the minimal requirements defined by the [NBD protocol](https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md#baseline), it is nevertheless usable with certain clients, in particular nbdfuse (provided by libnbd), the client I am using for this development. In a [RERO spirit](https://en.wikipedia.org/wiki/Release_early,_release_often) i publish this "AS-IS".
Although this server is not yet complete in respect of the minimal requirements defined by the [NBD protocol](https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md#baseline), it is nevertheless usable with certain clients. In a [RERO spirit](https://en.wikipedia.org/wiki/Release_early,_release_often) i publish this "AS-IS".

#TODO:
* fix NBD_FLAG_FIXED_NEWSTYLE negotiation
* NBD_OPT_INFO/NBD_OPT_GO, the server is not yet able to serve many export. Currently, the server takes the first on the list.
Known supported clients :

* nbdfuse (provided by libnbd), works on windows with WSL2.
* nbd-client -no-optgo

## TODO

* A GNU/Linux port
* fix NBD_FLAG_FIXED_NEWSTYLE negotiation
* NBD_OPT_INFO/NBD_OPT_GO, the server is not yet able to serve many export. Currently, the server takes the first on the list.
22 changes: 11 additions & 11 deletions modules/network/lwnbdsvr/lwNBD/nbd_opts.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/****************************************************************/ /**
*
* @file nbd_opts.h
*
* @author Ronan Bignaux <ronan@aimao.org>
*
* @brief Network Block Device Protocol implementation options
*
* Copyright (c) Ronan Bignaux. 2021
* All rights reserved.
*
********************************************************************/
*
* @file nbd_opts.h
*
* @author Ronan Bignaux <ronan@aimao.org>
*
* @brief Network Block Device Protocol implementation options
*
* Copyright (c) Ronan Bignaux. 2021
* All rights reserved.
*
********************************************************************/

/*
* Redistribution and use in source and binary forms, with or without
Expand Down
Loading

0 comments on commit 3f06d4b

Please sign in to comment.