Coda File System

64bit SPARC changes...

From: Roland Mainz <Roland.Mainz_at_informatik.med.uni-giessen.de>
Date: Thu, 28 Sep 2000 13:29:18 +0200
Hi !

----

Attached are two files from the solaris-code-0.03 kernel module sources:
1. solaris-coda-0.03/include/coda.h
2. solaris-coda-0.03/src/coda_upcalls.h
3. solaris-coda-0.03/src/Makefile.in
Both files have been modified to get 64bit and 32bit kernel modules
working with 32bit podfuk (venus untested but should work). 64bit
userspace daemon should work, too (untested).

Makefile.in is currently configured for producing 64bit kernel modules
with Sun Workshop 6 (Sun Forte) compiler. Still looking for a more
portable solution... :-)

Comments ?

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) Roland.Mainz_at_informatik.med.uni-giessen.de
  \__\/\/__/  gisburn_at_informatik.med.uni-giessen.de
  /O /==\ O\  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
 (;O/ \/ \O;) TEL +49 641 99-13193 FAX +49 641 99-41359
/* 
   You may distribute this file under either of the two licenses that
   follow at your discretion.
*/

/* BLURB lgpl

                           Coda File System
                              Release 5

          Copyright (c) 1987-2000 Carnegie Mellon University
                  Additional copyrights listed below

This code is distributed "AS IS" without warranty of any kind under
the terms of the GNU Library General Public Licence Version 2, as
shown in the file LICENSE, or under the license shown below. The
technical and financial contributors to Coda are listed in the file
CREDITS.

                        Additional copyrights 
*/

/*

            Coda: an Experimental Distributed File System
                             Release 4.0

          Copyright (c) 1987-2000 Carnegie Mellon University
                         All Rights Reserved

Permission  to  use, copy, modify and distribute this software and its
documentation is hereby granted,  provided  that  both  the  copyright
notice  and  this  permission  notice  appear  in  all  copies  of the
software, derivative works or  modified  versions,  and  any  portions
thereof, and that both notices appear in supporting documentation, and
that credit is given to Carnegie Mellon University  in  all  documents
and publicity pertaining to direct or indirect use of this code or its
derivatives.

CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
ANY DERIVATIVE WORK.

Carnegie  Mellon  encourages  users  of  this  software  to return any
improvements or extensions that  they  make,  and  to  grant  Carnegie
Mellon the rights to redistribute these changes without encumbrance.
*/

/*
 *
 * Based on cfs.h from Mach, but revamped for increased simplicity.
 * Linux modifications by 
 * Peter Braam, Aug 1996
 *
 * Solaris 64bit fixes by Roland Mainz <Roland.Mainz_at_informatik.med.uni-giessen.de>
 */

#ifndef _CODA_HEADER_
#define _CODA_HEADER_



/* Catch new _KERNEL defn for NetBSD */
#ifdef __NetBSD__
#include <sys/types.h>
#endif 

#ifndef CODA_MAXSYMLINKS
#define CODA_MAXSYMLINKS 10
#endif

#if defined(DJGPP) || defined(__CYGWIN32__)
#ifdef KERNEL
typedef unsigned long u_long;
typedef unsigned int u_int;
typedef unsigned short u_short;
typedef u_long ino_t;
typedef u_long dev_t;
typedef void * caddr_t;
#ifdef DOS
typedef unsigned __int64 u_quad_t;
#else 
typedef unsigned long long u_quad_t;
#endif

#define inline

struct timespec {
        long       ts_sec;
        long       ts_nsec;
};
#else  /* DJGPP but not KERNEL */
#include <sys/types.h>
#include <sys/time.h>
typedef unsigned long long u_quad_t;
#endif /* !KERNEL */
#endif /* !DJGPP */


#if defined(__linux__)
#define cdev_t u_quad_t
#ifndef __KERNEL__
#if !defined(_UQUAD_T_) && (!defined(__GLIBC__) || __GLIBC__ < 2)
#define _UQUAD_T_ 1
typedef unsigned long long u_quad_t;
#endif
#else /*__KERNEL__ */
typedef unsigned long long u_quad_t;
#endif /* __KERNEL__ */
#else
#define cdev_t dev_t
#endif

/* Solaris Definitions */
#ifdef __sun
#include <sys/types.h>
#include <sys/time.h>
#define __BIT_TYPES_DEFINED__
typedef unsigned char      u_int8_t;
typedef unsigned short     u_int16_t;
typedef unsigned int       u_int32_t;
typedef unsigned long long u_int64_t;
typedef unsigned long long u_quad_t;

#define inline
#endif

#ifdef __CYGWIN32__
struct timespec {
        time_t  tv_sec;         /* seconds */
        long    tv_nsec;        /* nanoseconds */
};
#endif

#ifndef __sun
/* for all platforms except 64bit sparc:
 * for all non-64bit platforms timespec == timespec32
 * timespec32 is a "special" timespec datatype which 
 * is used for 64bit compatibility
 */
typedef timespec timespec32
#endif

#ifndef __BIT_TYPES_DEFINED__
#define __BIT_TYPES_DEFINED__
typedef signed char	      int8_t;
typedef unsigned char	    u_int8_t;
typedef short		     int16_t;
typedef unsigned short	   u_int16_t;
typedef int		     int32_t;
typedef unsigned int	   u_int32_t;
#endif


/*
 * Cfs constants
 */
#define CODA_MAXNAMLEN   255
#define CODA_MAXPATHLEN  1024
#define CODA_MAXSYMLINK  10

/* these are Coda's version of O_RDONLY etc combinations
 * to deal with VFS open modes
 */
#define	C_O_READ	0x001
#define	C_O_WRITE       0x002
#define C_O_TRUNC       0x010
#define C_O_EXCL	0x100
#define C_O_CREAT	0x200

/* these are to find mode bits in Venus */ 
#define C_M_READ  00400
#define C_M_WRITE 00200

/* for access Venus will use */
#define C_A_C_OK    8               /* Test for writing upon create.  */
#define C_A_R_OK    4               /* Test for read permission.  */
#define C_A_W_OK    2               /* Test for write permission.  */
#define C_A_X_OK    1               /* Test for execute permission.  */
#define C_A_F_OK    0               /* Test for existence.  */

#ifdef __sun
#define _VENUS_DIRENT_T_ 1
struct venus_dirent {
        u_int32_t	d_fileno;		/* file number of entry */
        u_int16_t	d_reclen;		/* length of this record */
        u_int16_t	d_namlen;		/* length of string in d_name */
        char		d_name[CODA_MAXNAMLEN + 1];/* name must be no longer than this */
};
#undef DIRSIZ
#define DIRSIZ(dp)      ((sizeof (struct venus_dirent) - (CODA_MAXNAMLEN+1)) + \
                         (((dp)->d_namlen+1 + 3) &~ 3))
#endif

#ifndef _VENUS_DIRENT_T_
#define _VENUS_DIRENT_T_ 1
struct venus_dirent {
        u_int32_t       d_fileno;		/* file number of entry */
        u_int16_t	d_reclen;		/* length of this record */
        u_int8_t 	d_type;			/* file type, see below */
        u_int8_t	d_namlen;		/* length of string in d_name */
        char		d_name[CODA_MAXNAMLEN + 1];/* name must be no longer than this */
};
#undef DIRSIZ
#define DIRSIZ(dp)      ((sizeof (struct venus_dirent) - (CODA_MAXNAMLEN+1)) + \
                         (((dp)->d_namlen+1 + 3) &~ 3))

/*
 * File types
 */
#define	CDT_UNKNOWN	 0
#define	CDT_FIFO	 1
#define	CDT_CHR		 2
#define	CDT_DIR		 4
#define	CDT_BLK		 6
#define	CDT_REG		 8
#define	CDT_LNK		10
#define	CDT_SOCK	12
#define	CDT_WHT		14

/*
 * Convert between stat structure types and directory types.
 */
#define	IFTOCDT(mode)	(((mode) & 0170000) >> 12)
#define	CDTTOIF(dirtype)	((dirtype) << 12)

#endif

#ifndef	_FID_T_
#define _FID_T_	1
typedef u_int32_t VolumeId;
typedef u_int32_t VnodeId;
typedef u_int32_t Unique_t;
typedef u_int32_t FileVersion;
#endif 

#ifndef	_VICEFID_T_
#define _VICEFID_T_	1
typedef struct ViceFid {
    VolumeId Volume;
    VnodeId Vnode;
    Unique_t Unique;
} ViceFid;
#endif	/* VICEFID */


#ifdef __linux__
static __inline__ ino_t  coda_f2i(struct ViceFid *fid)
{
	if ( ! fid ) 
		return 0; 
	if (fid->Vnode == 0xfffffffe || fid->Vnode == 0xffffffff)
		return ((fid->Volume << 20) | (fid->Unique & 0xfffff));
	else
		return (fid->Unique + (fid->Vnode<<10) + (fid->Volume<<20));
}
	
#else
#define coda_f2i(fid)\
	((fid) ? ((fid)->Unique + ((fid)->Vnode<<10) + ((fid)->Volume<<20)) : 0)
#endif


#ifndef _VUID_T_
#define _VUID_T_
typedef u_int32_t vuid_t;
typedef u_int32_t vgid_t;
#endif /*_VUID_T_ */

#ifndef _CODACRED_T_
#define _CODACRED_T_
struct coda_cred {
    vuid_t cr_uid, cr_euid, cr_suid, cr_fsuid; /* Real, efftve, set, fs uid*/
    vgid_t cr_groupid,     cr_egid, cr_sgid, cr_fsgid; /* same for groups */
};
#endif 

#ifndef _VENUS_VATTR_T_
#define _VENUS_VATTR_T_
/*
 * Vnode types.  VNON means no type.
 */
enum coda_vtype	{ C_VNON, C_VREG, C_VDIR, C_VBLK, C_VCHR, C_VLNK, C_VSOCK, C_VFIFO, C_VBAD };

struct coda_vattr {
	int32_t     		va_type;	/* vnode type (for create) */
	u_int16_t		va_mode;	/* files access mode and type */
	int16_t			va_nlink;	/* number of references to file */
	vuid_t			va_uid;		/* owner user id */
	vgid_t			va_gid;		/* owner group id */
	int32_t			va_fileid;	/* file id */
	u_int64_t		va_size;	/* file size in bytes */
	u_int32_t		va_blocksize;	/* blocksize preferred for i/o */
	struct timespec32	va_atime;	/* time of last access */
	struct timespec32	va_mtime;	/* time of last modification */
	struct timespec32	va_ctime;	/* time file changed */
	u_int32_t		va_gen;		/* generation number of file */
	u_int32_t		va_flags;	/* flags defined for file */
	cdev_t	        	va_rdev;	/* device special file represents */
	u_int64_t		va_bytes;	/* bytes of disk space held by file */
	u_int64_t		va_filerev;	/* file modification number */
};

#endif 

/* structure used by CODA_STATFS for getting cache information from venus */
struct coda_statfs {
    int32_t f_blocks;
    int32_t f_bfree;
    int32_t f_bavail;
    int32_t f_files;
    int32_t f_ffree;
};

/*
 * Kernel <--> Venus communications.
 */

#define CODA_ROOT	2
#define CODA_OPEN	4
#define CODA_CLOSE	5
#define CODA_IOCTL	6
#define CODA_GETATTR	7
#define CODA_SETATTR	8
#define CODA_ACCESS	9
#define CODA_LOOKUP	10
#define CODA_CREATE	11
#define CODA_REMOVE	12
#define CODA_LINK	13
#define CODA_RENAME	14
#define CODA_MKDIR	15
#define CODA_RMDIR	16
#define CODA_SYMLINK	18
#define CODA_READLINK	19
#define CODA_FSYNC	20
#define CODA_VGET	22
#define CODA_SIGNAL	23
#define CODA_REPLACE	 24 /* DOWNCALL */
#define CODA_FLUSH       25 /* DOWNCALL */
#define CODA_PURGEUSER   26 /* DOWNCALL */
#define CODA_ZAPFILE     27 /* DOWNCALL */
#define CODA_ZAPDIR      28 /* DOWNCALL */
#define CODA_PURGEFID    30 /* DOWNCALL */
#define CODA_OPEN_BY_PATH 31
#define CODA_RESOLVE     32
#define CODA_REINTEGRATE 33
#define CODA_STATFS	 34
#define CODA_MAKE_CINODE 35 /* DOWNCALL */
#define CODA_NCALLS 36

#define DOWNCALL(opcode) \
	((opcode >= CODA_REPLACE && opcode <= CODA_PURGEFID) || \
	 opcode == CODA_MAKE_CINODE)

#define VC_MAXDATASIZE	    8192
#define VC_MAXMSGSIZE      sizeof(union inputArgs)+sizeof(union outputArgs) +\
                            VC_MAXDATASIZE  

#define CIOC_KERNEL_VERSION _IOWR('c', 10, sizeof (int))

#if 0
#define CODA_KERNEL_VERSION 0 /* don't care about kernel version number */
#define CODA_KERNEL_VERSION 1 /* The old venus 4.6 compatible interface */
/* Only linux-2.3 kernels use venus-kernel protocol version 3 */
#define CODA_KERNEL_VERSION 3 /* added CODA_MAKE_CINODE downcall */
#endif
#define CODA_KERNEL_VERSION 2 /* venus_lookup gets an extra parameter */

/*
 *        Venus <-> Coda  RPC arguments
 */
#ifndef __sun
struct coda_in_hdr {
    u_int32_t opcode;
    u_int32_t unique;	    /* Keep multiple outstanding msgs distinct */
    u_int16_t pid;		    /* Common to all */
    u_int16_t pgid;		    /* Common to all */
    u_int16_t sid;                  /* Common to all */
    struct coda_cred cred;	    /* Common to all */
};
#else
/* Solaris uses longs for pid, pgid.... change to pid_t for all? */
struct coda_in_hdr {
    u_int32_t opcode;
    u_int32_t unique;	    /* Keep multiple outstanding msgs distinct */
    pid_t pid;			    /* Common to all */
    pid_t pgid;			    /* Common to all */
    pid_t sid;                      /* Common to all */
    struct coda_cred cred;	    /* Common to all */
};
#endif

/* Really important that opcode and unique are 1st two fields! */
struct coda_out_hdr {
    u_int32_t opcode;
    u_int32_t unique;	
    u_int32_t result;
};

/* coda_root: NO_IN */
struct coda_root_out {
    struct coda_out_hdr oh;
    ViceFid VFid;
};

struct coda_root_in {
    struct coda_in_hdr in;
};

/* coda_sync: */
/* Nothing needed for coda_sync */

/* coda_open: */
struct coda_open_in {
    struct coda_in_hdr ih;
    ViceFid	VFid;
    int32_t	flags;
};

struct coda_open_out {
    struct coda_out_hdr oh;
    cdev_t	dev;
    ino_t	inode;
};


/* coda_close: */
struct coda_close_in {
    struct coda_in_hdr ih;
    ViceFid	VFid;
    int32_t	flags;
};

struct coda_close_out {
    struct coda_out_hdr out;
};

/* coda_ioctl: */
struct coda_ioctl_in {
    struct coda_in_hdr ih;
    ViceFid VFid;
    int32_t	cmd;
    int32_t	len;
    int32_t	rwflag;
    char *data;			/* Place holder for data. */
};

struct coda_ioctl_out {
    struct coda_out_hdr oh;
    int32_t	len;
    caddr_t	data;		/* Place holder for data. */
};


/* coda_getattr: */
struct coda_getattr_in {
    struct coda_in_hdr ih;
    ViceFid VFid;
};

struct coda_getattr_out {
    struct coda_out_hdr oh;
    struct coda_vattr attr;
};


/* coda_setattr: NO_OUT */
struct coda_setattr_in {
    struct coda_in_hdr ih;
    ViceFid VFid;
    struct coda_vattr attr;
};

struct coda_setattr_out {
    struct coda_out_hdr out;
};

/* coda_access: NO_OUT */
struct coda_access_in {
    struct coda_in_hdr ih;
    ViceFid	VFid;
    int32_t	flags;
};

struct coda_access_out {
    struct coda_out_hdr out;
};


/* lookup flags */
#define CLU_CASE_SENSITIVE     0x01
#define CLU_CASE_INSENSITIVE   0x02

/* coda_lookup: */
struct  coda_lookup_in {
    struct coda_in_hdr ih;
    ViceFid	VFid;
    int32_t     name;		/* Place holder for data. */
    int32_t     flags;	
};

struct coda_lookup_out {
    struct coda_out_hdr oh;
    ViceFid VFid;
    int32_t vtype;
};


/* coda_create: */
struct coda_create_in {
    struct coda_in_hdr ih;
    ViceFid VFid;
    struct coda_vattr attr;
    int32_t excl;
    int32_t mode;
    int32_t name;		/* Place holder for data. */
};

struct coda_create_out {
    struct coda_out_hdr oh;
    ViceFid VFid;
    struct coda_vattr attr;
};


/* coda_remove: NO_OUT */
struct coda_remove_in {
    struct coda_in_hdr ih;
    ViceFid	VFid;
    int32_t     name;		/* Place holder for data. */
};

struct coda_remove_out {
    struct coda_out_hdr out;
};

/* coda_link: NO_OUT */
struct coda_link_in {
    struct coda_in_hdr ih;
    ViceFid sourceFid;          /* cnode to link *to* */
    ViceFid destFid;            /* Directory in which to place link */
    int32_t tname;		/* Place holder for data. */
};

struct coda_link_out {
    struct coda_out_hdr out;
};


/* coda_rename: NO_OUT */
struct coda_rename_in {
    struct coda_in_hdr ih;
    ViceFid	sourceFid;
    int32_t 	srcname;
    ViceFid destFid;
    int32_t 	destname;
};

struct coda_rename_out {
    struct coda_out_hdr out;
};

/* coda_mkdir: */
struct coda_mkdir_in {
    struct coda_in_hdr ih;
    ViceFid	VFid;
    struct coda_vattr attr;
    int32_t	   name;		/* Place holder for data. */
};

struct coda_mkdir_out {
    struct coda_out_hdr oh;
    ViceFid VFid;
    struct coda_vattr attr;
};


/* coda_rmdir: NO_OUT */
struct coda_rmdir_in {
    struct coda_in_hdr ih;
    ViceFid	VFid;
    int32_t     name;		/* Place holder for data. */
};

struct coda_rmdir_out {
    struct coda_out_hdr out;
};

/* coda_readdir: */
struct coda_readdir_in {
    struct coda_in_hdr ih;
    ViceFid	VFid;
    int32_t	count;
    int32_t	offset;
};

struct coda_readdir_out {
    struct coda_out_hdr oh;
    int32_t	size;
    caddr_t	data;		/* Place holder for data. */
};

/* coda_symlink: NO_OUT */
struct coda_symlink_in {
    struct coda_in_hdr ih;
    ViceFid	VFid;          /* Directory to put symlink in */
    int32_t srcname;
    struct coda_vattr attr;
    int32_t tname;
};

struct coda_symlink_out {
    struct coda_out_hdr out;
};

/* coda_readlink: */
struct coda_readlink_in {
    struct coda_in_hdr ih;
    ViceFid VFid;
};

struct coda_readlink_out {
    struct coda_out_hdr oh;
    int32_t	count;
    caddr_t	data;		/* Place holder for data. */
};


/* coda_fsync: NO_OUT */
struct coda_fsync_in {
    struct coda_in_hdr ih;
    ViceFid VFid;
};

struct coda_fsync_out {
    struct coda_out_hdr out;
};

/* coda_inactive: NO_OUT */
struct coda_inactive_in {
    struct coda_in_hdr ih;
    ViceFid VFid;
};

/* coda_vget: */
struct coda_vget_in {
    struct coda_in_hdr ih;
    ViceFid VFid;
};

struct coda_vget_out {
    struct coda_out_hdr oh;
    ViceFid VFid;
    int32_t	vtype;
};


/* CODA_SIGNAL is out-of-band, doesn't need data. */
/* CODA_INVALIDATE is a venus->kernel call */
/* CODA_FLUSH is a venus->kernel call */

/* coda_purgeuser: */
/* CODA_PURGEUSER is a venus->kernel call */
struct coda_purgeuser_out {
    struct coda_out_hdr oh;
    struct coda_cred cred;
};

/* coda_zapfile: */
/* CODA_ZAPFILE is a venus->kernel call */
struct coda_zapfile_out {  
    struct coda_out_hdr oh;
    ViceFid CodaFid;
};

/* coda_zapdir: */
/* CODA_ZAPDIR is a venus->kernel call */	
struct coda_zapdir_out {	  
    struct coda_out_hdr oh;
    ViceFid CodaFid;
};

/* coda_zapnode: */
/* CODA_ZAPVNODE is a venus->kernel call */	
struct coda_zapvnode_out { 
    struct coda_out_hdr oh;
    struct coda_cred cred;
    ViceFid VFid;
};

/* coda_purgefid: */
/* CODA_PURGEFID is a venus->kernel call */	
struct coda_purgefid_out { 
    struct coda_out_hdr oh;
    ViceFid CodaFid;
};

struct coda_make_cinode_out {
    struct coda_out_hdr oh;
    ViceFid CodaFid;
    struct coda_vattr attr;
    int32_t fd;
};


/* coda_rdwr: */
struct coda_rdwr_in {
    struct coda_in_hdr ih;
    ViceFid	VFid;
    int32_t	rwflag;
    int32_t	count;
    int32_t	offset;
    int32_t	ioflag;
    caddr_t	data;		/* Place holder for data. */	
};

struct coda_rdwr_out {
    struct coda_out_hdr oh;
    int32_t	rwflag;
    int32_t	count;
    caddr_t	data;	/* Place holder for data. */
};


/* coda_replace: */
/* CODA_REPLACE is a venus->kernel call */	
struct coda_replace_out { /* coda_replace is a venus->kernel call */
    struct coda_out_hdr oh;
    ViceFid NewFid;
    ViceFid OldFid;
};

/* coda_open_by_path: */
struct coda_open_by_path_in {
    struct coda_in_hdr ih;
    ViceFid	VFid;
    int32_t	flags;
};

struct coda_open_by_path_out {
    struct coda_out_hdr oh;
	int32_t path;
};

/* coda_statfs: NO_IN */
struct coda_statfs_in {
    struct coda_in_hdr in;
};

struct coda_statfs_out {
    struct coda_out_hdr oh;
    struct coda_statfs stat;
};

/* 
 * Occasionally, we don't cache the fid returned by CODA_LOOKUP. 
 * For instance, if the fid is inconsistent. 
 * This case is handled by setting the top bit of the type result parameter.
 */
#define CODA_NOCACHE          0x80000000

union inputArgs {
    struct coda_in_hdr ih;		/* NB: every struct below begins with an ih */
    struct coda_open_in coda_open;
    struct coda_close_in coda_close;
    struct coda_ioctl_in coda_ioctl;
    struct coda_getattr_in coda_getattr;
    struct coda_setattr_in coda_setattr;
    struct coda_access_in coda_access;
    struct coda_lookup_in coda_lookup;
    struct coda_create_in coda_create;
    struct coda_remove_in coda_remove;
    struct coda_link_in coda_link;
    struct coda_rename_in coda_rename;
    struct coda_mkdir_in coda_mkdir;
    struct coda_rmdir_in coda_rmdir;
    struct coda_readdir_in coda_readdir;
    struct coda_symlink_in coda_symlink;
    struct coda_readlink_in coda_readlink;
    struct coda_fsync_in coda_fsync;
    struct coda_inactive_in coda_inactive;
    struct coda_vget_in coda_vget;
    struct coda_rdwr_in coda_rdwr;
    struct coda_open_by_path_in coda_open_by_path;
    struct coda_statfs_in coda_statfs;
};

union outputArgs {
    struct coda_out_hdr oh;		/* NB: every struct below begins with an oh */
    struct coda_root_out coda_root;
    struct coda_open_out coda_open;
    struct coda_ioctl_out coda_ioctl;
    struct coda_getattr_out coda_getattr;
    struct coda_lookup_out coda_lookup;
    struct coda_create_out coda_create;
    struct coda_mkdir_out coda_mkdir;
    struct coda_readdir_out coda_readdir;
    struct coda_readlink_out coda_readlink;
    struct coda_vget_out coda_vget;
    struct coda_purgeuser_out coda_purgeuser;
    struct coda_zapfile_out coda_zapfile;
    struct coda_zapdir_out coda_zapdir;
    struct coda_zapvnode_out coda_zapvnode;
    struct coda_purgefid_out coda_purgefid;
    struct coda_rdwr_out coda_rdwr;
    struct coda_replace_out coda_replace;
    struct coda_make_cinode_out coda_make_cinode;
    struct coda_open_by_path_out coda_open_by_path;
    struct coda_statfs_out coda_statfs;
};    

union coda_downcalls {
    /* CODA_INVALIDATE is a venus->kernel call */
    /* CODA_FLUSH is a venus->kernel call */
    struct coda_purgeuser_out purgeuser;
    struct coda_zapfile_out zapfile;
    struct coda_zapdir_out zapdir;
    struct coda_zapvnode_out zapvnode;
    struct coda_purgefid_out purgefid;
    struct coda_replace_out replace;
};


/*
 * Used for identifying usage of "Control" and pioctls
 */

#define PIOCPARM_MASK 0x0000ffff
struct ViceIoctl {
        caddr_t in, out;        /* Data to be transferred in, or out */
        int16_t in_size;          /* Size of input buffer <= 2K */
        int16_t out_size;         /* Maximum size of output buffer, <= 2K */
};

struct PioctlData {
        const char *path;
        int32_t     follow;
        struct ViceIoctl vi;
};

#define	CODA_CONTROL		".CONTROL"
#define CODA_CONTROLLEN           8
#define	CTL_VOL			-1
#define	CTL_VNO			-1
#define	CTL_UNI			-1
#define CTL_INO                 -1
#define	CTL_FILE		"/coda/.CONTROL"


#define	IS_CTL_FID(fidp)	((fidp)->Volume == CTL_VOL &&\
				 (fidp)->Vnode == CTL_VNO &&\
				 (fidp)->Unique == CTL_UNI)
#endif /+ !_CODA_HEADER_ */


/*
 * 
 *             Coda: an Experimental Distributed File System
 *                              Release 3.1
 * 
 *           Copyright (c) 1999 Carnegie Mellon University
 *                          All Rights Reserved
 * 
 * Permission  to  use, copy, modify and distribute this software and its
 * documentation is hereby granted,  provided  that  both  the  copyright
 * notice  and  this  permission  notice  appear  in  all  copies  of the
 * software, derivative works or  modified  versions,  and  any  portions
 * thereof, and that both notices appear in supporting documentation, and
 * that credit is given to Carnegie Mellon University  in  all  documents
 * and publicity pertaining to direct or indirect use of this code or its
 * derivatives.
 * 
 * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
 * SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
 * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
 * DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
 * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
 * ANY DERIVATIVE WORK.
 * 
 * Carnegie  Mellon  encourages  users  of  this  software  to return any
 * improvements or extensions that  they  make,  and  to  grant  Carnegie
 * Mellon the rights to redistribute these changes without encumbrance.
 * 
 */

/* $Id: coda_upcalls.c,v 1.3 2000/01/26 00:34:11 phil Exp $ */

#include <coda.h>
#include <coda_sys.h>
#include <coda_common.h>
#include <coda_fs.h>
#include <coda_dev.h>
#include <coda_debug.h>
#include <coda_upcalls.h>
#include <sys/types.h>
#include <sys/fcntl.h>


/* Useful definitions */

#define IN_SIZE(kind) sizeof(struct coda_ ## kind ## _in)
#define OUT_SIZE(kind) sizeof(struct coda_ ## kind ## _out)
#define MSGSIZE(kind) MAX (IN_SIZE(kind), OUT_SIZE(kind))

#define INIT_IN(in, op, cred, p) 					\
	(in).opcode = op; 						\
	(in).pid = ((p) ? (p)->p_pid : -1);				\
	(in).pgid = ((p) ? (p)->p_pgrp : -1);				\
	(in).sid = ((p && (p)->p_sessp) ? (p)->p_sessp->s_sid : -1); 	\
	cred_sol2coda (cred, &((in).cred));


/* Useful functions */
static void
cred_sol2coda (cred_t *sol_cred, struct coda_cred *coda_cred)
{
  bzero((char *)coda_cred,sizeof(struct coda_cred));
  if (sol_cred) {
    coda_cred->cr_uid     = sol_cred->cr_ruid;
    coda_cred->cr_groupid = sol_cred->cr_rgid;
    coda_cred->cr_euid    = sol_cred->cr_uid;
    coda_cred->cr_egid    = sol_cred->cr_gid;
  } else {
    coda_cred->cr_uid     =
    coda_cred->cr_groupid =
    coda_cred->cr_euid    =
    coda_cred->cr_egid    = -1;
  }
}

static vtype_t coda2vtype[]
	= {VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD};


#define timespec2timespec( a, b )  (a).tv_sec = (b).tv_sec; (a).tv_nsec = (b).tv_nsec;



static void
coda_attr2vattr(struct coda_vattr *cap, struct vattr *vap)
{
  vap->va_mask    = (AT_TYPE | AT_MODE | AT_UID | AT_GID | AT_NODEID
		     | AT_NLINK | AT_SIZE | AT_ATIME | AT_MTIME
		     | AT_CTIME | AT_BLKSIZE | AT_NBLOCKS
		     | AT_RDEV  | AT_FSID );
  vap->va_type    = coda2vtype[cap->va_type];
  vap->va_mode    = cap->va_mode;
  vap->va_uid     = cap->va_uid;
  vap->va_gid     = cap->va_gid;
  vap->va_nodeid  = cap->va_fileid;
  vap->va_nlink   = cap->va_nlink;
  vap->va_size    = cap->va_size;
#if 0  
  vap->va_atime   = cap->va_atime;
  vap->va_mtime   = cap->va_mtime;
  vap->va_ctime   = cap->va_ctime;
#else
  timespec2timespec( vap->va_atime, cap->va_atime );
  timespec2timespec( vap->va_mtime, cap->va_mtime );
  timespec2timespec( vap->va_ctime, cap->va_ctime );
#endif  
  vap->va_blksize = cap->va_blocksize;
  vap->va_nblocks = (cap->va_size+511)/512;
  vap->va_rdev    = cap->va_rdev;
  vap->va_fsid    = coda_fstype;
}


/* static enum coda_vtype vtype2coda[]
	= {C_VNON, C_VREG, C_VDIR, C_VBLK, C_VCHR, C_VLNK, C_VFIFO, C_VBAD,
	   C_VBAD, C_VSOCK, C_VBAD}; */

static timestruc_t notime = {-1, -1};

static void
vattr2coda_attr(struct vattr *vap, struct coda_vattr *cap) 
{
  /* Set fixed values ... i.e. can't change! */
  cap->va_type   = C_VNON;
  cap->va_flags  = -1;
  cap->va_fileid = -1;
  cap->va_gen    = -1;
  cap->va_rdev   = -1;
  cap->va_nlink  = -1;
  cap->va_bytes  = -1;
  cap->va_blocksize = -1;

  /* The ones to set! */
  cap->va_mode   = ( vap->va_mask & AT_MODE ? vap->va_mode : -1);
  cap->va_uid    = ( vap->va_mask & AT_UID ? vap->va_uid : -1);
  cap->va_gid    = ( vap->va_mask & AT_GID ? vap->va_gid : -1);
  cap->va_size   = ( vap->va_mask & AT_SIZE ? vap->va_size : -1);
#if 0  
  cap->va_atime  = ( vap->va_mask & AT_ATIME ? vap->va_atime : notime);
  cap->va_mtime  = ( vap->va_mask & AT_MTIME ? vap->va_mtime : notime);
  cap->va_ctime  = ( vap->va_mask & AT_CTIME ? vap->va_ctime : notime);
#else
  timespec2timespec( cap->va_atime, ( vap->va_mask & AT_ATIME ? vap->va_atime : notime) );
  timespec2timespec( cap->va_mtime, ( vap->va_mask & AT_MTIME ? vap->va_mtime : notime) );
  timespec2timespec( cap->va_ctime, ( vap->va_mask & AT_CTIME ? vap->va_ctime : notime) );
#endif
  CODADEB (CDEBUPC, (CE_NOTE, "vattr2coda_attr: mask=0x%x", vap->va_mask));
  CODADEB (CDEBUPC, (CE_NOTE, "mode 0%o, uid %d, gid %d, size %d",
		     cap->va_mode, cap->va_uid, cap->va_gid, cap->va_size));
}


/* Upcall functions */

int
coda_venus_root (int minor, ViceFid *VFidp)
{
  struct coda_in_hdr   *in;
  struct coda_root_out *out;
  struct proc *cp;
  cred_t *cred = CRED();
  int msgsize;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_root: minor = %d", minor));

  msgsize = MAX(sizeof(struct coda_in_hdr), OUT_SIZE(root));

  in  = (struct coda_in_hdr *) coda_alloc (msgsize);
  out = (struct coda_root_out *) in;
  cp = (curthread ? curproc : NULL);

  INIT_IN(*in, CODA_ROOT, cred, cp);

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  sizeof(struct coda_in_hdr), OUT_SIZE(root), UP_WAIT);

  if (!error) {
    *VFidp = out->VFid;

    CODADEB (CDEBUPC,(CE_NOTE,"coda_venus_root VFid: vol=0x%x vn=0x%x "
		      "uniq=0x%x",
		      VFidp->Volume, VFidp->Vnode, VFidp->Unique));
  }

  coda_free(in, msgsize);

  return error;
}

int
coda_venus_open (int minor, cred_t *cred, int flags, ViceFid *VFidp,
		dev_t *dev, ino_t *inode)
{
  struct coda_open_in   *in;
  struct coda_open_out *out;
  struct proc *cp;
  int msgsize;
  int codaflags;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_open: minor=%d", minor));

  msgsize = MSGSIZE(open);
  in  = (struct coda_open_in *) coda_alloc (msgsize);
  out = (struct coda_open_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_OPEN, cred, cp);
  in->VFid = *VFidp;
  /* Convert from Solaris flags to coda flags. */
  codaflags = 0;
  if (flags & FREAD)   codaflags |= C_O_READ;
  if (flags & FWRITE)  codaflags |= C_O_WRITE;
  if (flags & O_CREAT) codaflags |= C_O_CREAT;
  if (flags & O_TRUNC) codaflags |= C_O_TRUNC;
  if (flags & O_EXCL)  codaflags |= C_O_EXCL;
  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_open: codaflags=%d", codaflags));
  in->flags = codaflags; 


  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(open), OUT_SIZE(open), UP_WAIT);

  if (!error) {
    *dev   = out->dev;
    *inode = out->inode;
    
    CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_open: dev=%d inode=%d",
		       *dev, *inode));
  }
 
  coda_free(in, msgsize);

  return error;
}


int
coda_venus_open_by_path (int minor, cred_t *cred, int flags, ViceFid *VFidp,
		char *name)
{
  struct coda_open_by_path_in   *in;
  struct coda_open_by_path_out *out;
  struct proc *cp;
  int codaflags;
  int msgsize;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_open_by_path: minor = %d", minor));

  msgsize = MAX(IN_SIZE(open_by_path), OUT_SIZE(open_by_path)+CODA_MAXNAMLEN);
  in  = (struct coda_open_by_path_in *) coda_alloc (msgsize);
  out = (struct coda_open_by_path_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_OPEN_BY_PATH, cred, cp);
  in->VFid = *VFidp;
  /* Convert from Solaris flags to coda flags. */
  codaflags = 0;
  if (flags & FREAD)   codaflags |= C_O_READ;
  if (flags & FWRITE)  codaflags |= C_O_WRITE;
  if (flags & O_CREAT) codaflags |= C_O_CREAT;
  if (flags & O_TRUNC) codaflags |= C_O_TRUNC;
  if (flags & O_EXCL)  codaflags |= C_O_EXCL;
  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_open_by_path: codaflags=%d",
		     codaflags));
  in->flags = codaflags; 

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(open_by_path), OUT_SIZE(open_by_path), UP_WAIT);

  if (!error) {
    strcpy(name, (char *)out + OUT_SIZE(open_by_path));
    
    CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_open_by_path: name = %s",
		       name));
  }
 
  coda_free(in, msgsize);

  return error;
}


int
coda_venus_getattr (int minor, cred_t *cred, ViceFid *VFidp, struct vattr *vap)
{
  struct coda_getattr_in   *in;
  struct coda_getattr_out *out;
  struct proc *cp;
  int msgsize;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_getattr: minor = %d", minor));

  msgsize = MSGSIZE(getattr);
  in  = (struct coda_getattr_in *) coda_alloc (msgsize);
  out = (struct coda_getattr_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_GETATTR, cred, cp);
  in->VFid = *VFidp;

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(getattr), OUT_SIZE(getattr), UP_WAIT);

  if (!error) {

    coda_attr2vattr(&out->attr, vap);
    
    CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_getattr: success"));
  }
 
  coda_free(in, msgsize);

  return error;
}

int
coda_venus_setattr (int minor, cred_t *cred, ViceFid *VFidp, struct vattr *vap)
{
  struct coda_setattr_in   *in;
  struct coda_setattr_out *out;
  struct proc *cp;
  int msgsize;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_setattr: minor = %d, "
		     "VFid=(%d.%d.%d)",
		     minor, VFidp->Volume, VFidp->Vnode, VFidp->Unique));

  msgsize = MSGSIZE(setattr);
  in  = (struct coda_setattr_in *) coda_alloc (msgsize);
  out = (struct coda_setattr_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_SETATTR, cred, cp);
  in->VFid = *VFidp;
  vattr2coda_attr (vap, &in->attr);

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(setattr), OUT_SIZE(setattr), UP_WAIT);

    
  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_setattr: error = %d", error));
 
  coda_free(in, msgsize);

  return error;
}

int
coda_venus_access (int minor, cred_t *cred, ViceFid *VFidp, int mode)
{
  struct coda_access_in   *in;
  struct coda_access_out *out;
  struct proc *cp;
  int msgsize;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_access: minor = %d", minor));

  msgsize = MSGSIZE(access);
  in  = (struct coda_access_in *) coda_alloc (msgsize);
  out = (struct coda_access_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_ACCESS, cred, cp);
  in->VFid = *VFidp;
  in->flags = mode >> 6;  /* XXXX Does this work in all cases? */

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(access), OUT_SIZE(access), UP_WAIT);

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_access: error=%d", error));
 
  coda_free(in, msgsize);

  return error;
}


int
coda_venus_lookup (int minor, cred_t *cred, ViceFid *inVFidp, char *name,
		  ViceFid *outVFidp,  vtype_t *vtypep, int *nocache)
{
  struct coda_lookup_in   *in;
  struct coda_lookup_out *out;
  struct proc *cp;
  int msgsize;
  int namelen = strlen(name)+1;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_lookup: minor = %d, "
		     "name=\"%s\" len=%d", minor, name, namelen));

  msgsize = MAX(IN_SIZE(lookup)+namelen, OUT_SIZE(lookup));
  in  = (struct coda_lookup_in *) coda_alloc (msgsize);
  out = (struct coda_lookup_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_LOOKUP, cred, cp);
  in->VFid = *inVFidp;
  in->name = IN_SIZE(lookup);
  in->flags = CLU_CASE_SENSITIVE;
  bcopy (name, ((char *)in)+in->name, namelen);

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(lookup)+namelen, OUT_SIZE(lookup), UP_WAIT);

  if (!error) {
    /* Post processing */
    *outVFidp = out->VFid;
    *nocache = (out->vtype | CODA_NOCACHE) != 0;
    out->vtype &= ~CODA_NOCACHE;
    *vtypep = coda2vtype[out->vtype];
  }

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_lookup: error=%d", error));
 
  coda_free(in, msgsize);

  return error;
}
		

int
coda_venus_create (int minor, cred_t *cred, ViceFid *inVFidp, char *name,
		  int mode, struct vattr *va, vcexcl_t exclusive,
		  ViceFid *outVFidp)
{
  struct coda_create_in   *in;
  struct coda_create_out *out;
  struct proc *cp;
  int msgsize;
  int namelen = strlen(name)+1;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_create: minor = %d, "
		     "name=(%s) len=(%d)",
		     minor, name, namelen));

  msgsize = MAX(IN_SIZE(create)+namelen, OUT_SIZE(create));
  in  = (struct coda_create_in *) coda_alloc (msgsize);
  out = (struct coda_create_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_CREATE, cred, cp);
  in->VFid = *inVFidp;
  in->excl = exclusive; 		/* XXXX correct ? */
  in->mode = va->va_mode;		/* ignore mode parameter! */
  vattr2coda_attr(va, &in->attr);
  in->name = IN_SIZE(create);
  bcopy (name, ((char *)in)+in->name, namelen);

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(create)+namelen, OUT_SIZE(create), UP_WAIT);

  if (!error) {
    /* Post processing */
    *outVFidp = out->VFid;
    coda_attr2vattr(&out->attr, va);
  }

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_create: error=%d", error));
 
  coda_free(in, msgsize);

  return error;
}

int
coda_venus_mkdir (int minor, cred_t *cred, ViceFid *inVFidp, char *name,
		 struct vattr *va, ViceFid *outVFidp)
{
  struct coda_mkdir_in   *in;
  struct coda_mkdir_out *out;
  struct proc *cp;
  int msgsize;
  int namelen = strlen(name)+1;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_mkdir: minor = %d, "
		     "name=(%s) len=(%d)",
		     minor, name, namelen));

  msgsize = MAX(IN_SIZE(mkdir)+namelen, OUT_SIZE(mkdir));
  in  = (struct coda_mkdir_in *) coda_alloc (msgsize);
  out = (struct coda_mkdir_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_MKDIR, cred, cp);
  in->VFid = *inVFidp;
  vattr2coda_attr(va, &in->attr);
  in->name = IN_SIZE(mkdir);
  bcopy (name, ((char *)in)+in->name, namelen);

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(mkdir)+namelen, OUT_SIZE(mkdir), UP_WAIT);

  if (!error) {
    /* Post processing */
    *outVFidp = out->VFid;
    coda_attr2vattr(&out->attr, va);
  }

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_mkdir: error=%d", error));
 
  coda_free(in, msgsize);

  return error;
}

int
coda_venus_link (int minor, cred_t *cred, ViceFid *fileVFidp,
		 ViceFid *dirVFidp, char *name)
{
  struct coda_link_in   *in;
  struct coda_link_out *out;
  struct proc *cp;
  int msgsize;
  int namelen = strlen(name)+1;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_link: minor = %d, "
		     "name=(%s) len=(%d)",
		     minor, name, namelen));

  msgsize = MAX(IN_SIZE(link)+namelen, OUT_SIZE(link));
  in  = (struct coda_link_in *) coda_alloc (msgsize);
  out = (struct coda_link_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_LINK, cred, cp);
  in->sourceFid = *fileVFidp;
  in->destFid = *dirVFidp;
  in->tname = IN_SIZE(link);
  bcopy (name, ((char *)in)+in->tname, namelen);

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(link)+namelen, OUT_SIZE(link), UP_WAIT);

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_link: error=%d", error));
 
  coda_free(in, msgsize);

  return error;
}


int
coda_venus_symlink (int minor, cred_t *cred, ViceFid *VFidp,
		    char *linkname, struct vattr *tva, char *tname)
{
  struct coda_symlink_in   *in;
  struct coda_symlink_out *out;
  struct proc *cp;
  int msgsize;
  int linklen = strlen(linkname)+1;
  int tlen = strlen(tname)+1;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_symlink: minor = %d, "
		     "linkname=(%s) len=(%d) entry=(%s)",
		     minor, linkname, linklen, tname));

  msgsize = MAX(IN_SIZE(symlink)+linklen+tlen, OUT_SIZE(symlink));
  in  = (struct coda_symlink_in *) coda_alloc (msgsize);
  out = (struct coda_symlink_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_SYMLINK, cred, cp);
  in->VFid = *VFidp;
  vattr2coda_attr(tva, &in->attr);
  in->srcname = IN_SIZE(symlink);
  in->tname = IN_SIZE(symlink)+linklen;
  bcopy (linkname, ((char *)in)+in->srcname, linklen);
  bcopy (tname, ((char *)in)+in->tname, tlen);

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(symlink)+linklen+tlen, OUT_SIZE(symlink),
			  UP_WAIT);

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_symlink: error=%d", error));
 
  coda_free(in, msgsize);

  return error;
}


int
coda_venus_remove (int minor, cred_t *cred, ViceFid *VFidp, char *name)
{
  struct coda_remove_in   *in;
  struct coda_remove_out *out;
  struct proc *cp;
  int msgsize;
  int namelen = strlen(name)+1;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_remove: minor = %d, "
		     "name=(%s) len=(%d)",
		     minor, name, namelen));

  msgsize = MAX(IN_SIZE(remove)+namelen, OUT_SIZE(remove));
  in  = (struct coda_remove_in *) coda_alloc (msgsize);
  out = (struct coda_remove_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_REMOVE, cred, cp);
  in->VFid = *VFidp;
  in->name = IN_SIZE(remove);
  bcopy (name, ((char *)in)+in->name, namelen);

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(remove)+namelen, OUT_SIZE(remove), UP_WAIT);
  
  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_remove: error=%d", error));
 
  coda_free(in, msgsize);

  return error;
}

int
coda_venus_rmdir (int minor, cred_t *cred, ViceFid *VFidp, char *name)
{
  struct coda_rmdir_in   *in;
  struct coda_rmdir_out *out;
  struct proc *cp;
  int msgsize;
  int namelen = strlen(name)+1;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_rmdir: minor = %d, "
		     "name=(%s) len=(%d)",
		     minor, name, namelen));

  msgsize = MAX(IN_SIZE(rmdir)+namelen, OUT_SIZE(rmdir));
  in  = (struct coda_rmdir_in *) coda_alloc (msgsize);
  out = (struct coda_rmdir_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_RMDIR, cred, cp);
  in->VFid = *VFidp;
  in->name = IN_SIZE(rmdir);
  bcopy (name, ((char *)in)+in->name, namelen);

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(rmdir)+namelen, OUT_SIZE(rmdir), UP_WAIT);

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_rmdir: error=%d", error));
 
  coda_free(in, msgsize);

  return error;
}


int
coda_venus_readlink (int minor, cred_t *cred, ViceFid *VFidp, struct uio *uiop)
{
  struct coda_readlink_in   *in;
  struct coda_readlink_out *out;
  struct proc *cp;
  int msgsize;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_readlink: minor = %d, ", minor));

  msgsize = MAX(IN_SIZE(readlink), OUT_SIZE(readlink)+CODA_MAXNAMLEN);
  in  = (struct coda_readlink_in *) coda_alloc (msgsize);
  out = (struct coda_readlink_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_READLINK, cred, cp);
  in->VFid = *VFidp;

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(readlink), OUT_SIZE(readlink)+CODA_MAXNAMLEN,
			  UP_WAIT);
  if (!error) 
    /* Transfer data! */
    error = uiomove((caddr_t) ((char *)out+(int)out->data),
		    out->count, UIO_READ, uiop);
    
  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_readlink: error=%d", error));
 
  coda_free(in, msgsize);

  return error;
}


int
coda_venus_rename (int minor, cred_t *cred, ViceFid *srcFidp,
		   char *srcname, ViceFid *dstFidp, char *dstname)
{
  struct coda_rename_in   *in;
  struct coda_rename_out *out;
  struct proc *cp;
  int msgsize;
  int srclen = strlen(srcname)+1;
  int dstlen = strlen(dstname)+1;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_rename: minor = %d, "
		     "srcname=(%s) dstname=(%s)",
		     minor, srcname, dstname));

  msgsize = MAX(IN_SIZE(rename)+srclen+dstlen, OUT_SIZE(rename));
  in  = (struct coda_rename_in *) coda_alloc (msgsize);
  out = (struct coda_rename_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_RENAME, cred, cp);
  in->sourceFid = *srcFidp;
  in->destFid = *dstFidp;
  in->srcname = IN_SIZE(rename);
  in->destname = IN_SIZE(rename)+srclen;
  bcopy (srcname, ((char *)in)+in->srcname, srclen);
  bcopy (dstname, ((char *)in)+in->destname, dstlen);

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(rename)+srclen+dstlen, OUT_SIZE(rename),
			  UP_WAIT);

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_rename: error=%d", error));
 
  coda_free(in, msgsize);

  return error;
}

int
coda_venus_fsync (int minor, cred_t *cred, ViceFid *VFidp)
{
  struct coda_fsync_in   *in;
  struct coda_fsync_out *out;
  struct proc *cp;
  int msgsize;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_fsync: minor = %d", minor));

  msgsize = MSGSIZE(fsync);
  in  = (struct coda_fsync_in *) coda_alloc (msgsize);
  out = (struct coda_fsync_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_FSYNC, cred, cp);
  in->VFid = *VFidp;

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(fsync), OUT_SIZE(fsync), UP_WAIT);

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_fsync: error=%d", error));
 
  coda_free(in, msgsize);

  return error;
}

int
coda_venus_close (int minor, cred_t *cred, ViceFid *VFidp, int flag)
{
  struct coda_close_in   *in;
  struct coda_close_out *out;
  struct proc *cp;
  int msgsize;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_close: minor = %d", minor));

  msgsize = MSGSIZE(close);
  in  = (struct coda_close_in *) coda_alloc (msgsize);
  out = (struct coda_close_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_CLOSE, cred, cp);
  in->VFid = *VFidp;
  in->flags = 0;
  if (flag & FWRITE)  in->flags |= C_O_WRITE;
  if (flag & O_TRUNC) in->flags |= C_O_TRUNC;

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(close), OUT_SIZE(close), UP_WAIT);

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_close: error=%d", error));
 
  coda_free(in, msgsize);

  return error;
}

int
coda_venus_ioctl (int minor, cred_t *cred, ViceFid *VFidp, int cmd,
		  struct PioctlData *ioargp)
{
  struct coda_ioctl_in   *in;
  struct coda_ioctl_out *out;
  struct proc *cp;
  int msgsize;
  int error;

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_ioctl: minor = %d", minor));

  msgsize = MAX(IN_SIZE(ioctl)+ioargp->vi.in_size,
		OUT_SIZE(ioctl)+ioargp->vi.out_size);
  in  = (struct coda_ioctl_in *) coda_alloc (msgsize);
  out = (struct coda_ioctl_out *) in;
  cp = (curthread ? curproc : NULL);

  /* Prepare message */
  INIT_IN(in->ih, CODA_IOCTL, cred, cp);
  in->VFid = *VFidp;
  in->cmd  = cmd;
  in->len  = ioargp->vi.in_size;
  in->rwflag = 0;
  in->data = (char *)IN_SIZE(ioctl);
  error = copyin (ioargp->vi.in, (char *)in+(int)in->data, in->len);

  if (error) {
    coda_free(in, msgsize);
    return error;
  }

  error = coda_do_upcall (minor, (union inputArgs *)in,
			  IN_SIZE(ioctl)+ioargp->vi.in_size,
			  OUT_SIZE(ioctl)+ioargp->vi.out_size, UP_WAIT);

  if (error) {
    coda_free(in, msgsize);
    CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_ioctl: error=%d", error));
    return error;
  }

  if (out->len > ioargp->vi.out_size) {
    coda_free(in, msgsize);
    CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_ioctl: bad out size"));
    return EINVAL;
  }

  error = copyout ((char *)out+(int)out->data, ioargp->vi.out, out->len);

  CODADEB (CDEBUPC, (CE_NOTE, "coda_venus_ioctl: error=%d", error));

  coda_free(in, msgsize);

  return error;
}

# Solaris makefile

TOPDIR = ..

srcdir = ../src
VPATH  = ../src

CC=/opt/SUNWspro/bin/cc

INCLUDES	= -I$(TOPDIR)/include -I$(TOPDIR)/sol-include
DEFS		= -Dsun -D_KERNEL -DDEBUG -D_LARGEFILE64_SOURCE 
CFLAGS		= -g -Xa -xCC -xarch=v9 $(DEFS) $(INCLUDES) 

SRC		=				\
		coda_debug.c			\
		coda_common.c			\
		coda_dev.c			\
		coda_downcall.c			\
		coda_node.c			\
		coda_upcalls.c			\
		coda_vfsops.c			\
		coda_vnodeops.c			\
		coda_wrap.c

OBJ 		= $(SRC:.c=.o)
MOD 		= coda

all: $(MOD)

$(MOD): $(OBJ)
	$(LD) -r -o ./$(MOD) $(OBJ)

clean:	
	rm -f $(MOD) $(OBJ)

TAGS:	$(SRC)
	etags $(SRC)

.PHONY: all clean
Received on 2000-09-28 07:29:54