ZarfileVFS::~ZarfileVFS()
{
	if (ptable!=NULL)
	{
		mf_free(mf, ptable);
		ptable=NULL;
	}
	if (strtable!=NULL)
	{
		mf_free(mf, strtable);
		strtable=NULL;
	}
	if (chdr!=NULL) { mf_free(mf, chdr); }
	delete chdr_mutex;
	
	if (exploited_mmap_opportunities == 0)
	{
		delete zarfile_hdl;
	}
	else
	{
		// can't ever give back the jumbo packet, since
		// the user app has tentacles all pointing into it!
	}
}
ZarfileVFS::ZarfileVFS(MallocFactory *mf, SyncFactory* sf, XaxVFSHandleIfc *zarfile_hdl, ZLCEmit *ze)
{
	ptable = NULL;
	strtable = NULL;
	chdr = NULL;
	chdr_mutex = NULL;
	this->mf = mf;
	this->zarfile_hdl = zarfile_hdl;
	this->ze = ze;
	lost_mmap_opportunities_misaligned = 0;
	exploited_mmap_opportunities = 0;

	XfsErr err;

	zarfile_hdl->read(&err, &zhdr, sizeof(zhdr), 0);
	if (err != XFS_NO_ERROR) { goto fail; }

	if (zhdr.z_magic != Z_MAGIC) { goto fail; }
	if (zhdr.z_version != Z_VERSION) { goto fail; }
	if (zhdr.z_path_entsz != sizeof(ZF_Phdr)) { goto fail; }

	uint32_t ptable_size;
	ptable_size = sizeof(ZF_Phdr)*zhdr.z_path_num;
	ptable = (ZF_Phdr*) mf_malloc(mf, ptable_size);
	zarfile_hdl->read(&err, ptable, ptable_size, zhdr.z_path_off);
	if (err != XFS_NO_ERROR) { goto fail; }

	strtable = (char*) mf_malloc(mf, zhdr.z_strtab_len);
	zarfile_hdl->read(&err, strtable, zhdr.z_strtab_len, zhdr.z_strtab_off);
	if (err != XFS_NO_ERROR) { goto fail; }
	if (strtable[zhdr.z_strtab_len-1]!='\0') { goto fail; }

	// Read in an in-memory copy of all the chdrs. We update it when we
	// give away chunks via fast_mmap, so we need to make sure all
	// accesses of this zarfile use the in-memory (updated) chdrs.
	int chdr_len;
	chdr_len = sizeof(ZF_Chdr)*zhdr.z_chunktab_count;
	this->chdr = (ZF_Chdr*) mf_malloc(mf, chdr_len);
	chdr_mutex = sf->new_mutex(false);
	err = XFS_DIDNT_SET_ERROR;
	zarfile_hdl->read(&err, this->chdr, chdr_len, zhdr.z_chunktab_off);
	if (err != XFS_NO_ERROR) { goto fail; }

	return;

fail:
	if (ptable!=NULL)
	{
		mf_free(mf, ptable);
		ptable=NULL;
	}
	if (strtable!=NULL)
	{
		mf_free(mf, strtable);
		strtable=NULL;
	}
	zhdr.z_path_num = 0;	// cause lookups to fail.
}
bool KeyValClient::insert(KeyVal* kv) {
	int req_size = sizeof(KVRequest) + kv->val.len;
	KVRequest* req = (KVRequest*)mf_malloc(this->mf, req_size);

	req->type = TYPE_INSERT;
	req->kv = *kv;

	uint32_t hash131 = hash_buf(kv->val.bytes, kv->val.len);
#define READBACK_CHECK 1
#if READBACK_CHECK
	ZLC_TERSE(ze, "Insert val len %d hash 0x%x\n",, kv->val.len, hash131);
#endif // READBACK_CHECK

	lite_memcpy(req->kv.val.bytes, kv->val.bytes, kv->val.len);

	bool rc = this->sock->sendto(this->server, req, req_size);
	if (!rc) { return false; }

	ZeroCopyBuf* reply = this->sock->recvfrom(this->server);
	lite_assert(reply!=NULL);
	lite_assert(reply->len()==sizeof(uint32_t));
	lite_assert(((uint32_t*)reply->data())[0] == hash131);
	delete reply;

	mf_free(this->mf, req);
	return true;
}
예제 #4
0
파일: hashTable.c 프로젝트: mojadita/c2html
void hashTableFree (HashTable *t)
{
  extern void free(void *);

  mf_apply (&(t->mf_data), free);
  mf_free (&(t->mf_data));
} /* hashTableFree */
// Ask key-value server for the MAC for this file
// Expects an app and file specific string in key
// Returns true if mac contains a purported MAC value
bool ZFastFetch::lookup_mac(Key* key, mac_list* mac) {
	Value* val = this->keyval_client->lookup(key);

	if (val == NULL) {
		ZLC_COMPLAIN(ze, "FastFetch got NULL reply from KV server\n");
		return false;
	}

	if (val->len == 0) {
		// KV doesn't have this key
		mf_free(this->keyval_client->get_mf(), val);
		return false;
	} else if (val->len != sizeof(mac_list)) {
		mf_free(this->keyval_client->get_mf(), val);
		ZLC_COMPLAIN(ze, "FastFetch got bad MAC size %d from KV server\n",,val->len);
		return false;
	}
예제 #6
0
MfCumulative::MfCumulative(Sigma* const s, const double a) :
  n(1001)
{
  M_array= (double*) malloc(sizeof(double)*n*2); assert(M_array);
  nM_array= M_array + n;
  
  rho_m= cosmology_rho_m();

  const double z= 1.0/a - 1.0;
  MF* const mf= mf_alloc();
  mf_set_redshift(mf, a);

  const double D= growth_D(a);
  MfcParams params;
  params.mf= mf;
  params.s=  s;
  params.D= D;

  
  gsl_integration_cquad_workspace* const w= 
    gsl_integration_cquad_workspace_alloc(100);
      
  gsl_function F;
  F.function= &integrand_n_cumulative;
  F.params= (void*) &params;

  const double logMmin= log(s->M_min);
  const double logMmax= log(s->M_max);
  const double nu_min= delta_c*s->sinv_min;
  const double nu_max= delta_c*s->sinv_max;

  for(int i=0; i<n; ++i) {
    double MM= exp(logMmin + (n-i-1)*(logMmax - logMmin)/(n-1));
    M_array[i]= MM;

    double nu= delta_c/D*s->sigma0_inv(MM); assert(nu >= nu_min);
    double result;
  
    gsl_integration_cquad(&F, 1.0e-8, nu_max, 1.0e-5, 1.0e-5, w, &result, 0, 0);
    nM_array[i]= result;
  }

  nM_max= nM_array[n-1];
  
  interp= gsl_interp_alloc(gsl_interp_cspline, n);
  acc= gsl_interp_accel_alloc(); 

  //gsl_interp_init(interp, M_array, nM_array, n);
  gsl_interp_init(interp, nM_array, M_array, n);

  gsl_integration_cquad_workspace_free(w);
  mf_free(mf);
}
XaxVFSHandleIfc *ZarfileVFS::open(XfsErr *err, XfsPath *path, int oflag, XVOpenHooks *open_hooks)
{
	XaxVFSHandleIfc *result = NULL;

	char *url_hint, *url_for_stat;
	ZLCVFS::assemble_urls(mf, path, &url_hint, &url_for_stat);

	ZarfileAndKey zak;
	zak.zvfs = this;
	zak.key = url_hint;
	ZF_Phdr *phdr = (ZF_Phdr*) binsearch(&zak, ptable, zhdr.z_path_num,
		sizeof(ZF_Phdr), _phdr_key_cmp);
	if (phdr!=NULL)
	{
		if (phdr->protocol_metadata.flags & ZFTP_METADATA_FLAG_ENOENT)
		{
			*err = (XfsErr) ENOENT; // We found the path, and it's ENOENT.
		}
		else
		{
			*err = XFS_NO_ERROR;
			result = new ZarfileHandle(this, phdr, url_for_stat);
			url_for_stat = NULL;
		}
	}
	else if (phdr==NULL)
	{
		*err = XFS_NO_INFO;
	}

	mf_free(mf, url_hint);
	if (url_for_stat!=NULL)
	{
		mf_free(mf, url_for_stat);
	}

	return result;
}
예제 #8
0
int parameter_editor(FORMPTR fmp)
{
    DFORMPTR        dfmp;
    char            *save_ptr;


    /*------ temporarily modify validation message table ------*/
    save_ptr = _vv_valmsg[15];
    _vv_valmsg[15] = "Field may not be edited - Press <F2> for choice list.";

    latt_rpl(LWAIT,LREVERSE|BLINK,RED|BLINK,BLUE,LATT_SYS);

    /*------ add hot-keys to form event table ------*/
    et_rplevnt(KEY_CD,(EVENTFP)restore_defaults,FMETP);
    et_rplevnt(KEY_CS,(EVENTFP)save_defaults,   FMETP);

    /*------ define memory file and read choice list text ------*/
    clist_mfp = mf_def(60,40);
    mf_rd("CLIST.TXT",clist_mfp);

    /*------ create and process the parameters form ------*/
    dfmp = create_parameters_form();
    fm_proc(0,dfmp);
    fm_free(dfmp);

    mf_free(clist_mfp);

    /*------ restore form event table ------*/
    et_rplevnt(KEY_CD,NULLFP,FMETP);
    et_rplevnt(KEY_CS,NULLFP,FMETP);

    /*------ restore validation message table ------*/
    _vv_valmsg[15] = save_ptr;

    return(SAMELEVEL);

} /* parameter_editor() */
KeyValClient::~KeyValClient() {
	mf_free(this->mf, this->server);
	delete this->sock;
}
DecomposePath::~DecomposePath()
{
	mf_free(mf, prefix);
}
XUDSEndpoint::~XUDSEndpoint()
{
	mf_free(xufs->get_mf(), address);
	lite_assert(zq_is_empty(zq));	// it's superclass's job to drain the queue
	zq_free(zq);
}
XUDSMessage::~XUDSMessage()
{
	mf_free(mf, content);
}
ValidatedZCB::~ValidatedZCB() {
//	delete this->hashes;
	mf_free(cache->mf, this->hashes);
	socket->zc_release(buffer);
}