From d7c6e9aaa9df593e951e2f19106dcc71102e74f1 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Wed, 10 Apr 2013 20:28:40 -0700 Subject: [PATCH] Initial AROS support. The test app doesnt link yet since we are missing a bunch of symbols but it is a start --- Makefile.AROS | 27 ++++++++++++ aros/aros_compat.c | 87 +++++++++++++++++++++++++++++++++++++++ aros/aros_compat.h | 31 ++++++++++++++ configure.ac | 14 +++++++ include/libnfs-private.h | 28 +++++++++++++ include/nfsc/libnfs-zdr.h | 10 ++++- include/nfsc/libnfs.h | 3 ++ lib/libnfs-sync.c | 27 ++++++++---- lib/libnfs-zdr.c | 1 + lib/libnfs.c | 18 +++++--- lib/socket.c | 10 ++++- win32/win32_compat.c | 2 +- 12 files changed, 239 insertions(+), 19 deletions(-) create mode 100644 Makefile.AROS create mode 100644 aros/aros_compat.c create mode 100644 aros/aros_compat.h diff --git a/Makefile.AROS b/Makefile.AROS new file mode 100644 index 0000000..fb0c988 --- /dev/null +++ b/Makefile.AROS @@ -0,0 +1,27 @@ +AR=ar +CC=gcc +CFLAGS=-g -O0 -DAROS=1 -D_U_=" " -I. -Iinclude -Iinclude/nfsc -Iaros -Infs -Imount + +OBJS=lib/init.o lib/libnfs.o lib/libnfs-sync.o lib/libnfs-zdr.o lib/pdu.o lib/socket.o +OBJS+=mount/mount.o mount/libnfs-raw-mount.o +OBJS+=nfs/nfs.o nfs/nfsacl.o nfs/libnfs-raw-nfs.o +OBJS+=nlm/nlm.o nlm/libnfs-raw-nlm.o +OBJS+=portmap/portmap.o portmap/libnfs-raw-portmap.o +OBJS+=rquota/rquota.o rquota/libnfs-raw-rquota.o +OBJS+=aros/aros_compat.o + +EXAMPLES=examples/nfsclient-listservers + +all: lib/libnfs.a $(EXAMPLES) + +lib/libnfs.a: $(OBJS) + $(AR) cru $@ $(OBJS) + +.c.o: + echo $(CC) $(CFLAGS) -c -o $@ $< + $(CC) $(CFLAGS) -c -o $@ $< + +examples/nfsclient-listservers: examples/nfsclient-listservers.c lib/libnfs.a + + $(CC) $(CFLAGS) -o $@ $< lib/libnfs.a + diff --git a/aros/aros_compat.c b/aros/aros_compat.c new file mode 100644 index 0000000..10f127b --- /dev/null +++ b/aros/aros_compat.c @@ -0,0 +1,87 @@ +/* + Copyright (C) 2013 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 AROS + +#include +#include +#include "aros_compat.h" + +#undef poll + + +int aros_poll(struct pollfd *fds, unsigned int nfds, int timo) +{ + struct timeval timeout, *toptr; + fd_set ifds, ofds, efds, *ip, *op; + unsigned int i; + int rc; + + // Set up the file-descriptor sets in ifds, ofds and efds. + FD_ZERO(&ifds); + FD_ZERO(&ofds); + FD_ZERO(&efds); + for (i = 0, op = ip = 0; i < nfds; ++i) + { + fds[i].revents = 0; + if(fds[i].events & (POLLIN|POLLPRI)) + { + ip = &ifds; + FD_SET(fds[i].fd, ip); + } + if(fds[i].events & POLLOUT) + { + op = &ofds; + FD_SET(fds[i].fd, op); + } + FD_SET(fds[i].fd, &efds); + } + + // Set up the timeval structure for the timeout parameter + if(timo < 0) + { + toptr = 0; + } + else + { + toptr = &timeout; + timeout.tv_sec = timo / 1000; + timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000; + } + + rc = select(0, ip, op, &efds, toptr); + + if(rc <= 0) + return rc; + + if(rc > 0) + { + for (i = 0; i < nfds; ++i) + { + int fd = fds[i].fd; + if(fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds)) + fds[i].revents |= POLLIN; + if(fds[i].events & POLLOUT && FD_ISSET(fd, &ofds)) + fds[i].revents |= POLLOUT; + if(FD_ISSET(fd, &efds)) // Some error was detected ... should be some way to know. + fds[i].revents |= POLLHUP; + } + } + return rc; +} + +#endif diff --git a/aros/aros_compat.h b/aros/aros_compat.h new file mode 100644 index 0000000..f9db059 --- /dev/null +++ b/aros/aros_compat.h @@ -0,0 +1,31 @@ +#ifndef AROS_COMPAT_H +#define AROS_COMPAT_H + +#include +#include + +#define statvfs statfs + +#define f_flag f_flags +#define f_favail f_ffree +/* we dont have these at all */ +#define f_fsid f_spare[0] +#define f_frsize f_spare[0] +#define f_namemax f_spare[0] + +#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 */ +#define POLLNVAL 0x0020 /* Invalid request: fd not open */ + +struct pollfd { + int fd; /* file descriptor */ + short events; /* requested events */ + short revents; /* returned events */ +}; + +#define poll(x, y, z) aros_poll(x, y, z) + +#endif diff --git a/configure.ac b/configure.ac index 1183bd2..7578ef5 100644 --- a/configure.ac +++ b/configure.ac @@ -81,6 +81,10 @@ case $host in ;; esac +# check for poll.h +dnl Check for poll.h +AC_CHECK_HEADERS([poll.h]) + # check for SA_LEN dnl Check if sockaddr data structure includes a "sa_len" AC_CHECK_MEMBER([struct sockaddr.sa_len], @@ -91,6 +95,16 @@ AC_CHECK_MEMBER([struct sockaddr.sa_len], #include ]) +# check for sockaddr_storage +dnl Check if sockaddr structure includes a "ss_family" +AC_CHECK_MEMBER([struct sockaddr_storage.ss_family], + [ AC_DEFINE(HAVE_SOCKADDR_STORAGE,1,[Whether we have sockaddr_Storage]) ], + [], + [ +#include +#include +]) + #output AC_CONFIG_FILES([Makefile] [include/Makefile] diff --git a/include/libnfs-private.h b/include/libnfs-private.h index d3cd3ec..f153e35 100644 --- a/include/libnfs-private.h +++ b/include/libnfs-private.h @@ -14,10 +14,38 @@ You should have received a copy of the GNU Lesser General Public License along with this program; if not, see . */ +#ifdef HAVE_CONFIG_H +#include "config.h" /* HAVE_SOCKADDR_STORAGE ? */ +#endif + #include /* struct sockaddr_storage */ #include "libnfs-zdr.h" +#ifndef HAVE_SOCKADDR_STORAGE +/* + * RFC 2553: protocol-independent placeholder for socket addresses + */ +#define _SS_MAXSIZE 128 +#define _SS_ALIGNSIZE (sizeof(double)) +#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(unsigned char) * 2) +#define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(unsigned char) * 2 - \ + _SS_PAD1SIZE - _SS_ALIGNSIZE) + +struct sockaddr_storage { +#ifdef HAVE_SA_LEN + unsigned char ss_len; /* address length */ + unsigned char ss_family; /* address family */ +#else + unsigned short ss_family; +#endif + char __ss_pad1[_SS_PAD1SIZE]; + double __ss_align; /* force desired structure storage alignment */ + char __ss_pad2[_SS_PAD2SIZE]; +}; +#endif + + struct rpc_fragment { struct rpc_fragment *next; uint64_t size; diff --git a/include/nfsc/libnfs-zdr.h b/include/nfsc/libnfs-zdr.h index 44f7378..55daa12 100644 --- a/include/nfsc/libnfs-zdr.h +++ b/include/nfsc/libnfs-zdr.h @@ -26,7 +26,9 @@ * and slightly modified. ************************************************************/ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifndef _LIBNFS_ZDR_H_ #define _LIBNFS_ZDR_H_ @@ -58,8 +60,12 @@ typedef void SVCXPRT; #define IZDR_PUT_BOOL(...) assert(0) #define IZDR_GET_BOOL(...) (assert(0), 0) +#ifndef TRUE #define TRUE 1 +#endif +#ifndef FALSE #define FALSE 0 +#endif enum zdr_op { ZDR_ENCODE = 0, @@ -178,8 +184,8 @@ struct rejected_reply { enum reject_stat stat; union { struct { - u_long low; - u_long high; + uint32_t low; + uint32_t high; } mismatch_info; enum auth_stat stat; } reject_data; diff --git a/include/nfsc/libnfs.h b/include/nfsc/libnfs.h index 75613d7..094de3c 100644 --- a/include/nfsc/libnfs.h +++ b/include/nfsc/libnfs.h @@ -21,6 +21,9 @@ #if defined(ANDROID) #include #endif +#if defined(AROS) +#include +#endif struct nfs_context; struct rpc_context; diff --git a/lib/libnfs-sync.c b/lib/libnfs-sync.c index fd6f796..2fe5ed5 100644 --- a/lib/libnfs-sync.c +++ b/lib/libnfs-sync.c @@ -20,27 +20,36 @@ #ifdef WIN32 #include "win32_compat.h" #define DllExport +#define HAVE_POLL_H #else #include #include -#ifndef ANDROID -#include -#else -#include -#include -#define statvfs statfs -#endif -#include #include #include #include #include -#endif + +#ifdef AROS +#include "aros_compat.h" +#else +#ifdef ANDROID +#include +#include +#define statvfs statfs +#else +#include +#endif /*ANDRIOD*/ +#endif /*AROS*/ +#endif /*WIN32*/ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#ifdef HAVE_POLL_H +#include +#endif + #include #include #include diff --git a/lib/libnfs-zdr.c b/lib/libnfs-zdr.c index a243d1d..24bf6c2 100644 --- a/lib/libnfs-zdr.c +++ b/lib/libnfs-zdr.c @@ -23,6 +23,7 @@ #ifdef WIN32 #include "win32_compat.h" #else +#include #include #endif/*WIN32*/ diff --git a/lib/libnfs.c b/lib/libnfs.c index deab4f1..cd5a629 100644 --- a/lib/libnfs.c +++ b/lib/libnfs.c @@ -21,16 +21,22 @@ #include "win32_compat.h" #define DllExport #else + #include -#ifndef ANDROID -#include +#include +#include + +#ifdef AROS +#include "aros_compat.h" #else +#ifdef ANDROID #include #define statvfs statfs -#endif -#include -#include -#endif/*WIN32*/ +#else +#include +#endif /*ANDROID*/ +#endif /*AROS*/ +#endif /*WIN32*/ #define _GNU_SOURCE diff --git a/lib/socket.c b/lib/socket.c index 83ca50e..1dbbdea 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -18,7 +18,6 @@ #include "win32_compat.h" #else #include -#include #include #include #include @@ -28,6 +27,15 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif + +#ifdef AROS +#include "aros_compat.h" +#endif + +#ifdef HAVE_POLL_H +#include +#endif + #include #include #include diff --git a/win32/win32_compat.c b/win32/win32_compat.c index fe2ca05..87f9ab1 100644 --- a/win32/win32_compat.c +++ b/win32/win32_compat.c @@ -29,7 +29,7 @@ static int dummy ATTRIBUTE((unused)); #include "win32_compat.h" #include #include -#include < time.h > +#include #undef poll #undef socket -- 2.34.1