Skip to content

Commit

Permalink
lwnbd: sync with lwnbd repo
Browse files Browse the repository at this point in the history
  • Loading branch information
bignaux committed Aug 30, 2021
1 parent 640d8be commit b75de6f
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 295 deletions.
1 change: 1 addition & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./modules/network/lwnbdsvr/lwNBD/nbd-protocol.h
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ DETAILED_CHANGELOG
!.github
!.editorconfig
!.clang-format
!.clang-format-ignore
!modules/debug/*.irx

#
Expand Down
41 changes: 28 additions & 13 deletions modules/network/lwnbdsvr/drivers/atad.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
#include "atad.h"

int atad_init(struct nbd_context *me)
static inline int atad_read_(nbd_context const *const me, void *buffer, uint64_t offset, uint32_t length)
{
ata_devinfo_t *dev_info = ata_get_devinfo(0);
if (dev_info != NULL && dev_info->exists) {
me->export_size = (uint64_t)dev_info->total_sectors << me->blockshift;
return 0;
}
return 1;
return ata_device_sector_io(((atad_driver const *)me)->device, buffer, (uint32_t)offset, length, ATA_DIR_READ);
}

int atad_read(struct nbd_context *me, void *buffer, uint64_t offset, uint32_t length)
static inline int atad_write_(nbd_context const *const me, void *buffer, uint64_t offset, uint32_t length)
{
return ata_device_sector_io(0, buffer, (uint32_t)offset, length, ATA_DIR_READ);
return ata_device_sector_io(((atad_driver const *)me)->device, buffer, (uint32_t)offset, length, ATA_DIR_WRITE);
}

int atad_write(struct nbd_context *me, void *buffer, uint64_t offset, uint32_t length)
static inline int atad_flush_(nbd_context const *const me)
{
return ata_device_sector_io(0, buffer, (uint32_t)offset, length, ATA_DIR_WRITE);
return ata_device_flush_cache(((atad_driver const *)me)->device);
}

int atad_flush(struct nbd_context *me)
int atad_ctor(atad_driver *const me, int device)
{
return ata_device_flush_cache(0);
me->device = device;
ata_devinfo_t *dev_info = ata_get_devinfo(me->device);

static struct nbd_context_Vtbl const vtbl = {
&atad_read_,
&atad_write_,
&atad_flush_,
};

me->super.vptr = &vtbl; /* override the vptr */
// int ata_device_sce_identify_drive(int device, void *data);
strcpy(me->super.export_desc, "PlayStation 2 HDD via ATAD");
strcpy(me->super.export_name, "hdd0");
me->super.blockshift = 9;
me->super.buffer = nbd_buffer;

if (dev_info != NULL && dev_info->exists) {
me->super.export_size = (uint64_t)dev_info->total_sectors << me->super.blockshift;
return 0;
}
return 1;
}
11 changes: 7 additions & 4 deletions modules/network/lwnbdsvr/drivers/atad.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
extern "C" {
#endif

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);
typedef struct atad_driver
{
nbd_context super;
int device;
} atad_driver;

int atad_ctor(atad_driver *const me, int device);

#ifdef __cplusplus
}
Expand Down
33 changes: 0 additions & 33 deletions modules/network/lwnbdsvr/drivers/drivers.h

This file was deleted.

1 change: 1 addition & 0 deletions modules/network/lwnbdsvr/imports.lst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ I_DeleteThread
thbase_IMPORTS_end

sysclib_IMPORTS_start
I_strcpy
I_strlen
I_memset
sysclib_IMPORTS_end
Expand Down
38 changes: 20 additions & 18 deletions modules/network/lwnbdsvr/lwNBD/LICENSE
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
BSD 2 - Clause License
BSD 2-Clause License

Copyright(c) 2021,
Bignaux Ronan
All rights reserved.
Copyright (c) 2021, Bignaux Ronan
All rights reserved.

Redistribution and use in source and binary forms,
with or without
modification,
are permitted provided that the following conditions are met :
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and /
or other materials provided with the distribution.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10 changes: 5 additions & 5 deletions modules/network/lwnbdsvr/lwNBD/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# lwNBD

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

## History

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. Currently, the support for HDD is merged in OPL.
lwNBD is developed on MIPS R3000 IOP as an IRX module in [Open-PS2-Loader](https://github.com/ps2homebrew/Open-PS2-Loader). That provides a good uptodate use case.

## Status

Expand All @@ -20,9 +20,9 @@ Known supported clients :

* nbdfuse (provided by libnbd), works on windows with WSL2.
* nbd-client -no-optgo
* Ceph for Windows (wnbd-client.exe)

## 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.
* NBD_OPT_INFO/NBD_OPT_GO, the server is not yet able to serve many export or change blocksize. Currently, the server takes the first context on the list.
Loading

0 comments on commit b75de6f

Please sign in to comment.