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>
32 #include <afs/vlserver.h>
33 #include <afs/vldbint.h>
35 #include "afscp_internal.h"
37 /* this is not yet 64-bit clean */
39 afscp_PRead(const struct afscp_venusfid
* fid
, void *buffer
,
40 size_t count
, off_t offset
)
42 struct AFSFetchStatus fst
;
44 struct AFSCallBack cb
;
45 struct AFSFid tf
= fid
->fid
;
46 struct afscp_volume
*vol
;
47 struct afscp_server
*server
;
48 struct rx_call
*c
= NULL
;
50 int i
, j
, bytes
, totalbytes
= 0;
55 vol
= afscp_VolumeById(fid
->cell
, fid
->fid
.Volume
);
61 for (i
= 0; i
< vol
->nservers
; i
++) {
62 server
= afscp_ServerByIndex(vol
->servers
[i
]);
63 if (server
&& server
->naddrs
> 0) {
64 for (j
= 0; j
< server
->naddrs
; j
++) {
65 c
= rx_NewCall(server
->conns
[j
]);
68 code
= StartRXAFS_FetchData(c
, &tf
, offset
, count
);
70 code
= rx_EndCall(c
, code
);
74 rx_Read(c
, (char *)&bytesremaining
,
76 if (bytes
!= sizeof(afs_int32
)) {
77 code
= rx_EndCall(c
, RX_PROTOCOL_ERROR
);
80 bytesremaining
= ntohl(bytesremaining
);
82 while (bytesremaining
> 0) {
83 bytes
= rx_Read(c
, p
, bytesremaining
);
88 bytesremaining
-= bytes
;
90 if (bytesremaining
== 0) {
92 code
= EndRXAFS_FetchData(c
, &fst
, &cb
, &vs
);
94 afscp_AddCallBack(server
, &fid
->fid
, &fst
, &cb
,
97 code
= rx_EndCall(c
, code
);
109 /* this is not yet 64-bit clean */
111 afscp_PWrite(const struct afscp_venusfid
* fid
, const void *buffer
,
112 size_t count
, off_t offset
)
114 struct AFSFetchStatus fst
;
115 struct AFSStoreStatus sst
;
116 struct AFSVolSync vs
;
117 struct AFSCallBack cb
;
118 struct AFSFid tf
= fid
->fid
;
119 struct afscp_volume
*vol
;
120 struct afscp_server
*server
;
121 struct rx_call
*c
= NULL
;
123 int i
, j
, bytes
, totalbytes
= 0;
129 memset(&sst
, 0, sizeof(sst
));
130 vol
= afscp_VolumeById(fid
->cell
, fid
->fid
.Volume
);
132 afscp_errno
= ENOENT
;
135 if (vol
->voltype
!= RWVOL
) {
141 for (i
= 0; i
< vol
->nservers
; i
++) {
142 server
= afscp_ServerByIndex(vol
->servers
[i
]);
143 if (server
&& server
->naddrs
> 0) {
144 for (j
= 0; j
< server
->naddrs
; j
++) {
146 RXAFS_FetchStatus(server
->conns
[j
], &tf
, &fst
, &cb
, &vs
);
149 sst
.Mask
= AFS_SETMODTIME
;
151 sst
.ClientModTime
= now
;
152 filesize
= fst
.Length
;
153 if (offset
+ count
> filesize
)
154 filesize
= offset
+ count
;
155 c
= rx_NewCall(server
->conns
[j
]);
159 StartRXAFS_StoreData(c
, &tf
, &sst
, offset
, count
,
162 code
= rx_EndCall(c
, code
);
165 bytesremaining
= count
;
167 while (bytesremaining
> 0) {
168 bytes
= rx_Write(c
, (char *)p
, bytesremaining
);
173 bytesremaining
-= bytes
;
175 if (bytesremaining
== 0) {
176 code
= EndRXAFS_StoreData(c
, &fst
, &vs
);
178 code
= rx_EndCall(c
, code
);