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>
33 #include "afscp_internal.h"
35 /* this is not yet 64-bit clean */
37 afscp_PRead(const struct afscp_venusfid
* fid
, void *buffer
,
38 size_t count
, off_t offset
)
40 struct AFSFetchStatus fst
;
42 struct AFSCallBack cb
;
43 struct AFSFid tf
= fid
->fid
;
44 struct afscp_volume
*vol
;
45 struct afscp_server
*server
;
46 struct rx_call
*c
= NULL
;
48 int i
, j
, bytes
, totalbytes
= 0;
53 vol
= afscp_VolumeById(fid
->cell
, fid
->fid
.Volume
);
59 for (i
= 0; i
< vol
->nservers
; i
++) {
60 server
= afscp_ServerByIndex(vol
->servers
[i
]);
61 if (server
&& server
->naddrs
> 0) {
62 for (j
= 0; j
< server
->naddrs
; j
++) {
63 c
= rx_NewCall(server
->conns
[j
]);
66 code
= StartRXAFS_FetchData(c
, &tf
, offset
, count
);
68 code
= rx_EndCall(c
, code
);
72 rx_Read(c
, (char *)&bytesremaining
,
74 if (bytes
!= sizeof(afs_int32
)) {
75 code
= rx_EndCall(c
, bytes
);
78 bytesremaining
= ntohl(bytesremaining
);
80 while (bytesremaining
> 0) {
81 bytes
= rx_Read(c
, p
, bytesremaining
);
86 bytesremaining
-= bytes
;
88 if (bytesremaining
== 0) {
90 code2
= EndRXAFS_FetchData(c
, &fst
, &cb
, &vs
);
92 afscp_AddCallBack(server
, &fid
->fid
, &fst
, &cb
,
95 code
= rx_EndCall(c
, code2
);
107 /* this is not yet 64-bit clean */
109 afscp_PWrite(const struct afscp_venusfid
* fid
, const void *buffer
,
110 size_t count
, off_t offset
)
112 struct AFSFetchStatus fst
;
113 struct AFSStoreStatus sst
;
114 struct AFSVolSync vs
;
115 struct AFSCallBack cb
;
116 struct AFSFid tf
= fid
->fid
;
117 struct afscp_volume
*vol
;
118 struct afscp_server
*server
;
119 struct rx_call
*c
= NULL
;
121 int i
, j
, bytes
, totalbytes
= 0;
127 memset(&sst
, 0, sizeof(sst
));
128 vol
= afscp_VolumeById(fid
->cell
, fid
->fid
.Volume
);
130 afscp_errno
= ENOENT
;
133 if (vol
->voltype
!= RWVOL
) {
139 for (i
= 0; i
< vol
->nservers
; i
++) {
140 server
= afscp_ServerByIndex(vol
->servers
[i
]);
141 if (server
&& server
->naddrs
> 0) {
142 for (j
= 0; j
< server
->naddrs
; j
++) {
144 RXAFS_FetchStatus(server
->conns
[j
], &tf
, &fst
, &cb
, &vs
);
147 sst
.Mask
= AFS_SETMODTIME
;
149 sst
.ClientModTime
= now
;
150 filesize
= fst
.Length
;
151 if (offset
+ count
> filesize
)
152 filesize
= offset
+ count
;
153 c
= rx_NewCall(server
->conns
[j
]);
157 StartRXAFS_StoreData(c
, &tf
, &sst
, offset
, count
,
160 code
= rx_EndCall(c
, code
);
164 * seems to write file length to beginning of file -- why?
167 * bytesremaining = htonl(count);
168 * bytes = rx_Write(c, (char *)&bytesremaining,
169 * sizeof(afs_int32));
170 * if (bytes != sizeof(afs_int32)) {
171 * code = rx_EndCall(c, bytes);
175 bytesremaining
= count
;
177 while (bytesremaining
> 0) {
178 bytes
= rx_Write(c
, (char *)p
, bytesremaining
);
183 bytesremaining
-= bytes
;
185 if (bytesremaining
== 0) {
186 code2
= EndRXAFS_StoreData(c
, &fst
, &vs
);
188 code
= rx_EndCall(c
, code2
);