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