[23740] | 1 | /* $Id: ubik.c,v 1.6 2006-05-12 20:20:08 zacheiss Exp $ */ |
---|
[23095] | 2 | |
---|
| 3 | #include <sys/types.h> |
---|
| 4 | #include <netinet/in.h> |
---|
| 5 | |
---|
| 6 | #include <lock.h> |
---|
| 7 | #define UBIK_INTERNALS |
---|
| 8 | #include <stds.h> |
---|
| 9 | #include <rx/xdr.h> |
---|
| 10 | #include "print.h" |
---|
| 11 | #include "prserver.h" |
---|
| 12 | |
---|
| 13 | /* Stolen bits of ubik.h. */ |
---|
| 14 | |
---|
| 15 | struct ubik_version { |
---|
| 16 | afs_int32 epoch; |
---|
| 17 | afs_int32 counter; |
---|
| 18 | }; |
---|
| 19 | typedef struct ubik_version ubik_version; |
---|
| 20 | |
---|
| 21 | /* ubik header file structure */ |
---|
| 22 | struct ubik_hdr { |
---|
| 23 | afs_int32 magic; /* magic number */ |
---|
| 24 | short pad1; /* some 0-initd padding */ |
---|
| 25 | short size; /* header allocation size */ |
---|
| 26 | struct ubik_version version; /* the version for this file */ |
---|
| 27 | }; |
---|
| 28 | |
---|
| 29 | #define HDRSIZE 64 /* bytes of header per dbfile */ |
---|
| 30 | #define UBIK_MAGIC 0x354545 |
---|
| 31 | |
---|
| 32 | extern int dbase_fd; |
---|
| 33 | struct ubik_dbase *dbase; |
---|
| 34 | |
---|
| 35 | int ubik_ServerInit() |
---|
| 36 | { |
---|
| 37 | return(0); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | int ubik_BeginTrans() |
---|
| 41 | { |
---|
| 42 | static int init=0; |
---|
| 43 | struct ubik_hdr thdr; |
---|
| 44 | |
---|
| 45 | if (!init) { |
---|
| 46 | thdr.version.epoch = htonl(0); |
---|
| 47 | thdr.version.counter = htonl(0); |
---|
| 48 | thdr.magic = htonl(UBIK_MAGIC); |
---|
| 49 | thdr.size = htonl(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 ubik_BeginTransReadAny() |
---|
| 59 | { |
---|
| 60 | return(0); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | int ubik_AbortTrans() |
---|
| 64 | { |
---|
| 65 | return(0); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | int ubik_EndTrans() |
---|
| 69 | { |
---|
| 70 | return(0); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | int ubik_Tell() |
---|
| 74 | { |
---|
| 75 | return(0); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | int ubik_Truncate() |
---|
| 79 | { |
---|
| 80 | return(0); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | long ubik_SetLock() |
---|
| 84 | { |
---|
| 85 | return(0); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | int ubik_WaitVersion() |
---|
| 89 | { |
---|
| 90 | return(0); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | int ubik_CacheUpdate() |
---|
| 94 | { |
---|
| 95 | return(0); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | int panic(a, b, c, d) |
---|
| 99 | char *a, *b, *c, *d; |
---|
| 100 | { |
---|
| 101 | printf(a, b, c, d); |
---|
| 102 | abort(); |
---|
| 103 | printf("BACK FROM ABORT\n"); /* shouldn't come back from floating pt exception */ |
---|
| 104 | exit(1); /* never know, though */ |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | int ubik_GetVersion(dummy, ver) |
---|
| 108 | int dummy; |
---|
| 109 | struct ubik_version *ver; |
---|
| 110 | { |
---|
| 111 | memset(ver, 0, sizeof(struct ubik_version)); |
---|
| 112 | return(0); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | int ubik_Seek(tt, afd, pos) |
---|
| 117 | struct ubik_trans *tt; |
---|
| 118 | long afd; |
---|
| 119 | long pos; |
---|
| 120 | { |
---|
| 121 | if (lseek(dbase_fd, pos+HDRSIZE, 0) < 0) { |
---|
| 122 | perror("ubik_Seek"); |
---|
| 123 | return(-1); |
---|
| 124 | } |
---|
| 125 | return(0); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | int ubik_Write(tt, buf, len) |
---|
| 129 | struct ubik_trans *tt; |
---|
| 130 | char *buf; |
---|
| 131 | long len; |
---|
| 132 | { |
---|
| 133 | int status; |
---|
| 134 | |
---|
| 135 | status = write(dbase_fd, buf, len); |
---|
| 136 | if (status < len) { |
---|
| 137 | perror("ubik_Write"); |
---|
| 138 | return(1); |
---|
| 139 | } |
---|
| 140 | return(0); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | int ubik_Read(tt, buf, len) |
---|
| 144 | struct ubik_trans *tt; |
---|
| 145 | char *buf; |
---|
| 146 | long len; |
---|
| 147 | { |
---|
| 148 | int status; |
---|
| 149 | |
---|
| 150 | status = read(dbase_fd, buf, len); |
---|
| 151 | if (status < 0) { |
---|
| 152 | perror("ubik_Read"); |
---|
| 153 | return(1); |
---|
| 154 | } |
---|
| 155 | if (status < len) |
---|
| 156 | memset(&buf[status], 0, len - status); |
---|
| 157 | return(0); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | struct rx_securityClass *ubik_sc[3]; |
---|
| 161 | |
---|
| 162 | /* Other declarations */ |
---|
| 163 | |
---|
| 164 | afsconf_GetNoAuthFlag() |
---|
| 165 | { |
---|
| 166 | return(1); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | char *prdir = "/dev/null"; |
---|
| 171 | struct prheader cheader; |
---|
| 172 | int pr_realmNameLen; |
---|
| 173 | char *pr_realmName; |
---|