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