/*
 * Interface to Volumeserver, 
 * reference /afs/nada.kth.se/misc/reference/programming/afs/shadow/
 *
 * $Id: volumeserver.xg,v 1.20 2000/06/01 23:59:02 ahltorp Exp $
 */

package VOLSER_

%#include <config.h>
%#include <roken.h>
%#include <fs_errors.h>

error-function conv_to_arla_errno

const VLDB_MAXSERVER		= 80;
const VOLSERVICE_PORT		= 7005;
const VOLSERVICE_ID		= 4;
const INVALID_BID		= 0;
const VOLSER_MAXVOLNAME		= 65;
const VOLSER_OLDMAXVOLNAME	= 32;
const VOLSER_MAX_REPSITES	= 7;
const VNAMESIZE			= 32;

const VOLCREATEVOLUME	= 100;
const VOLDELETEVOLUME	= 101;
const VOLRESTORE	= 102;
const VOLFORWARD	= 103;
const VOLENDTRANS	= 104;
const VOLCLONE		= 105;
const VOLSETFLAGS	= 106;
const VOLGETFLAGS	= 107;
const VOLTRANSCREATE	= 108;
const VOLDUMP		= 109;
const VOLGETNTHVOLUME	= 110;
const VOLSETFORWARDING	= 111;
const VOLGETNAME	= 112;
const VOLGETSTATUS	= 113;
const VOLSIGNALRESTORE	= 114;
const VOLLISTPARTITIONS	= 115;
const VOLLISTVOLUMES	= 116;
const VOLSETIDTYPES	= 117;
const VOLMONITOR	= 118;
const VOLPARTITIONINFO	= 119;
const VOLRECLONE	= 120;
const VOLLISTONEVOLUME	= 121;
const VOLNUKEVOLUME	= 122;
const VOLSETDATE	= 123;
const VOLXLISTVOLUMES	= 124;
const VOLXLISTONEVOL	= 125;
const VOLSETINFO	= 126;
const VOLXLISTPARTITIONS= 127;
const VOLFORWARDMULTIPLE= 128;

const PARTVALID	= 0x01;
const VOK	= 0x02;
const VBUSY	= 110;

const VOLSERTRELE_ERROR       = 1492325120;
const VOLSERNO_OP             = 1492325121;
const VOLSERREAD_DUMPERROR    = 1492325122;
const VOLSERDUMPERROR         = 1492325123;
const VOLSERATTACH_ERROR      = 1492325124;
const VOLSERILLEGAL_PARTITION = 1492325125;
const VOLSERDETACH_ERROR      = 1492325126;
const VOLSERBAD_ACCESS        = 1492325127;
const VOLSERVLDB_ERROR        = 1492325128;
const VOLSERBADNAME           = 1492325129;
const VOLSERVOLMOVED          = 1492325130;
const VOLSERBADOP             = 1492325131;
const VOLSERBADRELEASE        = 1492325132;
const VOLSERVOLBUSY           = 1492325133;
const VOLSERNO_MEMORY         = 1492325134;
const VOLSERNOVOL	      = 1492325135;
const VOLSERMULTIRWVOL        = 1492325136;
const VOLSERFAILEDOP          = 1492325137;

const ITOffline = 0x1;
const ITBusy = 0x2;
const ITReadOnly = 0x8;
const ITCreate = 0x10;
const ITCreateVolID = 0x1000;

const VTDeleteOnSalvage = 1;
const VTOutOfService = 2;
const VTDeleted = 4;

#if 0
struct volser_trans { 
    volser_trans *next;
    long tid;
    long time;
    long creationTime;
    long returnCode;
    long volid;
    long partition;
    long dumpTransId;
    long dumpSeq;   /* Not used */
    short refCount;
    short iflags;
    char vflags;    
    char tflags;
    char incremental;
    char lastProcName[30];
/*    struct rx_call *rxCallPtr; XXXXXXX BROKEN /lha */
};
#endif
struct volDescription {
    char volName[VOLSER_MAXVOLNAME];
    long volId;
    long volSize;
    long volFlags;
    long volCloneId;
};

struct partList {
    int partId[26];
    long partFlags[26];
};

struct volser_status {
    long volID;
    long nextUnique;
    long type;
    long parentID;
    long cloneID;
    long backupID;
    long restoredFromID;
    long maxQuota;
    long minQuota;
    long owner;
    long creationDate;
    long accessDate;
    long updateDate;
    long exprirationDate;
    long backupDate;
    long copyDate;
};

struct destServer {
    long destHost;
    long destPort;
    long destSSID;   /* currently allways set to 1 */
};

struct volintInfo {
    char name[VNAMESIZE];
    long volid;
    long type;
    long backupID;
    long parentID;
    long cloneID;
    long status;
    long copyDate;
    char inUse;
    char needsSalvaged;
    char destroyMe;
    long creationDate;
    long accessDate;
    long updateDate;
    long backupDate;
    long dayUse;
    long filecount;
    long maxquota;
    long size;
    long flags;
    long spare0;
    long spare1;
    long spare2;
    long spare3;
};

struct xvolintInfo {
    char name[VNAMESIZE];
    long volid;
    long type;
    long backupID;
    long parentID;
    long cloneID;
    long status;
    long copyDate;
    char inUse;
    long creationDate;
    long accessDate;
    long updateDate;
    long backupDate;
    long dayUse;
    long filecount;
    long maxquota;
    long size;
    int32_t stat_reads[4];
    int32_t stat_writes[4];
    int32_t stat_fileSameAuthor[6];
    int32_t stat_fileDiffAuthor[6];
    int32_t stat_dirSameAuthor[6];
    int32_t stat_dirDiffAuthor[6];
};

/*
 * same site total, same site authenticated
 * diff site total, diff site authenticated
 */

/*
 * 0-60 s
 * 1-10 min
 * 10-60 min
 * 1-24 hour
 * 1-7 days
 * >7 days
 */

struct transDebugInfo {
    long tid;
    long time;
    long creationTime;
    long returnCode;
    long volid;
    long partition;
    short iflags;
    char vflags;
    char tflags;
    char lastProcName[30];
    long callValid;
    long readNext;
    long transmitNext;
    long lastSendTime;
    long lastReceiveTime;
};

struct pIDs {
    long partIds[26];		/* -1 if none */
};

struct diskPartition {
    char name[32];
    char devName[32];
    long lock_fd;
    long totalUsable;
    long free;
    long minFree;
};

struct restoreCookie {
    char name[32];
    long type;
    long clone;
    long parent;
};
  
typedef transDebugInfo transDebugEntries<>;
typedef volintInfo volEntries<>;
typedef xvolintInfo xvolEntries<>;
typedef int32_t part_entries<>;
typedef int32_t multi_results<>;

struct replica {
    int32_t trans_id;
    struct destServer destserver;
};

typedef replica replicas<>;

AFSVolCreateVolume(IN long partition,
		   IN string name,
		   IN long type,
		   IN long parent,
		   INOUT long *volid,
		   OUT long *trans) = VOLCREATEVOLUME;

AFSVolDeleteVolume(IN long trans) = VOLDELETEVOLUME;

AFSVolNukeVolume(IN long partID,
		 IN long volID) = VOLNUKEVOLUME;

AFSVolDump(IN long fromTrans,
	   IN long fromDate) split = VOLDUMP;

AFSVolSignalRestore(IN char *name,
		    IN int type,
		    IN long pid,
		    IN long cloneid) = VOLSIGNALRESTORE;

AFSVolRestore(IN long toTrans,
	      IN long flags,
	      IN restoreCookie *cookie) split = VOLRESTORE;

AFSVolForward(IN int32_t fromTrans,
	      IN int32_t fromData,
	      IN struct destServer *destination,
	      IN long destTrans,
	      IN struct restoreCookie *cookie) = VOLFORWARD;

AFSVolClone(IN long trans,
	    IN long purgeVol,
	    IN long newType,
	    IN char *newName,
	    INOUT long *newVol) = VOLCLONE;

AFSVolReClone(IN long tid,
	      IN long cloneID) = VOLRECLONE;

AFSVolSetForwarding(IN long tid,
		    IN long newsite) = VOLSETFORWARDING;

AFSVolTransCreate(IN long volume,
		  IN long partition,
		  IN long flags,
		  OUT long *trans) = VOLTRANSCREATE;

AFSVolEndTrans(IN long trans,
	       OUT long *rcode) = VOLENDTRANS;

AFSVolGetFlags(IN long trans,
	       OUT long *flags) = VOLGETFLAGS;

AFSVolSetFlags(IN long trans,
	       IN long flags) = VOLSETFLAGS;

AFSVolGetName(IN long tid,
	      OUT string tname<256>) = VOLGETNAME;

AFSVolGetStatus(IN long tid,
		OUT volser_status *status) = VOLGETSTATUS;

AFSVolSetIdsTypes(IN long tId,
		  IN char *name,
		  IN long type,
		  IN long pId,
		  IN long cloneId,
		  IN long backupId) = VOLSETIDTYPES;

AFSVolSetDate(IN long tid,
	      IN long newDate) = VOLSETDATE;

AFSVolListPartitions(OUT struct pIDs *partIDs) = VOLLISTPARTITIONS;

AFSVolPartitionInfo(IN string name<>, 
		    OUT struct diskPartition *partition) = VOLPARTITIONINFO;

AFSVolListVolumes(IN long partID,
		  IN long flags,
		  OUT struct volEntries *resultEntries) = VOLLISTVOLUMES;

AFSVolListOneVolume(IN long partID,
		    IN long volid,
		    OUT struct volEntries *resultEntries) = VOLLISTONEVOLUME;

AFSVolGetNthVolume(IN long index,
		   OUT long *volume,
		   OUT long *partition) = VOLGETNTHVOLUME;

AFSVolMonitor(OUT transDebugEntries *result) = VOLMONITOR;
    
AFSVolXListVolumes(IN long partID,
		   IN long flags,
		   OUT struct xvolEntries *resultEntries) = VOLXLISTVOLUMES;

AFSVolXListOneVolume(IN long partID,
		     IN long volid,
		     OUT struct xvolEntries *resultEntries) = VOLXLISTONEVOL;

AFSVolSetInfo(IN long transid,
	      IN volintInfo *volinfo) = VOLSETINFO;

AFSVolXListPartitions(OUT part_entries *ent) = VOLXLISTPARTITIONS;

AFSVolForwardMultiple(IN int32_t fromTrans,
		      IN int32_t fromData,
		      IN replicas *destinations,
		      IN long spare0,
		      IN struct restoreCookie *cookie,
		      IN multi_results *results) = VOLFORWARDMULTIPLE;
