cd7fc9e57d59050bd8a44a123f7a3b0f46883926
[openafs.git] / src / libafscp / afscp.h
1 #ifndef AFS_SRC_LIBAFSCP_AFSCP_H
2 #define AFS_SRC_LIBAFSCP_AFSCP_H
3
4 /* AUTORIGHTS */
5 #include <afs/param.h>
6 #include <afs/afsint.h>
7 #include <afs/afs_consts.h>
8 #include <afs/cellconfig.h>
9 #include <afs/dir.h>
10 #include <afs/afsutil.h>
11
12 #ifdef AFS_NT40_ENV
13 /* not included elsewhere for Windows */
14 #include <pthread.h>
15 #endif
16
17 struct afscp_server {
18     afsUUID id;
19     int index;
20     int cell;
21     int naddrs;
22     afs_uint32 addrs[AFS_MAXHOSTS];
23     struct rx_connection *conns[AFS_MAXHOSTS];
24 };
25
26 struct afscp_cell {
27     int id;
28     char name[MAXCELLCHARS + 1];
29     struct rx_securityClass *security;
30     int scindex;
31     struct ubik_client *vlservers;
32     int nservers;
33     int srvsalloced;
34     struct afscp_server **fsservers;
35     void *volsbyname;
36     void *volsbyid;
37     char *realm;
38 };
39
40 struct afscp_volume {
41     struct afscp_cell *cell;
42     afs_uint32 id;
43     int voltype;
44     int nservers;
45     int servers[AFS_MAXHOSTS];
46     char name[AFSNAMEMAX];
47     void *statcache;
48     void *dircache;
49 };
50
51 struct afscp_venusfid {
52     struct afscp_cell *cell;
53     struct AFSFid fid;
54 };
55
56 struct afscp_dirent {
57     afs_uint32 vnode;
58     afs_uint32 unique;
59     char name[16 + 32 * (EPP - 2)];
60 };
61
62 struct afscp_dirstream {
63     struct afscp_venusfid fid;
64     int buflen;
65     char *dirbuffer;
66     int hashent;
67     int entry;
68     int dv;
69     struct afscp_dirent ret;
70 };
71
72 struct afscp_dircache {
73     struct afscp_venusfid me;
74     int buflen;
75     char *dirbuffer;
76     int dv;
77     int nwaiters;
78     pthread_mutex_t mtx;
79     pthread_cond_t cv;
80 };
81
82 struct afscp_statent {
83     struct afscp_venusfid me;
84     struct AFSFetchStatus status;
85     int nwaiters;
86     int cleanup;
87     pthread_mutex_t mtx;
88     pthread_cond_t cv;
89 };
90
91 struct afscp_openfile {
92     struct afscp_venusfid fid;
93     off_t offset;
94 };
95
96 struct afscp_callback {
97     int valid;
98     const struct afscp_server *server;
99     struct AFSFid fid;
100     struct AFSCallBack cb;
101     time_t as_of;
102 };
103
104 extern int afscp_errno;
105 int afscp_Init(const char *);
106 void afscp_Finalize(void);
107
108 int afscp_Insecure(void);
109 int afscp_AnonymousAuth(int);
110
111 struct afscp_cell *afscp_DefaultCell(void);
112 struct afscp_cell *afscp_CellByName(const char *, const char *);
113 int afscp_SetDefaultRealm(const char *);
114 int afscp_SetDefaultCell(const char *);
115 struct afscp_cell *afscp_CellById(int);
116 int afscp_CellId(struct afscp_cell *);
117 void afscp_FreeAllCells(void);
118 void afscp_FreeAllServers(void);
119
120 struct afscp_server *afscp_ServerById(struct afscp_cell *, afsUUID *);
121 struct afscp_server *afscp_ServerByAddr(struct afscp_cell *, afs_uint32);
122 struct afscp_server *afscp_AnyServerByAddr(afs_uint32);
123 struct afscp_server *afscp_ServerByIndex(int);
124 struct rx_connection *afscp_ServerConnection(const struct afscp_server *,
125                                              int);
126
127 int afscp_CheckCallBack(const struct afscp_venusfid *fid,
128                         const struct afscp_server *server,
129                         afs_uint32 *expiretime);
130 int afscp_FindCallBack(const struct afscp_venusfid *f,
131                        const struct afscp_server *server,
132                        struct afscp_callback *ret);
133 int afscp_AddCallBack(const struct afscp_server *,
134                       const struct AFSFid *,
135                       const struct AFSFetchStatus *,
136                       const struct AFSCallBack *, const time_t);
137 int afscp_RemoveCallBack(const struct afscp_server *,
138                          const struct afscp_venusfid *);
139 int afscp_ReturnCallBacks(const struct afscp_server *);
140 int afscp_ReturnAllCallBacks(void);
141 int afscp_WaitForCallback(const struct afscp_venusfid *fid, int seconds);
142
143 /* file metastuff */
144 /* frees with free() */
145 struct afscp_venusfid *afscp_MakeFid(struct afscp_cell *, afs_uint32,
146                                      afs_uint32, afs_uint32);
147 struct afscp_venusfid *afscp_DupFid(const struct afscp_venusfid *);
148 void afscp_FreeFid(struct afscp_venusfid *);
149
150 struct stat;
151 int afscp_Stat(const struct afscp_venusfid *, struct stat *);
152
153 ssize_t afscp_PRead(const struct afscp_venusfid *, void *, size_t, off_t);
154 ssize_t afscp_PWrite(const struct afscp_venusfid *, const void *,
155                      size_t, off_t);
156 /*
157  * for future implementation: (?)
158  * struct afscp_openfile *afscp_FidOpen(const struct afscp_venusfid *);
159  * off_t afscp_FSeek(struct afscp_openfile *, off_t, int);
160  * ssize_t afscp_FRead(const struct afscp_openfile *, void *, size_t);
161  */
162
163 /* rpc wrappers */
164 int afscp_GetStatus(const struct afscp_venusfid *, struct AFSFetchStatus *);
165 int afscp_StoreStatus(const struct afscp_venusfid *, struct AFSStoreStatus *);
166 int afscp_CreateFile(const struct afscp_venusfid *, char *,
167                      struct AFSStoreStatus *, struct afscp_venusfid **);
168 int afscp_Lock(const struct afscp_venusfid *, int locktype);
169 int afscp_MakeDir(const struct afscp_venusfid *, char *,
170                   struct AFSStoreStatus *, struct afscp_venusfid **);
171 int afscp_Symlink(const struct afscp_venusfid *, char *,
172                   char *, struct AFSStoreStatus *);
173 int afscp_RemoveFile(const struct afscp_venusfid *, char *);
174 int afscp_RemoveDir(const struct afscp_venusfid *, char *);
175 int afscp_FetchACL(const struct afscp_venusfid *, struct AFSOpaque *);
176 int afscp_StoreACL(const struct afscp_venusfid *, struct AFSOpaque *);
177
178 /* directory parsing stuff*/
179 struct afscp_dirstream *afscp_OpenDir(const struct afscp_venusfid *);
180 struct afscp_dirent *afscp_ReadDir(struct afscp_dirstream *);
181 int afscp_RewindDir(struct afscp_dirstream *);
182 int afscp_CloseDir(struct afscp_dirstream *);
183 struct afscp_venusfid *afscp_DirLookup(struct afscp_dirstream *,
184                                        const char *);
185 struct afscp_venusfid *afscp_ResolveName(const struct afscp_venusfid *,
186                                          const char *);
187 struct afscp_venusfid *afscp_ResolvePath(const char *);
188 struct afscp_venusfid *afscp_ResolvePathFromVol(const struct afscp_volume *,
189                                                 const char *);
190
191 /* vldb stuff */
192 struct afscp_volume *afscp_VolumeByName(struct afscp_cell *,
193                                         const char *, afs_int32);
194 struct afscp_volume *afscp_VolumeById(struct afscp_cell *, afs_uint32);
195
196 #define DIRMODE_CELL    0
197 #define DIRMODE_DYNROOT 1
198 int afscp_SetDirMode(int);
199
200 #endif /* AFS_SRC_LIBAFSCP_AFSCP_H */