backport to buster
[hcoop/debian/openafs.git] / src / ptserver / ptubik.c
CommitLineData
805e021f
CE
1/* $Id$ */
2
3#include <afsconfig.h>
4#include <afs/param.h>
5#include <afs/stds.h>
6
7#include <roken.h>
8
9#include <lock.h>
10#include <afs/cellconfig.h>
11#define UBIK_INTERNALS
12#include <ubik.h>
13#include <rx/xdr.h>
14
15#include "ptint.h"
16#include "ptserver.h"
17
18extern int dbase_fd;
19struct ubik_dbase *dbase;
20
21int
22ubik_ServerInit(afs_uint32 myHost, short myPort, afs_uint32 serverList[],
23 const char *pathName, struct ubik_dbase **dbase)
24{
25 return (0);
26}
27
28int
29ubik_BeginTrans(struct ubik_dbase *dbase, afs_int32 transMode,
30 struct ubik_trans **transPtr)
31{
32 static int init = 0;
33 struct ubik_hdr thdr;
34 ssize_t count;
35
36 if (!init) {
37 memset(&thdr, 0, sizeof(thdr));
38 thdr.version.epoch = htonl(2);
39 thdr.version.counter = htonl(0);
40 thdr.magic = htonl(UBIK_MAGIC);
41 thdr.size = htons(HDRSIZE);
42 if (lseek(dbase_fd, 0, 0) == (off_t)-1)
43 return errno;
44 count = write(dbase_fd, &thdr, sizeof(thdr));
45 if (count < 0)
46 return errno;
47 else if (count != sizeof(thdr))
48 return UIOERROR;
49 if (fsync(dbase_fd))
50 return errno;
51 init = 1;
52 }
53 return (0);
54}
55
56int
57ubik_BeginTransReadAny(struct ubik_dbase *dbase, afs_int32 transMode,
58 struct ubik_trans **transPtr)
59{
60 return (0);
61}
62
63int
64ubik_AbortTrans(struct ubik_trans *transPtr)
65{
66 return (0);
67}
68
69int
70ubik_EndTrans(struct ubik_trans *transPtr)
71{
72 return (0);
73}
74
75int
76ubik_Tell(struct ubik_trans *transPtr, afs_int32 * fileid,
77 afs_int32 * position)
78{
79 return (0);
80}
81
82int
83ubik_Truncate(struct ubik_trans *transPtr, afs_int32 length)
84{
85 return (0);
86}
87
88int
89ubik_SetLock(struct ubik_trans *atrans, afs_int32 apos, afs_int32 alen,
90 int atype)
91{
92 return (0);
93}
94
95int
96ubik_WaitVersion(struct ubik_dbase *adatabase,
97 struct ubik_version *aversion)
98{
99 return (0);
100}
101
102int
103ubik_CheckCache(struct ubik_trans *atrans, ubik_updatecache_func cbf, void *rock)
104{
105 return (*cbf)(atrans, rock);
106}
107
108void
109panic(char *format, ...)
110{
111 va_list ap;
112
113 va_start(ap, format);
114 vprintf(format, ap);
115 va_end(ap);
116
117 abort();
118 printf("BACK FROM ABORT\n"); /* shouldn't come back from floating pt exception */
119 exit(1); /* never know, though */
120}
121
122int
123ubik_GetVersion(struct ubik_trans *dummy, struct ubik_version *ver)
124{
125 memset(ver, 0, sizeof(struct ubik_version));
126 return (0);
127}
128
129
130int
131ubik_Seek(struct ubik_trans *tt, afs_int32 afd, afs_int32 pos)
132{
133 if (lseek(dbase_fd, pos + HDRSIZE, 0) < 0) {
134 perror("ubik_Seek");
135 return (-1);
136 }
137 return (0);
138}
139
140int
141ubik_Write(struct ubik_trans *tt, void *buf, afs_int32 len)
142{
143 int status;
144
145 status = write(dbase_fd, buf, len);
146 if (status < len) {
147 perror("ubik_Write");
148 return (1);
149 }
150 return (0);
151}
152
153int
154ubik_Read(struct ubik_trans *tt, void *buf, afs_int32 len)
155{
156 int status;
157
158 status = read(dbase_fd, buf, len);
159 if (status < 0) {
160 perror("ubik_Read");
161 return (1);
162 }
163 if (status < len)
164 memset((char *)buf + status, 0, len - status);
165 return (0);
166}
167
168
169/* Global declarations from ubik.c */
170afs_int32 ubik_quorum = 0;
171struct ubik_dbase *ubik_dbase = 0;
172struct ubik_stats ubik_stats;
173afs_uint32 ubik_host[UBIK_MAX_INTERFACE_ADDR];
174afs_int32 ubik_epochTime = 0;
175afs_int32 urecovery_state = 0;
176
177struct rx_securityClass *ubik_sc[3];
178
179
180/* Other declarations */
181
182int
183afsconf_GetNoAuthFlag(struct afsconf_dir *adir)
184{
185 return (1);
186}
187
188
189char *prdir = "/dev/null";
190struct prheader cheader;