diff --git a/README b/README index 929fed7..7a4ddaa 100644 --- a/README +++ b/README @@ -146,6 +146,7 @@ Windows:- tested on Windows 7 64 and Windows XP 32 using Visual Studio 10 (see R - tested on Windows 7 64 using MingW on Linux to cross-compile (Debian and Ubuntu tested) Android:- tested with NDK r10e - running on Android 4.4 (should work starting from 2.3.3) AROS: - Build with 'make -f aros/Makefile.AROS' +Playstation 2: - Build and install with 'cd ps2ee; make -f Makefile.PS2_EE install' PlayStation 3: - Build and install the library with 'make -f ps3_ppu/Makefile.PS3_PPU install' diff --git a/include/libnfs-private.h b/include/libnfs-private.h index 6679b58..1cfd204 100644 --- a/include/libnfs-private.h +++ b/include/libnfs-private.h @@ -27,7 +27,7 @@ #include #endif -#ifndef WIN32 +#if !defined(WIN32) && !defined(PS2_EE) #include /* struct sockaddr_storage */ #endif @@ -39,6 +39,10 @@ #define IFNAMSIZ 16 #endif +#if defined(PS2_EE) && !defined(IFNAMSIZ) +#define IFNAMSIZ 16 +#endif + #include "libnfs-zdr.h" #include "../nfs/libnfs-raw-nfs.h" #include "../nfs4/libnfs-raw-nfs4.h" @@ -54,7 +58,7 @@ extern "C" { #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif -#if !defined(HAVE_SOCKADDR_STORAGE) && !defined(WIN32) +#if !defined(HAVE_SOCKADDR_STORAGE) && !defined(WIN32) && !defined(PS2_EE) /* * RFC 2553: protocol-independent placeholder for socket addresses */ diff --git a/include/nfsc/libnfs.h b/include/nfsc/libnfs.h index 7bc0a4b..f2fb319 100755 --- a/include/nfsc/libnfs.h +++ b/include/nfsc/libnfs.h @@ -23,6 +23,10 @@ #ifndef _LIBNFS_H_ #define _LIBNFS_H_ +#ifdef PS2_EE +#include "ps2_compat.h" +#endif + #include #if defined(__ANDROID__) || defined(AROS) || defined(__PPU__) \ || ( defined(__APPLE__) && defined(__MACH__) ) diff --git a/lib/init.c b/lib/init.c index c117e22..a7d5fd1 100644 --- a/lib/init.c +++ b/lib/init.c @@ -22,6 +22,10 @@ #include "aros_compat.h" #endif +#ifdef PS2_EE +#include "ps2_compat.h" +#endif + #ifdef PS3_PPU #include "ps3_compat.h" #endif diff --git a/lib/libnfs-sync.c b/lib/libnfs-sync.c index 34719d5..6b48da7 100644 --- a/lib/libnfs-sync.c +++ b/lib/libnfs-sync.c @@ -26,6 +26,10 @@ #include "aros_compat.h" #endif +#ifdef PS2_EE +#include "ps2_compat.h" +#endif + #ifdef PS3_PPU #include "ps3_compat.h" #endif @@ -2002,7 +2006,7 @@ mount_free_export_list(struct exportnode *exp) } } - +#if !defined(NO_SRV_AUTOSCAN) void free_nfs_srvr_list(struct nfs_server_list *srv) @@ -2369,4 +2373,6 @@ nfs_find_local_servers(void) } return data.srvrs; } -#endif//WIN32 +#endif /* WIN32 */ + +#endif /* !defined(NO_SRV_AUTOSCAN) */ diff --git a/lib/libnfs-zdr.c b/lib/libnfs-zdr.c index d364bba..b13e49d 100644 --- a/lib/libnfs-zdr.c +++ b/lib/libnfs-zdr.c @@ -33,6 +33,10 @@ #include "aros_compat.h" #endif +#ifdef PS2_EE +#include "ps2_compat.h" +#endif + #ifdef PS3_PPU #include "ps3_compat.h" #endif diff --git a/lib/libnfs.c b/lib/libnfs.c index 62d7a04..93bb4a2 100755 --- a/lib/libnfs.c +++ b/lib/libnfs.c @@ -30,6 +30,10 @@ #include "aros_compat.h" #endif +#ifdef PS2_EE +#include "ps2_compat.h" +#endif + #ifdef PS3_PPU #include "ps3_compat.h" #endif diff --git a/lib/nfs_v3.c b/lib/nfs_v3.c index 86a35d8..a668c11 100644 --- a/lib/nfs_v3.c +++ b/lib/nfs_v3.c @@ -30,6 +30,10 @@ #include "aros_compat.h" #endif +#ifdef PS2_EE +#include "ps2_compat.h" +#endif + #ifdef PS3_PPU #include "ps3_compat.h" #endif diff --git a/lib/nfs_v4.c b/lib/nfs_v4.c index d34ede2..10fe1fd 100644 --- a/lib/nfs_v4.c +++ b/lib/nfs_v4.c @@ -30,6 +30,10 @@ #include "aros_compat.h" #endif +#ifdef PS2_EE +#include "ps2_compat.h" +#endif + #ifdef PS3_PPU #include "ps3_compat.h" #endif diff --git a/lib/pdu.c b/lib/pdu.c index 28c88c8..4f587ee 100644 --- a/lib/pdu.c +++ b/lib/pdu.c @@ -23,6 +23,10 @@ #include "aros_compat.h" #endif +#ifdef PS2_EE +#include "ps2_compat.h" +#endif + #ifdef PS3_PPU #include "ps3_compat.h" #endif diff --git a/lib/socket.c b/lib/socket.c index 19aa233..ac1d004 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -23,6 +23,10 @@ #include "aros_compat.h" #endif +#ifdef PS2_EE +#include "ps2_compat.h" +#endif + #ifdef PS3_PPU #include "ps3_compat.h" #endif @@ -91,7 +95,7 @@ #endif #ifndef MSG_NOSIGNAL -#if (defined(__APPLE__) && defined(__MACH__)) +#if (defined(__APPLE__) && defined(__MACH__)) || defined(PS2_EE) #define MSG_NOSIGNAL 0 #endif #endif @@ -133,10 +137,12 @@ set_nonblocking(int fd) static void set_nolinger(int fd) { +#if !defined(PS2_EE) struct linger lng; lng.l_onoff = 1; lng.l_linger = 0; setsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&lng, sizeof(lng)); +#endif } static int @@ -601,7 +607,7 @@ rpc_connect_sockaddr_async(struct rpc_context *rpc) } if (rpc->old_fd) { -#if !defined(WIN32) && !defined(PS3_PPU) +#if !defined(WIN32) && !defined(PS3_PPU) && !defined(PS2_EE) if (dup2(rpc->fd, rpc->old_fd) == -1) { return -1; } @@ -667,7 +673,7 @@ rpc_connect_sockaddr_async(struct rpc_context *rpc) sizeof(struct sockaddr_in); #endif break; -#ifndef PS3_PPU +#if !defined(PS3_PPU) && !defined(PS2_EE) case AF_INET6: sin6->sin6_port = port; sin6->sin6_family = AF_INET6; @@ -725,7 +731,7 @@ rpc_set_sockaddr(struct rpc_context *rpc, const char *server, int port) sizeof(struct sockaddr_in); #endif break; -#ifndef PS3_PPU +#if !defined(PS3_PPU) && !defined(PS2_EE) case AF_INET6: ((struct sockaddr_in6 *)&rpc->s)->sin6_family = ai->ai_family; ((struct sockaddr_in6 *)&rpc->s)->sin6_port = htons(port); diff --git a/mount/mount.c b/mount/mount.c index e025072..47df147 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -15,6 +15,10 @@ along with this program; if not, see . */ +#ifdef PS2_EE +#include "ps2_compat.h" +#endif + #ifdef WIN32 #include #endif/*WIN32*/ diff --git a/nfs/nfs.c b/nfs/nfs.c index 9733f19..aa7866e 100644 --- a/nfs/nfs.c +++ b/nfs/nfs.c @@ -15,6 +15,10 @@ along with this program; if not, see . */ +#ifdef PS2_EE +#include "ps2_compat.h" +#endif + #ifdef WIN32 #include #else diff --git a/nfs4/nfs4.c b/nfs4/nfs4.c index 74da33e..148422c 100644 --- a/nfs4/nfs4.c +++ b/nfs4/nfs4.c @@ -16,6 +16,10 @@ along with this program; if not, see . */ +#ifdef PS2_EE +#include "ps2_compat.h" +#endif + #ifdef WIN32 #include #else diff --git a/ps2_ee/Makefile.PS2_EE b/ps2_ee/Makefile.PS2_EE new file mode 100644 index 0000000..1e65133 --- /dev/null +++ b/ps2_ee/Makefile.PS2_EE @@ -0,0 +1,40 @@ +EE_CFLAGS = -DPS2_EE \ + -D_U_=/**/ -I../include -I../include/nfsc \ + -I../mount -I../nfs -I../nfs4 -I../portmap + +EE_LIB = libnfs.a +EE_INCS = +EE_OBJS = ../lib/init.o ../lib/pdu.o ../lib/socket.o \ + ../lib/nfs_v3.o ../lib/nfs_v4.o \ + ../lib/libnfs.o ../lib/libnfs-sync.o ../lib/libnfs-zdr.o \ + ../mount/mount.o ../mount/libnfs-raw-mount.o \ + ../portmap/portmap.o ../portmap/libnfs-raw-portmap.o \ + ../nfs/nfs.o ../nfs/libnfs-raw-nfs.o \ + ../nfs4/nfs4.o ../nfs4/libnfs-raw-nfs4.o + +all: $(EE_LIB) $(EE_OBJS) + +install: all +ifeq ($(PS2SDK),) + @echo "$PS2SDK is not set. Can not install libnfs." + @exit 1 +endif + @echo Copying... + @[ -d $(PS2SDK)/ee/include/nfsc ] || mkdir -p $(PS2SDK)/ee/include/nfsc + @cp -frv ../include/nfsc/*.h $(PS2SDK)/ee/include/nfsc + @cp -frv ../mount/*.h $(PS2SDK)/ee/include/nfsc + @cp -frv ../portmap/*.h $(PS2SDK)/ee/include/nfsc + @cp -frv ../nfs/*.h $(PS2SDK)/ee/include/nfsc + @cp -frv ../nfs4/*.h $(PS2SDK)/ee/include/nfsc + @cp -frv *.a $(PS2SDK)/ee/lib + @echo Done! + +clean: + rm -rf *.a $(EE_OBJS) + +reset: + ps2client reset + +include $(PS2SDK)/samples/Makefile.pref +include $(PS2SDK)/samples/Makefile.eeglobal + diff --git a/ps2_ee/config.h b/ps2_ee/config.h new file mode 100644 index 0000000..f0c2ac3 --- /dev/null +++ b/ps2_ee/config.h @@ -0,0 +1,38 @@ +/* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ +/* + Copyright (C) 2021 by Ronnie Sahlberg + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, see . +*/ + +#ifndef __PS2_CONFIG_H__ + +#define HAVE_ARPA_INET_H 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_MEMORY_H 1 +#define HAVE_NETDB_H 1 +#define HAVE_NETINET_IN_H 1 +#define HAVE_SOCKADDR_LEN 1 +#define HAVE_STDINT_H 1 +#define HAVE_STDLIB_H 1 +#define HAVE_STRINGS_H 1 +#define HAVE_STRING_H 1 +/* #define HAVE_SYS_SOCKET_H */ +#define HAVE_SYS_STAT_H 1 +#define HAVE_SYS_TIME_H 1 +#define HAVE_SYS_TYPES_H 1 +#define HAVE_UNISTD_H 1 +#define HAVE_UTIME_H 1 + +#endif /* __PS2_CONFIG_H__ */ diff --git a/ps2_ee/ps2_compat.c b/ps2_ee/ps2_compat.c new file mode 100644 index 0000000..b3d5ed5 --- /dev/null +++ b/ps2_ee/ps2_compat.c @@ -0,0 +1,86 @@ +/* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ +/* + Copyright (C) 2021 by Ronnie Sahlberg + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, see . +*/ + +#ifdef PS2_EE + +#define NEED_READV +#define NEED_WRITEV +#define NEED_POLL +#define NEED_BE64TOH + +#include +#include +#include + +int getaddrinfo(const char *node, const char*service, + const struct addrinfo *hints, + struct addrinfo **res) +{ + struct sockaddr_in *sin; + struct hostent *host; + int i, ip[4]; + + sin = malloc(sizeof(struct sockaddr_in)); + sin->sin_len = sizeof(struct sockaddr_in); + sin->sin_family=AF_INET; + + /* Some error checking would be nice */ + if (sscanf(node, "%d.%d.%d.%d", ip, ip+1, ip+2, ip+3) == 4) { + for (i = 0; i < 4; i++) { + ((char *)&sin->sin_addr.s_addr)[i] = ip[i]; + } + } else { + host = gethostbyname(node); + if (host == NULL) { + return -1; + } + if (host->h_addrtype != AF_INET) { + return -2; + } + memcpy(&sin->sin_addr.s_addr, host->h_addr, 4); + } + + sin->sin_port=0; + if (service) { + sin->sin_port=htons(atoi(service)); + } + + *res = malloc(sizeof(struct addrinfo)); + + (*res)->ai_family = AF_INET; + (*res)->ai_addrlen = sizeof(struct sockaddr_in); + (*res)->ai_addr = (struct sockaddr *)sin; + + return 0; +} + +void freeaddrinfo(struct addrinfo *res) +{ + free(res->ai_addr); + free(res); +} + +int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, + char *host, socklen_t hostlen, + char *serv, socklen_t servlen, int flags) +{ + /* not implemented yet */ + return -1; +} + +#endif /* PS2_EE */ diff --git a/ps2_ee/ps2_compat.h b/ps2_ee/ps2_compat.h new file mode 100644 index 0000000..eaa4923 --- /dev/null +++ b/ps2_ee/ps2_compat.h @@ -0,0 +1,107 @@ +/* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ +/* + Copyright (C) 2021 by Ronnie Sahlberg + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, see . +*/ + +#ifndef _PS2_COMPAT_H_ +#define _PS2_COMPAT_H_ + +#ifdef PS2_EE + +#define NO_SRV_AUTOSCAN +#define IPPORT_RESERVED 1024 + +#include +#include +#include +#include + +typedef unsigned long int fsfilcnt_t; +typedef unsigned long int fsblkcnt_t; + +#define getservbyport(a,b) NULL +#define major(a) 0 +#define minor(a) 0 +#define O_NOFOLLOW 0 +#define X_OK 1 +#define W_OK 2 +#define R_OK 4 + +struct statvfs { + unsigned long int f_bsize; + unsigned long int f_frsize; + unsigned long int f_blocks; + unsigned long int f_bfree; + unsigned long int f_bavail; + unsigned long int f_files; + unsigned long int f_ffree; + unsigned long int f_favail; + unsigned long int f_fsid; + unsigned long int f_flag; + unsigned long int f_namemax; +}; + +#define getpid() 0 +#define getuid() 0 +#define getgid() 0 + +#define write(a,b,c) lwip_write(a,b,c) +#define read(a,b,c) lwip_read(a,b,c) +#define gethostbyname(a) lwip_gethostbyname(a) +#define close(a) lwip_close(a) + +#define getlogin_r(a,b) ENXIO +#define srandom srand +#define random rand + +#define POLLIN 0x0001 /* There is data to read */ +#define POLLPRI 0x0002 /* There is urgent data to read */ +#define POLLOUT 0x0004 /* Writing now will not block */ +#define POLLERR 0x0008 /* Error condition */ +#define POLLHUP 0x0010 /* Hung up */ + +struct pollfd { + int fd; + short events; + short revents; +}; + +int poll(struct pollfd *fds, unsigned int nfds, int timo); + +struct iovec { + void *iov_base; + size_t iov_len; +}; + +ssize_t writev(int fd, const struct iovec *iov, int iovcnt); +ssize_t readv(int fd, const struct iovec *iov, int iovcnt); + +int getaddrinfo(const char *node, const char*service, + const struct addrinfo *hints, + struct addrinfo **res); +void freeaddrinfo(struct addrinfo *res); + +long long int be64toh(long long int x); + +#define SOL_TCP IPPROTO_TCP +#define EAI_AGAIN EAGAIN + +/* just pretend they are the same so we compile */ +#define sockaddr_in6 sockaddr_in + +#endif /* PS2_EE */ + +#endif /* _PS2_COMPAT_H_ */