2 Copyright (C) 2003 - 2010 Chaskiel Grundman
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <afsconfig.h>
28 #include <afs/param.h>
30 #include <afs/vlserver.h>
31 #include <afs/vldbint.h>
34 #include "afscp_internal.h"
35 #include <afs/unified_afs.h>
38 afscp_CreateFile(const struct afscp_venusfid
*dir
, char *name
,
39 struct AFSStoreStatus
*sst
, struct afscp_venusfid
**ret
)
42 struct AFSFid df
= dir
->fid
;
43 struct afscp_volume
*vol
;
44 struct AFSFetchStatus dfst
, fst
;
46 struct AFSCallBack cb
;
48 struct afscp_server
*server
;
49 struct rx_connection
*c
;
52 if (dir
== NULL
|| name
== NULL
|| sst
== NULL
) {
54 "afscp_CreateFile called with NULL args, cannot continue\n");
57 vol
= afscp_VolumeById(dir
->cell
, dir
->fid
.Volume
);
63 for (i
= 0; i
< vol
->nservers
; i
++) {
64 server
= afscp_ServerByIndex(vol
->servers
[i
]);
65 if (server
&& server
->naddrs
> 0) {
66 for (j
= 0; j
< server
->naddrs
; j
++) {
67 c
= afscp_ServerConnection(server
, j
);
72 code
= RXAFS_CreateFile(c
, &df
, name
, sst
, &ff
,
73 &fst
, &dfst
, &cb
, &vs
);
88 _StatStuff(dir
, &dfst
);
89 afscp_AddCallBack(server
, &ff
, &fst
, &cb
, now
);
91 *ret
= afscp_MakeFid(vol
->cell
, ff
.Volume
, ff
.Vnode
, ff
.Unique
);
96 afscp_MakeDir(const struct afscp_venusfid
*dir
, char *name
,
97 struct AFSStoreStatus
*sst
, struct afscp_venusfid
**ret
)
100 struct AFSFid df
= dir
->fid
;
101 struct afscp_volume
*vol
;
102 struct AFSFetchStatus dfst
, fst
;
103 struct AFSVolSync vs
;
104 struct AFSCallBack cb
;
106 struct afscp_server
*server
;
107 struct rx_connection
*c
;
110 vol
= afscp_VolumeById(dir
->cell
, dir
->fid
.Volume
);
112 afscp_errno
= ENOENT
;
116 for (i
= 0; i
< vol
->nservers
; i
++) {
117 server
= afscp_ServerByIndex(vol
->servers
[i
]);
118 if (server
&& server
->naddrs
> 0) {
119 for (j
= 0; j
< server
->naddrs
; j
++) {
120 c
= afscp_ServerConnection(server
, j
);
124 code
= RXAFS_MakeDir(c
, &df
, name
, sst
, &ff
,
125 &fst
, &dfst
, &cb
, &vs
);
134 _StatInvalidate(dir
);
138 _StatStuff(dir
, &dfst
);
139 afscp_AddCallBack(server
, &ff
, &fst
, &cb
, now
);
141 *ret
= afscp_MakeFid(vol
->cell
, ff
.Volume
, ff
.Vnode
, ff
.Unique
);
146 afscp_Symlink(const struct afscp_venusfid
*dir
, char *name
,
147 char *target
, struct AFSStoreStatus
*sst
)
150 struct AFSFid df
= dir
->fid
;
151 struct afscp_volume
*vol
;
152 struct AFSFetchStatus dfst
, fst
;
153 struct AFSVolSync vs
;
155 struct afscp_server
*server
;
156 struct rx_connection
*c
;
158 vol
= afscp_VolumeById(dir
->cell
, dir
->fid
.Volume
);
160 afscp_errno
= ENOENT
;
164 for (i
= 0; i
< vol
->nservers
; i
++) {
165 server
= afscp_ServerByIndex(vol
->servers
[i
]);
166 if (server
&& server
->naddrs
> 0) {
167 for (j
= 0; j
< server
->naddrs
; j
++) {
168 c
= afscp_ServerConnection(server
, j
);
171 code
= RXAFS_Symlink(c
, &df
, name
, target
, sst
,
172 &ff
, &fst
, &dfst
, &vs
);
181 _StatInvalidate(dir
);
185 _StatStuff(dir
, &dfst
);
191 afscp_Lock(const struct afscp_venusfid
*fid
, int locktype
)
194 struct AFSFid ff
= fid
->fid
;
195 struct afscp_volume
*vol
;
196 struct AFSVolSync vs
;
197 struct afscp_server
*server
;
198 struct rx_connection
*c
;
200 vol
= afscp_VolumeById(fid
->cell
, fid
->fid
.Volume
);
202 afscp_errno
= ENOENT
;
206 for (i
= 0; i
< vol
->nservers
; i
++) {
207 server
= afscp_ServerByIndex(vol
->servers
[i
]);
208 if (server
&& server
->naddrs
> 0) {
209 for (j
= 0; j
< server
->naddrs
; j
++) {
210 c
= afscp_ServerConnection(server
, j
);
213 if (locktype
== LockRelease
)
214 code
= RXAFS_ReleaseLock(c
, &ff
, &vs
);
215 /* read, write, extend */
216 else if (locktype
< LockRelease
)
217 code
= RXAFS_SetLock(c
, &ff
, locktype
, &vs
);
226 if ((code
== EAGAIN
) || (code
== UAEWOULDBLOCK
) || (code
== UAEAGAIN
))
236 afscp_RemoveFile(const struct afscp_venusfid
*dir
, char *name
)
239 struct AFSFid df
= dir
->fid
;
240 struct afscp_volume
*vol
;
241 struct AFSFetchStatus dfst
;
242 struct AFSVolSync vs
;
243 struct afscp_server
*server
;
244 struct rx_connection
*c
;
246 vol
= afscp_VolumeById(dir
->cell
, dir
->fid
.Volume
);
248 afscp_errno
= ENOENT
;
252 for (i
= 0; i
< vol
->nservers
; i
++) {
253 server
= afscp_ServerByIndex(vol
->servers
[i
]);
254 if (server
&& server
->naddrs
> 0) {
255 for (j
= 0; j
< server
->naddrs
; j
++) {
256 c
= afscp_ServerConnection(server
, j
);
259 code
= RXAFS_RemoveFile(c
, &df
, name
, &dfst
, &vs
);
268 _StatInvalidate(dir
);
272 _StatStuff(dir
, &dfst
);
277 afscp_RemoveDir(const struct afscp_venusfid
*dir
, char *name
)
280 struct AFSFid df
= dir
->fid
;
281 struct afscp_volume
*vol
;
282 struct AFSFetchStatus dfst
;
283 struct AFSVolSync vs
;
284 struct afscp_server
*server
;
285 struct rx_connection
*c
;
287 vol
= afscp_VolumeById(dir
->cell
, dir
->fid
.Volume
);
289 afscp_errno
= ENOENT
;
293 for (i
= 0; i
< vol
->nservers
; i
++) {
294 server
= afscp_ServerByIndex(vol
->servers
[i
]);
295 if (server
&& server
->naddrs
> 0) {
296 for (j
= 0; j
< server
->naddrs
; j
++) {
297 c
= afscp_ServerConnection(server
, j
);
300 code
= RXAFS_RemoveDir(c
, &df
, name
, &dfst
, &vs
);
309 _StatInvalidate(dir
);
313 _StatStuff(dir
, &dfst
);