Skip to content

Commit

Permalink
c0appz_mw, c0appz_fr
Browse files Browse the repository at this point in the history
  • Loading branch information
nezzzu committed May 24, 2020
1 parent 607a672 commit 6bf5557
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
27 changes: 15 additions & 12 deletions buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,32 @@ static int copydata(const char *buf,uint64_t bsz,uint64_t cnt);
*/

/*
* file2buff()
* copy fsz bytes from input file inf to a memory
* buffer buf. Assume buf is large enough to copy
* fsz bytes.
* c0appz_fr()
* read from file.
* copy cnt number of bsz size of blocks from input
* file inf to a memory buffer buf. Assume buf is large
* enough to copy bsz*cnt bytes.
*/
int file2buff(char *inf,uint64_t fsz,char *buf)
int c0appz_fr(char *buf, char *inf, uint64_t bsz, uint64_t cnt)
{
uint64_t n;
FILE *fp=NULL;

/* open input file */
fp=fopen(inf,"rb");
if(!fp){
fprintf(stderr,"error! could not open input file %s\n", inf);
fprintf(stderr,"%s(): error! - ",__FUNCTION__);
fprintf(stderr,"could not open input file %s\n", inf);
return 11;
}

/* read into buf */
n=fread(buf,1,fsz,fp);
if(n!=fsz){
fprintf(stderr,"error! reading from %s failed.\n", inf);
n=fread(buf,bsz,cnt,fp);
if(n!=cnt){
fprintf(stderr,"%s(): error! - ",__FUNCTION__);
fprintf(stderr,"reading from %s failed.\n",inf);
fclose(fp);
return 22;

}

/* success */
Expand Down Expand Up @@ -142,12 +144,13 @@ int mero2buff(uint64_t idhi,uint64_t idlo,char *buf,uint64_t bsz)
}

/*
* buff2mero()
* c0appz_mw()
* write to mero object!
* writes data from memory buffer to a mero object.
* writes cnt number of blocks, each of size bsz from
* pos (byte) position of the object
*/
int buff2mero(const char *buf,uint64_t idhi,uint64_t idlo,uint64_t pos,uint64_t bsz,uint64_t cnt)
int c0appz_mw(const char *buf,uint64_t idhi,uint64_t idlo,uint64_t pos,uint64_t bsz,uint64_t cnt)
{
struct m0_uint128 id;
uint64_t max_bcnt_per_op;
Expand Down
6 changes: 4 additions & 2 deletions c0appz.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ int c0appz_timeout(uint64_t sz);
int c0appz_timein();

void *disp_realtime_bw(void *arg);
int file2buff(char *inf,uint64_t fsz,char *buf);
// int c0appz_fr(char *inf,uint64_t fsz,char *buf);
int c0appz_fr(char *buf, char *inf, uint64_t bsz, uint64_t cnt);

int buff2file(char *buf,uint64_t dsz,char *inf);
int mero2buff(uint64_t idhi,uint64_t idlo,char *buf,uint64_t bsz);

int buff2mero(const char *buf,uint64_t idhi,uint64_t idlo,uint64_t pos,uint64_t bsz,uint64_t cnt);
int c0appz_mw(const char *buf,uint64_t idhi,uint64_t idlo,uint64_t pos,uint64_t bsz,uint64_t cnt);

int write_data_to_object(struct m0_uint128 id, struct m0_indexvec *ext,
struct m0_bufvec *data, struct m0_bufvec *attr);
Expand Down
6 changes: 3 additions & 3 deletions c0cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ int main(int argc, char **argv)
rc = 111;
goto end;
}
if(file2buff(fname,fs.st_size + bsz - 1,fbuf)!=0){
fprintf(stderr,"%s(): file2buff failed!!\n",__FUNCTION__);
if(c0appz_fr(fbuf,fname,bsz,cnt)!=0){
fprintf(stderr,"%s(): c0appz_fr failed!!\n",__FUNCTION__);
rc = 555;
goto end;
}
Expand All @@ -166,7 +166,7 @@ int main(int argc, char **argv)
while(cont>0){
printf("[%d/%d]:\n",(int)laps-cont+1,(int)laps);
pos = (laps-cont)*cnt*bsz;
buff2mero(fbuf,idh,idl,pos,bsz,cnt);
c0appz_mw(fbuf,idh,idl,pos,bsz,cnt);
cont--;
}

Expand Down

0 comments on commit 6bf5557

Please sign in to comment.