Esempio n. 1
0
/*! \brief Destroy distributed L & U matrices. */
void
Destroy_LU(int_t n, gridinfo_t *grid, LUstruct_t *LUstruct)
{
    int_t i, nb, nsupers;
    Glu_persist_t *Glu_persist = LUstruct->Glu_persist;
    LocalLU_t *Llu = LUstruct->Llu;

#if ( DEBUGlevel>=1 )
    int iam;
    MPI_Comm_rank( MPI_COMM_WORLD, &iam );
    CHECK_MALLOC(iam, "Enter Destroy_LU()");
#endif

    nsupers = Glu_persist->supno[n-1] + 1;

    nb = CEILING(nsupers, grid->npcol);
    for (i = 0; i < nb; ++i) 
	if ( Llu->Lrowind_bc_ptr[i] ) {
	    SUPERLU_FREE (Llu->Lrowind_bc_ptr[i]);
#ifdef GPU_ACC
	    checkCuda(cudaFreeHost(Llu->Lnzval_bc_ptr[i]));
#else
	    SUPERLU_FREE (Llu->Lnzval_bc_ptr[i]);
#endif
	}
    SUPERLU_FREE (Llu->Lrowind_bc_ptr);
    SUPERLU_FREE (Llu->Lnzval_bc_ptr);

    nb = CEILING(nsupers, grid->nprow);
    for (i = 0; i < nb; ++i)
	if ( Llu->Ufstnz_br_ptr[i] ) {
	    SUPERLU_FREE (Llu->Ufstnz_br_ptr[i]);
	    SUPERLU_FREE (Llu->Unzval_br_ptr[i]);
	}
    SUPERLU_FREE (Llu->Ufstnz_br_ptr);
    SUPERLU_FREE (Llu->Unzval_br_ptr);

    /* The following can be freed after factorization. */
    SUPERLU_FREE(Llu->ToRecv);
    SUPERLU_FREE(Llu->ToSendD);
    SUPERLU_FREE(Llu->ToSendR[0]);
    SUPERLU_FREE(Llu->ToSendR);

    /* The following can be freed only after iterative refinement. */
    SUPERLU_FREE(Llu->ilsum);
    SUPERLU_FREE(Llu->fmod);
    SUPERLU_FREE(Llu->fsendx_plist[0]);
    SUPERLU_FREE(Llu->fsendx_plist);
    SUPERLU_FREE(Llu->bmod);
    SUPERLU_FREE(Llu->bsendx_plist[0]);
    SUPERLU_FREE(Llu->bsendx_plist);
    SUPERLU_FREE(Llu->mod_bit);

    SUPERLU_FREE(Glu_persist->xsup);
    SUPERLU_FREE(Glu_persist->supno);

#if ( DEBUGlevel>=1 )
    CHECK_MALLOC(iam, "Exit Destroy_LU()");
#endif
}
Esempio n. 2
0
/*! \brief
 *
 * <pre>
 * mem_usage consists of the following fields:
 *    - for_lu (float)
 *      The amount of space used in bytes for the L\U data structures.
 *    - total (float)
 *      The amount of space needed in bytes to perform factorization.
 *    - expansions (int)
 *      Number of memory expansions during the LU factorization.
 * </pre>
 */
int_t dQuerySpace_dist(int_t n, LUstruct_t *LUstruct, gridinfo_t *grid,
		       mem_usage_t *mem_usage)
{
    register int_t dword, gb, iword, k, maxsup, nb, nsupers;
    int_t *index, *xsup;
    int iam, mycol, myrow;
    Glu_persist_t *Glu_persist = LUstruct->Glu_persist;
    LocalLU_t *Llu = LUstruct->Llu;

    iam = grid->iam;
    myrow = MYROW( iam, grid );
    mycol = MYCOL( iam, grid );
    iword = sizeof(int_t);
    dword = sizeof(double);
    maxsup = sp_ienv_dist(3);
    nsupers = Glu_persist->supno[n-1] + 1;
    xsup = Glu_persist->xsup;
    mem_usage->for_lu = 0;

    /* For L factor */
    nb = CEILING( nsupers, grid->npcol ); /* Number of local column blocks */
    for (k = 0; k < nb; ++k) {
	gb = k * grid->npcol + mycol; /* Global block number. */
	if ( gb < nsupers ) {
	    index = Llu->Lrowind_bc_ptr[k];
	    if ( index ) {
		mem_usage->for_lu += (float)
		    ((BC_HEADER + index[0]*LB_DESCRIPTOR + index[1]) * iword);
		mem_usage->for_lu += (float)(index[1]*SuperSize( gb )*dword);
	    }
	}
    }

    /* For U factor */
    nb = CEILING( nsupers, grid->nprow ); /* Number of local row blocks */
    for (k = 0; k < nb; ++k) {
	gb = k * grid->nprow + myrow; /* Global block number. */
	if ( gb < nsupers ) {
	    index = Llu->Ufstnz_br_ptr[k];
	    if ( index ) {
		mem_usage->for_lu += (float)(index[2] * iword);
		mem_usage->for_lu += (float)(index[1] * dword);
	    }
	}
    }

    /* Working storage to support factorization */
    mem_usage->total = mem_usage->for_lu;
    mem_usage->total +=
	(float)(( Llu->bufmax[0] + Llu->bufmax[2] ) * iword +
		( Llu->bufmax[1] + Llu->bufmax[3] + maxsup ) * dword );
    /**** another buffer to use mpi_irecv in pdgstrf_irecv.c ****/
    mem_usage->total +=
	(float)( Llu->bufmax[0] * iword +  Llu->bufmax[1] * dword );
    mem_usage->total += (float)( maxsup * maxsup + maxsup) * iword;
    k = CEILING( nsupers, grid->nprow );
    mem_usage->total += (float)(2 * k * iword);

    return 0;
} /* dQuerySpace_dist */
Esempio n. 3
0
char * sanity_check()
{
    // proof of correct ceilling macro
    mu_assert(CEILING(7,4) == 2, "ceiling fail");
    // proof of implicit floor
    mu_assert(7/4  == 1, "floor fail");
    mu_assert(1/2  == 0, "floor fail");
    // proof of zero index
    mu_assert(LEADINGBIT(4) ==  2  ,"FAIL");
    mu_assert(LEADINGBIT(1) ==  0  ,"FAIL");
    mu_assert(LEADINGBIT(8) ==  3  ,"FAIL");

    index_t x,y, a = 0;
    index_t data_size = 1, super_count = 0, super_last_count = 0, super_size=1, length = 30;
    index_t ** index = malloc(length * sizeof(index_t));;
    fflush(stdout);
    //printf("\n");
    for(x = 0 ; x < length; x++){
        index[x] = malloc(data_size * sizeof(index_t));
        for(y = 0; y < data_size; y++){
            index[x][y]=a;
            a++;
            printf("%ld ", index[x][y]);
        }
        super_last_count++;
        printf("\n");
        if(super_last_count == super_size){
            super_last_count = 0;
            if(super_count%2){
                super_size *=2;
                super_count++;
            } else {
                    data_size *= 2;
                super_count++;
            }
        }
    }
    //log_success("Finished element dump");

    unsigned long int get_index(index_t i){
        index_t r,k,b,e,p;
       // log_info("Trying to get %ld", i);
        r = i + 1;
        k = LEADINGBIT(r); // no need for minus 1. already zero indexed PERFECT
      //  log_info("k/2=%ld, Ceil(k,2)=%ld",k/2,CEILING(k,2));
        b = BITSUBSET(r,k-k/2,k);
        e = BITSUBSET(r,0, CEILING(k,2));
        //p =  (1 << (k-1)) ; //PEFECT
        p = (1 << (k/2 + 1)) - 2 + (k & 1) * (1 << (k/2));
        //p = k==0 ? 0 :  (1 << k-1) ; //PEFECT
        //p = (1 << k-1) ; //PEFECT
        //log_info("K: %ld",k);
        //log_info("B: %ld",b);
        //log_info("E: %ld",e);
        //log_info("P: %ld super blocks prior",p);
        log_info("trying [%ld,%ld]",(p+b),e);
        printf("p+b,e : [%ld,%ld] \n",p+b,e);
        return index[(p+b)][e];
    }
Esempio n. 4
0
/**
  Attempts to read up to count bytes from UDF directory entry
  p_udf_dirent into the buffer starting at buf. buf should be a
  multiple of UDF_BLOCKSIZE bytes. Reading continues after the point
  at which we last read or from the beginning the first time.

  If count is zero, read() returns zero and has no other results. If
  count is greater than SSIZE_MAX, the result is unspecified.

  It is the caller's responsibility to ensure that count is less
  than the number of blocks recorded via p_udf_dirent.

  If there is an error, cast the result to driver_return_code_t for 
  the specific error code.
*/
ssize_t
udf_read_block(const udf_dirent_t *p_udf_dirent, void * buf, size_t count)
{
  if (count == 0) return 0;
  else {
    driver_return_code_t ret;
    uint32_t i_max_size=0;
    udf_t *p_udf = p_udf_dirent->p_udf;
    lba_t i_lba = offset_to_lba(p_udf_dirent, p_udf->i_position, &i_lba, 
				&i_max_size);
    if (i_lba != CDIO_INVALID_LBA) {
      uint32_t i_max_blocks = CEILING(i_max_size, UDF_BLOCKSIZE);
      if ( i_max_blocks < count ) {
	  fprintf(stderr, "Warning: read count %u is larger than %u extent size.\n",
		  count, i_max_blocks);
	  fprintf(stderr, "Warning: read count truncated to %u\n", count);
	  count = i_max_blocks;
      }
      ret = udf_read_sectors(p_udf, buf, i_lba, count);
      if (DRIVER_OP_SUCCESS == ret) {
	ssize_t i_read_len = MIN(i_max_size, count * UDF_BLOCKSIZE);
	p_udf->i_position += i_read_len;
	return i_read_len;
      }
      return ret;
    } else {
      return DRIVER_OP_ERROR;
    }
  }
}
Esempio n. 5
0
void *
VMCI_AllocQueue(uint64 size) // IN: size of queue (not including header)
{
    const uint64 numPages = CEILING(size, PAGE_SIZE);
    VMCIQueue *queue;

    queue = vmalloc(sizeof *queue + numPages * sizeof queue->page[0]);
    if (queue) {
        uint64 i;

        /*
         * Allocate physical pages, they will be mapped/unmapped on demand.
         */
        for (i = 0; i < numPages; i++) {
            queue->page[i] = alloc_pages(GFP_KERNEL, 0); /* One page. */
            if (!queue->page[i]) {
                /*
                 * Free all pages allocated.
                 */
                while (i) {
                    __free_page(queue->page[--i]);
                }
                vfree(queue);
                queue = NULL;
                break;
            }
        }
    }
    return queue;
}
Esempio n. 6
0
 FORCE_INLINE void draw_custom_bootscreen(const u8g_pgm_uint8_t * const bmp, const bool erase=true) {
   constexpr u8g_uint_t left = (LCD_PIXEL_WIDTH  - (CUSTOM_BOOTSCREEN_BMPWIDTH)) / 2,
                        top = (LCD_PIXEL_HEIGHT - (CUSTOM_BOOTSCREEN_BMPHEIGHT)) / 2;
   #if ENABLED(CUSTOM_BOOTSCREEN_INVERTED)
     constexpr u8g_uint_t right = left + CUSTOM_BOOTSCREEN_BMPWIDTH,
                         bottom = top + CUSTOM_BOOTSCREEN_BMPHEIGHT;
   #endif
   u8g.firstPage();
   do {
     u8g.drawBitmapP(
       left, top,
       CEILING(CUSTOM_BOOTSCREEN_BMPWIDTH, 8), CUSTOM_BOOTSCREEN_BMPHEIGHT, bmp
     );
     #if ENABLED(CUSTOM_BOOTSCREEN_INVERTED)
       if (erase) {
         u8g.setColorIndex(1);
         if (top) u8g.drawBox(0, 0, LCD_PIXEL_WIDTH, top);
         if (left) u8g.drawBox(0, top, left, CUSTOM_BOOTSCREEN_BMPHEIGHT);
         if (right < LCD_PIXEL_WIDTH) u8g.drawBox(right, top, LCD_PIXEL_WIDTH - right, CUSTOM_BOOTSCREEN_BMPHEIGHT);
         if (bottom < LCD_PIXEL_HEIGHT) u8g.drawBox(0, bottom, LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT - bottom);
       }
     #else
       UNUSED(erase);
     #endif
   } while (u8g.nextPage());
 }
Esempio n. 7
0
static void bounding_fullly_charged_level(int upperbd)
{
	static int pingpong = 1;
	int lowerbd;
	int current_level;
	b_is_charge_off_by_bounding = FALSE;
	if (upperbd <= 0)
		return; /* doesn't activated this function */
	lowerbd = upperbd - 5; /* 5% range */

	if (lowerbd < 0)
		lowerbd = 0;
	current_level = CEILING(poweralg.capacity_01p, 10);

	if (pingpong == 1 && upperbd <= current_level) {
		printk(DRIVER_ZONE "MFG: lowerbd=%d, upperbd=%d, current=%d, pingpong:1->0 turn off\n", lowerbd, upperbd, current_level);
		b_is_charge_off_by_bounding = TRUE;
		pingpong = 0;
	} else if (pingpong == 0 && lowerbd < current_level) {
		printk(DRIVER_ZONE "MFG: lowerbd=%d, upperbd=%d, current=%d, toward 0, turn off\n", lowerbd, upperbd, current_level);
		b_is_charge_off_by_bounding = TRUE;
	} else if (pingpong == 0 && current_level <= lowerbd) {
		printk(DRIVER_ZONE "MFG: lowerbd=%d, upperbd=%d, current=%d, pingpong:0->1 turn on\n", lowerbd, upperbd, current_level);
		pingpong = 1;
	} else {
		printk(DRIVER_ZONE "MFG: lowerbd=%d, upperbd=%d, current=%d, toward %d, turn on\n", lowerbd, upperbd, current_level, pingpong);
	}

}
Esempio n. 8
0
int
win_occpuants_cols(void)
{
    int occupants_win_percent = prefs_get_occupants_size();
    int cols = getmaxx(stdscr);
    return CEILING( (((double)cols) / 100) * occupants_win_percent);
}
Esempio n. 9
0
int
win_roster_cols(void)
{
    int roster_win_percent = prefs_get_roster_size();
    int cols = getmaxx(stdscr);
    return CEILING( (((double)cols) / 100) * roster_win_percent);
}
Esempio n. 10
0
int get_nof_cb(int recv_bits, int *nof_short_cb, int *nof_long_cb,
		int *len_short_cb, int *len_long_cb, int *nof_filler_bits) {

	int num_cb;
	int i, Bp, Ak;

	/** Calculate Number of output code blocks*/
	if (recv_bits <= Z) {
		num_cb = 1;
		*nof_long_cb = 1;
		*nof_short_cb = 0;
		*len_short_cb = 0;
		if (recv_bits < 40) {
			*len_long_cb = 40;
			*nof_filler_bits = Bmin - recv_bits;
		} else {
			*len_long_cb = recv_bits;
			*nof_filler_bits = 0;
		}
	}

	if (recv_bits > Z) {
		num_cb = CEILING((float)recv_bits/(float)(Z - L));
		Bp = recv_bits + num_cb * L;

		/** Calculate code block sizes*/
		for (i = 1; i < 189; i++) {
			/** First Segmentation size: K+*/
			*len_long_cb = Table5133[i];
			/** Second Segmentation Size: K-*/
			*len_short_cb = Table5133[i - 1];
			if (Table5133[i] * num_cb >= Bp) {
				break;
			}
		}
		if (num_cb == 1) {
			/** C+ :Number of segments of size K+ (Kp)*/
			*nof_long_cb = 1;
			*len_short_cb = 0; /** K- */
			/** C- :Number of segments of size K- (Km)*/
			*nof_short_cb = 0;
			/** Number of Filler Bits*/
			*nof_filler_bits = Bmin - recv_bits;
		}
		if (num_cb > 1) {
			Ak = *len_long_cb - *len_short_cb;
			*nof_short_cb = (int) floor(
					((float) (num_cb * *len_long_cb) - Bp) / (float) Ak);
			*nof_long_cb = num_cb - *nof_short_cb;
			/** Number of Filler Bits*/
			*nof_filler_bits = *nof_long_cb * *len_long_cb
					+ *nof_short_cb * *len_short_cb - Bp;
		}
		*len_long_cb = *len_long_cb - 24;
		if (*len_short_cb > 0)
			*len_short_cb = *len_short_cb - 24;
	}
	return num_cb;
}
Esempio n. 11
0
void
check_ablk(TestCaseState_t *tcs, Allctr_t *a, void *ptr, Ulong umem_sz)
{
    Ulong unit_sz = UNIT_SZ;
    Block_t *blk = UMEM2BLK(ptr);
    Block_t *nxt_blk = NXT_BLK(blk);
    Ulong real_sz = ((Ulong) nxt_blk) - ((Ulong) (blk));
    ASSERT(tcs, real_sz == BLK_SZ(blk));
    ASSERT(tcs, !IS_FREE_BLK(blk));
    ASSERT(tcs, real_sz >= CEILING(ABLK_HDR_SZ + umem_sz, unit_sz));
    if (real_sz > MIN_BLK_SZ(a)
	&& real_sz > CEILING(ABLK_HDR_SZ+umem_sz, unit_sz)) {
	ASSERT(tcs,
	       real_sz <= CEILING(MIN_BLK_SZ(a)+ABLK_HDR_SZ+umem_sz,
				  unit_sz));
	ASSERT(tcs, IS_LAST_BLK(blk) || !IS_FREE_BLK(nxt_blk));
    }
}
Esempio n. 12
0
static void __gnix_rma_fill_pd_indirect_get(struct gnix_fab_req *req,
					    struct gnix_tx_descriptor *txd)
{
	int head_off = req->rma.rem_addr & GNI_READ_ALIGN_MASK;

	/* Copy all data through an intermediate buffer. */
	txd->gni_desc.local_addr = (uint64_t)txd->int_buf;
	txd->gni_desc.local_mem_hndl = req->vc->ep->nic->int_bufs_mdh;
	txd->gni_desc.length = CEILING(req->rma.len + head_off, GNI_READ_ALIGN);
	txd->gni_desc.remote_addr =
			(uint64_t)req->rma.rem_addr & ~GNI_READ_ALIGN_MASK;
}
Esempio n. 13
0
extern inline DSTATUS flex_compare(flex_t flex, index_t requested_index, data_p user_data)
{
    index_t r,k,b,e,p;
    r = requested_index + 1;
    k = LEADINGBIT(r); // no need for minus 1. already zero indexed 
    b = BITSUBSET(r,k-k/2,k);
    e = BITSUBSET(r,0, CEILING(k,2));
    p = (1 << (k/2 + 1)) - 2 + (k & 1) * (1 << (k/2));
    if(p+b > flex->last_index_occup){ // we have an index which would seg fault
        return FAILURE;
    } 
    return (flex->cmp_func(&(flex->index_block[(p+b)][e]), user_data));
}
Esempio n. 14
0
extern inline data_p flex_get(flex_t flex, index_t requested_index)
{
    index_t r,k,b,e,p;
    r = requested_index + 1;
    k = LEADINGBIT(r); // no need for minus 1. already zero indexed 
    b = BITSUBSET(r,k-k/2,k);
    e = BITSUBSET(r,0, CEILING(k,2));
    p = (1 << (k/2 + 1)) - 2 + (k & 1) * (1 << (k/2));
    if(p+b > flex->last_index_occup){ // we have an index which would seg fault
        return NULL;
    } 
    return &flex->index_block[(p+b)][e];
}
Esempio n. 15
0
void DVDRipper::find_start_blocks() {
   CdioList_t *p_entlist;
   CdioListNode_t *p_entnode;
   
   if (!p_iso)
      return;
   
   p_entlist = iso9660_ifs_readdir (p_iso, "/video_ts/");
   
   if (p_entlist) {
      _CDIO_LIST_FOREACH (p_entnode, p_entlist) {
	 unsigned long long start;
	 unsigned long long blocks;
	 
	 char filename[4096];
	 int len;
	 
	 iso9660_stat_t *p_statbuf =
	    (iso9660_stat_t *) _cdio_list_node_data (p_entnode);
	 iso9660_name_translate(p_statbuf->filename, filename);
	 len = strlen(filename);
	 
	 if (!(2 == p_statbuf->type) ) {
	    if (! strcmp(filename + (len-3), "vob")) {
	       start = p_statbuf->lsn;
	       blocks = CEILING(p_statbuf->size, DVDCSS_BLOCK_SIZE);
	       
	       start_map[start] = strdup(filename);

	       if (blocks == 0) {
		  //file length of 0 would result in a blocks of 0, and don't want
		  //to subtract one from it.
		  end_blocks[start] = start;
	       } else {
		  //-1 as start block is included in count of blocks
		  end_blocks[start] = start - 1 + blocks;
	       }
	       
	       printf("%s: %llu->%llu (%llu blocks)\n", filename, start, end_blocks[start], blocks);
	       
	       if (blocks) {
		  if (find(start_blocks.begin(), start_blocks.end(), start) == start_blocks.end()) {
		     start_blocks.push_back(start);
		  }
	       }
	    }
	 }
      }
      
      _cdio_list_free (p_entlist, true);
   }
Esempio n. 16
0
ssize_t htc_battery_show_attr(struct device_attribute *attr, char *buf)
{
	int len = 0;
	if (!strcmp(attr->attr.name, "batt_attr_text")){
		len += scnprintf(buf +
				len,
				PAGE_SIZE -
				len,
				"Percentage(%%): %d;\n"
				"KADC(%%): %d;\n"
				"RARC(%%): %d;\n"
				"V_MBAT(mV): %d;\n"
				"Battery_ID: %d;\n"
				"pd_M: %d;\n"
				"Current(mA): %d;\n"
				"Temp: %d;\n"
				"Charging_source: %d;\n"
				"ACR(mAh): %d;\n"
				"FULL(mAh): %d;\n"
				"1st_dis_percentage(%%): %d;\n"
				"1st_dis_ACR: %d;\n",
				CEILING(poweralg.capacity_01p, 10),
				CEILING(poweralg.battery.KADC_01p, 10),
				CEILING(poweralg.battery.RARC_01p, 10),
				poweralg.battery.voltage_mV,
				poweralg.battery.id_index,
				poweralg.battery.pd_m,
				poweralg.battery.current_mA,
				CEILING(poweralg.battery.temp_01c, 10),
				poweralg.charging_source,
				poweralg.battery.charge_counter_mAh,
				poweralg.battery.charge_full_real_mAh,
				CEILING(poweralg.fst_discharge_capacity_01p, 10),
				poweralg.fst_discharge_acr_mAh
		);
	}
	return len;
}
Esempio n. 17
0
extern inline DSTATUS flex_delete(flex_t flex, index_t requested_index)
{
    index_t r,k,b,e,p;
    r = requested_index + 1;
    k = LEADINGBIT(r); // no need for minus 1. already zero indexed 
    b = BITSUBSET(r,k-k/2,k);
    e = BITSUBSET(r,0, CEILING(k,2));
    p = (1 << (k/2 + 1)) - 2 + (k & 1) * (1 << (k/2));
    if(p+b > flex->last_index_occup){ // we have an index which would seg fault
        return FAILURE;
    } 
    flex->index_block[(p+b)][e] = 0;
    return SUCCESS;
}
Esempio n. 18
0
void
VMCI_FreeQueue(void *q,     // IN:
               uint64 size) // IN: size of queue (not including header)
{
    VMCIQueue *queue = q;

    if (queue) {
        uint64 i;

        for (i = 0; i < CEILING(size, PAGE_SIZE); i++) {
            __free_page(queue->page[i]);
        }
        vfree(queue);
    }
}
Esempio n. 19
0
static bool
getGDGT(SparseGTInfo *gtInfo,
        const SparseExtentHeader *hdr)
{
	if (hdr->grainSize < 1 || hdr->grainSize > 128 || !isPow2(hdr->grainSize)) {
		return false;
	}
	/* disklib supports only 512 GTEs per GT (=> 4KB GT size).  Streaming is more flexible. */
	if (hdr->numGTEsPerGT < VMDK_SECTOR_SIZE / sizeof(uint32_t) || !isPow2(hdr->numGTEsPerGT)) {
		return false;
	}
	gtInfo->lastGrainNr = hdr->capacity / hdr->grainSize;
	gtInfo->lastGrainSize = (hdr->capacity & (hdr->grainSize - 1)) * VMDK_SECTOR_SIZE;

	{
		uint64_t GTEs = gtInfo->lastGrainNr + (gtInfo->lastGrainSize != 0);
		/* Number of GTEs must be less than 2^32.  Actually capacity must be less than 2^32 (2TB) for everything except streamOptimized format... */
		uint32_t GTs = CEILING(GTEs, hdr->numGTEsPerGT);
		uint32_t GDsectors = CEILING(GTs * sizeof(uint32_t), VMDK_SECTOR_SIZE);
		uint32_t GTsectors = CEILING(hdr->numGTEsPerGT * sizeof(uint32_t), VMDK_SECTOR_SIZE);
		uint32_t *gd = calloc(GDsectors + GTsectors * GTs, VMDK_SECTOR_SIZE);
		uint32_t *gt;

		if (!gd) {
			return false;
		}
		gt = gd + GDsectors * VMDK_SECTOR_SIZE / sizeof(uint32_t);
		gtInfo->GTEs = GTEs;
		gtInfo->GTs = GTs;
		gtInfo->GDsectors = GDsectors;
		gtInfo->gd = gd;
		gtInfo->GTsectors = GTsectors;
		gtInfo->gt = gt;
	}
	return true;
}
Esempio n. 20
0
int ds2746_get_battery_info(struct battery_info_reply *batt_info)
{
	/*printk(DRIVER_ZONE "%s\n",__func__);*/
	batt_info->batt_id = poweralg.battery.id_index; /*Mbat ID*/
	batt_info->batt_vol = poweralg.battery.voltage_mV; /*VMbat*/
	batt_info->batt_temp = poweralg.battery.temp_01c; /*Temperature*/
	batt_info->batt_current = poweralg.battery.current_mA; /*Current*/
	batt_info->level = CEILING(poweralg.capacity_01p, 10); /*last_show%*/
	/* do not write charging_source back to htc_battery
	batt_info->charging_source = poweralg.charging_source; */
	batt_info->charging_enabled = poweralg.charging_enable;
	batt_info->full_bat = poweralg.battery.charge_full_real_mAh;
	batt_info->temp_fault = poweralg.protect_flags.is_temperature_fault;
	return 0;
}
Esempio n. 21
0
/* Reduces the internal counters to our array, and subtracts one from the count of contained application elements.
 * ---------------------------------------------------------------------------------------------------------------
 * [params] {flex} a nonvoid flex array to work with.
 * [return] {SUCCESS} if shrinking was completed.
 *          {FAILURE} if array is shrunk to 0 elements, or if  memory error was encountered.
 */
extern inline DSTATUS flex_shrink(flex_t  flex)
{
    if(flex->num_user_elements_inserted == 0  )return FAILURE; // bail early

    //log_info("test %ld == %ld",flex->usable_data_blocks - flex->last_data_size, flex->num_user_elements_inserted-1);
    if(flex->num_user_elements_inserted != 1 && 
            flex->usable_data_blocks - flex->last_data_size == flex->num_user_elements_inserted-1){
        //log_info("REMOVED  @ %ld",flex->last_index_occup);
        free(flex->index_block[flex->last_index_occup]);
        flex->usable_data_blocks -= flex->last_data_size;

        //log_info("realloc %ld == %ld",flex->last_index_occup*2, flex->index_length);
        if((flex->last_index_occup) *2 ==  flex->index_length ){ //TODO! see grow x=4 and x=7
            flex->index_length =CEILING(flex->index_length,2);
            index_p new_index = realloc(flex->index_block,
                        sizeof(index_p) * flex->index_length);
            check(new_index,"Failed in Shrinking flex");
            flex->index_block = new_index;
        }
        flex->last_index_occup--;
        
        //log_info("size change 0 == %ld",flex->last_super_occup);
        if( 0== flex->last_super_occup){
            flex->num_super_blocks--;
            // if odd, cut data
            if(flex->num_super_blocks % 2){
                //log_info("cut data size");
                flex->last_data_size /= 2;
                //flex->last_data_size = CEILING(flex->last_data_size,2);
            } else {
                //log_info("cut super size");
                flex->last_super_size /= 2;
                //flex->last_super_size = CEILING(flex->last_super_size,2);
            }
            flex->last_super_occup = flex->last_super_size;
            flex->last_super_occup--;
        } else {
            flex->last_super_occup--;
        }
        flex->num_user_elements_inserted--;
    }  else {
    flex->num_user_elements_inserted--;
        return SUCCESS;
    }
error:
    return FAILURE;
}
Esempio n. 22
0
/* 
 * Print the blocks in the factored matrix L.
 */
void dPrintLblocks(int_t iam, int_t nsupers, gridinfo_t *grid,
		  Glu_persist_t *Glu_persist, LocalLU_t *Llu)
{
    register int_t c, extra, gb, j, lb, nsupc, nsupr, len, nb, ncb;
    register int_t k, mycol, r;
    int_t *xsup = Glu_persist->xsup;
    int_t *index;
    double *nzval;

    printf("\n(%d) L BLOCKS IN COLUMN-MAJOR ORDER -->\n", iam);
    ncb = nsupers / grid->npcol;
    extra = nsupers % grid->npcol;
    mycol = MYCOL( iam, grid );
    if ( mycol < extra ) ++ncb;
    for (lb = 0; lb < ncb; ++lb) {
	index = Llu->Lrowind_bc_ptr[lb];
	if ( index ) { /* Not an empty column */
	    nzval = Llu->Lnzval_bc_ptr[lb];
	    nb = index[0];
	    nsupr = index[1];
	    gb = lb * grid->npcol + mycol;
	    nsupc = SuperSize( gb );
	    printf("(%d) block column (local) %d, # row blocks %d\n",
		   iam, lb, nb);
	    for (c = 0, k = BC_HEADER, r = 0; c < nb; ++c) {
		len = index[k+1];
		printf("(%d) row-block %d: block # %d\tlength %d\n", 
		       iam, c, index[k], len);
		PrintInt10("lsub", len, &index[k+LB_DESCRIPTOR]);
		for (j = 0; j < nsupc; ++j) {
		    PrintDouble5("nzval", len, &nzval[r + j*nsupr]);
		}
		k += LB_DESCRIPTOR + len;
		r += len;
	    }
	}
	printf("(%d)", iam);
 	PrintInt10("ToSendR[]", grid->npcol, Llu->ToSendR[lb]);
	PrintInt10("fsendx_plist[]", grid->nprow, Llu->fsendx_plist[lb]);
    }
    printf("nfrecvx %4d\n", Llu->nfrecvx);
    k = CEILING( nsupers, grid->nprow );
    PrintInt10("fmod", k, Llu->fmod);
    
} /* DPRINTLBLOCKS */
Esempio n. 23
0
static char *
makeDiskDescriptorFile(const char *fileName,
                       uint64_t capacity,
                       uint32_t cid)
{
	static const char ddfTemplate[] =
"# Disk DescriptorFile\n"
"version=1\n"
"encoding=\"UTF-8\"\n"
"CID=%08x\n"
"parentCID=ffffffff\n"
"createType=\"streamOptimized\"\n"
"\n"
"# Extent description\n"
"RW %llu SPARSE \"%s\"\n"
"\n"
"# The Disk Data Base\n"
"#DDB\n"
"\n"
"ddb.longContentID = \"%08x%08x%08x%08x\"\n"
"ddb.toolsVersion = \"2147483647\"\n" /* OpenSource Tools version. */
"ddb.virtualHWVersion = \"4\"\n" /* This field is obsolete, used by ESX3.x and older only. */
"ddb.geometry.cylinders = \"%u\"\n"
"ddb.geometry.heads = \"255\"\n" /* 255/63 is good for anything bigger than 4GB. */
"ddb.geometry.sectors = \"63\"\n"
"ddb.adapterType = \"lsilogic\"\n";

	char *ret;
	unsigned int cylinders;

	if (capacity > 65535 * 255 * 63) {
		cylinders = 65535;
	} else {
		cylinders = CEILING(capacity, 255 * 63);
	}
	if (asprintf(&ret, ddfTemplate, cid, (long long int)capacity, fileName, (uint32_t)mrand48(), (uint32_t)mrand48(), (uint32_t)mrand48(), cid, cylinders) == -1) {
		return NULL;
	}
	return ret;
}
Esempio n. 24
0
extern inline DSTATUS flex_insert(flex_t flex, index_t requested_index, data_p user_data)
{
    DSTATUS status;
    index_t r,k,b,e,p;
    r = requested_index + 1;
    k = LEADINGBIT(r); // no need for minus 1. already zero indexed 
    b = BITSUBSET(r,k-k/2,k);
    e = BITSUBSET(r,0, CEILING(k,2));
    p = (1 << (k/2 + 1)) - 2 + (k & 1) * (1 << (k/2));
    //log_info("Grow Check P+B:[%ld], index: [%ld]",p+b, flex->index_length);
    //printf("k/2=[%ld], Ceil(k,2)=[%ld]\n",k/2,CEILING(k,2));
    //printf("K: [%ld] is the leading 1 bit\n",k); // printf("B: [%ld]\n",b);
    while(p+b > flex->last_index_occup){ // we have an index which would seg fault
        status = flex_grow(flex);  //flex_debug_out(flex);
        check_alt(status == SUCCESS);    
    }
    //log_info("trying [%ld,%ld]",(p+b),e);
    (flex->index_block[(p+b)][e]) = *user_data;
    return SUCCESS;
error:
    return FAILURE;
}
/**
 * Determine how many pages need to be allocated.
 *
 * @param[in] handle	Handle to the allocator being used.
 *
 * @return Number of pages that need to be allocated rounded up to the nearest
 * multiple of the page size.
 */
static size_t __page_count(struct gnix_mbox_alloc_handle *handle)
{
	size_t total_size = CEILING((handle->mbox_size * handle->mpmmap),
				     handle->page_size);
	size_t page_count;

	page_count = total_size / handle->page_size;

	GNIX_DEBUG(FI_LOG_EP_CTRL,
		   "Mbox_size: %zu, mpmmap: %zu, page_size: %zu\n",
		   handle->mbox_size, handle->mpmmap, handle->page_size);

	GNIX_DEBUG(FI_LOG_EP_CTRL,
		   "Total size: %zu, page_count: %zu\n", total_size,
		   page_count);

	if (page_count <= 0) {
		GNIX_WARN(FI_LOG_EP_CTRL,
			  "Invalid size requested, truncating to single page.\n");
		page_count = 1;
	}

	return page_count;
}
Esempio n. 26
0
GLint gluScaleImage( GLenum format,
                     GLint widthin, GLint heightin,
                     GLenum typein, const void *datain,
                     GLint widthout, GLint heightout,
                     GLenum typeout, void *dataout )
{
   GLuint components, i, j, k;
   GLfloat *tempin, *tempout;
   GLfloat sx, sy;
   GLint unpackrowlength, unpackalignment, unpackskiprows, unpackskippixels;
   GLint packrowlength, packalignment, packskiprows, packskippixels;
   GLint sizein, sizeout;
   GLint rowstride, rowlen;


   /* Determine number of components per pixel */
   switch (format) {
      case GL_COLOR_INDEX:
      case GL_STENCIL_INDEX:
      case GL_DEPTH_COMPONENT:
      case GL_RED:
      case GL_GREEN:
      case GL_BLUE:
      case GL_ALPHA:
      case GL_LUMINANCE:
         components = 1;
	 break;
      case GL_LUMINANCE_ALPHA:
	 components = 2;
	 break;
      case GL_RGB:
	 components = 3;
	 break;
      case GL_RGBA:
	 components = 4;
	 break;
      default:
	 return GLU_INVALID_ENUM;
   }

   /* Determine bytes per input datum */
   switch (typein) {
      case GL_UNSIGNED_BYTE:	sizein = sizeof(GLubyte);	break;
      case GL_BYTE:		sizein = sizeof(GLbyte);	break;
      case GL_UNSIGNED_SHORT:	sizein = sizeof(GLushort);	break;
      case GL_SHORT:		sizein = sizeof(GLshort);	break;
      case GL_UNSIGNED_INT:	sizein = sizeof(GLuint);	break;
      case GL_INT:		sizein = sizeof(GLint);		break;
      case GL_FLOAT:		sizein = sizeof(GLfloat);	break;
      case GL_BITMAP:
	 /* not implemented yet */
      default:
	 return GL_INVALID_ENUM;
   }

   /* Determine bytes per output datum */
   switch (typeout) {
      case GL_UNSIGNED_BYTE:	sizeout = sizeof(GLubyte);	break;
      case GL_BYTE:		sizeout = sizeof(GLbyte);	break;
      case GL_UNSIGNED_SHORT:	sizeout = sizeof(GLushort);	break;
      case GL_SHORT:		sizeout = sizeof(GLshort);	break;
      case GL_UNSIGNED_INT:	sizeout = sizeof(GLuint);	break;
      case GL_INT:		sizeout = sizeof(GLint);	break;
      case GL_FLOAT:		sizeout = sizeof(GLfloat);	break;
      case GL_BITMAP:
	 /* not implemented yet */
      default:
	 return GL_INVALID_ENUM;
   }

   /* Get glPixelStore state */
   glGetIntegerv( GL_UNPACK_ROW_LENGTH, &unpackrowlength );
   glGetIntegerv( GL_UNPACK_ALIGNMENT, &unpackalignment );
   glGetIntegerv( GL_UNPACK_SKIP_ROWS, &unpackskiprows );
   glGetIntegerv( GL_UNPACK_SKIP_PIXELS, &unpackskippixels );
   glGetIntegerv( GL_PACK_ROW_LENGTH, &packrowlength );
   glGetIntegerv( GL_PACK_ALIGNMENT, &packalignment );
   glGetIntegerv( GL_PACK_SKIP_ROWS, &packskiprows );
   glGetIntegerv( GL_PACK_SKIP_PIXELS, &packskippixels );

   /* Allocate storage for intermediate images */
   tempin = (GLfloat *) malloc( widthin * heightin
			        * components * sizeof(GLfloat) );
   if (!tempin) {
      return GLU_OUT_OF_MEMORY;
   }
   tempout = (GLfloat *) malloc( widthout * heightout
		 	         * components * sizeof(GLfloat) );
   if (!tempout) {
      free( tempin );
      return GLU_OUT_OF_MEMORY;
   }


   /*
    * Unpack the pixel data and convert to floating point
    */

   if (unpackrowlength>0) {
      rowlen = unpackrowlength;
   }
   else {
      rowlen = widthin;
   }
   if (sizein >= unpackalignment) {
      rowstride = components * rowlen;
   }
   else {
      rowstride = unpackalignment/sizein
	        * CEILING( components * rowlen * sizein, unpackalignment );
   }

   switch (typein) {
      case GL_UNSIGNED_BYTE:
	 k = 0;
	 for (i=0;i<heightin;i++) {
	    GLubyte *ubptr = (GLubyte *) datain
	                   + i * rowstride
			   + unpackskiprows * rowstride
			   + unpackskippixels * components;
	    for (j=0;j<widthin*components;j++) {
	       tempin[k++] = (GLfloat) *ubptr++;
	    }
	 }
	 break;
      case GL_BYTE:
	 k = 0;
	 for (i=0;i<heightin;i++) {
	    GLbyte *bptr = (GLbyte *) datain
	                 + i * rowstride
			 + unpackskiprows * rowstride
			 + unpackskippixels * components;
	    for (j=0;j<widthin*components;j++) {
	       tempin[k++] = (GLfloat) *bptr++;
	    }
	 }
	 break;
      case GL_UNSIGNED_SHORT:
	 k = 0;
	 for (i=0;i<heightin;i++) {
	    GLushort *usptr = (GLushort *) datain
	                    + i * rowstride
			    + unpackskiprows * rowstride
			    + unpackskippixels * components;
	    for (j=0;j<widthin*components;j++) {
	       tempin[k++] = (GLfloat) *usptr++;
	    }
	 }
	 break;
      case GL_SHORT:
	 k = 0;
	 for (i=0;i<heightin;i++) {
	    GLshort *sptr = (GLshort *) datain
	                  + i * rowstride
			  + unpackskiprows * rowstride
			  + unpackskippixels * components;
	    for (j=0;j<widthin*components;j++) {
	       tempin[k++] = (GLfloat) *sptr++;
	    }
	 }
	 break;
      case GL_UNSIGNED_INT:
	 k = 0;
	 for (i=0;i<heightin;i++) {
	    GLuint *uiptr = (GLuint *) datain
	                  + i * rowstride
			  + unpackskiprows * rowstride
			  + unpackskippixels * components;
	    for (j=0;j<widthin*components;j++) {
	       tempin[k++] = (GLfloat) *uiptr++;
	    }
	 }
	 break;
      case GL_INT:
	 k = 0;
	 for (i=0;i<heightin;i++) {
	    GLint *iptr = (GLint *) datain
	                + i * rowstride
			+ unpackskiprows * rowstride
			+ unpackskippixels * components;
	    for (j=0;j<widthin*components;j++) {
	       tempin[k++] = (GLfloat) *iptr++;
	    }
	 }
	 break;
      case GL_FLOAT:
	 k = 0;
	 for (i=0;i<heightin;i++) {
	    GLfloat *fptr = (GLfloat *) datain
	                  + i * rowstride
			  + unpackskiprows * rowstride
			  + unpackskippixels * components;
	    for (j=0;j<widthin*components;j++) {
	       tempin[k++] = *fptr++;
	    }
	 }
	 break;
      default:
	 return GLU_INVALID_ENUM;
   }


   /*
    * Scale the image!
    */

   sx = (GLfloat) widthin / (GLfloat) widthout;
   sy = (GLfloat) heightin / (GLfloat) heightout;

/*#define POINT_SAMPLE*/
#ifdef POINT_SAMPLE
   for (i=0;i<heightout;i++) {
      GLint ii = i * sy;
      for (j=0;j<widthout;j++) {
	 GLint jj = j * sx;

	 GLfloat *src = tempin + (ii * widthin + jj) * components;
	 GLfloat *dst = tempout + (i * widthout + j) * components;

	 for (k=0;k<components;k++) {
	    *dst++ = *src++;
	 }
      }
   }
#else
   if (sx<1.0 && sy<1.0) {
      /* magnify both width and height:  use weighted sample of 4 pixels */
      GLint i0, i1, j0, j1;
      GLfloat alpha, beta;
      GLfloat *src00, *src01, *src10, *src11;
      GLfloat s1, s2;
      GLfloat *dst;

      for (i=0;i<heightout;i++) {
	 i0 = i * sy;
	 i1 = (i+1) * sy - EPSILON;
	 alpha = i*sy - i0;
	 for (j=0;j<widthout;j++) {
	    j0 = j * sx;
	    j1 = (j+1) * sx - EPSILON;
	    beta = j*sx - j0;

	    /* compute weighted average of pixels in rect (i0,j0)-(i1,j1) */
	    src00 = tempin + (i0 * widthin + j0) * components;
	    src01 = tempin + (i0 * widthin + j1) * components;
	    src10 = tempin + (i1 * widthin + j0) * components;
	    src11 = tempin + (i1 * widthin + j1) * components;

	    dst = tempout + (i * widthout + j) * components;

	    for (k=0;k<components;k++) {
	       s1 = *src00++ * (1.0-beta) + *src01++ * beta;
	       s2 = *src10++ * (1.0-beta) + *src11++ * beta;
	       *dst++ = s1 * (1.0-alpha) + s2 * alpha;
	    }
	 }
      }
   }
   else {
      /* shrink width and/or height:  use an unweighted box filter */
      GLint i0, i1;
      GLint j0, j1;
      GLint ii, jj;
      GLfloat sum, *dst;

      for (i=0;i<heightout;i++) {
	 i0 = i * sy;
	 i1 = (i+1) * sy - EPSILON;
	 for (j=0;j<widthout;j++) {
	    j0 = j * sx;
	    j1 = (j+1) * sx - EPSILON;

	    dst = tempout + (i * widthout + j) * components;

	    /* compute average of pixels in the rectangle (i0,j0)-(i1,j1) */
	    for (k=0;k<components;k++) {
	       sum = 0.0;
	       for (ii=i0;ii<=i1;ii++) {
		  for (jj=j0;jj<=j1;jj++) {
		     sum += *(tempin + (ii * widthin + jj) * components + k);
		  }
	       }
	       sum /= (j1-j0+1) * (i1-i0+1);
	       *dst++ = sum;
	    }
	 }
      }
   }
#endif


   /*
    * Return output image
    */

   if (packrowlength>0) {
      rowlen = packrowlength;
   }
   else {
      rowlen = widthout;
   }
   if (sizeout >= packalignment) {
      rowstride = components * rowlen;
   }
   else {
      rowstride = packalignment/sizeout
	        * CEILING( components * rowlen * sizeout, packalignment );
   }

   switch (typeout) {
      case GL_UNSIGNED_BYTE:
	 k = 0;
	 for (i=0;i<heightout;i++) {
	    GLubyte *ubptr = (GLubyte *) dataout
	                   + i * rowstride
			   + packskiprows * rowstride
			   + packskippixels * components;
	    for (j=0;j<widthout*components;j++) {
	       *ubptr++ = (GLubyte) tempout[k++];
	    }
	 }
	 break;
      case GL_BYTE:
	 k = 0;
	 for (i=0;i<heightout;i++) {
	    GLbyte *bptr = (GLbyte *) dataout
	                 + i * rowstride
			 + packskiprows * rowstride
			 + packskippixels * components;
	    for (j=0;j<widthout*components;j++) {
	       *bptr++ = (GLbyte) tempout[k++];
	    }
	 }
	 break;
      case GL_UNSIGNED_SHORT:
	 k = 0;
	 for (i=0;i<heightout;i++) {
	    GLushort *usptr = (GLushort *) dataout
	                    + i * rowstride
			    + packskiprows * rowstride
			    + packskippixels * components;
	    for (j=0;j<widthout*components;j++) {
	       *usptr++ = (GLushort) tempout[k++];
	    }
	 }
	 break;
      case GL_SHORT:
	 k = 0;
	 for (i=0;i<heightout;i++) {
	    GLshort *sptr = (GLshort *) dataout
	                  + i * rowstride
			  + packskiprows * rowstride
			  + packskippixels * components;
	    for (j=0;j<widthout*components;j++) {
	       *sptr++ = (GLshort) tempout[k++];
	    }
	 }
	 break;
      case GL_UNSIGNED_INT:
	 k = 0;
	 for (i=0;i<heightout;i++) {
	    GLuint *uiptr = (GLuint *) dataout
	                  + i * rowstride
			  + packskiprows * rowstride
			  + packskippixels * components;
	    for (j=0;j<widthout*components;j++) {
	       *uiptr++ = (GLuint) tempout[k++];
	    }
	 }
	 break;
      case GL_INT:
	 k = 0;
	 for (i=0;i<heightout;i++) {
	    GLint *iptr = (GLint *) dataout
	                + i * rowstride
			+ packskiprows * rowstride
			+ packskippixels * components;
	    for (j=0;j<widthout*components;j++) {
	       *iptr++ = (GLint) tempout[k++];
	    }
	 }
	 break;
      case GL_FLOAT:
	 k = 0;
	 for (i=0;i<heightout;i++) {
	    GLfloat *fptr = (GLfloat *) dataout
	                  + i * rowstride
			  + packskiprows * rowstride
			  + packskippixels * components;
	    for (j=0;j<widthout*components;j++) {
	       *fptr++ = tempout[k++];
	    }
	 }
	 break;
      default:
	 return GLU_INVALID_ENUM;
   }


   /* free temporary image storage */
   free( tempin );
   free( tempout );

   return 0;
}
Esempio n. 27
0
int
main(int argc, const char *argv[])
{
  iso9660_stat_t *p_statbuf;
  FILE *p_outfd;
  int i;
  char const *psz_image;
  char const *psz_fname;
  char translated_name[256];
  char untranslated_name[256] = ISO9660_PATH;
  CdIo_t *p_cdio;
  unsigned int i_fname=sizeof(ISO9660_FILENAME);
  
  if (argc > 3) {
    printf("usage %s [CD-ROM-or-image [filename]]\n", argv[0]);
    printf("Extracts filename from CD-ROM-or-image.\n");
    return 1;
  }
  
  if (argc > 1) 
    psz_image = argv[1];
  else 
    psz_image = ISO9660_IMAGE;

  if (argc > 2) {
    psz_fname = argv[2];
    i_fname   = strlen(psz_fname)+1;    
  } else 
    psz_fname = ISO9660_FILENAME;

  strncat(untranslated_name, psz_fname, i_fname);

  p_cdio = cdio_open (psz_image, DRIVER_UNKNOWN);
  if (!p_cdio) {
    fprintf(stderr, "Sorry, couldn't open %s\n", psz_image);
    return 1;
  }

  p_statbuf = iso9660_fs_stat (p_cdio, untranslated_name);

  if (NULL == p_statbuf) 
    {
      fprintf(stderr, 
	      "Could not get ISO-9660 file information for file %s\n",
	      untranslated_name);
      cdio_destroy(p_cdio);
      return 2;
    }

  iso9660_name_translate(psz_fname, translated_name);
  
  if (!(p_outfd = fopen (translated_name, "wb")))
    {
      perror ("fopen()");
      cdio_destroy(p_cdio);
      free(p_statbuf);
      return 3;
    }

  /* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */
  {
    const unsigned int i_blocks = CEILING(p_statbuf->size, ISO_BLOCKSIZE);
    for (i = 0; i < i_blocks; i ++)
      {
	char buf[ISO_BLOCKSIZE];
	const lsn_t lsn = p_statbuf->lsn + i;
	
	memset (buf, 0, ISO_BLOCKSIZE);
	
	if ( 0 != cdio_read_data_sectors (p_cdio, buf, lsn, ISO_BLOCKSIZE, 1) )
	  {
	    fprintf(stderr, "Error reading ISO 9660 file at lsn %lu\n",
		    (long unsigned int) p_statbuf->lsn);
	    my_exit(4);
	  }
	
	
	fwrite (buf, ISO_BLOCKSIZE, 1, p_outfd);
	
	if (ferror (p_outfd))
	  {
	    perror ("fwrite()");
	    my_exit(5);
	  }
      }
  }
  
  
  fflush (p_outfd);

  /* Make sure the file size has the exact same byte size. Without the
     truncate below, the file will a multiple of ISO_BLOCKSIZE.
   */
  if (ftruncate (fileno (p_outfd), p_statbuf->size))
    perror ("ftruncate()");

  printf("Extraction of file '%s' from '%s' successful.\n", 
	 translated_name, untranslated_name);

  my_exit(0);
}
Esempio n. 28
0
static BOOL __battery_param_udpate(struct battery_type *battery)
{
	static int batt_id_stable_counter = 0;
	INT32 batt_id_index;
	INT32 temp_01c;

	if (support_ds2746_gauge_ic) {
		/* adc register value are read from __ds2746_battery_adc_udpate()*/
		if (!__ds2746_battery_adc_udpate(battery))
			return FALSE;
	}
	else{
		/* adc register value are read from BAHW_get_batt_info_all()
		if ( !BAHW_get_batt_info_all(battery) ) return FALSE;*/
	}

	/*real physical value*/
	battery->voltage_mV = (battery->voltage_adc * voltage_adc_to_mv_coef / voltage_adc_to_mv_resl);
	battery->current_mA = (battery->current_adc * current_adc_to_mv_coef / current_adc_to_mv_resl);
	battery->discharge_mA = (battery->discharge_adc * discharge_adc_to_mv_coef / discharge_adc_to_mv_resl);
	battery->charge_counter_mAh = (battery->charge_counter_adc * acr_adc_to_mv_coef / acr_adc_to_mv_resl) -	charge_counter_zero_base_mAh;
	battery->current_mA = battery->current_mA - battery->discharge_mA;
	/* prevent from adc out of range*/
	if (battery->id_adc >= id_adc_resl) {
		battery->id_adc = id_adc_resl - 1;
	}
	if (battery->id_adc <= 0) {
		battery->id_adc = 1;
	}
	if (battery->temp_adc >= temp_adc_resl) {
		battery->temp_adc = temp_adc_resl - 1;
	}
	if (battery->temp_adc <= 0) {
		battery->temp_adc = 1;
	}

	/* battery ID shall be ready first for temp/kadc calculation*/
	//   if ( id_conversion ) battery->id_ohm = ((float)id_R_kohm / ((float)id_adc_resl/battery->id_adc - 1)) * 1000;     // kohm -> ohm
	//   else   			  battery->id_ohm = battery->id_adc;
	battery->id_ohm = battery->id_adc;
	calibrate_id_ohm(battery);

	batt_id_index = get_id_index(battery);

	if (is_allow_batt_id_change) {
		/*! TODO: batt_id changes immediately; may need to modify in future*/
		if (batt_id_stable_counter >= 3 && batt_id_index != battery->id_index){
			/* if batt_id is stable but is different from previous one*/
			batt_id_stable_counter = 0; /* reset stable counter and set batt_id to new one*/
		}
	}

	if (batt_id_stable_counter < 3) {
		if (batt_id_stable_counter == 0) {
			/* first time to get the batt id*/
			battery->id_index = batt_id_index;
			battery->charge_full_design_mAh = FL_25[battery->id_index];
			battery->charge_full_real_mAh = battery->charge_full_design_mAh;
			batt_id_stable_counter = 1;
		}
		else{
			/* 2nd and further time to get the batt id*/
			if (batt_id_index == battery->id_index)
				batt_id_stable_counter++;
			else
				batt_id_stable_counter = 0;
		}
	}

	/* calculate temperature*/
	//    battery->temp_01c 			  = get_temp_c((float)temp_R_kohm / ((float)temp_adc_resl/battery->temp_adc - 1))*10;
	temp_01c = get_temp_01c(battery);
	if (temp_01c >= TEMP_MIN*10)
		battery->temp_01c = temp_01c;
	else
		printk(DRIVER_ZONE " get temp_01c(%d) failed...\n", temp_01c);
	battery->temp_index = get_temp_index(battery);

	/* calculate KADC and RARC*/
	battery->KADC_01p = CEILING(get_kadc_001p(battery), 10);
	battery->RARC_01p = CEILING(10000 * battery->charge_counter_mAh / battery->charge_full_real_mAh, 10);
	if (!support_ds2746_gauge_ic) {
		__software_acr_update(battery);
	}

	if (battery->voltage_mV <BATTERY_VOLTAGE_MIN ||
		battery->voltage_mV> BATTERY_VOLTAGE_MAX) {
		printk(DRIVER_ZONE " invalid V(%d).\n", battery->voltage_mV);
		return FALSE;
	}

	/*! star_lee 20100426 - minimum RARC is 0%*/
	if (battery->RARC_01p <= 0) {
		battery->RARC_01p = 0;
	}

	printk(DRIVER_ZONE " V=%d(%x) I=%d(%x) C=%d.%d/%d(%x) id=%d(%x) T=%d(%x) KADC=%d\n",
		battery->voltage_mV,
		battery->voltage_adc,
		battery->current_mA,
		battery->current_adc,
		battery->charge_counter_mAh,
		battery->software_charge_counter_mAms,
		battery->charge_full_real_mAh,
		battery->charge_counter_adc,
		battery->id_index,
		battery->id_adc,
		battery->temp_01c,
		battery->temp_adc,
		battery->KADC_01p);

	return TRUE;
}
Esempio n. 29
0
/*- RouteRead --------------------------------------------------*/
void networkRoute_Handler(OPERATION_HEADER_t* operation_header)
{
	if(operation_header->opCode == RouteTableRead)
	{
		
		routeTableResponse.header.sourceAddress = runningConfiguration.topConfiguration.networkConfig.deviceAddress;
		routeTableResponse.header.destinationAddress = operation_header->sourceAddress;
		
		if(readRouteSession.sendingState && operation_header->sourceAddress != readRouteSession.destinationAddress)
		{
			//BUSY SENDING CONFIG STATE
			routeTableResponse.response.fragment = 0;
			routeTableResponse.response.fragmentTotal = 0;
			routeTableResponse.response.length = 0;
		}else
		{
			NWK_CopyRouteTable(&routeTableBuffer, currentTableSize);
			
			readRouteSession.sendingState = true;
			readRouteSession.destinationAddress = operation_header->sourceAddress;
			
			readRouteSession.currentSendIndex = 0;
			readRouteSession.currentSendFragment = 0;
			readRouteSession.totalSendExpected = CEILING(currentTableSize , MAX_CONTENT_MESSAGE_SIZE);
			readRouteSession.currentSendFrameSize = MIN(MAX_CONTENT_MESSAGE_SIZE, currentTableSize - readRouteSession.currentSendIndex);
			
			routeTableResponse.response.fragment = readRouteSession.currentSendFragment;
			routeTableResponse.response.fragmentTotal = readRouteSession.totalSendExpected;
			routeTableResponse.response.length = readRouteSession.currentSendFrameSize;
			
			OM_ProccessResponseWithBodyOperation(&routeTableResponse.header, readRouteSession.readBuffer, readRouteSession.currentSendFrameSize);
		}
	}else if(operation_header->opCode == RouteTableReadConfirmation)
	{
		if(readRouteSession.sendingState)
		{
			ROUTE_TABLE_READ_CONFIRMATION_MESSAGE_t* msg = (ROUTE_TABLE_READ_CONFIRMATION_MESSAGE_t*)(operation_header + 1);
			
			if(msg->fragment == readRouteSession.currentSendFragment && msg->fragmentTotal == readRouteSession.totalSendExpected)
			{
				if(msg->code == 0x00) //'OK'
				{
					if(readRouteSession.currentSendFragment <= readRouteSession.totalSendExpected)	 //Something to send
					{
						readRouteSession.currentSendIndex += readRouteSession.currentSendFrameSize;
						readRouteSession.currentSendFragment++;
						
						readRouteSession.currentSendFrameSize = MIN(MAX_CONTENT_MESSAGE_SIZE, currentTableSize - readRouteSession.currentSendIndex);
						
						routeTableResponse.response.fragment = readRouteSession.currentSendFragment;
						routeTableResponse.response.fragmentTotal = readRouteSession.totalSendExpected;
						routeTableResponse.response.length = readRouteSession.currentSendFrameSize;
						
						OM_ProccessResponseWithBodyOperation(&routeTableResponse.header,&readRouteSession.readBuffer[readRouteSession.currentSendIndex], readRouteSession.currentSendFrameSize);
					}else
					{
						//Finish
						readRouteSession.sendingState = false;
					}
				}else
				{
					//Something wrong at server size. Abort current session
					readRouteSession.sendingState = false;
				}
			}else
			{
				readRouteSession.sendingState = false;
				//TODO: SEND OR LOG ERROR (FRAGMENT OR FRAGMENT TOTAL NOT EXPECTED)
			}
		}else
		{
			//TODO: SEND OR LOG ERROR (NOT SENDING)
		}
	}else if(operation_header->opCode == RouteTableReadResponse)
	{
		//TODO: SEND NOTIFICATION
	}				
}
Esempio n. 30
0
static void *mmap_alloc(size_t bytes)
{
    char *file_name = NULL;
    int fd = 0;
    char *directory = NULL;
    const char basename[] = "hugepagefile.SOS";
    int size;
    void *requested_base = 
        (void*) (((unsigned long) shmem_internal_data_base + 
                  shmem_internal_data_length + 2 * ONEGIG) & ~(ONEGIG - 1));
    void *ret;

    if (shmem_internal_heap_use_huge_pages) {

        /*
         * check what /proc/mounts has for explicit huge page support
         */

        if(find_hugepage_dir(shmem_internal_heap_huge_page_size, &directory) == 0) {

            size = snprintf(NULL, 0, "%s/%s.%d", directory, basename, getpid());
            if (size < 0) {

                RAISE_WARN_STR("snprint returned error, cannot use huge pages");

            } else {

                file_name = malloc(size + 1);
                if (file_name) {
                    sprintf(file_name, "%s/%s.%d", directory, basename, getpid());
                    fd = open(file_name, O_CREAT | O_RDWR, 0755);
                    if (fd < 0) {
                        RAISE_WARN_STR("file open failed, cannot use huge pages");
                        fd = 0;
                    } else {
                        /* have to round up
                           by the pagesize being used */
                        bytes = CEILING(bytes, shmem_internal_heap_huge_page_size);
                    }
                }
            }
        }
    }

    ret = mmap(requested_base,
               bytes,
               PROT_READ | PROT_WRITE,
               MAP_ANON | MAP_PRIVATE,
               fd,
               0);
    if (ret == MAP_FAILED) {
        RAISE_WARN_STR("mmap for symmetric heap failed");
        ret = NULL;
    }
    if (fd) {
        unlink(file_name);
        close(fd);
    }
    if (directory) {
        free(directory);
    }
    if (file_name) {
        free(file_name);
    }
    return ret;
}