darwin-x86-and-leopard-20060309
[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(afs_int32 myHost, short myPort, afs_int32 serverList[],
33                 char *pathName, struct ubik_dbase **dbase)
34 {
35     return (0);
36 }
37
38 int
39 ubik_BeginTrans(register struct ubik_dbase *dbase, afs_int32 transMode, 
40                 struct ubik_trans **transPtr)
41 {
42     static int init = 0;
43     struct ubik_hdr thdr;
44
45     if (!init) {
46         thdr.version.epoch = htonl(2);
47         thdr.version.counter = htonl(0);
48         thdr.magic = htonl(UBIK_MAGIC);
49         thdr.size = htons(HDRSIZE);
50         lseek(dbase_fd, 0, 0);
51         write(dbase_fd, &thdr, sizeof(thdr));
52         fsync(dbase_fd);
53         init = 1;
54     }
55     return (0);
56 }
57
58 int
59 ubik_BeginTransReadAny(register struct ubik_dbase *dbase, afs_int32 transMode,
60                        struct ubik_trans **transPtr)
61 {
62     return (0);
63 }
64
65 int
66 ubik_AbortTrans(register struct ubik_trans *transPtr)
67 {
68     return (0);
69 }
70
71 int
72 ubik_EndTrans(register struct ubik_trans *transPtr)
73 {
74     return (0);
75 }
76
77 int
78 ubik_Tell(register struct ubik_trans *transPtr, afs_int32 * fileid,
79           afs_int32 * position)
80 {
81     return (0);
82 }
83
84 int
85 ubik_Truncate(register struct ubik_trans *transPtr, afs_int32 length)
86 {
87     return (0);
88 }
89
90 long
91 ubik_SetLock(struct ubik_trans *atrans, afs_int32 apos, afs_int32 alen,
92              int atype)
93 {
94     return (0);
95 }
96
97 int
98 ubik_WaitVersion(register struct ubik_dbase *adatabase,
99                  register struct ubik_version *aversion)
100 {
101     return (0);
102 }
103
104 int
105 ubik_CacheUpdate(register struct ubik_trans *atrans)
106 {
107     return (0);
108 }
109
110 int
111 panic(char *a, char *b, char *c, char *d)
112 {
113     printf(a, b, c, d);
114     abort();
115     printf("BACK FROM ABORT\n");        /* shouldn't come back from floating pt exception */
116     exit(1);                    /* never know, though */
117 }
118
119 int
120 ubik_GetVersion(int dummy, struct ubik_version *ver)
121 {
122     memset(ver, 0, sizeof(struct ubik_version));
123     return (0);
124 }
125
126
127 int
128 ubik_Seek(struct ubik_trans *tt, long afd, 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(struct ubik_trans *tt, char *buf, long len)
139 {
140     int status;
141
142     status = write(dbase_fd, buf, len);
143     if (status < len) {
144         perror("ubik_Write");
145         return (1);
146     }
147     return (0);
148 }
149
150 int
151 ubik_Read(struct ubik_trans *tt, char *buf, long len)
152 {
153     int status;
154
155     status = read(dbase_fd, buf, len);
156     if (status < 0) {
157         perror("ubik_Read");
158         return (1);
159     }
160     if (status < len)
161         memset(&buf[status], 0, len - status);
162     return (0);
163 }
164
165
166 /* Global declarations from ubik.c */
167 afs_int32 ubik_quorum = 0;
168 struct ubik_dbase *ubik_dbase = 0;
169 struct ubik_stats ubik_stats;
170 afs_uint32 ubik_host[UBIK_MAX_INTERFACE_ADDR];
171 afs_int32 ubik_epochTime = 0;
172 afs_int32 urecovery_state = 0;
173
174 struct rx_securityClass *ubik_sc[3];
175
176
177 /* Other declarations */
178
179 int 
180 afsconf_GetNoAuthFlag(struct afsconf_dir *adir)
181 {
182     return (1);
183 }
184
185
186 char *prdir = "/dev/null";
187 struct prheader cheader;
188 int pr_realmNameLen;
189 char *pr_realmName;