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 vol = afscp_VolumeById(fid->cell, fid->fid.Volume);
131 afscp_errno = ENOENT;
134 if (vol->voltype != RWVOL) {
140 for (i = 0; i < vol->nservers; i++) {
141 server = afscp_ServerByIndex(vol->servers[i]);
142 if (server && server->naddrs > 0) {
143 for (j = 0; j < server->naddrs; j++) {
145 RXAFS_FetchStatus(server->conns[j], &tf, &fst, &cb, &vs);
148 sst.Mask = AFS_SETMODTIME;
150 sst.ClientModTime = now;
151 filesize = fst.Length;
152 if (offset + count > filesize)
153 filesize = offset + count;
154 c = rx_NewCall(server->conns[j]);
158 StartRXAFS_StoreData(c, &tf, &sst, offset, count,
161 code = rx_EndCall(c, code);
164 bytesremaining = count;
166 while (bytesremaining > 0) {
167 bytes = rx_Write(c, (char *)p, bytesremaining);
172 bytesremaining -= bytes;
174 if (bytesremaining == 0) {
175 code = EndRXAFS_StoreData(c, &fst, &vs);
177 code = rx_EndCall(c, code);