static int cmd_cache(char *args) { bool success; uint32_t tmpAddr = expr(args, &success); printf("addr:%x:%x cache_total:%u cache_nothit:%u\n", tmpAddr, readcache(tmpAddr, 4), cache.total, cache.nothitnum); return 0; }
ssize_t pfs_read(int filedes, void *buf, ssize_t nbyte, off_t offset, int *cache_hit) {//READ filename w offset length END. *cache_hit = readcache(filedes, offset, nbyte);//what's the usage of filedes here???? if(*cache_hit) return nbyte;//cachehit int ofI = 0; while((ofI < ofnum)&&(openfiles[ofI]->fd != filedes)) ofI++; if(ofI == ofnum) return -1; OpenFile* of = openfiles[ofI]; char spacket[BUFFER_SIZE]; //Buffer for client data /* char Offset[7]; char Length[7]; strcat(spacket,"READ "); strcat(spacket, of->filename); int2str(offset/ONEKB,Offset,10); int2str(nbyte/ONEKB,Length,10); strcat(spacket, Offset); strcat(spacket, " "); strcat(spacket, Length); strcat(spacket, " "); strcat(spacket," END."); if (send(mmFD, spacket, sizeof(spacket), 0) == -1) //READ pfs_file1 offset length END. perror("Error in sending!"); char rpacket[BUFFER_SIZE] = ""; //Buffer for client data int size = MMR(rpacket, BUFFER_SIZE);//READ filename offset length END. */ //offset ... nbyte //start = fsoffset + offset/(size*ONEKB), offset -> fsoffset + (offset+length)/(size*ONEKB) //first: offset % (size*ONEKB) -> min(offset+length, size*ONEKB) //intermediates: //last: 0 -> (offset+length)%(size*ONEKB) unsigned fsstart, from, to, plen; unsigned os = offset; unsigned len = nbyte; int i; for(i= of->fsoffset + (offset/(STRIP_SIZE*ONEKB)); (i-of->fsoffset)*(STRIP_SIZE*ONEKB) < (offset+nbyte); i++) {//Send for each FSs -> READ pfs_file1 w from to(plen) END. //if (!fork()) //{ // this is the child process // close(myTFD); // child doesn't need the listener strcpy(spacket,"READ "); strcat(spacket, of->filename); strcat(spacket, " "); strcat(spacket, of->mode); strcat(spacket, " "); //0 ,1 ,2 ,3 + 4 ,5 ,6 ,7 + 8 ,9 ,10,11 //12,13,14,15 + 16,17,18,19 + 20,21,22,23 //24,25,26,27 + 28,29,30,31 + 32,33,34,35 //os=19->32 -> l=13, i=4, sw=3, fsstart = (i/of->stripe_width)*(STRIP_SIZE*ONEKB); from = fsstart + os%(STRIP_SIZE*ONEKB); to = fsstart + min(os%(STRIP_SIZE*ONEKB)+len, STRIP_SIZE*ONEKB); plen = to - from; char From[10]; char PLen[10]; int2str(from, From, 10); int2str(plen, PLen, 10); strcat(spacket, From); strcat(spacket, " "); strcat(spacket, PLen); strcat(spacket, " END."); if (send(fs[i%of->stripe_width].fd, spacket, sizeof(spacket), 0) == -1) perror("Error in sending!"); // close(newfd); // exit(0); //} int size; char rpacket[plen]; //Buffer for client data if ((size = recv(fs[i%of->stripe_width].fd, rpacket, sizeof(rpacket), 0)) == -1) perror("Error in receiving!"); rpacket[size] = '\0'; printf("Server: %s\n",rpacket); strncat(buf, rpacket, plen); save2cache(filedes,os,plen); os += plen; len -= plen; } return nbyte; }