Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / ptserver / ptubik.c
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
18 extern int dbase_fd;
19 struct ubik_dbase *dbase;
20
21 int
22 ubik_ServerInit(afs_uint32 myHost, short myPort, afs_uint32 serverList[],
23 const char *pathName, struct ubik_dbase **dbase)
24 {
25 return (0);
26 }
27
28 int
29 ubik_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
56 int
57 ubik_BeginTransReadAny(struct ubik_dbase *dbase, afs_int32 transMode,
58 struct ubik_trans **transPtr)
59 {
60 return (0);
61 }
62
63 int
64 ubik_AbortTrans(struct ubik_trans *transPtr)
65 {
66 return (0);
67 }
68
69 int
70 ubik_EndTrans(struct ubik_trans *transPtr)
71 {
72 return (0);
73 }
74
75 int
76 ubik_Tell(struct ubik_trans *transPtr, afs_int32 * fileid,
77 afs_int32 * position)
78 {
79 return (0);
80 }
81
82 int
83 ubik_Truncate(struct ubik_trans *transPtr, afs_int32 length)
84 {
85 return (0);
86 }
87
88 int
89 ubik_SetLock(struct ubik_trans *atrans, afs_int32 apos, afs_int32 alen,
90 int atype)
91 {
92 return (0);
93 }
94
95 int
96 ubik_WaitVersion(struct ubik_dbase *adatabase,
97 struct ubik_version *aversion)
98 {
99 return (0);
100 }
101
102 int
103 ubik_CheckCache(struct ubik_trans *atrans, ubik_updatecache_func cbf, void *rock)
104 {
105 return (*cbf)(atrans, rock);
106 }
107
108 void
109 panic(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
122 int
123 ubik_GetVersion(struct ubik_trans *dummy, struct ubik_version *ver)
124 {
125 memset(ver, 0, sizeof(struct ubik_version));
126 return (0);
127 }
128
129
130 int
131 ubik_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
140 int
141 ubik_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
153 int
154 ubik_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 */
170 afs_int32 ubik_quorum = 0;
171 struct ubik_dbase *ubik_dbase = 0;
172 struct ubik_stats ubik_stats;
173 afs_uint32 ubik_host[UBIK_MAX_INTERFACE_ADDR];
174 afs_int32 ubik_epochTime = 0;
175 afs_int32 urecovery_state = 0;
176
177 struct rx_securityClass *ubik_sc[3];
178
179
180 /* Other declarations */
181
182 int
183 afsconf_GetNoAuthFlag(struct afsconf_dir *adir)
184 {
185 return (1);
186 }
187
188
189 char *prdir = "/dev/null";
190 struct prheader cheader;