From 270a30c1a350d791053937c72e6ce6cc63a64088 Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Thu, 13 Dec 2007 23:40:55 +0000 Subject: Replace plpnfsd with plpfuse. Other minor simplifications to the build system. --- Makefile.am | 2 +- configure.ac | 107 ++-- doc/Makefile.am | 10 +- doc/ncpd.man.in | 4 +- doc/plpftp.man.in | 2 +- doc/plpprintd.man.in | 2 +- doc/sisinstall.man.in | 2 +- etc/plptools.spec.in | 8 +- etc/psion.SuSE.in | 22 +- etc/psion.in | 22 +- include/OSdefs.h | 13 - include/fparam.h | 21 - include/linux-misc.h | 52 -- include/misc-aix3.h | 99 ---- include/mp.h | 166 ------ include/nfs_prot.h | 397 ------------- include/os-aix3.h | 182 ------ include/sun_stdlib.h | 268 --------- lib/Makefile.am | 3 - plpftp/Makefile.am | 3 - plpfuse/.cvsignore | 5 + plpfuse/Makefile.am | 9 + plpfuse/fuse.c | 528 +++++++++++++++++ plpfuse/main.cc | 380 +++++++++++++ plpfuse/plpfuse.h | 52 ++ plpfuse/rfsv_api.h | 76 +++ plpnfsd/Makefile.am | 17 - plpnfsd/builtins.h | 77 --- plpnfsd/main.cc | 622 -------------------- plpnfsd/mount_aix.c | 169 ------ plpnfsd/mp_inode.c | 338 ----------- plpnfsd/mp_main.c | 198 ------- plpnfsd/mp_mount.c | 630 --------------------- plpnfsd/mp_pfs_ops.c | 1474 ------------------------------------------------ plpnfsd/nfs_prot_svc.c | 232 -------- plpnfsd/nfs_prot_xdr.c | 519 ----------------- plpnfsd/rfsv_api.h | 81 --- plpprint/plpprintd.cc | 6 +- sisinstall/Makefile.am | 3 - 39 files changed, 1102 insertions(+), 5699 deletions(-) delete mode 100644 include/OSdefs.h delete mode 100644 include/fparam.h delete mode 100644 include/linux-misc.h delete mode 100644 include/misc-aix3.h delete mode 100644 include/mp.h delete mode 100644 include/nfs_prot.h delete mode 100644 include/os-aix3.h delete mode 100644 include/sun_stdlib.h create mode 100644 plpfuse/.cvsignore create mode 100644 plpfuse/Makefile.am create mode 100644 plpfuse/fuse.c create mode 100644 plpfuse/main.cc create mode 100644 plpfuse/plpfuse.h create mode 100644 plpfuse/rfsv_api.h delete mode 100644 plpnfsd/Makefile.am delete mode 100644 plpnfsd/builtins.h delete mode 100644 plpnfsd/main.cc delete mode 100644 plpnfsd/mount_aix.c delete mode 100644 plpnfsd/mp_inode.c delete mode 100644 plpnfsd/mp_main.c delete mode 100644 plpnfsd/mp_mount.c delete mode 100644 plpnfsd/mp_pfs_ops.c delete mode 100644 plpnfsd/nfs_prot_svc.c delete mode 100644 plpnfsd/nfs_prot_xdr.c delete mode 100644 plpnfsd/rfsv_api.h diff --git a/Makefile.am b/Makefile.am index f9268b3..2ac9481 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = intl po lib ncpd plpnfsd plpfuse plpftp plpprint sisinstall doc +SUBDIRS = intl po lib ncpd plpfuse plpftp plpprint sisinstall doc EXTRA_DIST = AUTHORS COPYING INSTALL NEWS README TODO HISTORY ABOUT-NLS include/*.h* \ etc/*magic etc/*.in etc/*.c etc/psidump* etc/udev-usbserial-plptools.rules \ diff --git a/configure.ac b/configure.ac index eb2cebb..7a7a763 100644 --- a/configure.ac +++ b/configure.ac @@ -59,18 +59,6 @@ dnl Large File Support AC_SYS_LARGEFILE AC_FUNC_FSEEKO -dnl checking for aix -AC_MSG_CHECKING(for AIX) -if test "`uname -s 2>/dev/null`" = AIX ; then - AC_MSG_RESULT(yes) - AC_CHECK_LIB(bsd, hostname) - EXTRA_OBJS=mount_aix.o - AC_DEFINE([_ALL_SOURCE], [], [Define _ALL_SOURCE on AIX]) -else - AC_MSG_RESULT(no) -fi -AC_SUBST(EXTRA_OBJS) - dnl checks for libraries dnl readline and history for plpftp @@ -113,50 +101,42 @@ fi LIBHISTORY=${ac_cv_libhistory} AC_SUBST(LIBHISTORY) +# FUSE for plpfuse +AC_CHECK_HEADER(fuse.h,, + [AC_MSG_ERROR([ + Can't find fuse.h - add the search path to CPPFLAGS and + rerun configure, eg: + export CPPFLAGS=-I/usr/local/include ])]) +AC_CHECK_LIB(fuse,fuse_new, [FUSE_LIBS="-lfuse"], + [AC_MSG_ERROR([ + Can't find libfuse.a - add the search path to LDFLAGS + and rerun configure, eg: + export LDFLAGS=-L/usr/local/lib ])],) + +# check for a supported version of FUSE +AC_MSG_CHECKING([For supported FUSE API version]) +AC_RUN_IFELSE([ + AC_LANG_PROGRAM([[ + #define FUSE_USE_VERSION 26 + #include ]], +[[ + if (FUSE_MAJOR_VERSION == 2 && FUSE_MINOR_VERSION >= 6) + return 0; + else + return -1; +]])], + [AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no]) + AC_MSG_FAILURE([plpfuse requires FUSE 2.5 or newer.]) + ] +) + dnl these three are for solaris AC_CHECK_LIB(socket, socket) AC_CHECK_LIB(nsl, gethostbyname) ac_save_LDFLAGS=$LDFLAGS; LDFLAGS="-L/usr/ucblib -R/usr/ucblib $LDFLAGS" AC_CHECK_LIB(rpcsoc, svcudp_create,,LDFLAGS=$ac_save_LDFLAGS) -dnl checks for mount table - if desired -ac_enable_mnttab=yes -AC_ARG_ENABLE(mnttab, - [ --disable-mnttab disable mnttab writing [no]], - if test "$enableval" = "no" ; then - AC_MSG_RESULT([support for mnttab disabled]) - ac_enable_mnttab=no - fi -) -if test "x$ac_enable_mnttab" = "xyes" ; then - AC_MSG_CHECKING(for mount table) - MTAB=NO - for i in /etc/mnttab /etc/mtab; do - if test -r "$i" ; then - MTAB=$i - break 2 - fi - done - AC_MSG_RESULT($MTAB) - if test "$MTAB" = "NO" ; then - AC_DEFINE_UNQUOTED(DONT_UPDATE_MTAB,1, - [Define this this if you want to prevent plpnfsd from updating mtab]) - else - AC_DEFINE_UNQUOTED(MTAB_PATH,"$MTAB", - [Define this to your mtab's path]) - ac_cv_mtab_tmp="${MTAB}~" - case "$target_alias" in - *linux*) - ;; - *) - ac_cv_mtab_tmp="${MTAB}.plpnfsd" - ;; - esac - AC_DEFINE_UNQUOTED(MTAB_TMP,"${ac_cv_mtab_tmp}", - [Define this to your temporary mtab's path]) - fi -fi - dnl Check, if bot time.h and sys/time.h may be included AC_HEADER_TIME @@ -237,22 +217,6 @@ AC_ARG_WITH(basedir, AC_DEFINE_UNQUOTED(DBASEDIR,"$DBASEDIR", [Define this to your default directory on your Psion]) -AC_ARG_WITH(mountdir, - [ --with-mountdir=DIR override default mount point [/mnt/psion]], - [ DMOUNTPOINT="$withval" - AC_MSG_RESULT(Overriding mount point: $DMOUNTPOINT) ], - [ DMOUNTPOINT="/mnt/psion" - AC_MSG_RESULT(Using default mount point: $DMOUNTPOINT) - ] -) -AC_DEFINE_UNQUOTED(DMOUNTPOINT,"$DMOUNTPOINT", - [Define this to your default mountpoint for plpnfsd]) -AC_SUBST(DMOUNTPOINT) -test "x$prefix" = xNONE && prefix="$ac_default_prefix" -eval PKGDATA="${datadir}/${PACKAGE}" -AC_DEFINE_UNQUOTED(PKGDATA,"$PKGDATA",[This defines the dir for support files]) -AC_SUBST(PKGDATA) - AC_ARG_WITH(initdir, [ --with-initdir=DIR override default init dir [/etc/rc.d/init.d]], [ initdir="$withval" @@ -278,11 +242,8 @@ AH_BOTTOM([ # define PSIONHOSTNAME "localhost" #endif -/* misc tweaks */ -#ifdef _IBMR2 -# undef DONT_UPDATE_MTAB -# define DONT_UPDATE_MTAB /* The mount table is obtained from the kernel (!?) */ -#endif +/* Select version of FUSE API */ +#define FUSE_USE_VERSION 26 ]) @@ -293,7 +254,7 @@ AC_CONFIG_FILES( lib/Makefile ncpd/Makefile plpftp/Makefile - plpnfsd/Makefile + plpfuse/Makefile plpprint/Makefile plpprint/prolog.ps sisinstall/Makefile @@ -303,7 +264,7 @@ AC_CONFIG_FILES( etc/psion.SuSE etc/plptools.spec doc/ncpd.man - doc/plpnfsd.man + doc/plpfuse.man doc/plpftp.man doc/sisinstall.man doc/plpprintd.man diff --git a/doc/Makefile.am b/doc/Makefile.am index 82ae0cc..2936821 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,9 +1,9 @@ SUBDIRS = api -EXTRA_DIST = ncpd.man.in plpnfsd.man.in plpftp.man.in sisinstall.man.in \ +EXTRA_DIST = ncpd.man.in plpfuse.man.in plpftp.man.in sisinstall.man.in \ plpprintd.man.in -man_MANS = ncpd.8 plpnfsd.8 plpftp.1 sisinstall.1 plpprintd.8 +man_MANS = ncpd.8 plpfuse.8 plpftp.1 sisinstall.1 plpprintd.8 %.1: %.man MANDATE=`grep CHECKIN $< | $(AWK) '{print $$4}'` ; \ @@ -13,9 +13,5 @@ man_MANS = ncpd.8 plpnfsd.8 plpftp.1 sisinstall.1 plpprintd.8 MANDATE=`grep CHECKIN $< | $(AWK) '{print $$4}'` ; \ $(SED) -e "s%@MANDATE@%$$MANDATE%g" $< > $@ -# -# remove all intermediate files that can be recreated using -# Makefile.cvs -# maintainer-clean-local: - rm -f Makefile.in *.1 *.8 + rm -f *.1 *.8 diff --git a/doc/ncpd.man.in b/doc/ncpd.man.in index f540c03..8cbfca0 100644 --- a/doc/ncpd.man.in +++ b/doc/ncpd.man.in @@ -24,7 +24,7 @@ ncpd \- Daemon which handles the serial link to a Psion .SH DESCRIPTION ncpd is the daemon which handles the serial link to your Psion. It listens at port @DPORT@ for local connections and provides -basic PLP/NCP services for plpnfsd and plpftp and other front-ends. +basic PLP/NCP services for plpfuse and plpftp and other front-ends. It auto-connects to the psion, even after unplugging/switching off therefore it can run always in background (if you have a spare serial-device) @@ -98,7 +98,7 @@ is specified, ncpd cycles through baud-rates of 115200, 57600, 38400, 19200 and 9600 baud. Default setting is @DSNAME@. .SH SEE ALSO -ncpd(8), plpnfsd(8), plpprintd(8), plpftp(1) and sisinstall(1) +plpfuse(8), plpprintd(8), plpftp(1) and sisinstall(1) .SH AUTHOR Fritz Elfert diff --git a/doc/plpftp.man.in b/doc/plpftp.man.in index d22f775..5416338 100644 --- a/doc/plpftp.man.in +++ b/doc/plpftp.man.in @@ -45,7 +45,7 @@ plpftp enters non interactive mode and terminates after executing the command. .SH SEE ALSO -ncpd(8), plpnfsd(8), plpprintd(8), plpftp(1) and sisinstall(1) +ncpd(8), plpfuse(8), plpprintd(8) and sisinstall(1) .SH AUTHOR Fritz Elfert diff --git a/doc/plpprintd.man.in b/doc/plpprintd.man.in index 1ce4ddb..c483ddf 100644 --- a/doc/plpprintd.man.in +++ b/doc/plpprintd.man.in @@ -76,7 +76,7 @@ can not be found in this file, a builtin default Courier is used. Using patterns in diagrams gives ugly results. .SH SEE ALSO -ncpd(8), plpnfsd(8), plpprintd(8), plpftp(1) and sisinstall(1) +ncpd(8), plpfuse(8), plpftp(1) and sisinstall(1) .SH AUTHOR Fritz Elfert diff --git a/doc/sisinstall.man.in b/doc/sisinstall.man.in index 9576692..1ce3bef 100644 --- a/doc/sisinstall.man.in +++ b/doc/sisinstall.man.in @@ -51,7 +51,7 @@ Level 2 is rather verbose, and is mostly meant for debugging. Ignores dependency records in the sis file. .SH SEE ALSO -ncpd(8), plpnfsd(8), plpprintd(8), plpftp(1) and sisinstall(1) +ncpd(8), plpfuse(8), plpprintd(8) and plpftp(1) .SH AUTHOR Written by Daniel Brahneborg (basic@chello.se). diff --git a/etc/plptools.spec.in b/etc/plptools.spec.in index 555c5e3..03f204f 100644 --- a/etc/plptools.spec.in +++ b/etc/plptools.spec.in @@ -171,8 +171,8 @@ mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig cat>$RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/psion<$RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/psion< -# include -# include -# include -#endif - -#if defined(__NeXT__) -# include -# include -# include -# define strdup NXCopyStringBuffer -#endif diff --git a/include/fparam.h b/include/fparam.h deleted file mode 100644 index cb881c2..0000000 --- a/include/fparam.h +++ /dev/null @@ -1,21 +0,0 @@ -/* $Id$ - * - */ - -#ifndef _fparam_h_ -#define _fparam_h_ - -#if defined(sun) && defined(__STDC__) && !defined(__SVR4) -# include "sun_stdlib.h" -# define __P(a) a -#endif - -#ifndef __P -# if defined(__STDC__) -# define __P(a) a -# else -# define __P(a) () -# endif -#endif - -#endif diff --git a/include/linux-misc.h b/include/linux-misc.h deleted file mode 100644 index afe1895..0000000 --- a/include/linux-misc.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Linux nfs_mount_data version 3 (as expected by mp_mount.c). - * - * We extract it here to avoid some rather nasty fiddling necessary - * to compile with v3 and v4 (the latter as found in the NFS v3 stuff). - */ - -#ifndef LINUX_MISC_H -#define LINUX_MISC_H - -/* - * WARNING! Do not delete or change the order of these fields. If - * a new field is required then add it to the end. The version field - * tracks which fields are present. This will ensure some measure of - * mount-to-kernel version compatibility. Some of these aren't used yet - * but here they are anyway. - */ -#define NFS_MOUNT_VERSION 3 - -struct nfs_mount_data { - int version; /* 1 */ - int fd; /* 1 */ - struct nfs_fh root; /* 1 */ - int flags; /* 1 */ - int rsize; /* 1 */ - int wsize; /* 1 */ - int timeo; /* 1 */ - int retrans; /* 1 */ - int acregmin; /* 1 */ - int acregmax; /* 1 */ - int acdirmin; /* 1 */ - int acdirmax; /* 1 */ - struct sockaddr_in addr; /* 1 */ - char hostname[256]; /* 1 */ - int namlen; /* 2 */ - unsigned int bsize; /* 3 */ -}; - -/* bits in the flags field */ - -#define NFS_MOUNT_SOFT 0x0001 /* 1 */ -#define NFS_MOUNT_INTR 0x0002 /* 1 */ -#define NFS_MOUNT_SECURE 0x0004 /* 1 */ -#define NFS_MOUNT_POSIX 0x0008 /* 1 */ -#define NFS_MOUNT_NOCTO 0x0010 /* 1 */ -#define NFS_MOUNT_NOAC 0x0020 /* 1 */ -#define NFS_MOUNT_TCP 0x0040 /* 2 */ -#define NFS_MOUNT_VER3 0x0080 /* 3 */ -#define NFS_MOUNT_KERBEROS 0x0100 /* 3 */ -#define NFS_MOUNT_NONLM 0x0200 /* 3 */ - -#endif diff --git a/include/misc-aix3.h b/include/misc-aix3.h deleted file mode 100644 index 36ce41f..0000000 --- a/include/misc-aix3.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 1990 Jan-Simon Pendry - * Copyright (c) 1990 Imperial College of Science, Technology & Medicine - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Jan-Simon Pendry at Imperial College, London. - * - * 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. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. - * - * %W% (Berkeley) %G% - * - * $Id$ - * - */ - -#include -#include - -struct ufs_args { - char *fspec; /* Block device */ -}; - -struct nfs_args { - struct sockaddr_in addr; /* file server address */ - fhandle_t fh; /* File handle to be mounted */ - int flags; /* flags */ - int wsize; /* write size in bytes */ - int rsize; /* read size in bytes */ - int timeo; /* initial timeout in .1 secs */ - int retrans; /* times to retry send */ - char *hostname; /* server's hostname */ - int acregmin; /* attr cache file min secs */ - int acregmax; /* attr cache file max secs */ - int acdirmin; /* attr cache dir min secs */ - int acdirmax; /* attr cache dir max secs */ - char *netname; /* server's netname */ - int biods; /* number of BIODS */ -}; - -/* - * NFS mount option flags - */ -#define MNTOPT_RO "ro" /* read only */ -#define MNTOPT_RW "rw" /* read/write */ -#define MNTOPT_SOFT "soft" /* soft mount */ -#define MNTOPT_HARD "hard" /* hard mount */ -#define MNTOPT_NOSUID "nosuid"/* no set uid allowed */ -#define MNTOPT_NOAUTO "noauto"/* hide entry from mount -a */ -#define MNTOPT_INTR "intr" /* allow interrupts on hard mount */ -#define MNTOPT_SECURE "secure"/* use secure RPC for NFS */ -#define MNTOPT_GRPID "grpid" /* SysV-compatible group-id on create */ -#define MNTOPT_NOSUB "nosub" /* disallow mounts beneath this one */ -#define MNTOPT_MULTI "multi" /* Do multi-component lookup */ -#define MNTOPT_NOAC "noac" /* don't cache attributes */ - -#define NFSMNT_SOFT 0x001 /* soft mount (hard is default) */ -#define NFSMNT_WSIZE 0x002 /* set write size */ -#define NFSMNT_RSIZE 0x004 /* set read size */ -#define NFSMNT_TIMEO 0x008 /* set initial timeout */ -#define NFSMNT_RETRANS 0x010 /* set number of request retrys */ -#define NFSMNT_HOSTNAME 0x020 /* set hostname for error printf */ -#define NFSMNT_INT 0x040 /* allow interrupts on hard mount */ -#define NFSMNT_NOAC 0x080 /* don't cache attributes */ -#define NFSMNT_ACREGMIN 0x0100 /* set min secs for file attr cache */ -#define NFSMNT_ACREGMAX 0x0200 /* set max secs for file attr cache */ -#define NFSMNT_ACDIRMIN 0x0400 /* set min secs for dir attr cache */ -#define NFSMNT_ACDIRMAX 0x0800 /* set max secs for dir attr cache */ -#define NFSMNT_SECURE 0x1000 /* secure mount */ -#define NFSMNT_BIODS 0x10000 /* Number of biods for the file system */ - -#define DEF_BIODS 6 diff --git a/include/mp.h b/include/mp.h deleted file mode 100644 index 362e223..0000000 --- a/include/mp.h +++ /dev/null @@ -1,166 +0,0 @@ -/* $Id$ - * - */ - -#ifndef _mp_h_ -#define _mp_h_ - -#include "fparam.h" -#include "nfs_prot.h" - -typedef struct p_inode { - int inode; - char *name; - struct p_inode *nextnam, *nextnum; -} p_inode; - -/** - * Description of a Psion-Device - */ -typedef struct p_device { - char *name; /* Volume-Name */ - char letter; /* Drive-Letter */ - long attrib; /* Device-Attribs */ - long total; /* Total capacity in bytes */ - long free; /* Free space in bytes */ - struct p_device *next; -} device; - -/* - * Description of a Psion-File/Dir - */ -typedef struct p_dentry -{ - char *name; - long time; - long attr; - long size; - long links; - struct p_dentry *next; -} dentry; - -/** - * data cache - */ -struct dcache { - struct dcache *next; - unsigned char *data; - unsigned int offset, len; - int towrite; -}; - -/** - * attribute cache - */ -struct cache { - struct cache *next; - time_t stamp; - unsigned int inode; - int actual_size; - struct dcache *dcache; - fattr attr; -}; - -extern int debug; -extern int exiting; -extern int query_cache; -extern int force_cache_clean; - -extern fattr root_fattr; -extern struct cache *attrcache; - -extern time_t cache_keep; -extern time_t devcache_keep; -extern time_t devcache_stamp; - -#ifdef __SVR4 -#define bzero(a,b) memset(a,0,b) -#define bcopy(a,b,c) memcpy(b,a,c) -#define bcmp(a,b,n) memcmp(a,b,n) -#define index strchr -#define rindex strrchr -#endif - -#if !defined(__STDC__) -extern char *index(), *rindex(), *strdup(); -#endif - - -#define PBUFSIZE 8192 - -#define BLOCKSIZE 512 -#define FID 7 /* File system id */ - -#if defined(sun) && defined(__SVR4) -/* - * at least /opt/SUNWspro/bin/cc on Solaris 2.4 likes these: - */ -# define SIGARG (int arg) -#else -# define SIGARG () -#endif - -/* mp_main.c */ -#if defined(hpux) || defined(__SVR4) && !defined(sun) - /* HPUX 10.20 declares int usleep( useconds_t useconds); */ -# ifndef HPUX10 - extern void usleep __P((int usec)); -# endif -#endif -extern int set_owner(char *user, int logstdio); -extern void cache_flush(void); - -/* mp_mount.c */ -void mount_and_run __P((char *dir, void (*proc)(), nfs_fh *root_fh)); - -/* mp_inode.c */ -extern p_inode *get_num __P((int)); -extern p_inode *get_nam __P((char *)); -extern p_inode *re_nam __P((char *, char *)); -extern void inode2fh __P((int, char *)); - -extern char *dirname __P((char *)); -extern char *filname __P((char *)); -extern char *build_path __P((char *, char *)); - -extern int fh2inode __P((char *)); -extern int getpinode __P((p_inode *inode)); -extern char *iso2cp __P((char *)); -extern char *cp2iso __P((char *)); - -extern struct cache *add_cache __P((struct cache **, unsigned int, fattr *)); -extern void rem_cache __P((struct cache **, unsigned int)); -extern void clean_cache __P((struct cache **)); -extern struct cache *search_cache __P((struct cache *, unsigned int)); - -extern struct dcache *add_dcache __P((struct cache *, unsigned int, unsigned int, unsigned char *)); -extern void clean_dcache __P((struct cache *)); -extern struct dcache *search_dcache __P((struct cache *, unsigned int, unsigned int)); - -/* mp_pfs_ops.c */ -extern void *nfsproc_null_2 __P((void)); -extern void *nfsproc_root_2 __P((void)); -extern void *nfsproc_writecache_2 __P((void)); -extern nfsstat *nfsproc_link_2 __P((struct linkargs *la)); -extern nfsstat *nfsproc_rmdir_2 __P((struct diropargs *da)); -extern nfsstat *nfsproc_remove_2 __P((struct diropargs *da)); -extern nfsstat *nfsproc_rename_2 __P((struct renameargs *ra)); -extern nfsstat *nfsproc_symlink_2 __P((struct symlinkargs *sa)); -extern struct readres *nfsproc_read_2 __P((struct readargs *ra)); -extern struct attrstat *nfsproc_write_2 __P((struct writeargs *wa)); -extern struct diropres *nfsproc_mkdir_2 __P((struct createargs *ca)); -extern struct diropres *nfsproc_create_2 __P((struct createargs *ca)); -extern struct diropres *nfsproc_lookup_2 __P((struct diropargs *da)); -extern struct attrstat *nfsproc_getattr_2 __P((struct nfs_fh *fh)); -extern struct attrstat *nfsproc_setattr_2 __P((struct sattrargs *sa)); -extern struct statfsres *nfsproc_statfs_2 __P((struct nfs_fh *fh)); -extern struct readdirres *nfsproc_readdir_2 __P((struct readdirargs *ra)); -extern struct readlinkres *nfsproc_readlink_2 __P((struct nfs_fh *fh)); - -extern int mp_main(int, char *, char *); - -extern int debuglog(char *fmt, ...); -extern int errorlog(char *fmt, ...); -extern int infolog(char *fmt, ...); - -#endif diff --git a/include/nfs_prot.h b/include/nfs_prot.h deleted file mode 100644 index acba688..0000000 --- a/include/nfs_prot.h +++ /dev/null @@ -1,397 +0,0 @@ -#ifndef _nfs_prot_h_ -#define _nfs_prot_h_ - -#include "fparam.h" - -#ifdef hpux -#include -#include -#endif -#ifdef linux -# include -#endif -#ifdef __sgi -# include -# include -# include -#endif - -/* - * Please do not edit this file. - * It was generated using rpcgen. - */ - -#include - -#define NFS_PORT 2049 -#define NFS_MAXDATA 8192 -#define NFS_MAXPATHLEN 1024 -#define NFS_MAXNAMLEN 255 -#define NFS_FHSIZE 32 -#define NFS_COOKIESIZE 4 -#ifndef NFS_FIFO_DEV -#define NFS_FIFO_DEV -1 -#endif -#define NFSMODE_FMT 0170000 -#define NFSMODE_DIR 0040000 -#define NFSMODE_CHR 0020000 -#define NFSMODE_BLK 0060000 -#define NFSMODE_REG 0100000 -#define NFSMODE_LNK 0120000 -#define NFSMODE_SOCK 0140000 -#define NFSMODE_FIFO 0010000 -#define NFSMODE_MASK 07770000 - -#if !defined(hpux) && !defined(__sgi) -enum nfsstat { - NFS_OK = 0, - NFSERR_PERM = 1, - NFSERR_NOENT = 2, - NFSERR_IO = 5, - NFSERR_NXIO = 6, - NFSERR_ACCES = 13, - NFSERR_EXIST = 17, - NFSERR_NODEV = 19, - NFSERR_NOTDIR = 20, - NFSERR_ISDIR = 21, - NFSERR_FBIG = 27, - NFSERR_NOSPC = 28, - NFSERR_ROFS = 30, - NFSERR_NAMETOOLONG = 63, - NFSERR_NOTEMPTY = 66, - NFSERR_DQUOT = 69, - NFSERR_STALE = 70, - NFSERR_WFLUSH = 99 -}; -#endif /* !hpux, sgi */ - -typedef enum nfsstat nfsstat; -bool_t xdr_nfsstat(); - -#if !defined(hpux) && !defined(__sgi) -enum ftype { - NFNON = 0, - NFREG = 1, - NFDIR = 2, - NFBLK = 3, - NFCHR = 4, - NFLNK = 5, - NFSOCK = 6, - NFBAD = 7, - NFFIFO = 8 -}; -typedef enum ftype ftype; -#endif /* !hpux, sgi */ - -#ifdef __sgi -typedef enum nfsftype ftype; -#endif - -#ifdef hpux -typedef enum nfsftype ftype; -#endif - -bool_t xdr_ftype(); - -struct nfs_fh { - char data[NFS_FHSIZE]; -}; -typedef struct nfs_fh nfs_fh; -bool_t xdr_nfs_fh(); - -struct nfstime { - u_int seconds; - u_int useconds; -}; -typedef struct nfstime nfstime; -bool_t xdr_nfstime(); - -struct fattr { - ftype type; - u_int mode; - u_int nlink; - u_int uid; - u_int gid; - u_int size; - u_int blocksize; - u_int rdev; - u_int blocks; - u_int fsid; - u_int fileid; - nfstime atime; - nfstime mtime; - nfstime ctime; -}; -typedef struct fattr fattr; -bool_t xdr_fattr(); - -struct sattr { - u_int mode; - u_int uid; - u_int gid; - u_int size; - nfstime atime; - nfstime mtime; -}; -typedef struct sattr sattr; -bool_t xdr_sattr(); - -typedef char *filename; -bool_t xdr_filename(); - -typedef char *nfspath; -bool_t xdr_nfspath(); - -struct attrstat { - nfsstat status; - union { - fattr attributes; - } attrstat_u; -}; -typedef struct attrstat attrstat; -bool_t xdr_attrstat(); - -struct sattrargs { - nfs_fh file; - sattr attributes; -}; -typedef struct sattrargs sattrargs; -bool_t xdr_sattrargs(); - -struct diropargs { - nfs_fh dir; - filename name; -}; -typedef struct diropargs diropargs; -bool_t xdr_diropargs(); - -struct diropokres { - nfs_fh file; - fattr attributes; -}; -typedef struct diropokres diropokres; -bool_t xdr_diropokres(); - -struct diropres { - nfsstat status; - union { - diropokres diropres; - } diropres_u; -}; -typedef struct diropres diropres; -bool_t xdr_diropres(); - -struct readlinkres { - nfsstat status; - union { - nfspath data; - } readlinkres_u; -}; -typedef struct readlinkres readlinkres; -bool_t xdr_readlinkres(); - -struct readargs { - nfs_fh file; - u_int offset; - u_int count; - u_int totalcount; -}; -typedef struct readargs readargs; -bool_t xdr_readargs(); - -struct readokres { - fattr attributes; - struct { - u_int data_len; - char *data_val; - } data; -}; -typedef struct readokres readokres; -bool_t xdr_readokres(); - -struct readres { - nfsstat status; - union { - readokres reply; - } readres_u; -}; -typedef struct readres readres; -bool_t xdr_readres(); - -struct writeargs { - nfs_fh file; - u_int beginoffset; - u_int offset; - u_int totalcount; - struct { - u_int data_len; - char *data_val; - } data; -}; -typedef struct writeargs writeargs; -bool_t xdr_writeargs(); - -struct createargs { - diropargs where; - sattr attributes; -}; -typedef struct createargs createargs; -bool_t xdr_createargs(); - -struct renameargs { - diropargs from; - diropargs to; -}; -typedef struct renameargs renameargs; -bool_t xdr_renameargs(); - -struct linkargs { - nfs_fh from; - diropargs to; -}; -typedef struct linkargs linkargs; -bool_t xdr_linkargs(); - -struct symlinkargs { - diropargs from; - nfspath to; - sattr attributes; -}; -typedef struct symlinkargs symlinkargs; -bool_t xdr_symlinkargs(); - -typedef char nfscookie[NFS_COOKIESIZE]; -bool_t xdr_nfscookie(); - -struct readdirargs { - nfs_fh dir; - nfscookie cookie; - u_int count; -}; -typedef struct readdirargs readdirargs; -bool_t xdr_readdirargs(); - -struct entry { - u_int fileid; - filename name; - nfscookie cookie; - struct entry *nextentry; -}; -typedef struct entry entry; -bool_t xdr_entry(); - -struct dirlist { - entry *entries; - bool_t eof; -}; -typedef struct dirlist dirlist; -bool_t xdr_dirlist(); - -struct readdirres { - nfsstat status; - union { - dirlist reply; - } readdirres_u; -}; -typedef struct readdirres readdirres; -bool_t xdr_readdirres(); - -struct statfsokres { - u_int tsize; - u_int bsize; - u_int blocks; - u_int bfree; - u_int bavail; -}; -typedef struct statfsokres statfsokres; -bool_t xdr_statfsokres(); - -struct statfsres { - nfsstat status; - union { - statfsokres reply; - } statfsres_u; -}; -typedef struct statfsres statfsres; -bool_t xdr_statfsres(); - -#ifndef NFS_PROGRAM -#define NFS_PROGRAM ((u_long)100003) -#endif -#ifndef NFS_VERSION -#define NFS_VERSION ((u_long)2) -#endif -#ifndef NFSPROC_NULL -#define NFSPROC_NULL ((u_long)0) -#endif -extern void *nfsproc_null_2 __P((void)); -#ifndef NFSPROC_GETATTR -#define NFSPROC_GETATTR ((u_long)1) -#endif -extern attrstat *nfsproc_getattr_2 __P((struct nfs_fh *fh)); -#ifndef NFSPROC_SETATTR -#define NFSPROC_SETATTR ((u_long)2) -#endif -extern attrstat *nfsproc_setattr_2 __P((struct sattrargs *sa)); -#ifndef NFSPROC_ROOT -#define NFSPROC_ROOT ((u_long)3) -#endif -extern void *nfsproc_root_2 __P((void)); -#ifndef NFSPROC_LOOKUP -#define NFSPROC_LOOKUP ((u_long)4) -#endif -extern diropres *nfsproc_lookup_2 __P((struct diropargs *da)); -#ifndef NFSPROC_READLINK -#define NFSPROC_READLINK ((u_long)5) -#endif -extern readlinkres *nfsproc_readlink_2 __P((struct nfs_fh *fh)); -#ifndef NFSPROC_READ -#define NFSPROC_READ ((u_long)6) -#endif -extern readres *nfsproc_read_2 __P((struct readargs *ra)); -#ifndef NFSPROC_WRITECACHE -#define NFSPROC_WRITECACHE ((u_long)7) -#endif -extern void *nfsproc_writecache_2 __P((void)); -#ifndef NFSPROC_WRITE -#define NFSPROC_WRITE ((u_long)8) -#endif -extern attrstat *nfsproc_write_2 __P((struct writeargs *wa)); -#ifndef NFSPROC_CREATE -#define NFSPROC_CREATE ((u_long)9) -#endif -extern diropres *nfsproc_create_2 __P((struct createargs *ca)); -#ifndef NFSPROC_REMOVE -#define NFSPROC_REMOVE ((u_long)10) -#endif -extern nfsstat *nfsproc_remove_2 __P((struct diropargs *da)); -#ifndef NFSPROC_RENAME -#define NFSPROC_RENAME ((u_long)11) -#endif -extern nfsstat *nfsproc_rename_2 __P((struct renameargs *ra)); -#ifndef NFSPROC_LINK -#define NFSPROC_LINK ((u_long)12) -#endif -extern nfsstat *nfsproc_link_2 __P((struct linkargs *la)); -#ifndef NFSPROC_SYMLINK -#define NFSPROC_SYMLINK ((u_long)13) -#endif -extern nfsstat *nfsproc_symlink_2 __P((struct symlinkargs *sa)); -#ifndef NFSPROC_MKDIR -#define NFSPROC_MKDIR ((u_long)14) -#endif -extern diropres *nfsproc_mkdir_2 __P((struct createargs *ca)); -#ifndef NFSPROC_RMDIR -#define NFSPROC_RMDIR ((u_long)15) -#endif -extern nfsstat *nfsproc_rmdir_2 __P((struct diropargs *da)); -#ifndef NFSPROC_READDIR -#define NFSPROC_READDIR ((u_long)16) -#endif -extern readdirres *nfsproc_readdir_2 __P((struct readdirargs *ra)); -#ifndef NFSPROC_STATFS -#define NFSPROC_STATFS ((u_long)17) -#endif -extern statfsres *nfsproc_statfs_2 __P((struct nfs_fh *fh)); - -#endif diff --git a/include/os-aix3.h b/include/os-aix3.h deleted file mode 100644 index f95e083..0000000 --- a/include/os-aix3.h +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (c) 1990 Jan-Simon Pendry - * Copyright (c) 1990 Imperial College of Science, Technology & Medicine - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Jan-Simon Pendry at Imperial College, London. - * - * 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. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. - * - * %W% (Berkeley) %G% - * - * $Id$ - * - * AIX 3.1 definitions for Amd (automounter) - */ - -/* - * Does the compiler grok void * - */ -#define VOIDP - -/* - * Which version of the Sun RPC library we are using - * This is the implementation release number, not - * the protocol revision number. - */ -#define RPC_4 - -/* - * Which version of the NFS interface are we using. - * This is the implementation release number, not - * the protocol revision number. - */ -#define NFS_AIX3 - -/* - * Does this OS have NDBM support? - */ -#define OS_HAS_NDBM - -/* - * The mount table is obtained from the kernel - */ -#undef UPDATE_MTAB - -/* - * Pick up BSD bits from include files - * Try for 4.4 compatibility if available (AIX 3.2 and later) - */ -#define _BSD 44 - -/* - * No mntent info on AIX 3 - */ -#undef MNTENT_HDR -#define MNTENT_HDR - -/* - * Name of filesystem types - */ -#define MOUNT_TYPE_NFS MNT_NFS -#define MOUNT_TYPE_UFS MNT_JFS -#undef MTAB_TYPE_UFS -#define MTAB_TYPE_UFS "jfs" - -/* - * How to unmount filesystems - */ -#undef MOUNT_TRAP -#define MOUNT_TRAP(type, mnt, flag, mnt_data) \ - aix3_mount(mnt->mnt_fsname, mnt->mnt_dir, flag, type, mnt_data, mnt->mnt_opts) -#undef UNMOUNT_TRAP -#define UNMOUNT_TRAP(mnt) uvmount(mnt->mnt_passno, 0) - - -/* - * Byte ordering - */ -#ifndef BYTE_ORDER -#include -#endif /* BYTE_ORDER */ - -#undef ARCH_ENDIAN -#if BYTE_ORDER == LITTLE_ENDIAN -#define ARCH_ENDIAN "little" -#else -#if BYTE_ORDER == BIG_ENDIAN -#define ARCH_ENDIAN "big" -#else -XXX - Probably no hope of running Amd on this machine! -#endif /* BIG */ -#endif /* LITTLE */ - -/* - * Miscellaneous AIX 3 bits - */ -#define NEED_MNTOPT_PARSER -#define SHORT_MOUNT_NAME - -#define MNTMAXSTR 128 - -#define MNTTYPE_UFS "jfs" /* Un*x file system */ -#define MNTTYPE_NFS "nfs" /* network file system */ -#define MNTTYPE_IGNORE "ignore" /* No type specified, ignore this entry */ - -struct mntent { - char *mnt_fsname; /* name of mounted file system */ - char *mnt_dir; /* file system path prefix */ - char *mnt_type; /* MNTTYPE_* */ - char *mnt_opts; /* MNTOPT* */ - int mnt_freq; /* dump frequency, in days */ - int mnt_passno; /* pass number on parallel fsck */ -}; - -#define NFS_HDR "misc-aix3.h" -#define UFS_HDR "misc-aix3.h" -#undef NFS_FH_DREF -#define NFS_FH_DREF(dst, src) { (dst) = *(src); } -#undef NFS_SA_DREF -#define NFS_SA_DREF(dst, src) { (dst).addr = *(src); } -#define M_RDONLY MNT_READONLY - -/* - * How to get a mount list - */ -#undef READ_MTAB_FROM_FILE -#define READ_MTAB_AIX3_STYLE - -/* - * The data for the mount syscall needs the path in addition to the - * host name since that is the only source of information about the - * mounted filesystem. -#define NFS_ARGS_NEEDS_PATH - */ - -#define NFS_LOMAP 34 -#define NFS_HIMAP 99 -#define NFS_ERROR_MAPPING \ -static nfs_errormap[] = { 0,75,77,99,99,99, \ - 99,99,99,99,99,78,99,99,99,79, \ - 99,99,70,99,35,36,37,38,39,40, \ - 41,42,43,44,45,46,47,48,49,50, \ - 51,52,53,54,55,56,57,58,60,61, \ - 64,65,99,67,68,62,63,66,69,68, \ - 99,99,99,71,99,99,99,99,99,99 \ - }; - -#define MOUNT_HELPER_SOURCE "mount_aix.c" - -/* - * Need this too - */ -#include -#include diff --git a/include/sun_stdlib.h b/include/sun_stdlib.h deleted file mode 100644 index ac6757a..0000000 --- a/include/sun_stdlib.h +++ /dev/null @@ -1,268 +0,0 @@ -/* - * sun_stdlib.h 95/06/07 - * - * Copyright 1994, BBW - * - */ -/* - * Copyright 1992-1994 Rudolf Koenig. - * sun_stdlib.h - * - * This header file is redundant/wrong for architectures that have sane - * header files. Grrr. - */ -#ifndef __sun_stdlib_h -#define __sun_stdlib_h -#if defined(FILE) - -#if !defined(STDIO_WRITE_NOW) - -extern int fputs(char *, FILE *); -extern int fseek(FILE *, int, int); -extern int fclose(FILE *); -extern int fread(char *, int, int, FILE *); -extern int fwrite(char *, int, int, FILE *); -extern int fflush(FILE *); -extern int fprintf(FILE *, const char *, ... ); -extern void rewind(FILE *); -extern void setvbuf(FILE *stream, char *buf, int type, int size); -extern void setbuffer(FILE *stream, char *buf, int size); - -extern int _filbuf( FILE * ); -extern int _flsbuf(unsigned char, FILE*); -#else -extern int _fill_buffer_( FILE * ); -extern int _flush_buffer_(int, FILE*); -#endif - -#endif - -extern int puts(char *); - -#if !defined(STDIO_WRITE_NOW) -extern int printf( const char *, ... ); -#endif - - -extern int getpid(void); -extern int getppid(void); -extern int pipe(int *); - -#if 1 -extern char *sprintf( char *, const char *, ... ); -extern char *vsprintf( char *, const char *, ... ); -#endif -extern int vfork(void); -extern int fork(void); -extern int close(int); -extern int dup(int); - -#ifndef __sys_unistd_h /* GNUCC has another imagination about this */ -extern int execl(char *, ... ); -extern int execv(char *, char *[]); -extern int execle(char *, ... ); -extern int execlp(char *, ... ); -extern int execvp(char *, char *[]); -extern int setuid(int); -#endif - -extern int seteuid(int); - -extern int getpgrp(int); -extern int setpgrp(int, int); - -extern int gethostname (char *, int); -extern int sethostname (char *, int); - -#ifdef _sys_socket_h -extern int getpeername(int, struct sockaddr *, int *); -extern int send(int, char *, int, int); -extern int sendto(int, char *, int, int, struct sockaddr *, int); -extern int recv(int, char *, int, int); -extern int recvfrom(int, char *, int, int, struct sockaddr *, int *); -#endif - -#ifdef _sys_vfs_h -extern int statfs(const char *, struct statfs *); -#endif - -#ifdef __sys_types_h /* def of caddr_t */ -extern time_t time(time_t *); -extern int ioctl(int, int, caddr_t); -extern int truncate(char *, off_t); -extern int ftruncate(int, off_t); -caddr_t mmap(caddr_t, size_t, int, int, int, off_t); -int munmap(caddr_t, int); -#endif -extern void perror(char *); - -extern int openlog(char *, int, int); - -extern int syslog(int, char *, ... ); -extern int closelog(void); -extern int setlogmask(int); - -extern unsigned int alarm(unsigned int); - -extern char *crypt(char *, char *); -extern char *_crypt(char *, char *); -extern int setkey(char *); -extern int encrypt(char *, int); - -extern char *getenv(char *name); -extern int putenv(char *); -extern void bcopy(char *, char *, int); -extern void bzero(char *, int); -extern int bcmp(char *, char *, int); -extern int tolower(int); -extern int toupper(int); - -#if !defined(__memory_h__) -extern void memset(char *, int, int); -#if !defined(__GNUC__) -extern char *memcpy(char *, char *, int); -extern int memcmp(char *, char *, int); -#endif -#endif - -extern int ffs(int); - -extern int sigblock(int); -extern int sigsetmask(int); -extern int sigpause(int); - -extern int unmount(char *name); -extern int umount(char *name); -int mount(char *type, char *dir, int flags, char *data); - - -#ifdef __sys_stat_h -extern int fchmod(int fd, mode_t mode); -#endif - -#ifdef _mntent_h -extern FILE *setmntent(char *filep, char *type); -extern struct mntent *getmntent(FILE *filep); -extern int addmntent(FILE *filep, struct mntent *mnt); -extern char *hasmntopt(struct mntent *mnt, char *opt); -extern int endmntent(FILE *filep); -#endif - -#ifdef __pwd_h -extern struct passwd *getpwent(void); -extern void endpwent(void); -#endif - - -extern int usleep(unsigned); -#if 0 -extern int lseek(int, int, int); -#endif - -#ifndef __sys_unistd_h /* GNUCC has another imagination about this */ -extern int read(int, char *, int); -extern int write(int, char *, int); -extern int sleep(unsigned int); -extern int getuid(void); -extern int geteuid(void); -#endif -extern int fsync(int); - -extern int rename(const char *, const char *); -extern int unlink(const char *); -#if defined(__sys_dirent_h) -extern int scandir(char *, struct dirent ***, int (*)(), int (*)()); -#else -#if defined(_sys_dir_h) -extern int scandir(char *, struct direct ***, int (*)(), int (*)()); -#endif -#endif - -#ifndef __stdlib_h -extern int atoi(char *); -extern int qsort(char *, int, int, int (*)()); -#endif - -extern char *rindex(const char *, const char); -extern char *index(const char *, const char); - -#ifndef __string_h /* GNUCC string.h */ -extern int strcmp(const char *, const char *); -extern int strncmp(const char *, const char *, int); -extern char *strcat(char *, const char *); -extern char *strdup(const char *); - -extern int strcpy(char *, const char *); -extern int strncpy(char *, const char *, int); - -extern int strtok(char *, char *); -#endif - -extern int strtol(char *, char **, int); - -extern int system(char *); -#ifdef RLIMIT_NOFILE -extern int getrlimit(int, struct rlimit *); -extern int setrlimit(int, struct rlimit *); -#endif - -extern int chdir(const char *); -#if defined(_sys_time_h) && defined(__sys_types_h) -extern int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); -extern int gettimeofday(struct timeval *tp, struct timezone *tzp); -extern int getitimer(int, struct itimerval *); -extern int setitimer(int, struct itimerval *, struct itimerval *); -#endif -extern char *getpass(char *); -#if !defined(__malloc_h) && !defined(__stdlib_h) /* GNU malloc defs */ -extern void *realloc(void *, unsigned); -extern void *calloc(unsigned, unsigned); -extern void *malloc(unsigned); -extern void free(const char *); -#endif - -#ifdef SOCK_STREAM -extern int socket(int, int, int); -extern int connect(int, struct sockaddr *, int); -extern int bind(int, struct sockaddr *, int); -extern int getsockname(int, struct sockaddr *, int *); -extern int accept(int, struct sockaddr *, int *); -extern int listen(int, int); -extern int shutdown(int, int); -extern int inet_addr(char *); -extern int getsockopt(int, int, int, char *, int *); -extern int setsockopt(int, int, int, char *, int); - -#endif - -#ifdef _nettli_tiuser_h -extern int t_open(char *, int, struct t_info *); -extern void t_error(char *); -extern int t_bind(int, struct t_bind *, struct t_bind *); -extern int t_listen(int, struct t_call *); -extern int t_accept(int, int, struct t_call *); -extern int t_rcv(int, char *, unsigned int, int *); -extern int t_snd(int, char *, unsigned int, int); -extern int t_close(int); -extern int t_connect(int, struct t_call *, struct t_call *); -#endif -#ifdef _sys_poll_h -extern int poll(struct pollfd *, unsigned long, int); -#endif - -#ifdef _sys_resource_h -int wait3(int *, int, struct rusage *); -#else -int wait3(int *, int, int); -#endif - -#ifdef _sys_asynch_h -extern aio_result_t *aiowait(struct timeval *); -extern int aioread(int, char *, int, int, int, aio_result_t *); -extern int aiowrite(int, char *, int, int, int, aio_result_t *); -extern int aiocancel(aio_result_t *); -#endif - -extern int on_exit(void (*procp)(), void *arg); - -#endif diff --git a/lib/Makefile.am b/lib/Makefile.am index ec6989b..af857cd 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -19,6 +19,3 @@ pkginclude_HEADERS = bufferarray.h bufferstore.h iowatch.h ppsocket.h \ rpcsfactory.h psitime.h Enum.h plpdirent.h wprt.h plpintl.h rclip.h \ siscomponentrecord.h sisfile.h sisfileheader.h sisfilerecord.h \ sislangrecord.h sisreqrecord.h sistypes.h psibitmap.h psiprocess.h - -maintainer-clean-local: - rm -f Makefile.in diff --git a/plpftp/Makefile.am b/plpftp/Makefile.am index 2301f56..36f5705 100644 --- a/plpftp/Makefile.am +++ b/plpftp/Makefile.am @@ -6,6 +6,3 @@ bin_PROGRAMS = plpftp plpftp_LDADD = $(LIB_PLP) $(LIBREADLINE) $(LIBHISTORY) $(INTLLIBS) plpftp_SOURCES = ftp.cc main.cc EXTRA_DIST = ftp.h - -maintainer-clean-local: - rm -f Makefile.in diff --git a/plpfuse/.cvsignore b/plpfuse/.cvsignore new file mode 100644 index 0000000..6ccdb58 --- /dev/null +++ b/plpfuse/.cvsignore @@ -0,0 +1,5 @@ +Makefile.in +Makefile +.libs +.deps +plpfuse diff --git a/plpfuse/Makefile.am b/plpfuse/Makefile.am new file mode 100644 index 0000000..467baaf --- /dev/null +++ b/plpfuse/Makefile.am @@ -0,0 +1,9 @@ +# $Id$ +# +INCLUDES=-I$(top_srcdir)/lib + +sbin_PROGRAMS = plpfuse +plpfuse_LDADD = $(LIB_PLP) $(INTLLIBS) -lfuse +plpfuse_SOURCES = main.cc fuse.c + +EXTRA_DIST = rfsv_api.h diff --git a/plpfuse/fuse.c b/plpfuse/fuse.c new file mode 100644 index 0000000..92720e2 --- /dev/null +++ b/plpfuse/fuse.c @@ -0,0 +1,528 @@ +/* + FUSE: Filesystem in Userspace + Copyright (C) 2001-2007 Miklos Szeredi + Copyright (C) 2007 Reuben Thomas + + This program can be distributed under the terms of the GNU GPL. + See the file COPYING. +*/ + +// FIXME: Map errors sensibly from EPOC to UNIX + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "rfsv_api.h" + +#include "plpfuse.h" + +#define NO_PSION ENOMEDIUM + +int debug; + +int +debuglog(char *fmt, ...) +{ + va_list ap; + char *buf; + + //if (!debug) + // return 0; + va_start(ap, fmt); + vasprintf(&buf, fmt, ap); + syslog(LOG_DEBUG, "%s", buf); + free(buf); + va_end(ap); + return 0; +} + +static void +attr2pattr(long oattr, long nattr, long *psisattr, long *psidattr) +{ + /* + * Following flags have to be set in order to let backups + * work properly + */ + *psisattr = *psidattr = 0; + if ((oattr & 0400) != (nattr & 0400)) { + if (nattr & 0400) /* readable */ + *psisattr |= PSI_A_READ; + else + *psidattr |= PSI_A_READ; + } + if ((oattr & 0200) != (nattr & 0200)) { + if (nattr & 0200) /* Not writable -> readonly */ + *psidattr |= PSI_A_RDONLY; + else + *psisattr |= PSI_A_RDONLY; + } + if ((oattr & 0020) != (nattr & 0020)) { + if (nattr & 0020) /* group-write -> archive */ + *psisattr |= PSI_A_ARCHIVE; + else + *psidattr |= PSI_A_ARCHIVE; + } + if ((oattr & 0004) != (nattr & 0004)) { + if (nattr & 0004) /* Not world-read -> hidden */ + *psidattr |= PSI_A_HIDDEN; + else + *psisattr |= PSI_A_HIDDEN; + } + if ((oattr & 0002) != (nattr & 0002)) { + if (nattr & 0002) /* world-write -> system */ + *psisattr |= PSI_A_SYSTEM; + else + *psidattr |= PSI_A_SYSTEM; + } +} + +static void +pattr2attr(long psiattr, long size, long ftime, struct stat *st) +{ + struct fuse_context *ct = fuse_get_context(); + + memset(st, 0, sizeof(*st)); + + st->st_uid = ct->uid; + st->st_gid = ct->gid; + + if (psiattr & PSI_A_DIR) { + st->st_mode = 0700 | S_IFDIR; + st->st_blocks = 1; + st->st_size = BLOCKSIZE; + st->st_nlink = 2; /* Call dircount for more accurate count */ + } else { + st->st_blocks = (size + BLOCKSIZE - 1) / BLOCKSIZE; + st->st_size = size; + st->st_nlink = 1; + st->st_mode = S_IFREG; + + /* + * Following flags have to be set in order to let backups + * work properly + */ + if (psiattr & PSI_A_READ) + st->st_mode |= 0400; /* File readable (?) */ + if (!(psiattr & PSI_A_RDONLY)) + st->st_mode |= 0200; /* File writeable */ + /* st->st_mode |= 0100; File executable */ + if (!(psiattr & PSI_A_HIDDEN)) + st->st_mode |= 0004; /* Not Hidden <-> world read */ + if (psiattr & PSI_A_SYSTEM) + st->st_mode |= 0002; /* System <-> world write */ + if (psiattr & PSI_A_VOLUME) + st->st_mode |= 0001; /* Volume <-> world exec */ + if (psiattr & PSI_A_ARCHIVE) + st->st_mode |= 0020; /* Modified <-> group write */ + /* st->st_mode |= 0040; Byte <-> group read */ + /* st->st_mode |= 0010; Text <-> group exec */ + } + + st->st_mtime = st->st_ctime = st->st_atime = ftime; +} + +static device *devices; + +static int +query_devices() +{ + device *dp, *np; + int link_count = 2; /* set the root link count */ + + for (dp = devices; dp; dp = np) { + np = dp->next; + free(dp->name); + free(dp); + } + devices = NULL; + if (rfsv_drivelist(&link_count, &devices)) + return 1; + return 0; +} + +char * +dirname(const char *dir) +{ + static char *namebuf = NULL; + if (namebuf) + free(namebuf); + asprintf(&namebuf, "%s\\", dir); + return namebuf; +} + +const char * +filname(const char *dir) +{ + char *p; + if ((p = (char *) rindex(dir, '\\'))) + return p + 1; + else + return dir; +} + +static int +dircount(const char *path, long *count) +{ + dentry *e = NULL; + long ret = 0; + + *count = 0; + debuglog("dircount: %s", path); + debuglog("RFSV dir %s", path); + if ((ret = rfsv_dir(dirname(path), &e))) + return ret; + while (e) { + struct stat st; + dentry *o = e; + pattr2attr(e->attr, e->size, e->time, &st); + free(e->name); + e = e->next; + free(o); + if (st.st_nlink > 1) + (*count)++; + } + + debuglog("count %d", *count); + return ret; +} + +static int getlinks(const char *path, struct stat *st) +{ + long dcount; + + if (dircount(path, &dcount)) + return rfsv_isalive() ? -ENOENT : -NO_PSION; + st->st_nlink = dcount + 2; + return 0; +} + +static int plp_getattr(const char *path, struct stat *st) +{ + debuglog("plp_getattr `%s'", ++path); + + if (strcmp(path, "") == 0) { + pattr2attr(PSI_A_DIR, 0, 0, st); + if (!query_devices()) { + device *dp; + + for (dp = devices; dp; dp = dp->next) + st->st_nlink++; + debuglog("root has %d links", st->st_nlink); + } else + return rfsv_isalive() ? -ENOENT : -NO_PSION; + } else { + long pattr, psize, ptime; + + if (strlen(path) == 2 && path[1] == ':') { + debuglog("getattr: device"); + if (!query_devices()) { + device *dp; + + for (dp = devices; dp; dp = dp->next) { + debuglog("cmp '%c', '%c'", dp->letter, + path[0]); + if (dp->letter == path[0]) + break; + } + debuglog("device: %s", dp ? "exists" : "does not exist"); + pattr2attr(PSI_A_DIR, 0, 0, st); + return getlinks(path, st); + } else + return rfsv_isalive() ? -ENOENT : -NO_PSION; + } + + debuglog("getattr: fileordir"); + if (rfsv_getattr(path, &pattr, &psize, &ptime)) + return rfsv_isalive() ? -ENOENT : -NO_PSION; + else { + pattr2attr(pattr, psize, ptime, st); + debuglog(" attrs Psion: %x %d %d, UNIX modes: %o", pattr, psize, ptime, st->st_mode); + if (st->st_nlink > 1) + return getlinks(path, st); + } + } + + debuglog("getattr: return OK"); + return 0; +} + +static int plp_access(const char *path, int mask) +{ + debuglog("plp_access `%s'", ++path); + return 0; +} + +static int plp_readlink(const char *path, char *buf, size_t size) +{ + debuglog("plp_readlink `%s'", ++path); + return -EINVAL; +} + + +static int plp_readdir(const char *path, void *buf, fuse_fill_dir_t filler, + off_t offset, struct fuse_file_info *fi) +{ + device *dp; + int ret; + dentry *e = NULL; + + debuglog("plp_readdir `%s'", ++path); + + (void)offset; + (void)fi; + + if (strcmp(path, "") == 0) { + debuglog("readdir root"); + if (query_devices() == 0) { + for (dp = devices; dp; dp = dp->next) { + dentry *o; + struct stat st; + unsigned char name[3]; + + name[0] = dp->letter; + name[1] = ':'; + name[2] = '\0'; + pattr2attr(dp->attrib, 1, 0, &st); + if (filler(buf, name, &st, 0)) + break; + } + } + } else { + debuglog("RFSV dir `%s'", dirname(path)); + if (rfsv_dir(dirname(path), &e)) + return rfsv_isalive() ? -ENOENT : -NO_PSION; + + debuglog("scanning contents"); + while (e) { + dentry *o; + struct stat st; + const char *name = filname(e->name); + + pattr2attr(e->attr, e->size, e->time, &st); + debuglog(" %s %o %d %d", name, st.st_mode, st.st_size, st.st_mtime); + if (filler(buf, name, &st, 0)) + break; + free(e->name); + o = e; + e = e->next; + free(o); + } + } + + debuglog("readdir OK"); + return 0; +} + +static int plp_mknod(const char *path, mode_t mode, dev_t dev) +{ + u_int32_t phandle; + + debuglog("plp_mknod `%s' %o", ++path, mode); + + if (S_ISREG(mode) && dev == 0) { + if (rfsv_fcreate(0x200, path, &phandle)) + return rfsv_isalive() ? -ENAMETOOLONG : -NO_PSION; + rfsv_fclose(phandle); + } else + return -EINVAL; + + return 0; +} + +static int plp_mkdir(const char *path, mode_t mode) +{ + debuglog("plp_mkdir `%s' %o", ++path, mode); + + if (rfsv_mkdir(path)) + return rfsv_isalive() ? -ENAMETOOLONG : -NO_PSION; + + return 0; +} + +static int plp_unlink(const char *path) +{ + debuglog("plp_unlink `%s'", ++path); + + if (rfsv_remove(path)) + return rfsv_isalive() ? -EACCES : -NO_PSION; + + return 0; +} + +static int plp_rmdir(const char *path) +{ + debuglog("plp_rmdir `%s'", ++path); + + if (rfsv_rmdir(path)) + return rfsv_isalive() ? -EACCES : -NO_PSION; + + return 0; +} + +static int plp_symlink(const char *from, const char *to) +{ + debuglog("plp_symlink `%s' -> `'%s'", ++from, ++to); + return -EPERM; +} + +static int plp_rename(const char *from, const char *to) +{ + debuglog("plp_rename `%s' -> `%s'", ++from, ++to); + + rfsv_remove(to); + if (rfsv_rename(from, to)) + return rfsv_isalive() ? -EACCES : -NO_PSION; + + return 0; +} + +static int plp_link(const char *from, const char *to) +{ + debuglog("plp_link `%s' -> `%s'", ++from, ++to); + return -EPERM; +} + +static int plp_chmod(const char *path, mode_t mode) +{ + long psisattr, psidattr, pattr, psize, ptime; + struct stat st; + + debuglog("plp_chmod `%s'", ++path); + + if (rfsv_getattr(path, &pattr, &psize, &ptime)) + return rfsv_isalive() ? -ENOENT : -NO_PSION; + pattr2attr(pattr, psize, ptime, &st); + attr2pattr(st.st_mode, mode, &psisattr, &psidattr); + debuglog(" UNIX old, new: %o, %o; Psion set, clear: %x, %x", st.st_mode, mode, psisattr, psidattr); + if (rfsv_setattr(path, psisattr, psidattr)) + return rfsv_isalive() ? -EACCES : -NO_PSION; + + debuglog("chmod succeeded"); + return 0; +} + +static int plp_chown(const char *path, uid_t uid, gid_t gid) +{ + debuglog("plp_chown `%s'", ++path); + return -EPERM; +} + +static int plp_truncate(const char *path, off_t size) +{ + debuglog("plp_truncate `%s'", ++path); + + if (rfsv_setsize(path, 0)) + return rfsv_isalive() ? -EPERM : -NO_PSION; + + return 0; +} + +static int plp_utimens(const char *path, const struct timespec ts[2]) +{ + struct timeval tv[2]; + + debuglog("plp_utimens `%s'", ++path); + + if (rfsv_setmtime(path, ts[1].tv_sec)) + return rfsv_isalive() ? -EPERM : -NO_PSION; + + return 0; +} + +static int plp_open(const char *path, struct fuse_file_info *fi) +{ + debuglog("plp_open `%s'", ++path); + (void)fi; + return 0; +} + +static int plp_read(const char *path, char *buf, size_t size, off_t offset, + struct fuse_file_info *fi) +{ + long read; + + (void)fi; + debuglog("plp_read `%s' offset %lld size %ld", ++path, offset, size); + + if ((read = rfsv_read(buf, (long)offset, size, path)) < 0) + return rfsv_isalive() ? -ENOENT : -NO_PSION; + + debuglog("read %ld bytes", read); + return read; +} + +static int plp_write(const char *path, const char *buf, size_t size, + off_t offset, struct fuse_file_info *fi) +{ + long written; + + (void)fi; + debuglog("plp_write `%s' offset %lld size %ld", ++path, offset, size); + if ((written = rfsv_write(buf, offset, size, path)) < 0) + return rfsv_isalive() ? -ENOSPC : -NO_PSION; + + debuglog("wrote %ld bytes", written); + return written; +} + +static int plp_statfs(const char *path, struct statvfs *stbuf) +{ + device *dp; + + debuglog("plp_statfs"); + + stbuf->f_bsize = BLOCKSIZE; + stbuf->f_frsize = BLOCKSIZE; + if (query_devices() == 0) { + for (dp = devices; dp; dp = dp->next) { + stbuf->f_blocks += (dp->total + BLOCKSIZE - 1) / BLOCKSIZE; + stbuf->f_bfree += (dp->free + BLOCKSIZE - 1) / BLOCKSIZE; + } + } + stbuf->f_bavail = stbuf->f_bfree; + + /* Don't have numbers for these */ + stbuf->f_files = 0; + stbuf->f_ffree = stbuf->f_favail = 0; + + stbuf->f_fsid = FID; + stbuf->f_flag = 0; /* don't have mount flags */ + stbuf->f_namemax = 255; /* KDMaxFileNameLen% */ + + return 0; +} + +struct fuse_operations plp_oper = { + .getattr = plp_getattr, + .access = plp_access, + .readlink = plp_readlink, + .readdir = plp_readdir, + .mknod = plp_mknod, + .mkdir = plp_mkdir, + .symlink = plp_symlink, + .unlink = plp_unlink, + .rmdir = plp_rmdir, + .rename = plp_rename, + .link = plp_link, + .chmod = plp_chmod, + .chown = plp_chown, + .truncate = plp_truncate, + .utimens = plp_utimens, + .open = plp_open, + .read = plp_read, + .write = plp_write, + .statfs = plp_statfs, +}; diff --git a/plpfuse/main.cc b/plpfuse/main.cc new file mode 100644 index 0000000..a6743b4 --- /dev/null +++ b/plpfuse/main.cc @@ -0,0 +1,380 @@ +/*-*-c++-*- + * $Id$ + * + * This file is part of plptools. + * + * Copyright (C) 1999-2001 Fritz Elfert + * Copyright (C) 2007 Reuben Thomas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include "rfsv_api.h" + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include + +using namespace std; + +static rfsv *a; +static rfsvfactory *rf; + +static rpcs *r; +static rpcsfactory *rp; +static bufferStore owner; + +long rfsv_isalive() { + if (!a) { + if (!(a = rf->create(true))) + return 0; + } + return (a->getStatus() == rfsv::E_PSI_GEN_NONE); +} + +long rfsv_dir(const char *file, dentry **e) { + PlpDir entries; + dentry *tmp; + long ret; + + if (!a) + return -1; + ret = a->dir(file, entries); + + for (int i = 0; i < entries.size(); i++) { + PlpDirent pe = entries[i]; + tmp = *e; + *e = (dentry *)calloc(1, sizeof(dentry)); + if (!*e) + return -1; + (*e)->time = pe.getPsiTime().getTime(); + (*e)->size = pe.getSize(); + (*e)->attr = pe.getAttr(); + (*e)->name = strdup(pe.getName()); + (*e)->next = tmp; + } + return ret; +} + +long rfsv_dircount(const char *file, u_int32_t *count) { + if (!a) + return -1; + return a->dircount(file, *count); +} + +long rfsv_rmdir(const char *name) { + if (!a) + return -1; + return a->rmdir(name); +} + +long rfsv_mkdir(const char *file) { + if (!a) + return -1; + return a->mkdir(file); +} + +long rfsv_remove(const char *file) { + if (!a) + return -1; + return a->remove(file); +} + +long rfsv_fclose(long handle) { + if (!a) + return -1; + return a->fclose(handle); +} + +long rfsv_fcreate(long attr, const char *file, u_int32_t *handle) { + u_int32_t ph; + long ret; + + if (!a) + return -1; + ret = a->fcreatefile(attr, file, ph); + *handle = ph; + return ret; +} + +long rfsv_open(const char *name, long mode, u_int32_t *handle) { + long ret, retry; + + if (!a) + return -1; + if (mode == O_RDONLY) + mode = rfsv::PSI_O_RDONLY; + else + mode = rfsv::PSI_O_RDWR; + for (retry = 100; retry > 0 && (ret = a->fopen(a->opMode(mode), name, *handle)) != rfsv::E_PSI_GEN_NONE; retry--) + usleep(20000); + return ret; +} + +long rfsv_read(char *buf, long offset, long len, const char *name) { + u_int32_t ret = 0, r_offset, handle; + + if (!a) + return -1; + if ((ret = rfsv_open(name, O_RDONLY, &handle))) + return ret; + if (a->fseek(handle, offset, rfsv::PSI_SEEK_SET, r_offset) != rfsv::E_PSI_GEN_NONE || + offset != r_offset || + a->fread(handle, (unsigned char *)buf, len, ret) != rfsv::E_PSI_GEN_NONE) + ret = -1; + rfsv_fclose(handle); + return ret; +} + +long rfsv_write(const char *buf, long offset, long len, const char *name) { + u_int32_t ret = 0, r_offset, handle; + + if (!a) + return -1; + if ((ret = rfsv_open(name, O_RDWR, &handle))) + return ret; + if (a->fseek(handle, offset, rfsv::PSI_SEEK_SET, r_offset) != rfsv::E_PSI_GEN_NONE || + offset != r_offset || + a->fwrite(handle, (unsigned char *)buf, len, ret) != rfsv::E_PSI_GEN_NONE) + ret = -1; + rfsv_fclose(handle); + return ret; +} + +long rfsv_setmtime(const char *name, long time) { + if (!a) + return -1; + return a->fsetmtime(name, PsiTime(time)); +} + +long rfsv_setsize(const char *name, long size) { + u_int32_t ph; + long ret; + + if (!a) + return -1; + ret = a->fopen(a->opMode(rfsv::PSI_O_RDWR), name, ph); + if (!ret) { + ret = a->fsetsize(ph, size); + a->fclose(ph); + } + return ret; +} + +long rfsv_setattr(const char *name, long sattr, long dattr) { + if (!a) + return -1; + return a->fsetattr(name, sattr, dattr); +} + +long rfsv_getattr(const char *name, long *attr, long *size, long *time) { + long res; + PlpDirent e; + + if (!a) + return -1; + res = a->fgeteattr(name, e); + *attr = e.getAttr(); + *size = e.getSize(); + *time = e.getPsiTime().getTime(); + return res; +} + +long rfsv_statdev(char letter) { + PlpDrive drive; + + if (!a) + return -1; + return (a->devinfo(letter, drive) != rfsv::E_PSI_GEN_NONE); +} + +long rfsv_rename(const char *oldname, const char *newname) { + if (!a) + return -1; + return a->rename(oldname, newname); +} + +long rfsv_drivelist(int *cnt, device **dlist) { + *dlist = NULL; + u_int32_t devbits; + long ret; + int i; + + if (!a) + return -1; + ret = a->devlist(devbits); + if (ret == 0) + for (i = 0; i < 26; i++) { + PlpDrive drive; + + if ((devbits & 1) && + ((a->devinfo(i + 'A', drive) == rfsv::E_PSI_GEN_NONE))) { + + device *next = *dlist; + *dlist = (device *)malloc(sizeof(device)); + (*dlist)->next = next; + (*dlist)->name = strdup(drive.getName().c_str()); + (*dlist)->total = drive.getSize(); + (*dlist)->free = drive.getSpace(); + (*dlist)->letter = 'A' + i; + (*dlist)->attrib = drive.getMediaType(); + (*cnt)++; + } + devbits >>= 1; + } + return ret; +} + +static void +help() +{ + cerr << _( + "Usage: plpfuse [OPTION...] MOUNTPOINT\n" + "\n" + "Supported options:\n" + "\n" + " -u, --user=USER Specify USER who owns mounted dir\n" + " -d, --debug Increase debugging\n" + " -h, --help Display this text\n" + " -V, --version Print version and exit\n" + " -p, --port=[HOST:]PORT Connect to port PORT on host HOST\n" + " Default for HOST is 127.0.0.1\n" + " Default for PORT is " + ) << DPORT << "\n\n"; +} + +static void +usage() { + cerr << _("Try `plpfuse --help' for more information") << endl; +} + +static struct option opts[] = { + {"help", no_argument, 0, 'h'}, + {"debug", no_argument, 0, 'd'}, + {"version", no_argument, 0, 'V'}, + {"port", required_argument, 0, 'p'}, + {"user", required_argument, 0, 'u'}, + {NULL, 0, 0, 0 } +}; + +static void +parse_destination(const char *arg, const char **host, int *port) +{ + if (!arg) + return; + // We don't want to modify argv, therefore copy it first ... + char *argcpy = strdup(arg); + char *pp = strchr(argcpy, ':'); + + if (pp) { + // host.domain:400 + // 10.0.0.1:400 + *pp ++= '\0'; + *host = argcpy; + } else { + // 400 + // host.domain + // host + // 10.0.0.1 + if (strchr(argcpy, '.') || !isdigit(argcpy[0])) { + *host = argcpy; + pp = 0L; + } else + pp = argcpy; + } + if (pp) + *port = atoi(pp); +} + +int main(int argc, char**argv) { + ppsocket *skt; + ppsocket *skt2; + const char *host = "127.0.0.1"; + int sockNum = DPORT; + int status = 0; + int i, c; + + struct servent *se = getservbyname("psion", "tcp"); + endservent(); + if (se != 0L) + sockNum = ntohs(se->s_port); + +// while ((c = getopt_long(argc, argv, "hVp:d", opts, NULL)) != -1) { +// switch (c) { +// case 'V': +// cerr << _("plpfuse version ") << VERSION << endl; +// return 0; +// case 'h': +// help(); +// break; +// case 'd': +// debug++; +// break; +// case 'p': +// parse_destination(optarg, &host, &sockNum); +// break; +// } +// } + + skt = new ppsocket(); + if (!skt->connect(host, sockNum)) { + cerr << "plpfuse: could not connect to ncpd" << endl; + status = 1; + } + skt2 = new ppsocket(); + if (!skt2->connect(host, sockNum)) { + cerr << "plpfuse: could not connect to ncpd" << endl; + status = 1; + } + if (status == 0) { + rf = new rfsvfactory(skt); + rp = new rpcsfactory(skt2); + a = rf->create(true); + r = rp->create(true); + if (a != NULL && r != NULL) + debuglog("plpfuse: connected, status is %d", status); + else + debuglog("plpfuse: could not create rfsv or rpcs object, connect delayed"); +// for (i = 0; i < optind; i++) +// argv[i + 1] = argv[i + optind]; +// argc -= optind - 1; + status = fuse_main(argc, argv, &plp_oper, NULL); + delete a; + delete r; + } + exit(status); +} diff --git a/plpfuse/plpfuse.h b/plpfuse/plpfuse.h new file mode 100644 index 0000000..c36d717 --- /dev/null +++ b/plpfuse/plpfuse.h @@ -0,0 +1,52 @@ +/* $Id$ + * + */ + +#ifndef _plpfuse_h_ +#define _plpfuse_h_ + +#include + +typedef struct p_inode { + int inode; + char *name; + struct p_inode *nextnam, *nextnum; +} p_inode; + +/** + * Description of a Psion-Device + */ +typedef struct p_device { + char *name; /* Volume-Name */ + char letter; /* Drive-Letter */ + long attrib; /* Device-Attribs */ + long total; /* Total capacity in bytes */ + long free; /* Free space in bytes */ + struct p_device *next; +} device; + +/* + * Description of a Psion-File/Dir + */ +typedef struct p_dentry +{ + char *name; + long time; + long attr; + long size; + long links; + struct p_dentry *next; +} dentry; + +extern int debug; + +extern int debuglog(char *fmt, ...); +extern int errorlog(char *fmt, ...); +extern int infolog(char *fmt, ...); + +#define BLOCKSIZE 512 +#define FID 7 /* File system id */ + +#endif + +extern struct fuse_operations plp_oper; diff --git a/plpfuse/rfsv_api.h b/plpfuse/rfsv_api.h new file mode 100644 index 0000000..0fe4793 --- /dev/null +++ b/plpfuse/rfsv_api.h @@ -0,0 +1,76 @@ +/*-*-c++-*- + * $Id$ + * + * This file is part of plptools. + * + * Copyright (C) 1999-2001 Fritz Elfert + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#ifndef _rfsv_api_h_ +#define _rfsv_api_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "plpfuse.h" + +extern long rfsv_dir(const char *name, dentry **e); +extern long rfsv_mkdir(const char *name); +extern long rfsv_rmdir(const char *name); +extern long rfsv_remove(const char *name); +extern long rfsv_rename(const char *oldname, const char *newname); +extern long rfsv_open(const char *name, long mode, u_int32_t *handle); +extern long rfsv_fclose(long handle); +extern long rfsv_fcreate(long attr, const char *name, u_int32_t *handle); +extern long rfsv_read(char *buf, long offset, long len, const char *name); +extern long rfsv_write(const char *buf, long offset, long len, const char *name); +extern long rfsv_getattr(const char *name, long *attr, long *size, long *time); +extern long rfsv_setattr(const char *name, long sattr, long dattr); +extern long rfsv_setsize(const char *name, long size); +extern long rfsv_setmtime(const char *name, long time); +extern long rfsv_drivelist(int *cnt, device **devlist); +extern long rfsv_dircount(const char *name, long *count); +extern long rfsv_statdev(char letter); +extern long rfsv_isalive(); + +/* File attributes, C-style */ +#define PSI_A_RDONLY 0x0001 +#define PSI_A_HIDDEN 0x0002 +#define PSI_A_SYSTEM 0x0004 +#define PSI_A_DIR 0x0008 +#define PSI_A_ARCHIVE 0x0010 +#define PSI_A_VOLUME 0x0020 +#define PSI_A_NORMAL 0x0040 +#define PSI_A_TEMP 0x0080 +#define PSI_A_COMPRESSED 0x0100 +#define PSI_A_READ 0x0200 +#define PSI_A_EXEC 0x0400 +#define PSI_A_STREAM 0x0800 +#define PSI_A_TEXT 0x1000 + +#ifdef __cplusplus +} +#endif + +#endif + +/* + * Local variables: + * c-basic-offset: 4 + * End: + */ diff --git a/plpnfsd/Makefile.am b/plpnfsd/Makefile.am deleted file mode 100644 index 5d74075..0000000 --- a/plpnfsd/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ -# $Id$ -# -INCLUDES=-I$(top_srcdir)/lib - -sbin_PROGRAMS = plpnfsd -plpnfsd_LDADD = $(LIB_PLP) $(INTLLIBS) -plpnfsd_SOURCES = mp_main.c mp_mount.c nfs_prot_svc.c nfs_prot_xdr.c \ - mp_pfs_ops.c mp_inode.c main.cc - -EXTRA_plpnfsd_SOURCES = mount_aix.c -EXTRA_DIST = rfsv_api.h builtins.h - -install-exec-hook: - chmod u+s $(DESTDIR)$(sbindir)/plpnfsd - -maintainer-clean-local: - rm -f Makefile.in diff --git a/plpnfsd/builtins.h b/plpnfsd/builtins.h deleted file mode 100644 index 1eda763..0000000 --- a/plpnfsd/builtins.h +++ /dev/null @@ -1,77 +0,0 @@ -/*-*-c++-*- - * $Id$ - * - * This file is part of plptools. - * - * Copyright (C) 1999-2001 Fritz Elfert - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -#ifndef _BUILTINS_H_ -#define _BUILTINS_H_ - -struct builtin_node_t; - -typedef struct builtin_child_t { - struct builtin_child_t *next; - struct builtin_node_t *node; -} builtin_child; - -/** - * Support for procfs-like builtin virtual files/directories - */ -typedef struct builtin_node_t { - struct builtin_node_t *next; - struct builtin_node_t *parent; - builtin_child *childs; - char *private_data; - char *name; - unsigned long flags; - long attr; - long size; - long (*getsize)(struct builtin_node_t *node); - long (*read)(struct builtin_node_t *node, char *buf, unsigned long offset, long len); - long (*write)(struct builtin_node_t *node, char *buf, unsigned long offset, long len); - long (*sattr)(struct builtin_node_t *node, unsigned long sa, unsigned long da); - long (*getlinks)(struct builtin_node_t *node); - long (*getdents)(struct builtin_node_t *node, dentry **entries); -} builtin_node; - -#define BF_EXISTS_ALWAYS 1 -#define BF_NOCACHE 2 -#define BF_ISPROCESS 4 - -/** - * Register a builtin handler for an entry in /proc - */ -builtin_node *register_builtin(char *parent, builtin_node *node); - -/** - * Deregister a previously registered handler. - */ -extern int unregister_builtin(builtin_node *); - -extern char *builtin_path(builtin_node *node); -extern long generic_getlinks(builtin_node *node); -extern long generic_getdents(builtin_node *node, dentry **entries); - -#endif /* _BUILTINS_H_ */ - -/* - * Local variables: - * c-basic-offset: 4 - * End: - */ diff --git a/plpnfsd/main.cc b/plpnfsd/main.cc deleted file mode 100644 index 263d55e..0000000 --- a/plpnfsd/main.cc +++ /dev/null @@ -1,622 +0,0 @@ -/*-*-c++-*- - * $Id$ - * - * This file is part of plptools. - * - * Copyright (C) 1999-2001 Fritz Elfert - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include - -#include "rfsv_api.h" - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif -#include - -using namespace std; - -static rfsv *a; -static rfsvfactory *rf; -static char *a_filename = NULL; -static u_int32_t a_handle; -static u_int32_t a_offset; -static u_int32_t a_openmode; - -static rpcs *r; -static rpcsfactory *rp; -static bufferStore owner; - -long rpcs_isalive() { - long s; - - if (!r) { - if (!(r = rp->create(true))) - return 0; - } - s = r->getStatus(); - if (s == rfsv::E_PSI_FILE_DISC) - r->reconnect(); - return (r->getStatus() == rfsv::E_PSI_GEN_NONE); -} - -long rpcs_ownerRead(builtin_node *, char *buf, unsigned long offset, long len) { - - if (offset >= (owner.getLen() - 1)) - return 0; - const char *s = owner.getString(offset); - int sl = strlen(s); - if (sl > len) - sl = len; - strncpy(buf, s, sl); - return sl; -} - -long rpcs_ownerSize(builtin_node *) { - Enum res; - bufferArray a; - - if (!rpcs_isalive()) - return 0; - res = r->getOwnerInfo(a); - owner.init(); - if (res == rfsv::E_PSI_GEN_NONE) { - while (!a.empty()) { - owner.addString(a.pop().getString()); - owner.addByte('\n'); - } - } - owner.addByte(0); - return owner.getLen() - 1; -} - -static long psread(builtin_node *node, char *buf, unsigned long offset, long len) { - char *s = (char *)node->private_data; - - if (!s) - return 0; - if (offset >= ((unsigned long)node->size - 1)) - return 0; - s += offset; - int sl = node->size - offset; - if (sl > len) - sl = len; - strncpy(buf, s, sl); - return sl; -} - -long rpcs_ps() { - Enum res; - processList psbuf; - - if (!rpcs_isalive()) - return -1; - res = r->queryPrograms(psbuf); - if (res != rfsv::E_PSI_GEN_NONE) - return -1; - processList::iterator i; - for (i = psbuf.begin(); i != psbuf.end(); i++) { - builtin_node *dn; - builtin_node *fn1; - builtin_node *fn2; - builtin_node *bn; - char bname[40]; - - sprintf(bname, "%d", i->getPID()); - - dn = (builtin_node *)malloc(sizeof(builtin_node)); - if (!dn) - return -1; - fn1 = (builtin_node *)malloc(sizeof(builtin_node)); - if (!fn1) { - free(dn); - return -1; - } - fn2 = (builtin_node *)malloc(sizeof(builtin_node)); - if (!fn2) { - free(fn1); - free(dn); - return -1; - } - memset(dn, 0, sizeof(builtin_node)); - memset(fn1, 0, sizeof(builtin_node)); - memset(fn2, 0, sizeof(builtin_node)); - - /** - * Directory, named by the PID - */ - dn->flags = BF_ISPROCESS; - dn->name = bname; - dn->attr = PSI_A_DIR; - dn->getlinks = generic_getlinks; - dn->getdents = generic_getdents; - - fn1->name = "cmd"; - fn1->attr = PSI_A_READ | PSI_A_RDONLY; - fn1->private_data = (char *)malloc(strlen(i->getName())+2); - if (!fn1->private_data) { - free(fn1); - free(fn2); - free(dn); - return -1; - } - fn1->read = psread; - sprintf(fn1->private_data, "%s\n", i->getName()); - fn1->size = strlen(fn1->private_data); - - fn2->name = "args"; - fn2->attr = PSI_A_READ | PSI_A_RDONLY; - fn2->private_data = (char *)malloc(strlen(i->getArgs())+2); - if (!fn2->private_data) { - free(fn1->private_data); - free(fn1); - free(fn2); - free(dn); - return -1; - } - fn2->read = psread; - sprintf(fn2->private_data, "%s\n", i->getArgs()); - fn2->size = strlen(fn2->private_data); - - if (!(bn = register_builtin("proc", dn))) { - free(fn1->private_data); - free(fn1); - free(fn2->private_data); - free(fn2); - free(dn); - return -1; - } - strcpy(bname, builtin_path(bn)); - if (!register_builtin(bname, fn1)) { - free(fn1->private_data); - free(fn1); - free(fn2->private_data); - free(fn2); - unregister_builtin(bn); - free(dn); - return -1; - } - if (!register_builtin(bname, fn2)) { - free(fn2->private_data); - free(fn2); - unregister_builtin(bn); - free(dn); - return -1; - } - free(fn1); - free(fn2); - free(dn); - } - return 0; -} - -long rfsv_isalive() { - if (!a) { - if (!(a = rf->create(true))) - return 0; - } - return (a->getStatus() == rfsv::E_PSI_GEN_NONE); -} - -long rfsv_closecached() { - if (!a) - return -1; - if (!a_filename) - return 0; - a->fclose(a_handle); - free(a_filename); - a_filename = NULL; - return 0; -} - -long rfsv_dir(const char *file, dentry **e) { - PlpDir entries; - dentry *tmp; - long ret; - - if (!a) - return -1; - ret = a->dir(file, entries); - - for (int i = 0; i < entries.size(); i++) { - PlpDirent pe = entries[i]; - tmp = *e; - *e = (dentry *)calloc(1, sizeof(dentry)); - if (!*e) - return -1; - (*e)->time = pe.getPsiTime().getTime(); - (*e)->size = pe.getSize(); - (*e)->attr = pe.getAttr(); - (*e)->name = strdup(pe.getName()); - (*e)->next = tmp; - } - return ret; -} - -long rfsv_dircount(const char *file, u_int32_t *count) { - if (!a) - return -1; - return a->dircount(file, *count); -} - -long rfsv_rmdir(const char *name) { - if (!a) - return -1; - rfsv_closecached(); /* Just in case we're caching stuff in this dir */ - return a->rmdir(name); -} - -long rfsv_mkdir(const char *file) { - if (!a) - return -1; - return a->mkdir(file); -} - -long rfsv_remove(const char *file) { - if (!a) - return -1; - if (a_filename && !strcmp(a_filename, file)) - rfsv_closecached(); - return a->remove(file); -} - -long rfsv_fclose(long handle) { - if (!a) - return -1; - if (a_filename && (handle == a_handle)) { - free(a_filename); - a_filename = NULL; - } - return a->fclose(handle); -} - -long rfsv_fcreate(long attr, const char *file, u_int32_t *handle) { - u_int32_t ph; - long ret; - - if (!a) - return -1; - if (a_filename && !strcmp(a_filename, file)) - rfsv_closecached(); - ret = a->fcreatefile(attr, file, ph); - *handle = ph; - return ret; -} - -static long rfsv_opencached(const char *name, long mode) { - long ret; - int retry = 100; - - if (!a) - return -1; - while (((ret = a->fopen(a->opMode(mode), name, a_handle)) - == rfsv::E_PSI_GEN_INUSE) && retry--) - ; - if (ret) - return ret; - a_offset = 0; - a_openmode = mode; - a_filename = strdup(name); - return ret; -} - -long rfsv_read(char *buf, long offset, long len, char *name) { - u_int32_t ret = 0; - u_int32_t r_offset; - - if (!a) - return -1; - if (!a_filename || strcmp(a_filename, name) || a_openmode != rfsv::PSI_O_RDONLY) { - rfsv_closecached(); - if((ret = rfsv_opencached(name, rfsv::PSI_O_RDONLY))) - return ret; - } - if (a_offset != offset) { - if (a->fseek(a_handle, offset, rfsv::PSI_SEEK_SET, r_offset) != rfsv::E_PSI_GEN_NONE) - return -1; - if (offset != r_offset) - return -1; - } - a_offset = offset; - if (a->fread(a_handle, (unsigned char *)buf, len, ret) != rfsv::E_PSI_GEN_NONE) - return -1; - a_offset += ret; - return ret; -} - -long rfsv_write(char *buf, long offset, long len, char *name) { - u_int32_t ret = 0; - u_int32_t r_offset; - - if (!a) - return -1; - - if (!a_filename || strcmp(a_filename, name) || a_openmode != rfsv::PSI_O_RDWR) { - if ((ret = rfsv_closecached())) - return ret; - if ((ret = rfsv_opencached(name, rfsv::PSI_O_RDWR))) - return ret; - } - if (a_offset != offset) { - if (a->fseek(a_handle, offset, rfsv::PSI_SEEK_SET, r_offset) != rfsv::E_PSI_GEN_NONE) - return -1; - if (offset != r_offset) - return -1; - } - a_offset = offset; - if (a->fwrite(a_handle, (unsigned char *)buf, len, ret) != rfsv::E_PSI_GEN_NONE) - return -1; - a_offset += ret; - return ret; -} - -long rfsv_setmtime(const char *name, long time) { - if (!a) - return -1; - if (a_filename && !strcmp(a_filename, name)) - rfsv_closecached(); - return a->fsetmtime(name, PsiTime(time)); -} - -long rfsv_setsize(const char *name, long size) { - u_int32_t ph; - long ret; - - if (!a) - return -1; - if (a_filename && !strcmp(name, a_filename)) - return a->fsetsize(a_handle, size); - ret = a->fopen(a->opMode(rfsv::PSI_O_RDWR), name, ph); - if (!ret) { - ret = a->fsetsize(ph, size); - a->fclose(ph); - } - return ret; -} - -long rfsv_setattr(const char *name, long sattr, long dattr) { - if (!a) - return -1; - if (a_filename && !strcmp(name, a_filename)) - rfsv_closecached(); - return a->fsetattr(name, sattr, dattr); -} - -long rfsv_getattr(const char *name, long *attr, long *size, long *time) { - long res; - PlpDirent e; - - if (!a) - return -1; - res = a->fgeteattr(name, e); - *attr = e.getAttr(); - *size = e.getSize(); - *time = e.getPsiTime().getTime(); - return res; -} - -long rfsv_statdev(char letter) { - PlpDrive drive; - - if (!a) - return -1; - return (a->devinfo(letter, drive) != rfsv::E_PSI_GEN_NONE); -} - -long rfsv_rename(const char *oldname, const char *newname) { - if (!a) - return -1; - /* We could be renaming a directory containing the cached item, so - always flush */ - rfsv_closecached(); - return a->rename(oldname, newname); -} - -long rfsv_drivelist(int *cnt, device **dlist) { - *dlist = NULL; - u_int32_t devbits; - long ret; - int i; - - if (!a) - return -1; - ret = a->devlist(devbits); - if (ret == 0) - for (i = 0; i < 26; i++) { - PlpDrive drive; - - if ((devbits & 1) && - ((a->devinfo(i + 'A', drive) == rfsv::E_PSI_GEN_NONE))) { - - device *next = *dlist; - *dlist = (device *)malloc(sizeof(device)); - (*dlist)->next = next; - (*dlist)->name = strdup(drive.getName().c_str()); - (*dlist)->total = drive.getSize(); - (*dlist)->free = drive.getSpace(); - (*dlist)->letter = 'A' + i; - (*dlist)->attrib = drive.getMediaType(); - (*cnt)++; - } - devbits >>= 1; - } - return ret; -} - -static void -help() -{ - cerr << _( - "Usage: plpnfsd [OPTIONS]...\n" - "\n" - "Supported options:\n" - "\n" - " -d, --mountpoint=DIR Specify DIR as mountpoint\n" - " Default for DIR is " DMOUNTPOINT "\n" - " -u, --user=USER Specify USER who owns mounted dir\n" - " -v, --verbose Increase verbosity\n" - " -h, --help Display this text\n" - " -V, --version Print version and exit\n" - " -p, --port=[HOST:]PORT Connect to port PORT on host HOST\n" - " Default for HOST is 127.0.0.1\n" - " Default for PORT is " - ) << DPORT << "\n\n"; -} - -static void -usage() { - cerr << _("Try `plpnfsd --help' for more information") << endl; -} - -static struct option opts[] = { - {"help", no_argument, 0, 'h'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {"port", required_argument, 0, 'p'}, - {"user", required_argument, 0, 'u'}, - {"mountpoint", required_argument, 0, 'd'}, - {NULL, 0, 0, 0 } -}; - -static void -parse_destination(const char *arg, const char **host, int *port) -{ - if (!arg) - return; - // We don't want to modify argv, therefore copy it first ... - char *argcpy = strdup(arg); - char *pp = strchr(argcpy, ':'); - - if (pp) { - // host.domain:400 - // 10.0.0.1:400 - *pp ++= '\0'; - *host = argcpy; - } else { - // 400 - // host.domain - // host - // 10.0.0.1 - if (strchr(argcpy, '.') || !isdigit(argcpy[0])) { - *host = argcpy; - pp = 0L; - } else - pp = argcpy; - } - if (pp) - *port = atoi(pp); -} - -int main(int argc, char**argv) { - ppsocket *skt; - ppsocket *skt2; - char *user = 0L; - char *mdir = DMOUNTPOINT; - const char *host = "127.0.0.1"; - int sockNum = DPORT; - int verbose = 0; - int status = 0; - - struct servent *se = getservbyname("psion", "tcp"); - endservent(); - if (se != 0L) - sockNum = ntohs(se->s_port); - - while (1) { - int c = getopt_long(argc, argv, "hvVp:u:d:", opts, NULL); - if (c == -1) - break; - switch (c) { - case '?': - usage(); - return -1; - case 'V': - cerr << _("plpnfsd Version ") << VERSION << endl; - return 0; - case 'h': - help(); - return 0; - case 'v': - verbose++; - break; - case 'd': - mdir = optarg; - break; - case 'u': - user = optarg; - break; - case 'p': - parse_destination(optarg, &host, &sockNum); - break; - } - } - if (optind < argc) { - usage(); - return -1; - } - - skt = new ppsocket(); - if (!skt->connect(host, sockNum)) { - cerr << "plpnfsd: could not connect to ncpd" << endl; - status = 1; - } - skt2 = new ppsocket(); - if (!skt2->connect(host, sockNum)) { - cerr << "plpnfsd: could not connect to ncpd" << endl; - status = 1; - } - if (status == 0) { - rf = new rfsvfactory(skt); - rp = new rpcsfactory(skt2); - a = rf->create(true); - r = rp->create(true); - openlog("plpnfsd", LOG_PID|LOG_CONS, LOG_DAEMON); - if ((a != NULL) && (r != NULL)) - syslog(LOG_INFO, "connected, status is %d", status); - else - syslog(LOG_INFO, "could not create rfsv or rpcs object, connect delayed"); - status = mp_main(verbose, mdir, user); - delete a; - delete r; - } - exit(status); -} - -/* - * Local variables: - * c-basic-offset: 4 - * End: - */ diff --git a/plpnfsd/mount_aix.c b/plpnfsd/mount_aix.c deleted file mode 100644 index b2d565d..0000000 --- a/plpnfsd/mount_aix.c +++ /dev/null @@ -1,169 +0,0 @@ -/* $Id$ - * - * Copyright (c) 1990 Jan-Simon Pendry - * Copyright (c) 1990 Imperial College of Science, Technology & Medicine - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Jan-Simon Pendry at Imperial College, London. - * - * 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. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. - * - * %W% (Berkeley) %G% - * - */ - - -/* - * AIX 3 Mount helper - */ - -#include -#include -#include -#include -#include - -#include "misc-aix3.h" -#include "os-aix3.h" - -typedef void * voidp; - -#undef DEBUG - -char hostname[MAXHOSTNAMELEN] = "localhost"; /* Hostname */ - -static int aix3_mkvp(p, gfstype, flags, object, stub, host, info, info_size, args) -char *p; -int gfstype; -int flags; -char *object; -char *stub; -char *host; -char *info; -int info_size; -char *args; -{ - struct vmount *vp = (struct vmount *) p; - bzero((voidp) vp, sizeof(*vp)); - /* - * Fill in standard fields - */ - vp->vmt_revision = VMT_REVISION; - vp->vmt_flags = flags; - vp->vmt_gfstype = gfstype; - -#define VMT_ROUNDUP(len) (4 * ((len + 3) / 4)) -#define VMT_ASSIGN(vp, idx, data, size) \ - vp->vmt_data[idx].vmt_off = p - (char *) vp; \ - vp->vmt_data[idx].vmt_size = size; \ - bcopy(data, p, size); \ - p += VMT_ROUNDUP(size); - - /* - * Fill in all variable length data - */ - p += sizeof(*vp); - - VMT_ASSIGN(vp, VMT_OBJECT, object, strlen(object) + 1); - VMT_ASSIGN(vp, VMT_STUB, stub, strlen(stub) + 1); - VMT_ASSIGN(vp, VMT_HOST, host, strlen(host) + 1); - VMT_ASSIGN(vp, VMT_HOSTNAME, host, strlen(host) + 1); - VMT_ASSIGN(vp, VMT_INFO, info, info_size); - VMT_ASSIGN(vp, VMT_ARGS, args, strlen(args) + 1); - -#undef VMT_ASSIGN -#undef VMT_ROUNDUP - - /* - * Return length - */ - return vp->vmt_length = p - (char *) vp; -} - -/* - * Map from conventional mount arguments - * to AIX 3-style arguments. - */ -aix3_mount(fsname, dir, flags, type, data, args) -char *fsname; -char *dir; -int flags; -int type; -void *data; -char *args; -{ - char buf[4096]; - int size; - - for (size = 0; size < 4096; size++) buf[size] = 0; -#ifdef DEBUG - printf("aix3_mount: fsname %s, dir %s, type %d\n", fsname, dir, type); -#endif - -/* aix3_mkvp(p, gfstype, flags, object, stub, host, info, info_size, args) */ - - switch (type) { - - case MOUNT_TYPE_NFS: { - char *host = strdup(fsname); - char *rfs = strchr(host, ':'); - int free_rfs = 0; - if (rfs) { - *rfs++ = '\0'; - } else { - rfs = host; - free_rfs = 1; - host = strdup(hostname); - } - - size = aix3_mkvp(buf, type, flags, rfs, dir, host, data, sizeof(struct nfs_args), args); - if (free_rfs) - free((voidp) rfs); - free(host); - - } break; - - case MOUNT_TYPE_UFS: - /* Need to open block device and extract log device info from sblk. */ - errno = EINVAL; - return -1; - - default: - errno = EINVAL; - return -1; - } -#ifdef DEBUG - printf("aix3_mkvp: flags %#x, size %d, args %s\n", flags, size, args); - printf("revision %d\n", ((struct vmount *)buf)->vmt_revision); -#endif - - return vmount(buf, size); -} diff --git a/plpnfsd/mp_inode.c b/plpnfsd/mp_inode.c deleted file mode 100644 index eab6aa4..0000000 --- a/plpnfsd/mp_inode.c +++ /dev/null @@ -1,338 +0,0 @@ -/* $Id$ - * - * Original version of this file from p3nfsd-5.4 by - * Rudolf Koenig (rfkoenig@immd4.informatik.uni-erlangen.de) - * - * Modifications for plputils by Fritz Elfert - * - */ -#include -#include "nfs_prot.h" -#include "mp.h" -#include "rfsv_api.h" - -#if defined(__SVR4) || defined(__GLIBC__) || defined(__FreeBSD__) || defined(__NetBSD__) -#include -#include -#endif -#ifdef __NeXT__ -#include -#include -#define strdup NXCopyStringBuffer -#endif -#define HASHSIZE 999 - -static int nextinode = 6; -static p_inode *numtab[HASHSIZE]; -static p_inode *namtab[HASHSIZE]; - -/* - * Verrry simple hash :-) - */ -static unsigned -hash(str) -char *str; -{ - unsigned i = 0, hashval = 3 * HASHSIZE / 4; - - while (*str) { - i = *str++; - hashval = (hashval << (i & 7)) + i; - } - - return hashval % HASHSIZE; -} - -/* Get struct with inode */ -p_inode * -get_num(i) -int i; -{ - p_inode *ptr; - - for (ptr = numtab[i % HASHSIZE]; ptr; ptr = ptr->nextnum) - if (i == ptr->inode) - break; - if (!ptr) { - errorlog("Inode %d not found (aborting)\n", i); - abort(); - } - return ptr; -} - -static p_inode * -newinode(name, inode) -char *name; -int inode; -{ - p_inode *ptr; - int idx = hash(name); - - ptr = (p_inode *) malloc(sizeof(*ptr)); - ptr->name = (char *) strdup(name); - ptr->inode = inode; - -/* insert into both hashtabs */ - ptr->nextnam = namtab[idx]; - namtab[idx] = ptr; - - ptr->nextnum = numtab[inode % HASHSIZE]; - numtab[inode % HASHSIZE] = ptr; - - return ptr; -} - -/* Get/create struct with name */ -p_inode * -get_nam(name) -char *name; -{ - p_inode *ptr; - int idx = hash(name); - - for (ptr = namtab[idx]; ptr; ptr = ptr->nextnam) - if (!strcmp(name, ptr->name)) - break; - if (!ptr) - ptr = newinode(name, nextinode++); - if (debug > 1) - debuglog("get_nam(\"%s\") returns %08x -> inode = %d\n", - name, (unsigned int) ptr, ptr->inode); - return ptr; -} - -void -inode2fh(inode, fh) -int inode; -char *fh; -{ - bzero(fh, NFS_FHSIZE); - bcopy((char *) &inode, fh, sizeof(inode)); -} - -int -fh2inode(fh) -char *fh; -{ - int inode; - - bcopy(fh, (char *) &inode, sizeof(inode)); - return inode; -} - - - -/* Rename: the inode must be preserved */ -p_inode * -re_nam(old, new) -char *old, *new; -{ - p_inode *nptr, *optr, **nampp, **numpp; - int idx = hash(old); - - if (debug) - debuglog("re_nam: %s->%s\n", old, new); - for (nampp = &namtab[idx]; *nampp; nampp = &(*nampp)->nextnam) - if (!strcmp(old, (*nampp)->name)) - break; - if (!*nampp) - return get_nam(new); - - optr = *nampp; - if (debug) - debuglog("re_nam: %d\n", optr->inode); - *nampp = optr->nextnam; - - /* delete it from the other hashtab too */ - idx = optr->inode % HASHSIZE; - for (numpp = &numtab[idx]; *numpp; numpp = &(*numpp)->nextnum) - if (optr == (*numpp)) - break; - if (!*numpp) { - errorlog("Entry in one hashtab only (aborting)\n"); - abort(); - } - *numpp = optr->nextnum; - - nptr = newinode(new, optr->inode); - if (debug) - debuglog("re_nam: new entry created\n"); - free(optr->name); - free(optr); - - return nptr; -} - -/* Cache routines */ -struct cache * -search_cache(root, inode) -struct cache *root; -unsigned inode; -{ - struct cache *cp; - - if (debug) - debuglog("search_cache %d\n", inode); - for (cp = root; cp; cp = cp->next) - if (cp->inode == inode) { - cp->stamp = time(0); - return cp; - } - return 0; -} - -struct cache * -add_cache(struct cache **root, unsigned int inode, fattr *fp) { - struct cache *cp; - - if (debug) - debuglog("add_cache %d\n", inode); - cp = (struct cache *) malloc(sizeof(*cp)); - if (cp != NULL) { - cp->stamp = time(0); - cp->inode = inode; - cp->attr = *fp; - cp->dcache = 0; - cp->actual_size = fp->size; - cp->next = *root; - *root = cp; - } - return cp; -} - -struct dcache * -add_dcache(cp, offset, len, data) -struct cache *cp; -unsigned offset, len; -unsigned char *data; -{ - struct dcache *dcp; - dcp = (struct dcache *) malloc(sizeof(*dcp)); - dcp->towrite = 1; - dcp->offset = offset; - dcp->data = 0; - dcp->len = len; - if (len) { - dcp->data = (unsigned char *) malloc(len); - bcopy(data, dcp->data, len); - } - dcp->next = cp->dcache; - cp->dcache = dcp; - return dcp; -} - -void -clean_dcache(cp) -struct cache *cp; -{ - struct dcache *dcp, *dcpn; - for (dcp = cp->dcache; dcp; dcp = dcpn) { - dcpn = dcp->next; - if (dcp->len) - free(dcp->data); - free(dcp); - } - cp->dcache = 0; -} - -struct dcache * -search_dcache(cp, off, len) -struct cache *cp; -unsigned int off, len; -{ - struct dcache *dcp; - for (dcp = cp->dcache; dcp; dcp = dcp->next) - if (dcp->offset == off && dcp->len >= len) - return dcp; - return 0; -} - -void -rem_cache(struct cache **root, unsigned int inode) { - struct cache *cp, **cpp; - - if (debug) - debuglog("rem_cache %d\n", inode); - for (cpp = root; (cp = *cpp); cpp = &cp->next) - if (cp->inode == inode) - break; - if (!cp) - return; - *cpp = cp->next; - clean_dcache(cp); - free(cp); -} - -time_t cache_keep = 30; - -void -clean_cache(struct cache **root) { - struct cache **cp = root; - time_t now = time(0); - - while (*cp) { - if (force_cache_clean || ((now - (*cp)->stamp) > cache_keep)) { - struct cache *old = *cp; - if (debug) - debuglog("clean_cache %d\n", (*cp)->inode); - *cp = (*cp)->next; - clean_dcache(old); - free(old); - } else - cp = &(*cp)->next; - } -} - -char * -build_path(dir, file) -char *dir, *file; -{ - /* FIXME: Buffer overflow */ - static char namebuf[300]; - - if (!strcmp(dir, "")) - strcpy(namebuf, file); - else - sprintf(namebuf, "%s\\%s", dir, file); - - return namebuf; -} - -int -getpinode(inode) -p_inode *inode; -{ - char *p; - int i; - - if (inode->inode == root_fattr.fileid) /* Root inode */ - i = root_fattr.fileid - 1; /* RUDI !!! */ - else if (!(p = (char *) rindex(inode->name, '\\'))) /* device inode */ - i = root_fattr.fileid; - else { - *p = 0; - i = get_nam(inode->name)->inode; - *p = '\\'; - } - return i; -} - -char * -dirname(dir) -char *dir; -{ - static char namebuf[300]; - sprintf(namebuf, "%s\\", dir); - return namebuf; -} - -char * -filname(dir) -char *dir; -{ - char *p; - if ((p = (char *) rindex(dir, '\\'))) - return p + 1; - else - return dir; -} diff --git a/plpnfsd/mp_main.c b/plpnfsd/mp_main.c deleted file mode 100644 index e491ff4..0000000 --- a/plpnfsd/mp_main.c +++ /dev/null @@ -1,198 +0,0 @@ -/* $Id$ - * - * Original version of this file from p3nfsd-5.4 by - * Rudolf Koenig (rfkoenig@immd4.informatik.uni-erlangen.de) - * - * Modifications for plputils by Fritz Elfert - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "nfs_prot.h" -#include "mp.h" -#if defined (__SVR4) || defined(__sgi) || defined(__NetBSD__) -#include /* getenv */ -#include /* strcmp */ -#endif -#include /* getuid */ - -#include -#if defined(__NeXT__) -#include -#include -#define DIRENT struct direct -#else -#define DIRENT struct dirent -#endif - - -extern void nfs_program_2(); - -int debug, exiting, query_cache = 0; -time_t devcache_keep = 120; -time_t devcache_stamp = 0; - -fattr root_fattr = -{ - NFDIR, 0040500, 1, 0, 0, - BLOCKSIZE, BLOCKSIZE, FID, 1, FID, 1, - {0, 0}, - {0, 0}, - {0, 0} -}; - -int -debuglog(char *fmt, ...) -{ - va_list ap; - char *buf; - - if (!debug) - return 0; - buf = (char *)malloc(1024); - va_start(ap, fmt); - vsnprintf(buf, 1024, fmt, ap); - syslog(LOG_DEBUG, "%s", buf); - free(buf); - va_end(ap); - return 0; -} - -int -errorlog(char *fmt, ...) -{ - va_list ap; - char *buf = (char *)malloc(1024); - - va_start(ap, fmt); - vsnprintf(buf, 1024, fmt, ap); - va_end(ap); - syslog(LOG_ERR, "%s", buf); - free(buf); - return 0; -} - -int -infolog(char *fmt, ...) -{ - va_list ap; - char *buf = (char *)malloc(1024); - - va_start(ap, fmt); - vsnprintf(buf, 1024, fmt, ap); - syslog(LOG_INFO, "%s", buf); - free(buf); - va_end(ap); - return 0; -} - -int force_cache_clean = 0; - -int set_owner(char *user, int logstdio) { - struct passwd *pw = NULL; - - if (user && *user) { - if (!(pw = getpwnam(user))) { - if (logstdio) - fprintf(stderr, "User %s not found.\n", user); - else - errorlog("User %s not found.\n", user); - endpwent(); - return 1; - } - if (getuid() && pw->pw_uid != getuid()) { - if (logstdio) - fprintf(stderr, "Only root can set owner to someone other.\n"); - else - errorlog("Only root can set owner to someone other.\n"); - endpwent(); - return 1; - } - } else { - if (!logstdio) { - errorlog("Request to change owner with empty argument.\n"); - return 1; - } - if (!(pw = getpwuid(getuid()))) { - fprintf(stderr, "You don't exist, go away!\n"); - endpwent(); - return 1; - } - } - if (pw) { - if ((root_fattr.uid != pw->pw_uid) || (root_fattr.gid != pw->pw_gid)) { - struct group *g = getgrgid(pw->pw_gid); - char *gname = (g && g->gr_name && *(g->gr_name)) ? g->gr_name : "???"; - root_fattr.uid = pw->pw_uid; - root_fattr.gid = pw->pw_gid; - if (logstdio) - printf("Owner set to %s.%s\n", pw->pw_name, gname); - else - infolog("Owner set to %s.%s\n", pw->pw_name, gname); - endgrent(); - force_cache_clean = 1; - cache_flush(); - } - } - endpwent(); - return 0; -} - -int -mp_main(int verbose, char *dir, char *user) -{ - struct passwd *pw; - struct timeval tv; - struct timezone tz; - p_inode *rp; - nfs_fh root_fh; - DIR *dirp; - DIRENT *diep; - int i; - - - if (!(pw = getpwuid(getuid()))) { - fprintf(stderr, "You don't exist, go away!\n"); - return 1; - } - if (!user) { - if (!(user = (char *) getenv("USER"))) - user = (char *) getenv("logname"); - } - endpwent(); - if (set_owner(user, 1)) - return 1; - gettimeofday(&tv, &tz); - - debug = verbose; - if (debug) - printf("plpnfsd: version %s, mounting on %s ...\n", VERSION, dir); - - openlog("plpnfsd", LOG_PID|LOG_CONS, LOG_DAEMON); - rp = get_nam(""); - inode2fh(rp->inode, root_fh.data); - root_fattr.fileid = rp->inode; - root_fattr.atime.seconds = root_fattr.mtime.seconds = - root_fattr.ctime.seconds = tv.tv_sec; - - mount_and_run(dir, nfs_program_2, &root_fh); - return 0; -} - -/* - * Local variables: - * c-basic-offset: 4 - * End: - */ diff --git a/plpnfsd/mp_mount.c b/plpnfsd/mp_mount.c deleted file mode 100644 index 8b8a515..0000000 --- a/plpnfsd/mp_mount.c +++ /dev/null @@ -1,630 +0,0 @@ -/* $Id$ - * - * Original version of this file from p3nfsd-5.4 by - * Rudolf Koenig (rfkoenig@immd4.informatik.uni-erlangen.de) - * - * Modifications for plputils by Fritz Elfert - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#if defined(__SVR4) || defined(__sgi) || defined(linux) -#include -#include -#include /* strdup */ -#ifndef linux -extern int inet_addr(char *); -#endif -#define PORTMAP /* I need svcudp_create in rpc/svc_soc.h, sol 2.4 */ -#endif - -#include "OSdefs.h" -#include -#include -#include -#include - -#ifdef __sgi -#include -#endif - -#if defined(__NetBSD__) || defined(__FreeBSD__) -#include /* Needs NGROUPS for mount.h */ -#define umount(dir) unmount(dir, 1) -#endif - -#if defined(__NeXT__) -#include -#include -#include -#define umount(dir) unmount(dir) -#endif - - -static char nfshost[128]; - -#define NFSCLIENT -#ifdef __FreeBSD__ -#define NFS -#endif /* __FreeBSD__ */ -#include - -#ifdef __FreeBSD__ -#include -#include -#include -#include -#include -#if __FreeBSD_version >= 300001 -#include -#endif -#endif /* __FreeBSD__ */ - -#ifdef __NetBSD__ -#include -#include -#include -#include -#include -#include -#include -#include -#endif /* __NetBSD__ */ - -#include -#include "nfs_prot.h" - -#ifdef linux -#ifndef __GLIBC__ -#include /* struct nfs_mount_data */ -#endif -#include "linux-misc.h" /* struct nfs_mount_data */ -#include /* inet_addr() */ -#endif -#ifdef _IBMR2 -#include "os-aix3.h" -#include "misc-aix3.h" -#include -#endif - -#ifndef DONT_UPDATE_MTAB -#if defined(sun) && defined(__SVR4) -#include -#else -#include -#endif -#endif - -#if defined(sun) && defined(__SVR4) /*gec */ -#include -#include -#include -#include -#include -#define PORTMAP -#endif - -#if defined(sun) && !defined(__SVR4) -extern int _rpc_dtablesize(); -#define umount unmount -#endif - -#include -#include - -#include "rfsv_api.h" - -#ifdef __sgi -#define vfork fork -#define NFSMNT_NOCTO 0 -#endif - -#if defined(sun) && defined(__SVR4) -#define setmntent fopen -#define endmntent fclose -#define addmntent putmntent -#define mntent mnttab -#endif - -static char *mntdir; /* where we mounted the psion */ - -#ifdef __STDC__ -static void doexit(void); -#endif - -static RETSIGTYPE -usr1_handler SIGARG -{ - debug = (debug + 1) & 3; - infolog("Set debug level to %d\n", debug); -}; - -static RETSIGTYPE -hup_handler SIGARG -{ - if (debug > 1) - debuglog("Got HUP signal\n"); - exiting = 5; -}; - -static RETSIGTYPE -term_handler SIGARG -{ - if (debug > 1) - debuglog("Got TERM signal\n"); - exiting = 5; -}; - -static void doexit() { -#ifndef DONT_UPDATE_MTAB - FILE *fpin, *fpout; -#if defined(sun) && defined(__SVR4) - struct mntent entr; -#else - struct mntent *ent; -#endif -#endif -#if !defined(__FreeBSD__) && !defined(__NetBSD__) - struct stat statb; -#endif - - exiting--; - debuglog("Doing exit\n"); - -#ifdef _IBMR2 - if (stat(mntdir, &statb)) { - errorlog("stat %s: %m\n", mntdir); - return; - } - debuglog("Next call: uvmount(%d, 0)\n", statb.st_vfs); - if (uvmount(statb.st_vfs, 0)) { - errorlog("uvmount: %m\n"); - return; - } -#else - if (umount(mntdir)) { - errorlog("umount %s: %m\n", mntdir); - return; - } -#endif - -#ifndef DONT_UPDATE_MTAB - debuglog("unmount succeeded, trying to fix mtab.\n"); - - if (!(fpout = setmntent(MTAB_TMP, "w"))) { - errorlog("%s: %m\n", MTAB_TMP); - return; - } - if (!(fpin = setmntent(MTAB_PATH, "r"))) { - endmntent(fpout); - unlink(MTAB_TMP); - errorlog("%s: %m\n", MTAB_PATH); - exit(0); - } - if (fstat(fileno(fpin), &statb)) - errorlog("fstat: %m\n"); - else - fchmod(fileno(fpout), statb.st_mode); - -#if defined(sun) && defined(__SVR4) - while (!getmntent(fpin, &entr)) - if (strcmp(entr.mnt_special, nfshost) || strcmp(entr.mnt_mountp, mntdir)) - putmntent(fpout, &entr); -#else - while ((ent = getmntent(fpin))) - if (strcmp(ent->mnt_fsname, nfshost) || strcmp(ent->mnt_dir, mntdir)) - addmntent(fpout, ent); -#endif - endmntent(fpin); - endmntent(fpout); - - if (rename(MTAB_TMP, MTAB_PATH)) { - errorlog("%s: %m\n", MTAB_PATH); - unlink(MTAB_TMP); - } -#else - debuglog("no mtab fixing needed\n"); -#endif - infolog("plpnfsd: terminating.\n"); - - exit(0); -} - -void cache_flush() { - struct cache *cp; - struct dcache *dcp; - - /* - * Solaris sends blocks in a way which is not very pleasent - * for us. It sends blocks 0,1,2,3,4,5,6, then 9,10,11 and - * do on. A little bit later block 7 and 8 arrives. This "bit" - * is more that 2 seconds, it is about 6 seconds. It occurs - * if we're rewriting a file. We set MAXWRITE to 15, meaning - * that we are waiting for 30 seconds to receive the missing - * blocks. - */ - -#define MAXWRITE 15 - - int doclean = 1; - for (cp = attrcache; cp; cp = cp->next) - for (dcp = cp->dcache; dcp; dcp = dcp->next) - if (dcp->towrite) { - debuglog("waiting for block %d in %s to write (%d)\n", - dcp->offset, get_num(cp->inode)->name, dcp->towrite); - if (++dcp->towrite <= MAXWRITE) - doclean = 0; /* Wait with cleaning */ - } - if (doclean || force_cache_clean) { - for (cp = attrcache; cp; cp = cp->next) - for (dcp = cp->dcache; dcp; dcp = dcp->next) - if (dcp->towrite) - errorlog("PLPNFSD WARNING: file %s block at %d not written\n", - get_num(cp->inode)->name, dcp->offset); - clean_cache(&attrcache); - if (force_cache_clean || ((time(0) - devcache_stamp) > devcache_keep)) - query_cache = 0; /* clear the GETDENTS "cache". */ - rfsv_closecached(); - force_cache_clean = 0; - } -} - -void -mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh) -{ - int sock, port, pid, doclean; - struct sockaddr_in sain; - int isalive = 0, ret, dtbsize; - SVCXPRT *nfsxprt; - int bufsiz = 0xc000; /* room for a few biods */ -#ifdef linux - struct nfs_mount_data nfs_mount_data; - int mount_flags; - int ksock, kport; - struct sockaddr_in kaddr; -#else - struct nfs_args nfs_args; -#endif -#if defined(__FreeBSD__) || defined(__NetBSD__) - int mount_flags; -#endif - - sprintf(nfshost, "localhost:/psion"); - bzero((char *) &sain, sizeof(struct sockaddr_in)); -#ifdef linux - bzero(&nfs_mount_data, sizeof(struct nfs_mount_data)); -#else - bzero((char *) &nfs_args, sizeof(struct nfs_args)); -#endif - -/*** First part: set up the rpc service */ - /* Create udp socket */ - sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *) &bufsiz, sizeof(bufsiz))) - errorlog("setsockopt: %m\n"); - - /* Bind it to a reserved port */ - sain.sin_family = AF_INET; - sain.sin_addr.s_addr = inet_addr("127.0.0.1"); - for (port = IPPORT_RESERVED - 1; port > IPPORT_RESERVED / 2; port--) { - sain.sin_port = htons(port); - if (bind(sock, (struct sockaddr *) &sain, sizeof(sain)) >= 0) - break; - } - if (port <= IPPORT_RESERVED / 2) { - errorlog("bind to reserved port: %m\n"); - exit(1); - } - if ((nfsxprt = svcudp_create(sock)) == 0) { - errorlog("svcudp_create: %m\n"); - exit(1); - } - if (!svc_register(nfsxprt, NFS_PROGRAM, NFS_VERSION, proc, 0)) { - errorlog("svc_register: %m\n"); - exit(1); - } - debuglog("created svc PROG=%d, VER=%d port=%d\n", - NFS_PROGRAM, NFS_VERSION, port); - - -/*** Second part: mount the directory */ -#ifdef linux - /* - * Hold your hat! Another odd internet socket coming up. The linux - * kernel needs the socket to talk to the nfs daemon. - */ - ksock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (ksock < 0) { - errorlog("Cannot create kernel socket: %m\n"); - exit(1); - } - kaddr.sin_family = AF_INET; - kaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); - for (kport = IPPORT_RESERVED - 1; kport > IPPORT_RESERVED / 2; kport--) { - kaddr.sin_port = htons(kport); - if (bind(ksock, (struct sockaddr *) &kaddr, sizeof(kaddr)) >= 0) - break; - } - if (kport <= IPPORT_RESERVED / 2) { - errorlog("bind to reserved port: %m\n"); - exit(1); - } - nfs_mount_data.version = NFS_MOUNT_VERSION; - nfs_mount_data.fd = ksock; - nfs_mount_data.root = *root_fh; /* structure copy */ - nfs_mount_data.flags = NFS_MOUNT_INTR | NFS_MOUNT_NOCTO; - /* NFS_MOUNT_SECURE | NFS_MOUNT_POSIX | NFS_MOUNT_SOFT | NFS_MOUNT_NOAC */ - nfs_mount_data.rsize = PBUFSIZE; - nfs_mount_data.wsize = PBUFSIZE; - nfs_mount_data.timeo = 600; - nfs_mount_data.retrans = 10; /* default 3 */ - nfs_mount_data.acregmin = 3; /* default 3 seconds */ - nfs_mount_data.acregmax = 60; /* default 60 seconds */ - nfs_mount_data.acdirmin = 30; /* default 30 seconds */ - nfs_mount_data.acdirmax = 60; /* default 60 seconds */ - nfs_mount_data.addr = sain; /* structure copy */ - strcpy(nfs_mount_data.hostname, PSIONHOSTNAME); - - if (connect(ksock, (struct sockaddr *) &nfs_mount_data.addr, sizeof(nfs_mount_data.addr)) < 0) { - errorlog("Cannot connect to plpnfsd: %m\n"); - exit(1); - } - mount_flags = MS_MGC_VAL; /* | MS_SYNCHRONOUS | MS_RDONLY | MS_NOEXEC | MS_NODEV | MS_NOSUID */ - -#endif - -#if defined(sun) && defined (__SVR4) - { /*gec */ - struct netbuf myaddr; - struct stat stb; - struct knetconfig knc; - struct netconfig *nc = getnetconfigent("udp"); - if (!nc) { - extern int errno; - errorlog("getnetconfigent \"udp\": (errno %d) %m\n", errno); - exit(1); - } - knc.knc_semantics = nc->nc_semantics; - knc.knc_protofmly = strdup(nc->nc_protofmly); - knc.knc_proto = strdup(nc->nc_proto); - - if (stat(nc->nc_device, &stb)) { - extern int errno; - errorlog("stat \"%s\": (errno %d) %m\n", nc->nc_device, errno); - exit(1); - } - knc.knc_rdev = stb.st_rdev; - - /*freenetconfigent(nc) has the struct been allocated, or is it static ?!? */ - - debuglog("%d,%s,%s,%lx (1,inet,udp,0x002c0029)\n", (int) knc.knc_semantics, - knc.knc_protofmly, knc.knc_proto, knc.knc_rdev); - - myaddr.maxlen = myaddr.len = sizeof(sain); - myaddr.buf = (char *) &sain; - - nfs_args.knconf = &knc; - nfs_args.wsize = PBUFSIZE; - nfs_args.rsize = PBUFSIZE; - nfs_args.addr = &myaddr; - nfs_args.fh = (char *) root_fh; - nfs_args.retrans = 10; - /* 1 minute timeout - see below */ - nfs_args.timeo = 600; - nfs_args.hostname = PSIONHOSTNAME; - nfs_args.flags = NFSMNT_INT | NFSMNT_HOSTNAME | NFSMNT_NOCTO | - NFSMNT_RETRANS | NFSMNT_TIMEO | NFSMNT_WSIZE | - NFSMNT_RSIZE | NFSMNT_KNCONF /* | NFSMNT_NOAC */ ; - /* eventually drop knc-strings now (memory-leak) */ - } -#endif /* solaris */ - -/* BSD Derived systems */ -#if (defined(sun) && !defined(__SVR4)) || defined(hpux) || defined(__sgi) || defined(__NeXT__) - nfs_args.addr = &sain; - nfs_args.fh = (void *) root_fh; - nfs_args.wsize = PBUFSIZE; - nfs_args.rsize = PBUFSIZE; - nfs_args.retrans = 10; - /* 1 minute timeout - means that we receive double requests in worst case, - if the file is longer than 100k. So long for the theory. Since SunOS uses - dynamic retransmission (hardwired), nfs_args.timeo is only a hint. :-( */ - nfs_args.timeo = 600; - nfs_args.hostname = PSIONHOSTNAME; - nfs_args.flags = NFSMNT_INT | NFSMNT_HOSTNAME | NFSMNT_NOCTO | - NFSMNT_RETRANS | NFSMNT_TIMEO | NFSMNT_WSIZE | NFSMNT_RSIZE; -#endif - -#ifdef __FreeBSD__ -#if __FreeBSD_version >= 300001 - nfs_args.version = NFS_ARGSVERSION; -#endif - nfs_args.addr = (struct sockaddr *) &sain; - nfs_args.addrlen = sizeof(sain); - nfs_args.sotype = SOCK_DGRAM; - nfs_args.fh = (void *) root_fh; - nfs_args.fhsize = sizeof(*root_fh); - nfs_args.wsize = PBUFSIZE; - nfs_args.rsize = PBUFSIZE; - nfs_args.retrans = 10; - /* 1 minute timeout - see below */ - nfs_args.timeo = 600; - nfs_args.hostname = PSIONHOSTNAME; - nfs_args.flags = - NFSMNT_INT | - NFSMNT_SOFT | - NFSMNT_RETRANS | - NFSMNT_TIMEO | - NFSMNT_WSIZE | - NFSMNT_RSIZE; - mount_flags = MNT_NOSUID | MNT_NODEV | MNT_NOEXEC | MNT_NOATIME; -#endif - -#ifdef __NetBSD__ - nfs_args.version = NFS_ARGSVERSION; - nfs_args.addrlen = sizeof(sain); - nfs_args.sotype = SOCK_DGRAM; - nfs_args.maxgrouplist = NGROUPS; - nfs_args.readahead = 1; - nfs_args.addr = (struct sockaddr *) &sain; - nfs_args.fh = (void *) root_fh; - nfs_args.fhsize = sizeof(*root_fh); - nfs_args.wsize = PBUFSIZE; - nfs_args.rsize = PBUFSIZE; - nfs_args.retrans = 10; - nfs_args.timeo = 600; - nfs_args.hostname = PSIONHOSTNAME; - nfs_args.flags = NFSMNT_INT | NFSMNT_RETRANS | NFSMNT_TIMEO - | NFSMNT_NOCONN | NFSMNT_DUMBTIMR - | NFSMNT_WSIZE | NFSMNT_RSIZE; - mount_flags = MNT_NOSUID | MNT_NODEV | MNT_NOEXEC | MNT_NOATIME; -#endif - -#if defined(_IBMR2) - nfs_args.addr = sain; - nfs_args.fh = *(fhandle_t *) root_fh; - nfs_args.wsize = PBUFSIZE; - nfs_args.rsize = PBUFSIZE; - nfs_args.retrans = 0; /* Shouldn't need bigger retrans since there is - only one biod. Somebody prove it ? Nice feature. */ - nfs_args.biods = 1; - nfs_args.timeo = 150; - nfs_args.hostname = PSIONHOSTNAME; - nfs_args.flags = NFSMNT_INT | NFSMNT_HOSTNAME | NFSMNT_BIODS | - NFSMNT_RETRANS | NFSMNT_TIMEO | NFSMNT_WSIZE | NFSMNT_RSIZE; -#endif - - mntdir = dir; - switch (pid = fork()) { - case 0: - break; - case -1: - errorlog("fork: %m\n"); - exit(1); - default: - debuglog("Going to mount...\n"); - -#if defined(__sgi) || (defined(sun) && defined(__SVR4)) - if (mount("", dir, MS_DATA, "nfs", &nfs_args, sizeof(nfs_args))) -#endif -#if defined(__NeXT__) - if (mount(MOUNT_NFS, dir, 0, (caddr_t) & nfs_args)) -#endif -#ifdef hpux - if (vfsmount(MOUNT_NFS, dir, 0, &nfs_args)) -#endif -#if defined(sun) && !defined(__SVR4) - if (mount("nfs", dir, M_NEWTYPE, (caddr_t) & nfs_args)) -#endif -#ifdef linux - if (mount("nfs", dir, "nfs", mount_flags, &nfs_mount_data)) -#endif -#ifdef _IBMR2 - if (aix3_mount("psion:loc", dir, 0, MOUNT_TYPE_NFS, &nfs_args, "plpnfsd")) -#endif - -#if defined(__NetBSD__) || defined(__FreeBSD__) -#if __FreeBSD_version >= 300001 - if (mount("nfs", dir, mount_flags, &nfs_args)) -#else - if (mount(MOUNT_NFS, dir, mount_flags, &nfs_args)) -#endif -#endif - - { - errorlog("nfs mount %s: %m\n", dir); - kill(pid, SIGTERM); - exit(0); - } else { -#ifndef DONT_UPDATE_MTAB - FILE *mfp; - struct mntent mnt; -#if defined(sun) && defined(__SVR4) /*gec */ - char tim[32]; -#endif - - debuglog("Mount succeeded, making mtab entry.\n"); - -#if defined(sun) && defined(__SVR4) /*gec */ - mnt.mnt_special = nfshost; - mnt.mnt_mountp = mntdir; - mnt.mnt_fstype = "nfs"; - mnt.mnt_mntopts = "hard,intr"; /* dev=??? */ - sprintf(tim, "%ld", time(NULL)); /* umount crashes! without this */ - mnt.mnt_time = tim; -#else - mnt.mnt_fsname = nfshost; - mnt.mnt_dir = mntdir; - mnt.mnt_type = "nfs"; - mnt.mnt_opts = "hard,intr"; - mnt.mnt_freq = mnt.mnt_passno = 0; -#endif - - if ((mfp = setmntent(MTAB_PATH, "a"))) - addmntent(mfp, &mnt); - else - errorlog("%s: %m\n", MTAB_PATH); - endmntent(mfp); -#endif /* !DONT_UPDATE_MTAB */ - } - exit(0); - } - -/*** Third part: let's go */ - infolog("to stop the server do \"echo stop > %s/proc/exit\".\n", mntdir); - -#if defined(sun) && !defined(__SVR4) - dtbsize = _rpc_dtablesize(); -#else - dtbsize = FD_SETSIZE; -#endif - - /* - * Signal handling, etc. should only happen in one process, so let's - * make it this one (the other one might well go away). We really - * ought to block off the other signals, but that's OK... - */ - signal(SIGUSR1, usr1_handler); - signal(SIGHUP, hup_handler); - signal(SIGTERM, term_handler); - - for (;;) { - fd_set readfd; - struct timeval tv; - - readfd = svc_fdset; - tv.tv_sec = 2; - tv.tv_usec = 0; - - ret = select(dtbsize, &readfd, 0, 0, &tv); - if (ret > 0) - svc_getreqset(&readfd); - if (ret != 0) - continue; - - /* Do some housekeeping */ - - if (exiting) - doexit(); - - cache_flush(); - - ret = rfsv_isalive(); - if (isalive) { - if (!ret) { - debuglog("Disconnected...\n"); - doclean = 1; - root_fattr.mtime.seconds = time(0); - } - } else { - if (ret) { - debuglog("Connected...\n"); - root_fattr.mtime.seconds = time(0); - } - } - isalive = ret; - } -} diff --git a/plpnfsd/mp_pfs_ops.c b/plpnfsd/mp_pfs_ops.c deleted file mode 100644 index 46310ed..0000000 --- a/plpnfsd/mp_pfs_ops.c +++ /dev/null @@ -1,1474 +0,0 @@ -/* $Id$ - * - * Original version of this file from p3nfsd-5.4 by - * Rudolf Koenig (rfkoenig@immd4.informatik.uni-erlangen.de) - * - * Modifications for plputils by Fritz Elfert - * - */ -#include "OSdefs.h" -#include -#include -#include -#if defined(__SVR4) || defined(__GLIBC__) || defined(__NetBSD__) -#include -#include -#include -#endif -#include "nfs_prot.h" -#include "mp.h" -#include "rfsv_api.h" -#include "builtins.h" - -static device *devices; -struct cache *attrcache = NULL; - -long param_read(builtin_node *node, char *buf, unsigned long offset, long len) { - char tmp[10]; - unsigned long val = 0; - - if (!strcmp(node->name, "acache")) - val = cache_keep; - if (!strcmp(node->name, "dcache")) - val = devcache_keep; - if (!strcmp(node->name, "debuglevel")) - val = debug; - sprintf(tmp, "%ld\n", val); - if (offset >= strlen(tmp)) - return 0; - strncpy(buf, &tmp[offset], len); - return strlen(buf); -} - -long param_write(builtin_node *node, char *buf, unsigned long offset, long len) { - unsigned long val; - - if (len > 1 && offset == 0) { - int res = sscanf(buf, "%ld", &val); - if (res == 1) { - if (!strcmp(node->name, "acache")) - cache_keep = val; - if (!strcmp(node->name, "dcache")) - devcache_keep = val; - if (!strcmp(node->name, "debuglevel")) { - if (val != debug) { - if (val > debug) - debug = val; - debuglog("Set debug level to %d\n", val); - debug = val; - } - } - } - } - return len; -} - -long param_getsize(builtin_node *node) { - char tmp[10]; - return param_read(node, tmp, 0, sizeof(tmp)); -} - -long exit_write(builtin_node *node, char *buf, unsigned long offset, long len) { - if (len >= 4 && offset == 0) { - if (!strncmp(buf, "stop", 4)) - exiting = 5; /* Let's try it 5 times (10 sec) */ - } - return len; -} - -long exit_read(builtin_node *node, char *buf, unsigned long offset, long len) { - if (offset > 4) - return 0; - if ((len + offset) > 5) - len = 5 - offset; - strncpy(buf, "----\n", len); - return strlen(buf); -} - -long user_write(builtin_node *node, char *buf, unsigned long offset, long len) { - char tmp[256]; - if (len > 1 && offset == 0) { - char *p; - - if (len > (sizeof(tmp) - 1)) - len = sizeof(tmp) - 1; - strncpy(tmp, buf, len); - debuglog("pwrite: %d\n", len); - tmp[len] = '\0'; - if ((p = strchr(tmp, '\n'))) - *p = '\0'; - set_owner(tmp, 0); - } - return len; -} - -long user_read(builtin_node *node, char *buf, unsigned long offset, long len) { - struct passwd *pw = getpwuid(root_fattr.uid); - char tmp[255]; - - if (pw) - sprintf(tmp, "%s\n", pw->pw_name); - else - sprintf(tmp, "???\n"); - endpwent(); - if (offset >= strlen(tmp)) - return 0; - strncpy(buf, &tmp[offset], len); - return strlen(buf); -} - -long user_getsize(builtin_node *node) { - char tmp[255]; - return user_read(node, tmp, 0, sizeof(tmp)); -} - -static long generic_sattr(builtin_node *p, unsigned long sa, unsigned long da) { - p->attr |= sa; - p->attr &= ~da; - return 0; -} - -long generic_getlinks(builtin_node *node) { - builtin_child *cp = node->childs; - long ncount = 0; - - while (cp) { - if ((cp->node->flags & BF_EXISTS_ALWAYS) || rfsv_isalive()) - ncount++; - cp = cp->next; - } - return ncount; -} - -long generic_getdents(builtin_node *node, dentry **e) { - builtin_child *cp = node->childs; - - while (cp) { - if ((cp->node->flags & BF_EXISTS_ALWAYS) || rfsv_isalive()) { - dentry *tmp = (dentry *)calloc(1, sizeof(dentry)); - if (!tmp) - return -1; - tmp->time = time(0); - tmp->size = cp->node->getsize ? cp->node->getsize(cp->node) : cp->node->size; - tmp->attr = cp->node->attr; - tmp->name = strdup(cp->node->name); - tmp->next = *e; - *e = tmp; - } - cp = cp->next; - } - return 0; -} - -static builtin_node *builtins = NULL; -static void dump_proctree(builtin_node *n); - -static void clear_procs(builtin_child **childs) { - builtin_child **cp = childs; - - debuglog("Before clear_procs\n"); - dump_proctree(builtins); - while (*cp) { - if ((*cp)->node->flags & BF_ISPROCESS) { - builtin_child *tmp = *cp; - *cp = (*cp)->next; - unregister_builtin(tmp->node); - free(tmp); - } else - cp = &((*cp)->next); - } - debuglog("After clear_procs\n"); - dump_proctree(builtins); -} - -static time_t procs_stamp = 0; -static long procs_keep = 10; - -static long proc_getlinks(builtin_node *node) { - builtin_child *cp; - long ncount = 0; - - if ((time(0) - procs_stamp) > procs_keep) { - debuglog("PROCESSLIST\n"); - clear_procs(&node->childs); - rpcs_ps(); - procs_stamp = time(0); - debuglog("After rpcs_ps\n"); - dump_proctree(builtins); - } - cp = node->childs; - while (cp) { - if ((cp->node->flags & BF_EXISTS_ALWAYS) || rfsv_isalive()) - ncount++; - cp = cp->next; - } - return ncount; -} - -static long proc_getdents(builtin_node *node, dentry **e) { - builtin_child *cp = node->childs; - - while (cp) { - if ((cp->node->flags & BF_EXISTS_ALWAYS) || rfsv_isalive()) { - dentry *tmp = (dentry *)calloc(1, sizeof(dentry)); - if (!tmp) - return -1; - tmp->time = time(0); - tmp->size = cp->node->getsize ? cp->node->getsize(cp->node) : cp->node->size; - tmp->attr = cp->node->attr; - tmp->name = strdup(cp->node->name); - tmp->next = *e; - *e = tmp; - } - cp = cp->next; - } - return 0; -} - - -static builtin_node proc_node = { - NULL, NULL, NULL, NULL, "proc", BF_EXISTS_ALWAYS|BF_NOCACHE, PSI_A_DIR, 0, NULL, NULL, NULL, NULL, proc_getlinks, proc_getdents -}; - -static builtin_node fixed_builtins[] = { - { NULL, NULL, NULL, NULL, "owner", 0, PSI_A_READ | PSI_A_RDONLY, 0, rpcs_ownerSize, rpcs_ownerRead, NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL, "debuglevel", BF_EXISTS_ALWAYS|BF_NOCACHE, PSI_A_READ, 0, param_getsize, param_read, param_write, generic_sattr, NULL, NULL }, - { NULL, NULL, NULL, NULL, "acache", BF_EXISTS_ALWAYS|BF_NOCACHE, PSI_A_READ, 0, param_getsize, param_read, param_write, generic_sattr, NULL, NULL }, - { NULL, NULL, NULL, NULL, "dcache", BF_EXISTS_ALWAYS|BF_NOCACHE, PSI_A_READ, 0, param_getsize, param_read, param_write, generic_sattr, NULL, NULL }, - { NULL, NULL, NULL, NULL, "unixowner", BF_EXISTS_ALWAYS|BF_NOCACHE, PSI_A_READ, 0, user_getsize, user_read, user_write, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL, "exit", BF_EXISTS_ALWAYS|BF_NOCACHE, PSI_A_READ, 5, NULL, exit_read, exit_write, NULL, NULL, NULL }, -}; -static int num_fixed_builtins = sizeof(fixed_builtins) / sizeof(builtin_node); - -static void dump_proctree(builtin_node *n) { - while (n) { - if (n->name) - debuglog("node@%p, \"%s\"\n", n, n->name); - else - debuglog("node@%p, \"(null)\"\n", n); - if (n->childs) { - builtin_child *c = n->childs; - debuglog("Childs:\n"); - while (c) { - if (c->node) - debuglog(" %s\n", c->node->name ? c->node->name : "(null)"); - c = c->next; - } - } - if (n->parent) - debuglog("Parent: %s\n", n->parent->name); - n = n->next; - } -} - -static int add_child(builtin_child **childs, builtin_node *node) { - builtin_child *newc = malloc(sizeof(builtin_child)); - if (!newc) { - errorlog("Out of memory in add_child %s\n", node->name); - return -1; - } - newc->next = *childs; - newc->node = node; - *childs = newc; - return 0; -} - -static int remove_child(builtin_child **childs, builtin_node *node) { - builtin_child **cp = childs; - - if (debug) - debuglog("remove_child %s\n", node->name); - while (*cp) { - if ((*cp)->node == node) { - builtin_child *tmp = *cp; - *cp = (*cp)->next; - free(tmp); - return 0; - } - cp = &((*cp)->next); - } - return -1; -} - -char *builtin_path(builtin_node *node) { - static char tmp[1024]; - char tmp2[1024]; - - strcpy(tmp, node->name); - node = node->parent; - while (node) { - sprintf(tmp2, "%s\\%s", node->name, tmp); - strcpy(tmp, tmp2); - node = node->parent; - } - return tmp; -} - -int unregister_builtin(builtin_node *node) { - builtin_child *cp = node->childs; - builtin_node **n; - - /** - * Unlink and free childs. - */ - if (debug) - debuglog("unregister_builtin %s\n", node->name); - - while (cp) { - builtin_child *old = cp; - cp->node->parent = 0L; - unregister_builtin(cp->node); - cp = cp->next; - free(old); - } - /** - * Unlink ourselves from parent child list. - */ - if (node->parent) - remove_child(&node->parent->childs, node); - n = &builtins; - while (*n) { - if (*n == node) { - *n = node->next; - break; - } else - n = &(*n)->next; - } - if (node->name) - free(node->name); - if (node->private_data) - free(node->private_data); - free(node); - return 0; -} - -builtin_node *register_builtin(char *parent, builtin_node *node) { - builtin_node *bn; - builtin_node *parent_node = 0L; - - debuglog("register_builtin node=%p\n", node); - if (!node) { - errorlog("register_builtin called with NULL node\n"); - return NULL; - } - if (!node->name) { - errorlog("register_builtin called without name\n"); - return NULL; - } - if (parent) { - debuglog("register_builtin parent: %s\n", parent); - for (bn = builtins; bn; bn = bn->next) { - debuglog("cmp parent: %s %s\n", builtin_path(bn), parent); - if (!strcmp(builtin_path(bn), parent)) { - debuglog("cmp parent found bn=%s\n", bn->name); - break; - } - } - if (!bn) { - errorlog("register_builtin for %s called with nonexistent parent %s\n", node->name, parent); - return NULL; - } - parent_node = bn; - } - bn = malloc(sizeof(builtin_node)); - if (!bn) { - errorlog("out of memory while registering builtin %s\n", node->name); - return NULL; - } - memset(bn, 0, sizeof(builtin_node)); - bn->name = strdup(node->name); - if (!bn->name) { - errorlog("out of memory while registering builtin %s\n", node->name); - free(bn); - return NULL; - } - if (parent_node) - debuglog("register_builtin %s in %s\n", node->name, builtin_path(parent_node)); - else - debuglog("register_builtin %s\n", node->name); - bn->parent = parent_node; - bn->flags = node->flags; - bn->attr = node->attr; - bn->size = node->size; - bn->getsize = node->getsize; - bn->read = node->read; - bn->write = node->write; - bn->sattr = node->sattr; - bn->getlinks = node->getlinks; - bn->getdents = node->getdents; - bn->private_data = node->private_data; - if (parent_node) { - debuglog("Add child %s in %s\n", bn->name, bn->parent->name); - if (add_child(&(parent_node->childs), bn)) { - errorlog("Couldn't add child %s\n", bn->name); - free(bn->name); - free(bn); - return NULL; - } - } - bn->next = builtins; - builtins = bn; - debuglog("After register_builtin\n"); - dump_proctree(builtins); - debuglog("register_builtin new node=%p\n", bn); - return bn; -} - -/* - * nfsd returned NFSERR_STALE if the Psion wasn't present, but I didn't like - * it because the kernel returns the same when the nfsd itself is absent - */ - -#define NO_PSION NFSERR_NXIO - -/* FIXME: Send create attributes */ -static struct diropres * -create_it(createargs *ca, int isdir) -{ - static struct diropres res; - p_inode *dirinode = get_num(fh2inode(ca->where.dir.data)); - char *name = dirinode->name; - fattr *fp; - p_inode *inode; - u_int32_t phandle; - int rfsv_ret; - - debuglog("create: in %s %s (%#o, %d)\n", - name, ca->where.name, ca->attributes.mode, isdir); - - name = build_path(name, ca->where.name); - - if (isdir) - rfsv_ret = rfsv_mkdir(name); - else { - rfsv_ret = rfsv_fcreate(0x200, name, &phandle); - if (rfsv_ret == 0) - rfsv_ret = rfsv_fclose(phandle); - } - if (rfsv_ret) { - res.status = rfsv_isalive() ? NFSERR_NAMETOOLONG : NO_PSION; - return &res; - } - inode = get_nam(name); - inode2fh(inode->inode, res.diropres_u.diropres.file.data); - - fp = &res.diropres_u.diropres.attributes; - bzero((char *) fp, sizeof(fp)); - if (isdir) { - fp->type = NFDIR; - fp->mode = NFSMODE_DIR | 0700; - fp->nlink = 2; - } else { - fp->type = NFREG; - fp->mode = NFSMODE_REG | 0600; - fp->nlink = 1; - } - - fp->uid = root_fattr.uid; - fp->gid = root_fattr.gid; - fp->blocksize = BLOCKSIZE; - fp->fileid = inode->inode; - fp->atime.seconds = fp->mtime.seconds = fp->ctime.seconds = time((time_t *) 0); - - res.status = NFS_OK; - - rem_cache(&attrcache, dirinode->inode); - rem_cache(&attrcache, inode->inode); - if (rfsv_isalive()) - add_cache(&attrcache, inode->inode, fp); - return &res; -} - -struct diropres * -nfsproc_create_2(createargs *ca) -{ - return create_it(ca, 0); -} - -struct diropres * -nfsproc_mkdir_2(createargs *ca) -{ - return create_it(ca, 1); -} - -static void -attr2pattr(long oattr, long nattr, long *psisattr, long *psidattr) -{ - /* - * Following flags have to be set in order to let backups - * work properly - */ - *psisattr = *psidattr = 0; - if ((oattr & 0400) != (nattr & 0400)) { - if (nattr & 0400) /* readable */ - *psisattr |= PSI_A_READ; - else - *psidattr |= PSI_A_READ; - } - if ((oattr & 0200) != (nattr & 0200)) { - if (nattr & 0200) /* readonly */ - *psidattr |= PSI_A_RDONLY; - else - *psisattr |= PSI_A_RDONLY; - } - if ((oattr & 0020) != (nattr & 0020)) { - if (nattr & 0020) /* group-write -> archive */ - *psisattr |= PSI_A_ARCHIVE; - else - *psidattr |= PSI_A_ARCHIVE; - } - if ((oattr & 0004) != (nattr & 0004)) { - if (nattr & 0004) /* Not world-read -> hidden */ - *psidattr |= PSI_A_HIDDEN; - else - *psisattr |= PSI_A_HIDDEN; - } - if ((oattr & 0002) != (nattr & 0002)) { - if (nattr & 0002) /* world-write -> system */ - *psisattr |= PSI_A_SYSTEM; - else - *psidattr |= PSI_A_SYSTEM; - } -} - -static void -pattr2attr(long psiattr, long size, long ftime, fattr *fp, int inode) -{ - bzero((char *) fp, sizeof(*fp)); - - if (psiattr & PSI_A_DIR) { - fp->type = NFDIR; - fp->mode = NFSMODE_DIR | 0700; - /* - * Damned filesystem. - * We have to count the number of subdirectories - * on the psion. - */ - fp->nlink = 0; - fp->size = BLOCKSIZE; - fp->blocks = 1; - } else { - fp->type = NFREG; - fp->mode = NFSMODE_REG; - fp->nlink = 1; - fp->size = size; - fp->blocks = (fp->size + BLOCKSIZE - 1) / BLOCKSIZE; - - /* - * Following flags have to be set in order to let backups - * work properly - */ - if (psiattr & PSI_A_READ) - fp->mode |= 0400; /* File readable (?) */ - if (!(psiattr & PSI_A_RDONLY)) - fp->mode |= 0200; /* File writeable */ - /* fp->mode |= 0100; File executable */ - if (!(psiattr & PSI_A_HIDDEN)) - fp->mode |= 0004; /* Not Hidden <-> world read */ - if (psiattr & PSI_A_SYSTEM) - fp->mode |= 0002; /* System <-> world write */ - if (psiattr & PSI_A_VOLUME) - fp->mode |= 0001; /* Volume <-> world exec */ - if (psiattr & PSI_A_ARCHIVE) - fp->mode |= 0020; /* Modified <-> group write */ - /* fp->mode |= 0040; Byte <-> group read */ - /* fp->mode |= 0010; Text <-> group exec */ - } - - fp->uid = root_fattr.uid; - fp->gid = root_fattr.gid; - fp->blocksize = BLOCKSIZE; - fp->fileid = inode; - fp->rdev = fp->fsid = FID; - fp->atime.seconds = ftime; - fp->mtime.seconds = fp->ctime.seconds = fp->atime.seconds; -} - -static int proc_top = 0; - -static int -query_devices() -{ - device *dp, *np; - int link_count = 2; /* set the root link count */ - - if (!proc_top) { - int i; - if (register_builtin(NULL, &proc_node)) { - for (i = 0; i < num_fixed_builtins; i++) - if (register_builtin(proc_node.name, &fixed_builtins[i])) - proc_top++; - } else - errorlog("Couldn't register /proc\n"); - if (proc_top != num_fixed_builtins) - proc_top = 0; - } - if (query_cache) - return 0; - for (dp = devices; dp; dp = np) { - np = dp->next; - free(dp->name); - free(dp); - } - devices = 0; - debuglog("RFSV drivelist\n"); - if (rfsv_drivelist(&link_count, &devices)) - return 1; - query_cache = 1; - devcache_stamp = time(0); - root_fattr.nlink = link_count + 1; - return 0; -} - -static int -mp_dircount(p_inode *inode, long *count) -{ - dentry *e = NULL; - long ret; - builtin_node *bn; - - *count = 0; - debuglog("dircount: %s\n", inode->name); - for (bn = builtins; bn; bn = bn->next) { - if ((!strcmp(builtin_path(bn), inode->name) && (bn->attr & PSI_A_DIR))) { - if (bn->getlinks) - *count = bn->getlinks(bn); - return 0; - } - } - debuglog("RFSV dir %s\n", inode->name); - if ((ret = rfsv_dir(dirname(inode->name), &e))) - return ret; - while (e) { - fattr fp; - char *bp; - dentry *o; - int ni; - - bp = filname(e->name); - ni = get_nam(build_path(inode->name, bp))->inode; - free(e->name); - if (!search_cache(attrcache, ni)) { - pattr2attr(e->attr, e->size, e->time, &fp, ni); - if (rfsv_isalive()) - add_cache(&attrcache, ni, &fp); - } - o = e; - e = e->next; - free(o); - if (fp.type == NFDIR) - (*count)++; - } - debuglog("count %d\n", *count); - return 0; -} - -struct attrstat * -nfsproc_getattr_2(struct nfs_fh *fh) -{ - static struct attrstat res; - p_inode *inode = get_num(fh2inode(fh->data)); - fattr *fp = &res.attrstat_u.attributes; - struct cache *cp; - long pattr; - long psize; - long ptime; - long dcount; - int builtin = 0; - int l; - - debuglog("getattr: '%s', %d\n", inode->name, inode->inode); - res.status = NFS_OK; - - if ((cp = search_cache(attrcache, inode->inode))) { - debuglog("getattr: cache hit\n"); - *fp = cp->attr; /* gotcha */ - if (fp->nlink > 0) - return &res; - } - l = strlen(inode->name); - - if (inode->inode == root_fattr.fileid) { - /* It's the root inode */ - debuglog("getattr: root inode (%#o)\n", root_fattr.mode); - - if (query_devices()) /* root inode and proc is always there */ - root_fattr.nlink = 3; - *fp = root_fattr; - } else if (l == 2 && inode->name[1] == ':') { - debuglog("getattr: device\n"); - res.status = NO_PSION; - if (!query_devices()) { - device *dp; - - for (dp = devices; dp; dp = dp->next) { - debuglog("cmp '%c', '%s'\n", dp->letter, - inode->name); - if (dp->letter == inode->name[0]) - break; - } - debuglog("device: %s\n", dp ? "exists" : "does not exist"); - if (dp) { - res.status = NFS_OK; - *fp = root_fattr; - /* If it's writeable... */ - if (dp->attrib != 7) - fp->mode |= 0200; - fp->fileid = inode->inode; - if (mp_dircount(inode, &dcount)) { - res.status = rfsv_isalive() ? NFSERR_NOENT : NO_PSION; - return &res; - } - if (fp->nlink != dcount + 2) - fp->mtime.seconds = time(0); - fp->nlink = dcount + 2; - } - } - } else { - builtin_node *bn; - - for (bn = builtins; bn; bn = bn->next) { - if (!strcmp(inode->name, builtin_path(bn))) { - pattr = bn->attr; - if (pattr & PSI_A_DIR) - psize = 0; - else - psize = (bn->getsize) ? bn->getsize(bn) : bn->size; - ptime = time(0); - res.status = NFS_OK; - builtin = 1; - if (bn->flags && BF_NOCACHE) - builtin++; - break; - } - } - - if (!builtin) { - debuglog("getattr: fileordir\n"); - /* It's a normal file/dir */ - debuglog("RFSV getattr %s\n", inode->name); - if (rfsv_getattr(inode->name, &pattr, &psize, &ptime)) { - res.status = rfsv_isalive() ? NFSERR_NOENT : NO_PSION; - return &res; - } - } - pattr2attr(pattr, psize, ptime, fp, fh2inode((char *) fh->data)); - if (fp->type == NFDIR) { - debuglog("%s is a dir\n", inode->name); - if (mp_dircount(inode, &dcount)) { - res.status = rfsv_isalive() ? NFSERR_NOENT : NO_PSION; - return &res; - } - if (fp->nlink != dcount + 2) - fp->mtime.seconds = time(0); - fp->nlink = dcount + 2; - } - } - if (rfsv_isalive() && builtin < 2) - add_cache(&attrcache, inode->inode, fp); - return &res; -} - -struct diropres * -nfsproc_lookup_2(diropargs *da) -{ - static struct diropres res; - struct attrstat *gres; - p_inode *inode = get_num(fh2inode(da->dir.data)); - char *fp = res.diropres_u.diropres.file.data; - - if (!inode) { - debuglog("lookup: stale fh\n"); - res.status = NO_PSION; - return &res; - } - debuglog("lookup: in '%s' (%d) finding '%s'\n", - inode->name, inode->inode, da->name); - if (!strcmp(da->name, ".")) - inode2fh(fh2inode(da->dir.data), fp); - else if (!strcmp(da->name, "..")) - inode2fh(getpinode(inode), fp); - else - inode2fh(get_nam(build_path(inode->name, da->name))->inode, fp); - - gres = nfsproc_getattr_2((struct nfs_fh *) fp); - - res.status = gres->status; - res.diropres_u.diropres.attributes = gres->attrstat_u.attributes; - return &res; -} - -#define RA_MAXCOUNT ~0 - -static void -addentry(readdirargs *ra, entry ***where, int *searchi, int inode, char *name) -{ - int l, rndup; - - if (*searchi) { - if (*searchi == inode) - *searchi = 0; - return; - } - if (ra->count == RA_MAXCOUNT) - return; - - /* - * Count the bytes needed for the xdr encoded data. Xdr is trickier than - * one (me :-) might think: Xdr converts a string into - * length (4 bytes) + data (rounded up to 4 bytes). - */ -#define XDR_UNIT 4 - l = strlen(name); - if ((rndup = l % XDR_UNIT) > 0) - l += XDR_UNIT - rndup; - l += XDR_UNIT; /* Length of name */ - l += sizeof(entry); - - if (l > ra->count) { - ra->count = RA_MAXCOUNT; - return; - } - ra->count -= l; - - **where = (entry *) malloc(sizeof(entry)); - (**where)->fileid = inode; - (**where)->name = (char *) strdup(name); - *(int *) (**where)->cookie = inode; - (**where)->nextentry = 0; - *where = &(**where)->nextentry; -} - -struct readdirres * -nfsproc_readdir_2(readdirargs *ra) -{ - static readdirres res; - p_inode *inode = get_num(fh2inode(ra->dir.data)); - entry *centry, *fentry, **cp; - int searchinode; - - if (!inode) { - debuglog("readdir: stale fh\n"); - res.status = NO_PSION; - return &res; - } - cp = &res.readdirres_u.reply.entries; - for (fentry = *cp; fentry; fentry = centry) { - centry = fentry->nextentry; - free(fentry->name); - free(fentry); - } - *cp = 0; - searchinode = *(int *) ra->cookie; - - debuglog("readdir: %s, cookie:%x, count:%d\n", - inode->name, searchinode, ra->count); - - /* . & .. */ - addentry(ra, &cp, &searchinode, inode->inode, "."); - addentry(ra, &cp, &searchinode, getpinode(inode), ".."); - - if (inode->inode == root_fattr.fileid) { /* Root directory */ - device *dp; - - addentry(ra, &cp, &searchinode, get_nam("/proc")->inode, "proc"); - if (query_devices()) { - res.readdirres_u.reply.eof = ra->count == RA_MAXCOUNT ? 0 : 1; - res.status = NFS_OK; - debuglog("readdir: eof=%d\n", res.readdirres_u.reply.eof); - return &res; - } - for (dp = devices; dp; dp = dp->next) { - char n[3]; - sprintf(n, "%c:", dp->letter); - addentry(ra, &cp, &searchinode, get_nam(dp->name)->inode, n); - } - } else { - builtin_node *bn; - int builtin = 0; - dentry *e = NULL; - debuglog("nfsdir: dir\n"); - - for (bn = builtins; bn ; bn = bn->next) - if (!strcmp(inode->name, builtin_path(bn))) { - if (bn->attr & PSI_A_DIR) { - if (bn->getdents) - bn->getdents(bn, &e); - builtin = 1; - } else { - res.status = NFSERR_NOTDIR; - return &res; - } - } - if (!builtin) { - debuglog("RFSV dir2 %s\n", inode->name); - if (rfsv_dir(dirname(inode->name), &e)) { - res.status = rfsv_isalive() ? NFSERR_NOENT : NO_PSION; - return &res; - } - } - while (e) { - fattr fp; - dentry *o; - int ni; - char *bp; - - bp = filname(e->name); - if (debug > 1) - debuglog(" %s\n", bp); - ni = get_nam(build_path(inode->name, bp))->inode; - addentry(ra, &cp, &searchinode, ni, (char *) bp); - free(e->name); - pattr2attr(e->attr, e->size, e->time, &fp, ni); - if (rfsv_isalive()) - add_cache(&attrcache, ni, &fp); - o = e; - e = e->next; - free(o); - } - } - - res.readdirres_u.reply.eof = ra->count == RA_MAXCOUNT ? 0 : 1; - res.status = NFS_OK; - debuglog("readdir: eof=%d\n", res.readdirres_u.reply.eof); - return &res; -} - -struct attrstat * -nfsproc_setattr_2(sattrargs *sa) -{ - static struct attrstat res; - p_inode *inode = get_num(fh2inode(sa->file.data)); - fattr *fp; - builtin_node *bn; - int builtin = 0; - - if (!inode) { - debuglog("setattr: stale fh\n"); - res.status = NO_PSION; - return &res; - } - debuglog("setattr '%s'\n", inode->name); - res = *nfsproc_getattr_2(&sa->file); - if (res.status != NFS_OK) - return &res; - fp = &res.attrstat_u.attributes; - - for (bn = builtins; bn; bn = bn->next) - if (!strcmp(inode->name, builtin_path(bn))) { - builtin = 1; - break; - } - - if ((fp->type == NFREG) && - (sa->attributes.size != -1) && - (sa->attributes.size != fp->size)) { - debuglog("RFSV setsize %s %d\n", inode->name, sa->attributes.size); - if (builtin) { - if (bn->attr & PSI_A_RDONLY) { - res.status = NFSERR_ACCES; - return &res; - } - } else { - if (rfsv_setsize(inode->name, sa->attributes.size) != 0) { - // FIXME: more different error codes - res.status = rfsv_isalive() ? NFSERR_ROFS : NO_PSION; - return &res; - } - } - fp->size = sa->attributes.size; - rem_cache(&attrcache, inode->inode); - if (rfsv_isalive()) - add_cache(&attrcache, inode->inode, fp); - } - if ((sa->attributes.mtime.seconds != fp->mtime.seconds) && - (sa->attributes.mtime.seconds != -1) && !builtin) { - debuglog("RFSV setmtime %s %d\n", inode->name, sa->attributes.mtime.seconds); - if (rfsv_setmtime(inode->name, sa->attributes.mtime.seconds)) { - res.status = (rfsv_isalive()) ? NFSERR_ACCES : NO_PSION; - return &res; - } - fp->mtime.seconds = fp->atime.seconds = sa->attributes.mtime.seconds; - rem_cache(&attrcache, inode->inode); - if (rfsv_isalive()) - add_cache(&attrcache, inode->inode, fp); - } - if ((sa->attributes.mode != (fp->mode & ~NFSMODE_MASK)) && - (sa->attributes.mode != -1)) { - long psisattr, psidattr; - attr2pattr(sa->attributes.mode, fp->mode, &psisattr, &psidattr); - debuglog("RFSV setattr '%s' %d %d\n", inode->name, psisattr, psidattr); - if (builtin) { - if ((bn->sattr == NULL) || bn->sattr(bn, psisattr, psidattr)) { - res.status = NFSERR_ACCES; - return &res; - } - } else { - if (rfsv_setattr(inode->name, psisattr, psidattr)) { - res.status = (rfsv_isalive()) ? NFSERR_ACCES : NO_PSION; - return &res; - } - } - debuglog("changing mode from %o to %o\n", fp->mode, (fp->mode & NFSMODE_MASK) | sa->attributes.mode); - fp->mode = (fp->mode & NFSMODE_MASK) | sa->attributes.mode; - rem_cache(&attrcache, inode->inode); - if (rfsv_isalive() && !builtin) - add_cache(&attrcache, inode->inode, fp); - } - res.status = NFS_OK; - return &res; -} - -static nfsstat * -remove_it(diropargs *da, int isdir) -{ - static nfsstat res; - p_inode *inode = get_num(fh2inode(da->dir.data)); - long rfsv_res; - - if (!inode) { - debuglog("remove_it: stale fh\n"); - res = NO_PSION; - return &res; - } - debuglog("remove_it: in %s: %s (%d)\n", inode->name, da->name, isdir); - - rem_cache(&attrcache, inode->inode); - if (isdir) { - debuglog("RFSV rmdir %s\n", build_path(inode->name, da->name)); - rfsv_res = rfsv_rmdir(build_path(inode->name, da->name)); - } else { - debuglog("RFSV remove %s\n", build_path(inode->name, da->name)); - rfsv_res = rfsv_remove(build_path(inode->name, da->name)); - } - if (rfsv_res != 0) { - res = rfsv_isalive() ? NFSERR_ACCES : NO_PSION; - return &res; - } - res = NFS_OK; - return &res; -} - -nfsstat * -nfsproc_remove_2(diropargs *da) -{ - return remove_it(da, 0); -} - -nfsstat * -nfsproc_rmdir_2(diropargs *da) -{ - return remove_it(da, 1); -} - -nfsstat * -nfsproc_rename_2(renameargs *ra) -{ - static nfsstat res; - p_inode *from = get_num(fh2inode(ra->from.dir.data)); - p_inode *to = get_num(fh2inode(ra->to.dir.data)); - /* FIXME: Buffer overflow */ - char ldata[300], *old, c; - - if (!from || !to) { - debuglog("rename: stale fh\n"); - res = NO_PSION; - return &res; - } - strcpy(ldata + 1, build_path(to->name, ra->to.name)); - *ldata = strlen(ldata + 1); - c = *ldata + 1; - old = build_path(from->name, ra->from.name); - - res = NFS_OK; - debuglog("RFSV rename %s -> %s\n", old, ldata + 1); - if (rfsv_rename(old, ldata + 1)) { - res = (rfsv_isalive()) ? NFSERR_ACCES : NO_PSION; - return &res; - } - if (res == NFS_OK) { - /* Preserve inode */ - strcpy((char *) ldata, build_path(to->name, ra->to.name)); - (void) re_nam(build_path(from->name, ra->from.name), ldata); - } - rem_cache(&attrcache, from->inode); - rem_cache(&attrcache, to->inode); - return &res; -} - -/* ARGSUSED */ -struct statfsres * -nfsproc_statfs_2(struct nfs_fh *fh) -{ - static statfsres res; - statfsokres *rp; - device *dp; - - debuglog("statfs..\n"); - - rp = &res.statfsres_u.reply; - rp->tsize = PBUFSIZE; - rp->bsize = BLOCKSIZE; - rp->blocks = rp->bfree = 0; - res.status = NFS_OK; - - if (query_devices()) { - /* Allow to mount it without the psion attached */ - if (rfsv_isalive()) - return &res; /* res.status = NO_PSION; Hmm */ - } - for (dp = devices; dp; dp = dp->next) { - rp->blocks += (dp->total + BLOCKSIZE - 1) / BLOCKSIZE; - rp->bfree += (dp->free + BLOCKSIZE - 1) / BLOCKSIZE; - } - rp->bavail = rp->bfree; - - return &res; -} - -/* - * Problem: - * Since we are slow (Max 2Kbyte/s) and the biods are very impatient, - * we receive each request (number of biods + 1 for the kernel itself) - * times, this number can be lower for the last block. :-( - * Solution: (not the best, probably) - * Cache the read data. This cache will be invalidated if there are - * no more requests in the queue for at least XXX seconds. - * See also write :-( - */ -struct readres * -nfsproc_read_2(struct readargs *ra) -{ - static struct readres res; - static unsigned char rop[NFS_MAXDATA]; - p_inode *inode = get_num(fh2inode(ra->file.data)); - fattr *fp; - struct cache *cp; - struct dcache *dcp; - long pattr; - long psize; - long ptime; - int len = 0; - builtin_node *bn; - int builtin = 0; - - if (!inode) { - debuglog("read: stale fh\n"); - res.status = NO_PSION; - return &res; - } - debuglog("read: %s off:%d count:%d\n", inode->name, ra->offset, ra->count); - - cp = search_cache(attrcache, inode->inode); - if (cp && (dcp = search_dcache(cp, ra->offset, ra->count))) { - debuglog("read: dcache hit\n"); - res.readres_u.reply.attributes = cp->attr; - bcopy(dcp->data, res.readres_u.reply.data.data_val, ra->count); - res.readres_u.reply.data.data_len = ra->count; - - res.status = NFS_OK; - return &res; - } - - debuglog("RFSV read %s\n", inode->name); - - for (bn = builtins; bn; bn = bn->next) { - if (!strcmp(inode->name, builtin_path(bn))) { - if (bn->attr & PSI_A_DIR) { - res.status = NFSERR_ISDIR; - return &res; - } - if (bn->read) { - len = bn->read(bn, rop, ra->offset, ra->count); - builtin = 1; - break; - } else { - res.status = NFSERR_IO; - return &res; - } - } - } - - if (!builtin) { - if (rfsv_read(rop, ra->offset, - ra->count, inode->name) < 0) { - res.status = rfsv_isalive() ? NFSERR_NOENT : NO_PSION; - return &res; - } - } - fp = &res.readres_u.reply.attributes; - if (!cp) { - // Problem: if an EPOC process is enlarging the file, we won't recognize it - debuglog("RFSV getattr '%s'\n", inode->name); - if (builtin) { - pattr = bn->attr; - psize = (bn->getsize) ? bn->getsize(bn) : bn->size; - ptime = time(0); - } else - rfsv_getattr(inode->name, &pattr, &psize, &ptime); - pattr2attr(pattr, psize, ptime, fp, fh2inode((char *)ra->file.data)); - cp = add_cache(&attrcache, inode->inode, fp); - } else { - *fp = cp->attr; - } - - len = cp->actual_size - ra->offset; - if (len > ra->count) - len = ra->count; - if (cp->actual_size < ra->offset) - len = 0; - if (debug > 1) - debuglog("Read: filesize %d read %d @ %d\n", cp->actual_size, len, ra->offset); - if (len) { - dcp = add_dcache(cp, ra->offset, ra->count, rop); - dcp->towrite = 0; /* don't write it back */ - } - if (builtin) - rem_cache(&attrcache, inode->inode); - res.readres_u.reply.data.data_len = len; - res.readres_u.reply.data.data_val = (char *) rop; - - res.status = NFS_OK; - return &res; -} - - -/* - * Returns cachepointer on full hit, 0 on partial or no hit, - * see below solaris comment - */ - -static int -addwritecache(struct cache *cp, int doff, int dlen, unsigned char *dp) -{ - struct dcache *dcp; - int len, changed, os, oe; - unsigned char *pd, *pc; - - /* - * do the cachesearch: we are interested in partial hits, as we don't - * want to write anything twice (flash ram) - */ - for (dcp = cp->dcache; dcp; dcp = dcp->next) - if (doff < dcp->offset + dcp->len && doff + dlen > dcp->offset) - break; - - if (!dcp) { - /* phew, nothing fancy to do */ - add_dcache(cp, doff, dlen, dp); - return 0; - } - os = doff > dcp->offset ? doff : dcp->offset; - oe = doff + dlen < dcp->offset + dcp->len ? doff + dlen : dcp->offset + dcp->len; - pd = dp + os - doff; - pc = dcp->data + os - dcp->offset; - len = oe - os; - - changed = 0; - if (bcmp(pd, pc, len)) { - bcopy(pd, pc, len); - dcp->towrite = 1; - changed = 1; - } - if (doff >= dcp->offset && doff + dlen <= dcp->offset + dcp->len) { - debuglog("write: full cache hit\n"); - return !changed; - } - debuglog("write: partial cache hit (off %d len %d)\n", dcp->offset, dcp->len); - - /* Do we have some data below the cached area... */ - if (doff < dcp->offset) - (void) addwritecache(cp, doff, dcp->offset - doff, dp); - - /* ...or some above? */ - len = (doff + dlen) - (dcp->offset + dcp->len); - if (len > 0) - (void) addwritecache(cp, dcp->offset + dcp->len, len, dp + dlen - len); - - return 0; -} - - - -/* - * The same problem here as above: we receive numerous requests, - * not even in a specified order. The only good thing is that each request - * up to the last is exactly the same size. - * A new problem: - * Since I dunno how to seek to a point beyond the end of the file (psion), - * I can't support the exact semantics of write. Such files will never be - * written completely. :-( - * - * Another dumb solaris (sysv?) problem: if the client is writing 512 byte - * blocks we receive following write requests: - * off 0 len 512, off 0 len 1024, off 0 len 1536, ... so on till len 4096, - * that means 4 times as much data as actually needed. - * We should check if the block was partially written, and write only the - * difference - */ -struct attrstat * -nfsproc_write_2(writeargs *wa) -{ - static struct attrstat res; - p_inode *inode = get_num(fh2inode(wa->file.data)); - struct cache *cp; - struct dcache *dcp; - fattr *fp; - struct attrstat *gres; - int len = 0; - int dlen, doff; - builtin_node *bn; - - if (!inode) { - debuglog("write: stale fh\n"); - res.status = NO_PSION; - return &res; - } - debuglog("write:%s off:%d l:%d\n", inode->name, wa->offset, wa->data.data_len); - - dlen = wa->data.data_len; - doff = wa->offset; - - for (bn = builtins; bn ; bn = bn->next) { - if (!strcmp(inode->name, builtin_path(bn))) { - if (bn->attr & PSI_A_DIR) - res.status = NFSERR_ISDIR; - else { - debuglog("builtin write %s %d@%d\n", inode->name, dlen, doff); - if (bn->write) { - int l = bn->write(bn, (unsigned char *)wa->data.data_val, doff, dlen); - res.status = (l == dlen) ? NFS_OK : NFSERR_IO; - } else - res.status = NFSERR_ACCES; - } - return &res; - } - } - /* fetch attributes */ - if ((cp = search_cache(attrcache, inode->inode)) == 0) { - gres = nfsproc_getattr_2((struct nfs_fh *) wa->file.data); - if (gres->status != NFS_OK) { - res.status = gres->status; - return &res; - } - cp = search_cache(attrcache, inode->inode); - if (!cp) { - errorlog("nfsproc_write_2: cache is NULL\n"); - res.status = NFSERR_IO; - return &res; - } - } - fp = &cp->attr; - if (fp->size < doff + dlen) - fp->size = doff + dlen; - fp->blocks = (fp->size + (BLOCKSIZE - 1)) / BLOCKSIZE; - fp->atime.seconds = fp->mtime.seconds = fp->ctime.seconds = time(0); - - res.attrstat_u.attributes = *fp; - - if (addwritecache(cp, doff, dlen, (unsigned char *) wa->data.data_val)) { - res.status = NFS_OK; - return &res; - } - /* Write out as many blocks from the cache as we can */ - for (;;) { - if (debug > 2) - for (dcp = cp->dcache; dcp; dcp = dcp->next) - debuglog("Check: %d=%d,%d,%d>=%d\n", - inode->inode, cp->inode, dcp->towrite, - cp->actual_size, dcp->offset); - for (dcp = cp->dcache; dcp; dcp = dcp->next) - if (dcp->towrite && cp->actual_size >= dcp->offset) - break; - if (!dcp) /* Can't write any blocks */ - break; - - debuglog("writing off: %d, len: %d, act: %d\n", - dcp->offset, dcp->len, cp->actual_size); - - debuglog("RFSV write %s\n", inode->name); - - if (rfsv_write(dcp->data, dcp->offset, dcp->len, inode->name) != dcp->len) { - debuglog("write: dump failed\n"); - res.status = rfsv_isalive() ? NFSERR_NOSPC : NO_PSION; - return &res; - } - dcp->towrite = 0; - len = dcp->offset + dcp->len; - if (len > cp->actual_size) - cp->actual_size = len; - debuglog("written: new length: %d\n", cp->actual_size); - } - - debuglog("write -> ISOK (%d, %d %d)\n", - res.attrstat_u.attributes.size, - res.attrstat_u.attributes.fileid, - res.attrstat_u.attributes.fsid); - res.status = NFS_OK; - return &res; -} - -/* Dummy routines */ -void * -nfsproc_writecache_2() -{ - static char res; - debuglog("writecache???\n"); - res = (char) NFSERR_FBIG; - return (void *) &res; -} - -void * -nfsproc_null_2() -{ - static char res; - debuglog("null (NFS operation)\n"); - res = (char) NFSERR_FBIG; - return (void *) &res; -} - -void * -nfsproc_root_2() -{ - static char res; - debuglog("root????\n"); - res = (char) NFSERR_FBIG; - return (void *) &res; -} - -/* - * Links and symlinks are not supported on Psion - */ - -/* ARGSUSED */ -nfsstat * -nfsproc_link_2(linkargs *la) -{ - static nfsstat res; - - debuglog("link: not supported\n"); - res = NFSERR_ACCES; - return &res; -} - -/* ARGSUSED */ -struct readlinkres * -nfsproc_readlink_2(struct nfs_fh *fh) -{ - static readlinkres res; - - debuglog("readlink: not supported\n"); - res.status = NFSERR_ACCES; - return &res; -} - -/* ARGSUSED */ -nfsstat * -nfsproc_symlink_2(symlinkargs *sa) -{ - static nfsstat res; - - debuglog("symlink: not supported\n"); - res = NFSERR_ACCES; - return &res; -} diff --git a/plpnfsd/nfs_prot_svc.c b/plpnfsd/nfs_prot_svc.c deleted file mode 100644 index f1ab702..0000000 --- a/plpnfsd/nfs_prot_svc.c +++ /dev/null @@ -1,232 +0,0 @@ -/* $Id$ - * - * Please do not edit this file. - * It was generated using rpcgen. - * And tuned by me (Rudi) - */ - -#include "OSdefs.h" - -#define PORTMAP -#if defined(__SVR4) || defined(__NetBSD__) -#include -#include -#endif -#include -#include -#include "nfs_prot.h" -#include "mp.h" -#if defined(__GLIBC__) || defined(__NetBSD__) -#include -#endif - -#if 0 -static void nfs_program_2(); - -main() -{ - register SVCXPRT *transp; - - (void) pmap_unset(NFS_PROGRAM, NFS_VERSION); - - transp = svcudp_create(RPC_ANYSOCK); - if (transp == NULL) { - fprintf(stderr, "cannot create udp service."); - exit(1); - } - if (!svc_register(transp, NFS_PROGRAM, NFS_VERSION, nfs_program_2, IPPROTO_UDP)) { - fprintf(stderr, "unable to register (NFS_PROGRAM, NFS_VERSION, udp)."); - exit(1); - } - - transp = svctcp_create(RPC_ANYSOCK, 0, 0); - if (transp == NULL) { - fprintf(stderr, "cannot create tcp service."); - exit(1); - } - if (!svc_register(transp, NFS_PROGRAM, NFS_VERSION, nfs_program_2, IPPROTO_TCP)) { - fprintf(stderr, "unable to register (NFS_PROGRAM, NFS_VERSION, tcp)."); - exit(1); - } - - svc_run(); - fprintf(stderr, "svc_run returned"); - exit(1); - /* NOTREACHED */ -} -#endif - -void -nfs_program_2(rqstp, transp) - struct svc_req *rqstp; - register SVCXPRT *transp; -{ - union { - nfs_fh nfsproc_getattr_2_arg; - sattrargs nfsproc_setattr_2_arg; - diropargs nfsproc_lookup_2_arg; - nfs_fh nfsproc_readlink_2_arg; - readargs nfsproc_read_2_arg; - writeargs nfsproc_write_2_arg; - createargs nfsproc_create_2_arg; - diropargs nfsproc_remove_2_arg; - renameargs nfsproc_rename_2_arg; - linkargs nfsproc_link_2_arg; - symlinkargs nfsproc_symlink_2_arg; - createargs nfsproc_mkdir_2_arg; - diropargs nfsproc_rmdir_2_arg; - readdirargs nfsproc_readdir_2_arg; - nfs_fh nfsproc_statfs_2_arg; - } argument; - char *result; - bool_t (*xdr_argument)(), (*xdr_result)(); - char *(*local)(); - - switch (rqstp->rq_proc) { - case NFSPROC_NULL: - xdr_argument = xdr_void; - xdr_result = xdr_void; - local = (char *(*)()) nfsproc_null_2; - break; - - case NFSPROC_GETATTR: - xdr_argument = xdr_nfs_fh; - xdr_result = xdr_attrstat; - local = (char *(*)()) nfsproc_getattr_2; - break; - - case NFSPROC_SETATTR: - xdr_argument = xdr_sattrargs; - xdr_result = xdr_attrstat; - local = (char *(*)()) nfsproc_setattr_2; - break; - - case NFSPROC_ROOT: - xdr_argument = xdr_void; - xdr_result = xdr_void; - local = (char *(*)()) nfsproc_root_2; - break; - - case NFSPROC_LOOKUP: - xdr_argument = xdr_diropargs; - xdr_result = xdr_diropres; - local = (char *(*)()) nfsproc_lookup_2; - break; - - case NFSPROC_READLINK: - xdr_argument = xdr_nfs_fh; - xdr_result = xdr_readlinkres; - local = (char *(*)()) nfsproc_readlink_2; - break; - - case NFSPROC_READ: - xdr_argument = xdr_readargs; - xdr_result = xdr_readres; - local = (char *(*)()) nfsproc_read_2; - break; - - case NFSPROC_WRITECACHE: - xdr_argument = xdr_void; - xdr_result = xdr_void; - local = (char *(*)()) nfsproc_writecache_2; - break; - - case NFSPROC_WRITE: - xdr_argument = xdr_writeargs; - xdr_result = xdr_attrstat; - local = (char *(*)()) nfsproc_write_2; - break; - - case NFSPROC_CREATE: - xdr_argument = xdr_createargs; - xdr_result = xdr_diropres; - local = (char *(*)()) nfsproc_create_2; - break; - - case NFSPROC_REMOVE: - xdr_argument = xdr_diropargs; - xdr_result = xdr_nfsstat; - local = (char *(*)()) nfsproc_remove_2; - break; - - case NFSPROC_RENAME: - xdr_argument = xdr_renameargs; - xdr_result = xdr_nfsstat; - local = (char *(*)()) nfsproc_rename_2; - break; - - case NFSPROC_LINK: - xdr_argument = xdr_linkargs; - xdr_result = xdr_nfsstat; - local = (char *(*)()) nfsproc_link_2; - break; - - case NFSPROC_SYMLINK: - xdr_argument = xdr_symlinkargs; - xdr_result = xdr_nfsstat; - local = (char *(*)()) nfsproc_symlink_2; - break; - - case NFSPROC_MKDIR: - xdr_argument = xdr_createargs; - xdr_result = xdr_diropres; - local = (char *(*)()) nfsproc_mkdir_2; - break; - - case NFSPROC_RMDIR: - xdr_argument = xdr_diropargs; - xdr_result = xdr_nfsstat; - local = (char *(*)()) nfsproc_rmdir_2; - break; - - case NFSPROC_READDIR: - xdr_argument = xdr_readdirargs; - xdr_result = xdr_readdirres; - local = (char *(*)()) nfsproc_readdir_2; - break; - - case NFSPROC_STATFS: - xdr_argument = xdr_nfs_fh; - xdr_result = xdr_statfsres; - local = (char *(*)()) nfsproc_statfs_2; - break; - - default: - svcerr_noproc(transp); - return; - } - memset((char *)&argument, 0, sizeof(argument)); -#if !defined(__SVR4) && !defined(__FreeBSD__) -#if defined(__GLIBC__) || defined(__NetBSD__) - if (!svc_getargs(transp, (xdrproc_t)xdr_argument, (caddr_t)&argument)) { -#else - if (!svc_getargs(transp, xdr_argument, &argument)) { -#endif -#else - if (!svc_getargs(transp, xdr_argument, (char *)&argument)) { -#endif - svcerr_decode(transp); - return; - } - result = (*local)(&argument, rqstp); -#ifdef linux - if (result != NULL && !svc_sendreply(transp, (xdrproc_t) xdr_result, result)) { -#else - if (result != NULL && !svc_sendreply(transp, xdr_result, result)) { -#endif - svcerr_systemerr(transp); - } -#if !defined(__SVR4) && !defined(__FreeBSD__) -#if defined(__GLIBC__) || defined(__NetBSD__) - if (!svc_freeargs(transp, (xdrproc_t)xdr_argument,(caddr_t)&argument)) { -#else - if (!svc_freeargs(transp, xdr_argument, &argument)) { -#endif -#else - if (!svc_freeargs(transp, xdr_argument, (char *)&argument)) { -#endif - fprintf(stderr, "unable to free arguments"); - exit(1); - } - return; -} diff --git a/plpnfsd/nfs_prot_xdr.c b/plpnfsd/nfs_prot_xdr.c deleted file mode 100644 index 6eb7e6d..0000000 --- a/plpnfsd/nfs_prot_xdr.c +++ /dev/null @@ -1,519 +0,0 @@ -/* $Id$ - * - * Please do not edit this file. - * It was generated using rpcgen. - */ - -#define PORTMAP -#include -#include "nfs_prot.h" - -bool_t -xdr_nfsstat(xdrs, objp) - XDR *xdrs; - nfsstat *objp; -{ - if (!xdr_enum(xdrs, (enum_t *)objp)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ftype(xdrs, objp) - XDR *xdrs; - ftype *objp; -{ - if (!xdr_enum(xdrs, (enum_t *)objp)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_nfs_fh(xdrs, objp) - XDR *xdrs; - nfs_fh *objp; -{ - if (!xdr_opaque(xdrs, objp->data, NFS_FHSIZE)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_nfstime(xdrs, objp) - XDR *xdrs; - nfstime *objp; -{ - if (!xdr_u_int(xdrs, &objp->seconds)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->useconds)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_fattr(xdrs, objp) - XDR *xdrs; - fattr *objp; -{ - if (!xdr_ftype(xdrs, &objp->type)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->mode)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->nlink)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->uid)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->gid)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->size)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->blocksize)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->rdev)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->blocks)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->fsid)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->fileid)) { - return (FALSE); - } - if (!xdr_nfstime(xdrs, &objp->atime)) { - return (FALSE); - } - if (!xdr_nfstime(xdrs, &objp->mtime)) { - return (FALSE); - } - if (!xdr_nfstime(xdrs, &objp->ctime)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_sattr(xdrs, objp) - XDR *xdrs; - sattr *objp; -{ - if (!xdr_u_int(xdrs, &objp->mode)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->uid)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->gid)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->size)) { - return (FALSE); - } - if (!xdr_nfstime(xdrs, &objp->atime)) { - return (FALSE); - } - if (!xdr_nfstime(xdrs, &objp->mtime)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_filename(xdrs, objp) - XDR *xdrs; - filename *objp; -{ - if (!xdr_string(xdrs, objp, NFS_MAXNAMLEN)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_nfspath(xdrs, objp) - XDR *xdrs; - nfspath *objp; -{ - if (!xdr_string(xdrs, objp, NFS_MAXPATHLEN)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_attrstat(xdrs, objp) - XDR *xdrs; - attrstat *objp; -{ - if (!xdr_nfsstat(xdrs, &objp->status)) { - return (FALSE); - } - switch (objp->status) { - case NFS_OK: - if (!xdr_fattr(xdrs, &objp->attrstat_u.attributes)) { - return (FALSE); - } - default: - break; - } - return (TRUE); -} - -bool_t -xdr_sattrargs(xdrs, objp) - XDR *xdrs; - sattrargs *objp; -{ - if (!xdr_nfs_fh(xdrs, &objp->file)) { - return (FALSE); - } - if (!xdr_sattr(xdrs, &objp->attributes)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_diropargs(xdrs, objp) - XDR *xdrs; - diropargs *objp; -{ - if (!xdr_nfs_fh(xdrs, &objp->dir)) { - return (FALSE); - } - if (!xdr_filename(xdrs, &objp->name)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_diropokres(xdrs, objp) - XDR *xdrs; - diropokres *objp; -{ - if (!xdr_nfs_fh(xdrs, &objp->file)) { - return (FALSE); - } - if (!xdr_fattr(xdrs, &objp->attributes)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_diropres(xdrs, objp) - XDR *xdrs; - diropres *objp; -{ - if (!xdr_nfsstat(xdrs, &objp->status)) { - return (FALSE); - } - switch (objp->status) { - case NFS_OK: - if (!xdr_diropokres(xdrs, &objp->diropres_u.diropres)) { - return (FALSE); - } - default: - break; - } - return (TRUE); -} - -bool_t -xdr_readlinkres(xdrs, objp) - XDR *xdrs; - readlinkres *objp; -{ - if (!xdr_nfsstat(xdrs, &objp->status)) { - return (FALSE); - } - switch (objp->status) { - case NFS_OK: - if (!xdr_nfspath(xdrs, &objp->readlinkres_u.data)) { - return (FALSE); - } - default: - break; - } - return (TRUE); -} - -bool_t -xdr_readargs(xdrs, objp) - XDR *xdrs; - readargs *objp; -{ - if (!xdr_nfs_fh(xdrs, &objp->file)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->offset)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->count)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->totalcount)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_readokres(xdrs, objp) - XDR *xdrs; - readokres *objp; -{ - if (!xdr_fattr(xdrs, &objp->attributes)) { - return (FALSE); - } - if (!xdr_bytes(xdrs, (char **)&objp->data.data_val, (u_int *)&objp->data.data_len, NFS_MAXDATA)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_readres(xdrs, objp) - XDR *xdrs; - readres *objp; -{ - if (!xdr_nfsstat(xdrs, &objp->status)) { - return (FALSE); - } - switch (objp->status) { - case NFS_OK: - if (!xdr_readokres(xdrs, &objp->readres_u.reply)) { - return (FALSE); - } - default: - break; - } - return (TRUE); -} - -bool_t -xdr_writeargs(xdrs, objp) - XDR *xdrs; - writeargs *objp; -{ - if (!xdr_nfs_fh(xdrs, &objp->file)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->beginoffset)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->offset)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->totalcount)) { - return (FALSE); - } - if (!xdr_bytes(xdrs, (char **)&objp->data.data_val, (u_int *)&objp->data.data_len, NFS_MAXDATA)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_createargs(xdrs, objp) - XDR *xdrs; - createargs *objp; -{ - if (!xdr_diropargs(xdrs, &objp->where)) { - return (FALSE); - } - if (!xdr_sattr(xdrs, &objp->attributes)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_renameargs(xdrs, objp) - XDR *xdrs; - renameargs *objp; -{ - if (!xdr_diropargs(xdrs, &objp->from)) { - return (FALSE); - } - if (!xdr_diropargs(xdrs, &objp->to)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_linkargs(xdrs, objp) - XDR *xdrs; - linkargs *objp; -{ - if (!xdr_nfs_fh(xdrs, &objp->from)) { - return (FALSE); - } - if (!xdr_diropargs(xdrs, &objp->to)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_symlinkargs(xdrs, objp) - XDR *xdrs; - symlinkargs *objp; -{ - if (!xdr_diropargs(xdrs, &objp->from)) { - return (FALSE); - } - if (!xdr_nfspath(xdrs, &objp->to)) { - return (FALSE); - } - if (!xdr_sattr(xdrs, &objp->attributes)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_nfscookie(xdrs, objp) - XDR *xdrs; - nfscookie objp; -{ - if (!xdr_opaque(xdrs, objp, NFS_COOKIESIZE)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_readdirargs(xdrs, objp) - XDR *xdrs; - readdirargs *objp; -{ - if (!xdr_nfs_fh(xdrs, &objp->dir)) { - return (FALSE); - } - if (!xdr_nfscookie(xdrs, objp->cookie)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->count)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_entry(xdrs, objp) - XDR *xdrs; - entry *objp; -{ - if (!xdr_u_int(xdrs, &objp->fileid)) { - return (FALSE); - } - if (!xdr_filename(xdrs, &objp->name)) { - return (FALSE); - } - if (!xdr_nfscookie(xdrs, objp->cookie)) { - return (FALSE); - } -#ifdef linux - if (!xdr_pointer(xdrs, (char **)&objp->nextentry, sizeof(entry), (xdrproc_t)xdr_entry)) { -#else - if (!xdr_pointer(xdrs, (char **)&objp->nextentry, sizeof(entry), xdr_entry)) { -#endif - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_dirlist(xdrs, objp) - XDR *xdrs; - dirlist *objp; -{ -#ifdef linux - if (!xdr_pointer(xdrs, (char **)&objp->entries, sizeof(entry), (xdrproc_t)xdr_entry)) { -#else - if (!xdr_pointer(xdrs, (char **)&objp->entries, sizeof(entry), xdr_entry)) { -#endif - return (FALSE); - } - if (!xdr_bool(xdrs, &objp->eof)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_readdirres(xdrs, objp) - XDR *xdrs; - readdirres *objp; -{ - if (!xdr_nfsstat(xdrs, &objp->status)) { - return (FALSE); - } - switch (objp->status) { - case NFS_OK: - if (!xdr_dirlist(xdrs, &objp->readdirres_u.reply)) { - return (FALSE); - } - default: - break; - } - return (TRUE); -} - -bool_t -xdr_statfsokres(xdrs, objp) - XDR *xdrs; - statfsokres *objp; -{ - if (!xdr_u_int(xdrs, &objp->tsize)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->bsize)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->blocks)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->bfree)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->bavail)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_statfsres(xdrs, objp) - XDR *xdrs; - statfsres *objp; -{ - if (!xdr_nfsstat(xdrs, &objp->status)) { - return (FALSE); - } - switch (objp->status) { - case NFS_OK: - if (!xdr_statfsokres(xdrs, &objp->statfsres_u.reply)) { - return (FALSE); - } - default: - break; - } - return (TRUE); -} diff --git a/plpnfsd/rfsv_api.h b/plpnfsd/rfsv_api.h deleted file mode 100644 index 934c5fe..0000000 --- a/plpnfsd/rfsv_api.h +++ /dev/null @@ -1,81 +0,0 @@ -/*-*-c++-*- - * $Id$ - * - * This file is part of plptools. - * - * Copyright (C) 1999-2001 Fritz Elfert - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -#ifndef _rfsv_api_h_ -#define _rfsv_api_h_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "mp.h" -#include "builtins.h" - -extern long rfsv_dir(const char *name, dentry **e); -extern long rfsv_mkdir(const char *name); -extern long rfsv_rmdir(const char *name); -extern long rfsv_remove(const char *name); -extern long rfsv_rename(const char *oldname, const char *newname); -extern long rfsv_fclose(long handle); -extern long rfsv_fcreate(long attr, const char *name, u_int32_t *handle); -extern long rfsv_read(char *buf, long offset, long len, char *name); -extern long rfsv_write(char *buf, long offset, long len, char *name); -extern long rfsv_getattr(const char *name, long *attr, long *size, long *time); -extern long rfsv_setattr(const char *name, long sattr, long dattr); -extern long rfsv_setsize(const char *name, long size); -extern long rfsv_setmtime(const char *name, long time); -extern long rfsv_drivelist(int *cnt, device **devlist); -extern long rfsv_dircount(const char *name, long *count); -extern long rfsv_statdev(char letter); -extern long rfsv_isalive(); -extern long rfsv_closecached(void); - -extern long rpcs_ownerRead(builtin_node *, char *buf, unsigned long offset, long len); -extern long rpcs_ownerSize(builtin_node *); -extern long rpcs_ps(); - -/* File attributes, C-style */ -#define PSI_A_RDONLY 0x0001 -#define PSI_A_HIDDEN 0x0002 -#define PSI_A_SYSTEM 0x0004 -#define PSI_A_DIR 0x0008 -#define PSI_A_ARCHIVE 0x0010 -#define PSI_A_VOLUME 0x0020 -#define PSI_A_NORMAL 0x0040 -#define PSI_A_TEMP 0x0080 -#define PSI_A_COMPRESSED 0x0100 -#define PSI_A_READ 0x0200 -#define PSI_A_EXEC 0x0400 -#define PSI_A_STREAM 0x0800 -#define PSI_A_TEXT 0x1000 - -#ifdef __cplusplus -} -#endif - -#endif - -/* - * Local variables: - * c-basic-offset: 4 - * End: - */ diff --git a/plpprint/plpprintd.cc b/plpprint/plpprintd.cc index 73bd813..f96c6b1 100644 --- a/plpprint/plpprintd.cc +++ b/plpprint/plpprintd.cc @@ -165,7 +165,7 @@ init_fontmap() { fontmap_entry *new_fontmap = NULL; fontmap_entry *fe; - if ((f = fopen(PKGDATA "/fontmap", "r"))) { + if ((f = fopen(PKGDATADIR "/fontmap", "r"))) { char *p; int bold; int italic; @@ -216,7 +216,7 @@ init_fontmap() { fontmap = new_fontmap; else { errorlog("No fontmap found in %s/fontmap, using builtin mapping", - PKGDATA); + PKGDATADIR); fe = default_fontmap; while (fe->psifont) { fontmap_entry *nfe = (fontmap_entry *)malloc(sizeof(fontmap_entry)); @@ -333,7 +333,7 @@ convertPage(FILE *f, int page, bool last, bufferStore buf) "%%EndComments\n" "%%BeginProlog\n", f); char pbuf[1024]; - FILE *pf = fopen(PKGDATA "/prolog.ps", "r"); + FILE *pf = fopen(PKGDATADIR "/prolog.ps", "r"); while (fgets(pbuf, sizeof(pbuf), pf)) fputs(pbuf, f); fclose(pf); diff --git a/sisinstall/Makefile.am b/sisinstall/Makefile.am index 0a0ff93..11b729a 100644 --- a/sisinstall/Makefile.am +++ b/sisinstall/Makefile.am @@ -7,6 +7,3 @@ sisinstall_LDADD = $(top_srcdir)/lib/libplp.la $(LIBNEWT) $(INTLLIBS) sisinstall_SOURCES = psion.cpp sisinstaller.cpp sismain.cpp \ fakepsion.cpp sisfilelink.cpp sisfilelink.h EXTRA_DIST = psion.h sisinstaller.h fakepsion.h - -maintainer-clean-local: - rm -f Makefile.in -- cgit v1.2.3