/*
*
* Coda: an Experimental Distributed File System
* Release 3.1
*
* Copyright (c) 1987-1998 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.
*
* @(#) coda/coda_venus.c,v 1.1.1.1 1998/08/29 21:26:45 rvb Exp $
*/
/*
* Isize and Osize are the sizes of the input and output arguments.
* SEMI-INVARIANT: name##_size (e.g. coda_readlink_size) is the max of
* the input and output. This invariant is not well maintained, but
* should be true after ALLOC_*. Isize is modified after allocation
* by STRCPY below - this is in general unsafe and needs fixing.
*/
#define DECL_NO_IN(name) \
struct coda_in_hdr *inp; \
struct name ## _out *outp; \
int name ## _size = sizeof (struct coda_in_hdr); \
int Isize = sizeof (struct coda_in_hdr); \
int Osize = sizeof (struct name ## _out); \
int error
#define DECL(name) \
struct name ## _in *inp; \
struct name ## _out *outp; \
int name ## _size = sizeof (struct name ## _in); \
int Isize = sizeof (struct name ## _in); \
int Osize = sizeof (struct name ## _out); \
int error
#define DECL_NO_OUT(name) \
struct name ## _in *inp; \
int name ## _size = sizeof (struct name ## _in); \
int Isize = sizeof (struct name ## _in); \
int Osize = sizeof (struct coda_out_hdr); \
int error
#define ALLOC_NO_IN(name) \
if (Osize > name ## _size) \
name ## _size = Osize; \
CODA_ALLOC(inp, struct coda_in_hdr *, name ## _size);\
outp = (struct name ## _out *) inp
#define ALLOC(name) \
if (Osize > name ## _size) \
name ## _size = Osize; \
CODA_ALLOC(inp, struct name ## _in *, name ## _size);\
outp = (struct name ## _out *) inp
#define ALLOC_NO_OUT(name) \
if (Osize > name ## _size) \
name ## _size = Osize; \
CODA_ALLOC(inp, struct name ## _in *, name ## _size);\
#define STRCPY(struc, name, len) \
memcpy((char *)inp + (int)inp->struc, name, len); \
((char*)inp + (int)inp->struc)[len++] = 0; \
Isize += len
/* XXX verify that Isize has not overrun available storage */
#define CNV_OFLAG(to, from) \
do { \
to = 0; \
if (from & FREAD) to |= C_O_READ; \
if (from & FWRITE) to |= C_O_WRITE; \
if (from & O_TRUNC) to |= C_O_TRUNC; \
if (from & O_EXCL) to |= C_O_EXCL; \
if (from & O_CREAT) to |= C_O_CREAT; \
} while (/*CONSTCOND*/ 0)
/*
* these two calls will not exist!!! the container file is read/written
* directly.
*/
void
venus_read(void)
{
}
void
venus_write(void)
{
}
/*
* this is a bit sad too. the ioctl's are for the control file, not for
* normal files.
*/
int
venus_ioctl(void *mdp, CodaFid *fid,
int com, int flag, void *data,
kauth_cred_t cred, struct lwp *l)
{
DECL(coda_ioctl); /* sets Isize & Osize */
struct PioctlData *iap = (struct PioctlData *)data;
int tmp;
/* command was mutated by increasing its size field to reflect the
* path and follow args. we need to subtract that out before sending
* the command to venus.
*/
inp->cmd = (com & ~(IOCPARM_MASK << 16));
tmp = ((com >> 16) & IOCPARM_MASK) - sizeof (char *) - sizeof (int);
inp->cmd |= (tmp & IOCPARM_MASK) << 16;
/* Check count for reasonableness */
if (outp->count <= 0 || outp->count > CODA_MAXPATHLEN) {
printf("venus_readlink: bad count %d\n", outp->count);
error = EINVAL;
goto out;
}
/*
* Check data pointer for reasonableness. It must point after
* itself, and within the allocated region.
*/
if ((intptr_t) outp->data < sizeof(struct coda_readlink_out) ) {
printf("venus_readlink: data pointer %lld too low\n",
(long long)((intptr_t) outp->data));
error = EINVAL;
goto out;
}
if ((intptr_t) outp->data + outp->count >
sizeof(struct coda_readlink_out) + CODA_MAXPATHLEN) {
printf("venus_readlink: data pointer %lld too high\n",
(long long)((intptr_t) outp->data));
error = EINVAL;
goto out;
}
int
venus_lookup(void *mdp, CodaFid *fid,
const char *nm, int len,
kauth_cred_t cred, struct lwp *l,
/*out*/ CodaFid *VFid, int *vtype)
{
DECL(coda_lookup); /* sets Isize & Osize */
coda_lookup_size += len + 1;
ALLOC(coda_lookup); /* sets inp & outp */
/* send the open to venus. */
INIT_IN_L(&inp->ih, CODA_LOOKUP, cred, l);
inp->Fid = *fid;
/* NOTE:
* Between version 1 and version 2 we have added an extra flag field
* to this structure. But because the string was at the end and because
* of the weird way we represent strings by having the slot point to
* where the string characters are in the "heap", we can just slip the
* flag parameter in after the string slot pointer and veni that don't
* know better won't see this new flag field ...
* Otherwise we'd need two different venus_lookup functions.
*/
inp->name = Isize;
inp->flags = CLU_CASE_SENSITIVE; /* doesn't really matter for BSD */
/* This is safe because we preallocated len+1 extra. */
STRCPY(name, nm, len); /* increments Isize */