Esempio n. 1
0
/*-----------------------------------------------------------------------------
 * APIs
 */
char *vcdiffencode(const char *ptr, size_t ptrsiz) {
  if (ptr == NULL || ptrsiz == 0) return NULL;
  char *compressedptr = NULL;
  VCDIFFENC *enc = NULL;
  BLKHASH *bhash = NULL;
  ROLLINGHASH *rhash = NULL;
  enc = encodernew();
  if (enc == NULL) goto error;
  bhash = blkhashnew(ptr, ptrsiz);
  if (bhash == NULL) goto error;
  if (ptrsiz < bhash->blksiz) {
    /* too small to compress */
    adddata(enc, ptr, ptrsiz);
    goto end;
  }
  size_t blksiz = bhash->blksiz;
  const char *unencodedptr = ptr;
  const char *ptrbegin = ptr;
  const char *ptrend = ptr + ptrsiz;
  const char *ptrlastblk = ptrend - blksiz;
  rhash = rollinghashnew(blksiz);
  if (rhash == NULL) goto error;
  /* iterate througth the data */
  uint32_t hash = rollinghashdohash(rhash, ptr);
  while (1) {
    assert(unencodedptr <= ptrend);
    int encoded = findbestmatch(enc, hash, ptr, unencodedptr, ptrend - unencodedptr, bhash);
    if (encoded > 0) {
      /* matching block is found */
      unencodedptr += encoded;
      if (ptr > ptrlastblk) break;
      while (ptr < unencodedptr) {
        blkhashaddhash(bhash, ptr - ptrbegin, hash);
        hash = rollinghashupdate(rhash, hash, ptr[0], ptr[blksiz]);
        ptr++;
      }
      assert(ptr == unencodedptr);
    } else {
      /* no matching block was found */
      if (ptr + 1 > ptrlastblk) break;
      blkhashaddhash(bhash, ptr - ptrbegin, hash);
      hash = rollinghashupdate(rhash, hash, ptr[0], ptr[blksiz]);
      ptr++;
    }
  }
  /* add remaining unencoded data */
  if (unencodedptr < ptrend)
    adddata(enc, unencodedptr, ptrend - unencodedptr);
end:
  compressedptr = encoderout(enc);
  blkhashdel(bhash);
  rollinghashdel(rhash);
  encoderdel(enc);
  return compressedptr;
error:
  if (bhash) blkhashdel(bhash);
  if (rhash) rollinghashdel(rhash);
  if (enc) encoderdel(enc);
  return NULL;
}
Esempio n. 2
0
int
nfs_write(struct cookie *fh, int offset, int count, void *data,
     void (*func) (uintptr_t, int, fattr_t *),
     uintptr_t token)
{
    struct pbuf *pbuf;
    writeargs_t args;
    
    /* now the user data struct is setup, do some call stuff! */
    pbuf = initbuf(NFS_NUMBER, NFS_VERSION, NFSPROC_WRITE);

    /* copy in the fhandle */
    memcpy(&args.file, (char*) fh, sizeof(struct cookie));
    
    args.offset = offset;
    args.beginoffset = 0; /* unused as per RFC */
    args.totalcount = 0;  /* unused as per RFC */
    
    /* add them to the buffer */
    addtobuf(pbuf, (char*) &args, sizeof(args));
    
    /* put the data in */
    adddata(pbuf, data, count);

    return rpc_send(pbuf, nfs_port, nfs_write_cb, func, token);
}
Esempio n. 3
0
main(){

    ROCHA array[10];
    int i=0; //arbitrary, for looping only
    char choice;
    int recordnumber; //itemnumber in the struct array
    //int recordname; //name in struct array
    //int recordqty; //qty in struct array

    while (i<1){
        choice=getch();

        switch(choice){
            case 49:
            printf("Enter record number from 1 to 10: ");
            fflush(stdin);
            scanf("%d",&recordnumber);
            adddata(recordnumber,array);
            printf("\nSuccessfully added.");


            break;

            case 50:
            printf("Enter record number to delete: ");
            fflush(stdin);
            scanf("%d",&recordnumber);
            deletedata(recordnumber,array);
            printf("\nDeleted successfully.");

            break;

            case 51:
            printf("The records:");
            printdata(array);
            break;

            case 52:
            i=1;
            break;

            default:
            printf("Enter a valid choice from 1-4.");
            break;

        }

    }

}
Esempio n. 4
0
static int findbestmatch(VCDIFFENC *enc, uint32_t hash, const char *targetptr,
                         const char *targetptrbegin, size_t targetsiz, BLKHASH *bhash) {
  int blknum;
  BLKHASHMATCH match;
  blknum = blkhashfindbestmatch(bhash, hash, targetptr, targetptrbegin, targetsiz, &match);
  if (blknum == -1) return -1; /* match not found */
  if (match.targetoff > 0) {
    /* ADD */
    adddata(enc, targetptrbegin, match.targetoff);
  }
  /* COPY */
  copydata(enc, match.sourceoff, match.size);
  return match.targetoff + match.size;
}
Esempio n. 5
0
int adddata_r(data_t data) {        /* allocate a node on list to hold data */
   int error;
   if (error = pthread_mutex_lock(&listlock)) {        /* no mutex, give up */
      errno = error;
      return -1;
   }
   if (adddata(data) == -1) {
      error = errno;
      pthread_mutex_unlock(&listlock);
      errno = error;
      return -1;
   }
   if (error = pthread_mutex_unlock(&listlock)) {
      errno = error;
      return -1;
   }
   return 0; 
}
Esempio n. 6
0
File: transport.c Progetto: gz/aos10
/* Add a string to the packet */
void
addstring(struct pbuf* pbuf, char *data)
{
    adddata(pbuf, data, strlen(data));
}