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 <afs/param.h>
28 #include <afs/afsint.h>
29 #include <afs/vlserver.h>
30 #include <afs/vldbint.h>
35 #include "afscp_internal.h"
37 ssize_t afs_pread(const struct afs_venusfid *fid, void *buffer, size_t count, off_t offset) {
38 struct AFSFetchStatus fst;
40 struct AFSCallBack cb;
41 struct AFSFid tf = fid->fid;
42 struct afs_volume *vol;
43 struct afs_server *server;
45 struct rx_call *c=NULL;
47 int i,j,bytes,totalbytes;
51 vol=afs_volumebyid(fid->cell, fid->fid.Volume);
57 for (i=0;i<vol->nservers;i++) {
58 server=afs_serverbyindex(vol->servers[i]);
59 if (server && server->naddrs > 0) {
60 for (j=0;j < server->naddrs;j++) {
61 c=rx_NewCall(server->conns[j]);
64 code=StartRXAFS_FetchData(c, &tf, offset, count);
66 code=rx_EndCall(c,code);
69 bytes=rx_Read(c,(char *)&bytesremaining,sizeof(afs_int32));
70 if (bytes != sizeof(afs_int32)) {
71 code=rx_EndCall(c,bytes);
74 bytesremaining=ntohl(bytesremaining);
76 while (bytesremaining > 0) {
77 bytes=rx_Read(c, p, bytesremaining);
82 bytesremaining-=bytes;
84 if (bytesremaining == 0) {
85 code2=EndRXAFS_FetchData(c, &fst, &cb, &vs);
87 AddCallBack(server, &fid->fid, &fst, &cb);
89 code=rx_EndCall(c, code2);
102 ssize_t afs_pwrite(const struct afs_venusfid *fid, const void *buffer, size_t count, off_t offset) {
104 struct AFSFetchStatus fst;
105 struct AFSStoreStatus sst;
106 struct AFSVolSync vs;
107 struct AFSCallBack cb;
108 struct AFSFid tf=fid->fid;
109 struct afs_volume *vol;
110 struct afs_server *server;
112 struct rx_call *c=NULL;
114 int i,j,bytes,totalbytes;
121 vol=afs_volumebyid(fid->cell, fid->fid.Volume);
126 if (vol->voltype != VOLTYPE_RW) {
132 for (i=0;i<vol->nservers;i++) {
133 server=afs_serverbyindex(vol->servers[i]);
134 if (server && server->naddrs > 0) {
135 for (j=0;j < server->naddrs;j++) {
136 code=RXAFS_FetchStatus(server->conns[j], &tf, &fst, &cb, &vs);
139 sst.Mask=AFS_SETMODTIME;
141 sst.ClientModTime = now;
143 if (offset + count > filesize)
144 filesize = offset + count;
145 c=rx_NewCall(server->conns[j]);
148 code=StartRXAFS_StoreData(c, &tf, &sst, offset, count, filesize);
150 code=rx_EndCall(c,code);
153 bytesremaining=htonl(count);
154 bytes=rx_Write(c,(char *)&bytesremaining,sizeof(afs_int32));
155 if (bytes != sizeof(afs_int32)) {
156 code=rx_EndCall(c,bytes);
159 bytesremaining=count;
161 while (bytesremaining > 0) {
162 bytes=rx_Write(c, (char *)p, bytesremaining);
167 bytesremaining-=bytes;
169 if (bytesremaining == 0) {
170 code2=EndRXAFS_StoreData(c, &fst, &vs);
172 code=rx_EndCall(c, code2);