ticket-2618-patches-20031207
[openafs.git] / src / ptserver / ubik.c
1 /* $Id$ */
2
3 #include <afsconfig.h>
4 #include <afs/param.h>
5
6 RCSID
7     ("$Header$");
8
9 #include <sys/types.h>
10 #include <netinet/in.h>
11
12 #ifdef HAVE_STRING_H
13 #include <string.h>
14 #else
15 #ifdef HAVE_STRINGS_H
16 #include <strings.h>
17 #endif
18 #endif
19
20 #include <lock.h>
21 #define UBIK_INTERNALS
22 #include <afs/stds.h>
23 #include <ubik.h>
24 #include <rx/xdr.h>
25 #include "ptint.h"
26 #include "ptserver.h"
27
28 extern int dbase_fd;
29 struct ubik_dbase *dbase;
30
31 int
32 ubik_ServerInit()
33 {
34     return (0);
35 }
36
37 int
38 ubik_BeginTrans()
39 {
40     static int init = 0;
41     struct ubik_hdr thdr;
42
43     if (!init) {
44         thdr.version.epoch = htonl(2);
45         thdr.version.counter = htonl(0);
46         thdr.magic = htonl(UBIK_MAGIC);
47         thdr.size = htonl(HDRSIZE);
48         lseek(dbase_fd, 0, 0);
49         write(dbase_fd, &thdr, sizeof(thdr));
50         fsync(dbase_fd);
51         init = 1;
52     }
53     return (0);
54 }
55
56 int
57 ubik_BeginTransReadAny()
58 {
59     return (0);
60 }
61
62 int
63 ubik_AbortTrans()
64 {
65     return (0);
66 }
67
68 int
69 ubik_EndTrans()
70 {
71     return (0);
72 }
73
74 int
75 ubik_Tell()
76 {
77     return (0);
78 }
79
80 int
81 ubik_Truncate()
82 {
83     return (0);
84 }
85
86 long
87 ubik_SetLock()
88 {
89     return (0);
90 }
91
92 int
93 ubik_WaitVersion()
94 {
95     return (0);
96 }
97
98 int
99 ubik_CacheUpdate()
100 {
101     return (0);
102 }
103
104 int
105 panic(a, b, c, d)
106      char *a, *b, *c, *d;
107 {
108     printf(a, b, c, d);
109     abort();
110     printf("BACK FROM ABORT\n");        /* shouldn't come back from floating pt exception */
111     exit(1);                    /* never know, though */
112 }
113
114 int
115 ubik_GetVersion(dummy, ver)
116      int dummy;
117      struct ubik_version *ver;
118 {
119     memset(ver, 0, sizeof(struct ubik_version));
120     return (0);
121 }
122
123
124 int
125 ubik_Seek(tt, afd, pos)
126      struct ubik_trans *tt;
127      long afd;
128      long pos;
129 {
130     if (lseek(dbase_fd, pos + HDRSIZE, 0) < 0) {
131         perror("ubik_Seek");
132         return (-1);
133     }
134     return (0);
135 }
136
137 int
138 ubik_Write(tt, buf, len)
139      struct ubik_trans *tt;
140      char *buf;
141      long 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(tt, buf, len)
155      struct ubik_trans *tt;
156      char *buf;
157      long len;
158 {
159     int status;
160
161     status = read(dbase_fd, buf, len);
162     if (status < 0) {
163         perror("ubik_Read");
164         return (1);
165     }
166     if (status < len)
167         memset(&buf[status], 0, len - status);
168     return (0);
169 }
170
171
172 /* Global declarations from ubik.c */
173 afs_int32 ubik_quorum = 0;
174 struct ubik_dbase *ubik_dbase = 0;
175 struct ubik_stats ubik_stats;
176 afs_uint32 ubik_host[UBIK_MAX_INTERFACE_ADDR];
177 afs_int32 ubik_epochTime = 0;
178 afs_int32 urecovery_state = 0;
179
180 struct rx_securityClass *ubik_sc[3];
181
182
183 /* Other declarations */
184
185 int
186 afsconf_GetNoAuthFlag()
187 {
188     return (1);
189 }
190
191
192 char *prdir = "/dev/null";
193 struct prheader cheader;
194 int pr_realmNameLen;
195 char *pr_realmName;