示例#1
0
文件: thin.c 项目: tasleson/lvm2
static void _thin_pool_display(const struct lv_segment *seg)
{
	log_print("  Chunk size\t\t%s",
		  display_size(seg->lv->vg->cmd, seg->chunk_size));
	log_print("  Discards\t\t%s", get_pool_discards_name(seg->discards));
	log_print("  Thin count\t\t%u",
		  dm_list_size(&seg->lv->segs_using_this_lv));
	log_print("  Transaction ID\t%" PRIu64, seg->transaction_id);
	log_print("  Zero new blocks\t%s",
		  (seg->zero_new_blocks == THIN_ZERO_YES) ? "yes" : "no");

	log_print(" ");
}
示例#2
0
int cow_has_min_chunks(const struct volume_group *vg, uint32_t cow_extents, uint32_t chunk_size)
{
	if (((uint64_t)vg->extent_size * cow_extents) >= (SNAPSHOT_MIN_CHUNKS * chunk_size))
		return 1;

	log_error("Snapshot volume cannot be smaller than " DM_TO_STRING(SNAPSHOT_MIN_CHUNKS)
		  " chunks (%u extents, %s).", (unsigned)
		  (((uint64_t) SNAPSHOT_MIN_CHUNKS * chunk_size +
		    vg->extent_size - 1) / vg->extent_size),
		  display_size(vg->cmd, (uint64_t) SNAPSHOT_MIN_CHUNKS * chunk_size));

	return 0;
}
/*
 * Print out each valid partition in the disklabel of a FreeBSD slice.
 * For size calculations, we assume a 512 byte sector size.
 */
static void
bd_printbsdslice(struct open_disk *od, daddr_t offset, char *prefix,
    int verbose)
{
    char		line[80];
    char		buf[BIOSDISK_SECSIZE];
    struct disklabel	*lp;
    int			i;

    /* read disklabel */
    if (bd_read(od, offset + LABELSECTOR, 1, buf))
	return;
    lp =(struct disklabel *)(&buf[0]);
    if (lp->d_magic != DISKMAGIC) {
	sprintf(line, "%s: FFS  bad disklabel\n", prefix);
	pager_output(line);
	return;
    }
    
    /* Print partitions */
    for (i = 0; i < lp->d_npartitions; i++) {
	/*
	 * For each partition, make sure we know what type of fs it is.  If
	 * not, then skip it.  However, since floppies often have bogus
	 * fstypes, print the 'a' partition on a floppy even if it is marked
	 * unused.
	 */
	if ((lp->d_partitions[i].p_fstype == FS_BSDFFS) ||
            (lp->d_partitions[i].p_fstype == FS_SWAP) ||
            (lp->d_partitions[i].p_fstype == FS_VINUM) ||
	    ((lp->d_partitions[i].p_fstype == FS_UNUSED) && 
	     (od->od_flags & BD_FLOPPY) && (i == 0))) {

	    /* Only print out statistics in verbose mode */
	    if (verbose)
	        sprintf(line, "  %s%c: %s %s (%d - %d)\n", prefix, 'a' + i,
		    (lp->d_partitions[i].p_fstype == FS_SWAP) ? "swap " : 
		    (lp->d_partitions[i].p_fstype == FS_VINUM) ? "vinum" :
		    "FFS  ",
		    display_size(lp->d_partitions[i].p_size),
		    lp->d_partitions[i].p_offset,
		    lp->d_partitions[i].p_offset + lp->d_partitions[i].p_size);
	    else
	        sprintf(line, "  %s%c: %s\n", prefix, 'a' + i,
		    (lp->d_partitions[i].p_fstype == FS_SWAP) ? "swap" : 
		    (lp->d_partitions[i].p_fstype == FS_VINUM) ? "vinum" :
		    "FFS");
	    pager_output(line);
	}
    }
}
示例#4
0
//tells you how long each element of the graph should be
int make_graph()
{
    int j,k,total=0,graph_string_toggle=0;
    float graph_i_length[ARRAYSIZE],a=0;

    i=0;
    a=(float)display_size()/sum;
//    printf("a=%.3f\n",a);
    for(j=0;j<ARRAYSIZE;j++)
    {
        if(letternumsum[i]!=0)
        {
//            printf("letternumsum[%d]\n",i);
            graph_i_length[j]=a*letternumsum[i]*onepercent();
            rounded_graph_length[j]=roundf(graph_i_length[j]);
//            printf("The number of \"=\" in %d letter words is %.2f\n",i,rounded_graph_length[j]);
            total+=rounded_graph_length[j];
            //graphical part
            do
            {
                if(i<10)
                {
                    printf("Word #%3d: ",i);
                    graph_string_toggle=1;
                }
                else if(i==(ARRAYSIZE-1))
                {
                    printf("Word #%d+: ",i);
                }
                else
                {
                    printf("Word #%3d: ",i);
                    graph_string_toggle=1;
                }
            }while(graph_string_toggle==0);
            for(k=0;k<=rounded_graph_length[j];k++)
            {
                printf("=");
                if(k==rounded_graph_length[j])
                {
                    printf("\n");
                }
            }
        }
        i++;
    }
//    printf("total=%d\n",total);

}
/*
 * Print information about slices on a disk.  For the size calculations we
 * assume a 512 byte sector.
 */
static void
bd_printslice(struct open_disk *od, struct pc98_partition *dp, char *prefix,
	int verbose)
{
	int cylsecs, start, size;
	char stats[80];
	char line[80];

	cylsecs = od->od_hds * od->od_sec;
	start = dp->dp_scyl * cylsecs + dp->dp_shd * od->od_sec + dp->dp_ssect;
	size = (dp->dp_ecyl - dp->dp_scyl + 1) * cylsecs;

	if (verbose)
		sprintf(stats, " %s (%d - %d)", display_size(size),
		    start, start + size);
	else
		stats[0] = '\0';

	switch(dp->dp_mid & PC98_MID_MASK) {
	case PC98_MID_386BSD:
		bd_printbsdslice(od, start, prefix, verbose);
		return;
	case 0x00:				/* unused partition */
		return;
	case 0x01:
		sprintf(line, "%s: FAT-12%s\n", prefix, stats);
		break;
	case 0x11:
	case 0x20:
	case 0x21:
	case 0x22:
	case 0x23:
	case 0x24:
		sprintf(line, "%s: FAT-16%s\n", prefix, stats);
		break;
	default:
		sprintf(line, "%s: Unknown fs: 0x%x %s\n", prefix, dp->dp_mid,
		    stats);
	}
	pager_output(line);
}
示例#6
0
int display_hash(state *s)
{
  /* We can't call display_size here because we don't know if we're
     going to display *anything* yet. If we're in matching mode, we
     have to evaluate if there was a match first. */
  if ((s->mode & mode_match) || (s->mode & mode_match_neg))
    return display_match_result(s);

  display_size(s);
  _tprintf (_TEXT("%s"), s->hash_result);

  if (s->mode & mode_quiet)
    _tprintf (_TEXT("  "));
  else
  {
    if ((s->mode & mode_piecewise) ||
	!(s->is_stdin))
    {
      if (s->mode & mode_timestamp)
      {
	struct tm * my_time = gmtime(&(s->timestamp));

	// The format is four digit year, two digit month, 
	// two digit hour, two digit minute, two digit second
	strftime(s->time_str, 
		 MAX_TIME_STRING_LENGTH, 
		 "%Y:%m:%d:%H:%M:%S", 
		 my_time);

	printf (" %s", s->time_str);
      }


      printf(" %c", display_asterisk(s));      
      display_filename(stdout,s->full_name);
    }
  }

  make_newline(s);
  return FALSE;
}
示例#7
0
static void _mirrored_display(const struct lv_segment *seg)
{
        const char *size;
        uint32_t s;

        log_print("  Mirrors\t\t%u", seg->area_count);
        log_print("  Mirror size\t\t%u", seg->area_len);
        if (seg->log_lv)
                log_print("  Mirror log volume\t%s", seg->log_lv->name);

        if (seg->region_size) {
                size = display_size(seg->lv->vg->cmd,
                                    (uint64_t) seg->region_size);
                log_print("  Mirror region size\t%s", size);
        }

        log_print("  Mirror original:");
        display_stripe(seg, 0, "    ");
        log_print("  Mirror destinations:");
        for (s = 1; s < seg->area_count; s++)
                display_stripe(seg, s, "    ");
        log_print(" ");
}
示例#8
0
static void _striped_display(const struct lv_segment *seg)
{
	uint32_t s;

	if (seg->area_count == 1)
		display_stripe(seg, 0, "  ");
	else {
		log_print("  Stripes\t\t%u", seg->area_count);

		if (seg->lv->vg->cmd->si_unit_consistency)
			log_print("  Stripe size\t\t%s",
				  display_size(seg->lv->vg->cmd,
					       (uint64_t) seg->stripe_size));
		else
			log_print("  Stripe size\t\t%u KB",
				  seg->stripe_size / 2);

		for (s = 0; s < seg->area_count; s++) {
			log_print("  Stripe %d:", s);
			display_stripe(seg, s, "    ");
		}
	}
	log_print(" ");
}
示例#9
0
文件: stats.c 项目: Strongc/ccache
static void
display_size_times_1024(uint64_t size)
{
	display_size(size * 1024);
}
示例#10
0
文件: vdo_manip.c 项目: tasleson/lvm2
/*
 * convert_vdo_pool_lv
 * @data_lv
 * @vtp
 * @virtual_extents
 *
 * Convert given data LV and its target parameters into a VDO LV with VDO pool.
 *
 * Returns: old data LV on success (passed data LV becomes VDO LV), NULL on failure
 */
struct logical_volume *convert_vdo_pool_lv(struct logical_volume *data_lv,
					   const struct dm_vdo_target_params *vtp,
					   uint32_t *virtual_extents)
{
	const uint64_t header_size = DEFAULT_VDO_POOL_HEADER_SIZE;
	const uint32_t extent_size = data_lv->vg->extent_size;
	struct cmd_context *cmd = data_lv->vg->cmd;
	struct logical_volume *vdo_pool_lv = data_lv;
	const struct segment_type *vdo_pool_segtype;
	struct lv_segment *vdo_pool_seg;
	uint64_t vdo_logical_size = 0;
	uint64_t adjust;

	if (!(vdo_pool_segtype = get_segtype_from_string(cmd, SEG_TYPE_NAME_VDO_POOL)))
		return_NULL;

	adjust = (*virtual_extents * (uint64_t) extent_size) % DM_VDO_BLOCK_SIZE;
	if (adjust) {
		*virtual_extents += (DM_VDO_BLOCK_SIZE - adjust) / extent_size;
		log_print_unless_silent("Rounding size up to 4,00 KiB VDO logical extent boundary: %s.",
					display_size(data_lv->vg->cmd, *virtual_extents * (uint64_t) extent_size));
	}

	if (*virtual_extents)
		vdo_logical_size =
			_get_virtual_size(*virtual_extents, extent_size, header_size);

	if (!dm_vdo_validate_target_params(vtp, vdo_logical_size))
		return_0;

	/* Format data LV as VDO volume */
	if (!_format_vdo_pool_data_lv(data_lv, vtp, &vdo_logical_size)) {
		log_error("Cannot format VDO pool volume %s.", display_lvname(data_lv));
		return NULL;
	}

	if (!deactivate_lv(data_lv->vg->cmd, data_lv)) {
		log_error("Aborting. Manual intervention required.");
		return NULL;
	}

	vdo_logical_size -= 2 * header_size;

	if (vdo_logical_size < extent_size) {
		if (!*virtual_extents)
			/* User has not specified size and at least 1 extent is necessary */
			log_error("Cannot create fully fitting VDO volume, "
				  "--virtualsize has to be specified.");

		log_error("Size %s for VDO volume cannot be smaller then extent size %s.",
			  display_size(data_lv->vg->cmd, vdo_logical_size),
			  display_size(data_lv->vg->cmd, extent_size));
		return NULL;
	}

	*virtual_extents = vdo_logical_size / extent_size;

	/* Move segments from existing data_lv into LV_vdata */
	if (!(data_lv = insert_layer_for_lv(cmd, vdo_pool_lv, 0, "_vdata")))
		return_NULL;

	vdo_pool_seg = first_seg(vdo_pool_lv);
	vdo_pool_seg->segtype = vdo_pool_segtype;
	vdo_pool_seg->vdo_params = *vtp;
	vdo_pool_seg->vdo_pool_header_size = DEFAULT_VDO_POOL_HEADER_SIZE;
	vdo_pool_seg->vdo_pool_virtual_extents = *virtual_extents;

	vdo_pool_lv->status |= LV_VDO_POOL;
	data_lv->status |= LV_VDO_POOL_DATA;

	return data_lv;
}
示例#11
0
文件: vdo_manip.c 项目: tasleson/lvm2
/*
 * Formats data LV for a use as a VDO pool LV.
 *
 * Calls tool 'vdoformat' on the already active volume.
 */
static int _format_vdo_pool_data_lv(struct logical_volume *data_lv,
				    const struct dm_vdo_target_params *vtp,
				    uint64_t *logical_size)
{
	char *dpath;
	const struct dm_config_node *cn;
	const struct dm_config_value *cv;
	struct pipe_data pdata;
	FILE *f;
	uint64_t lb;
	unsigned slabbits;
	int args = 1;
	char buf_args[5][128];
	char buf[256]; /* buffer for short disk header (64B) */
	const char *argv[19] = { /* Max supported args */
		find_config_tree_str_allow_empty(data_lv->vg->cmd, global_vdo_format_executable_CFG, NULL)
	};

	if (!(dpath = lv_path_dup(data_lv->vg->cmd->mem, data_lv))) {
		log_error("Failed to build device path for VDO formating of data volume %s.",
			  display_lvname(data_lv));
		return 0;
	}

	if (*logical_size) {
		if (dm_snprintf(buf_args[args], sizeof(buf_args[0]), "--logical-size=" FMTu64 "K",
			       (*logical_size / 2)) < 0)
			return_0;

		argv[args] = buf_args[args];
		args++;
	}

	slabbits = 31 - clz(vtp->slab_size_mb / DM_VDO_BLOCK_SIZE * 512);
	log_debug("Slab size %s converted to %u bits.",
		  display_size(data_lv->vg->cmd, vtp->slab_size_mb * UINT64_C(2 * 1024)), slabbits);
	if (dm_snprintf(buf_args[args], sizeof(buf_args[0]), "--slab-bits=%u", slabbits) < 0)
		return_0;

	argv[args] = buf_args[args];
	args++;

	if (vtp->check_point_frequency) {
		if (dm_snprintf(buf_args[args], sizeof(buf_args[0]), "--uds-checkpoint-frequency=%u",
				vtp->check_point_frequency) < 0)
			return_0;
		argv[args] = buf_args[args];
		args++;
	}

	/* Convert size to GiB units or one of these strings: 0.25, 0.50, 0.75 */
	if (vtp->index_memory_size_mb >= 1024) {
		if (dm_snprintf(buf_args[args], sizeof(buf_args[0]), "--uds-memory-size=%u",
				vtp->index_memory_size_mb / 1024) < 0)
			return_0;
	} else if (dm_snprintf(buf_args[args], sizeof(buf_args[0]), "--uds-memory-size=0.%u",
			       (vtp->index_memory_size_mb < 512) ? 25 :
			       (vtp->index_memory_size_mb < 768) ? 50 : 75) < 0)
		   return_0;

	argv[args] = buf_args[args];
	args++;

	if (vtp->use_sparse_index)  {
		if (dm_snprintf(buf_args[args], sizeof(buf_args[0]), "--uds-sparse") < 0)
			return_0;

		argv[args] = buf_args[args];
		args++;
	}

	/* Any other user opts add here */
	if (!(cn = find_config_tree_array(data_lv->vg->cmd, global_vdo_format_options_CFG, NULL))) {
		log_error(INTERNAL_ERROR "Unable to find configuration for vdoformat command options.");
		return 0;
	}

	for (cv = cn->v; cv && args < 16; cv = cv->next) {
		if (cv->type != DM_CFG_STRING) {
			log_error("Invalid string in config file: "
				  "global/vdoformat_options.");
			return 0;
		}
		if (cv->v.str[0])
			argv[++args] = cv->v.str;
	}

	/* Only unused VDO data LV could be activated and wiped */
	if (!dm_list_empty(&data_lv->segs_using_this_lv)) {
		log_error(INTERNAL_ERROR "Failed to wipe logical VDO data for volume %s.",
			  display_lvname(data_lv));
		return 0;
	}

	argv[args] = dpath;

	if (!(f = pipe_open(data_lv->vg->cmd, argv, 0, &pdata))) {
		log_error("WARNING: Cannot read output from %s.", argv[0]);
		return 0;
	}

	if (!*logical_size)
		while (fgets(buf, sizeof(buf), f)) {
			/* TODO: Watch out for locales */
			if (sscanf(buf, "Logical blocks defaulted to " FMTu64 " blocks", &lb) == 1) {
				*logical_size = lb * DM_VDO_BLOCK_SIZE;
				log_verbose("Available VDO logical blocks " FMTu64 " (%s).",
					    lb, display_size(data_lv->vg->cmd, *logical_size));
				break;
			} else
				log_warn("WARNING: Cannot parse output '%s' from %s.", buf, argv[0]);
		}

	if (!pipe_close(&pdata)) {
		log_error("Command %s failed.", argv[0]);
		return 0;
	}

	return 1;
}
示例#12
0
int import_pv(const struct format_type *fmt, struct dm_pool *mem,
	      struct device *dev, struct volume_group *vg,
	      struct physical_volume *pv, struct pv_disk *pvd,
	      struct vg_disk *vgd)
{
	uint64_t size;

	memset(pv, 0, sizeof(*pv));
	memcpy(&pv->id, pvd->pv_uuid, ID_LEN);

	pv->dev = dev;
	if (!*pvd->vg_name)
		pv->vg_name = fmt->orphan_vg_name;
	else if (!(pv->vg_name = dm_pool_strdup(mem, (char *)pvd->vg_name))) {
		log_error("Volume Group name allocation failed.");
		return 0;
	}

	memcpy(&pv->vgid, vgd->vg_uuid, sizeof(vg->id));

	/* Store system_id from first PV if PV belongs to a VG */
	if (vg && !*vg->lvm1_system_id)
		strncpy(vg->lvm1_system_id, (char *)pvd->system_id, NAME_LEN);

	if (vg &&
	    strncmp(vg->lvm1_system_id, (char *)pvd->system_id, sizeof(pvd->system_id)))
		    log_very_verbose("System ID %s on %s differs from %s for "
				     "volume group", pvd->system_id,
				     pv_dev_name(pv), vg->lvm1_system_id);

	/*
	 * If exported, we still need to flag in pv->status too because
	 * we don't always have a struct volume_group when we need this.
	 */
	if (pvd->pv_status & VG_EXPORTED)
		pv->status |= EXPORTED_VG;

	if (pvd->pv_allocatable)
		pv->status |= ALLOCATABLE_PV;

	pv->size = pvd->pv_size;
	pv->pe_size = pvd->pe_size;
	pv->pe_start = pvd->pe_start;
	pv->pe_count = pvd->pe_total;
	pv->pe_alloc_count = 0;
	pv->pe_align = 0;
        pv->is_labelled = 0; /* format1 PVs have no label */
        pv->label_sector = 0;

	/* Fix up pv size if missing or impossibly large */
	if (!pv->size || pv->size > (1ULL << 62)) {
		if (!dev_get_size(dev, &pv->size)) {
			log_error("%s: Couldn't get size.", pv_dev_name(pv));
			return 0;
		}
		log_verbose("Fixing up missing format1 size (%s) "
			    "for PV %s", display_size(fmt->cmd, pv->size),
			    pv_dev_name(pv));
		if (vg) {
			size = pv->pe_count * (uint64_t) vg->extent_size +
			       pv->pe_start;
			if (size > pv->size)
				log_warn("WARNING: Physical Volume %s is too "
					 "large for underlying device",
					 pv_dev_name(pv));
		}
	}

	dm_list_init(&pv->tags);
	dm_list_init(&pv->segments);

	if (!alloc_pv_segment_whole_pv(mem, pv))
		return_0;

	return 1;
}
示例#13
0
文件: resize.c 项目: att/uwin
/*
 * Starts a window resize operation
 */
void
RESIZE_EventLoop(ScreenInfo *scr, Window w, MwmWindow *tmp_win,
		 int val1, int val2, int val1_unit, int val2_unit)
{
    Bool finished = False, done = False;
    int x, y, delta_x, delta_y;
    Window ResizeWindow;
    XEvent oevent;

    if ((w == None) || (tmp_win == NULL))
	return;

    /* Already checked this in functions.c, but its here too incase
     * there's a resize on initial placement. */
    if (tmp_win && !(tmp_win->functions & MWM_FUNC_RESIZE))
    {
	XBell(dpy, scr->screen);
	return;
    }
    /* can't resize icons */
    if (tmp_win->flags & ICONIFIED)
	return;

    ResizeWindow = tmp_win->frame;

    if ((val1 != 0) && (val2 != 0))
    {
	dragWidth = val1 * val1_unit / 100;
	dragHeight = val2 * val2_unit / 100;

	WIN_ConstrainWindow(scr, tmp_win, &dragWidth, &dragHeight);
	DEC_ConfigureDecorations(scr, tmp_win, tmp_win->frame_x,
			       tmp_win->frame_y, dragWidth, dragHeight, False);

	ResizeWindow = None;
	PAGER_Clear(scr);
	return;
    }

    COLOR_PushRootColorMap(scr);
    if (menuFromFrameOrWindowOrTitlebar)
    {
	/* warp the pointer to the cursor position from before menu appeared */
	XWarpPointer(dpy, None, scr->root_win, 0, 0, 0, 0, Stashed_X, Stashed_Y);
	XFlush(dpy);
    }

    if (!MISC_Grab(scr, MOVE_CURS))
    {
	XBell(dpy, scr->screen);
	return;
    }

    if ((!(scr->flags & OpaqueResize)) ||
	((scr->flags & OpaqueResize) && (!(tmp_win->flags & MAPPED))))
	XGrabServer(dpy);


    pagerOn = False;
    XGetGeometry(dpy, (Drawable)ResizeWindow, &JunkRoot,
		 &dragx, &dragy, (unsigned int *)&dragWidth,
		 (unsigned int *)&dragHeight, &JunkBW, &JunkDepth);

    dragx += tmp_win->bw;
    dragy += tmp_win->bw;
    origx = dragx;
    origy = dragy;
    origWidth = dragWidth;
    origHeight = dragHeight;
    ymotion = xmotion = 0;

    /* pop up a resize dimensions window */
    if (Mwm.show_feedback & MWM_FEEDBACK_RESIZE)
	XMapRaised(dpy, scr->size_win);

    last_width = 0;
    last_height = 0;

    if (Mwm.show_feedback & MWM_FEEDBACK_RESIZE)
	display_size(scr, tmp_win, origWidth, origHeight, True);

    /* Get the current position to determine which border to resize */
    if ((scr->pressed_win != scr->root_win) && (scr->pressed_win != None))
    {
	if (scr->pressed_win == tmp_win->sides[0])	/* top */
	    ymotion = 1;
	if (scr->pressed_win == tmp_win->sides[1])	/* right */
	    xmotion = -1;
	if (scr->pressed_win == tmp_win->sides[2])	/* bottom */
	    ymotion = -1;
	if (scr->pressed_win == tmp_win->sides[3])	/* left */
	    xmotion = 1;
	if (scr->pressed_win == tmp_win->corners[0])
	{			/* upper-left */
	    ymotion = 1;
	    xmotion = 1;
	}
	if (scr->pressed_win == tmp_win->corners[1])
	{			/* upper-right */
	    xmotion = -1;
	    ymotion = 1;
	}
	if (scr->pressed_win == tmp_win->corners[2])
	{			/* lower right */
	    ymotion = -1;
	    xmotion = 1;
	}
	if (scr->pressed_win == tmp_win->corners[3])
	{			/* lower left */
	    ymotion = -1;
	    xmotion = -1;
	}
    }
    /* draw the rubber-band window */
    if ((!(scr->flags & OpaqueResize)) ||
	((scr->flags & OpaqueResize) && (!(tmp_win->flags & MAPPED))))
	WIN_DrawOutline(scr, scr->root_win, dragx - tmp_win->bw, dragy - tmp_win->bw, dragWidth + 2 * tmp_win->bw,
			dragHeight + 2 * tmp_win->bw);

    /* loop to resize */
    while (!finished)
    {
	XMaskEvent(dpy, ButtonPressMask | ButtonReleaseMask | KeyPressMask |
		 ButtonMotionMask | PointerMotionMask | ExposureMask, &oevent);
	MISC_StashEventTime(&oevent);

	if (oevent.type == MotionNotify)
	    /* discard any extra motion events before a release */
	    while (XCheckMaskEvent(dpy, ButtonMotionMask | ButtonReleaseMask |
				   PointerMotionMask, &oevent))
	    {
		MISC_StashEventTime(&oevent);
		if (oevent.type == ButtonRelease)
		    break;
	    }

	done = False;
	/* Handle a limited number of key press events to allow mouseless
	 * operation */
	if (oevent.type == KeyPress)
	    MISC_KeyboardShortcut(scr, &oevent, ButtonRelease);
	switch (oevent.type)
	{
	case ButtonPress:
	    XAllowEvents(dpy, ReplayPointer, CurrentTime);
	case KeyPress:
	    done = True;
	    break;

	case ButtonRelease:
	    finished = True;
	    done = True;
	    break;

	case MotionNotify:
	    x = oevent.xmotion.x_root;
	    y = oevent.xmotion.y_root;
	    /* need to move the viewport */
	    PAN_PanDesktop(scr, scr->edge_scroll_x, scr->edge_scroll_y, &x, &y,
			   &delta_x, &delta_y, False, &oevent);
	    origx -= delta_x;
	    origy -= delta_y;
	    dragx -= delta_x;
	    dragy -= delta_y;

	    resize_window(scr, x, y, tmp_win);
	    done = True;
	default:
	    break;
	}
	if (!done)
	{
	    if ((!(scr->flags & OpaqueResize)) ||
		((scr->flags & OpaqueResize) && (!(tmp_win->flags & MAPPED))))
		WIN_DrawOutline(scr, scr->root_win, 0, 0, 0, 0);

	    EVENT_Dispatch(&oevent);

	    if ((!(scr->flags & OpaqueResize)) ||
		((scr->flags & OpaqueResize) && (!(tmp_win->flags & MAPPED))))
		WIN_DrawOutline(scr, scr->root_win, dragx - tmp_win->bw, dragy - tmp_win->bw,
		    dragWidth + 2 * tmp_win->bw, dragHeight + 2 * tmp_win->bw);

	}
    }

    /* erase the rubber-band */
    if ((!(scr->flags & OpaqueResize)) ||
	((scr->flags & OpaqueResize) && (!(tmp_win->flags & MAPPED))))
	WIN_DrawOutline(scr, scr->root_win, 0, 0, 0, 0);

    /* pop down the size window */
    if (Mwm.show_feedback & MWM_FEEDBACK_RESIZE)
	XUnmapWindow(dpy, scr->size_win);

    pagerOn = True;
    WIN_ConstrainWindow(scr, tmp_win, &dragWidth, &dragHeight);
    DEC_ConfigureDecorations(scr, tmp_win, dragx - tmp_win->bw,
			     dragy - tmp_win->bw, dragWidth, dragHeight, False);

    COLOR_PopRootColorMap(scr);
    ResizeWindow = None;
    XUngrabServer(dpy);
    MISC_Ungrab(scr);
    PAGER_Clear(scr);
}
示例#14
0
文件: resize.c 项目: att/uwin
/*
 * move the rubberband around.  This is called for each motion event when we
 * are resizing
 */
static void
resize_window(ScreenInfo *scr, int x_root, int y_root, MwmWindow *tmp_win)
{
    int action = 0;
    unsigned int width, height;
    int ww, wh;
    int wx, wy;
    int MaxH, MaxW;
    static int last_w = -10000, last_h = -10000;

    if ((y_root <= origy) || ((ymotion == 1) && (y_root < origy + origHeight - 1)))
    {
	dragy = y_root;
	dragHeight = origy + origHeight - y_root;
	action = 1;
	ymotion = 1;
    }
    else if ((y_root >= origy + origHeight - 1) ||
	     ((ymotion == -1) && (y_root > origy)))
    {
	dragy = origy;
	dragHeight = 1 + y_root - dragy;
	action = 1;
	ymotion = -1;
    }

    if ((x_root <= origx) ||
	((xmotion == 1) && (x_root < origx + origWidth - 1)))
    {
	dragx = x_root;
	dragWidth = origx + origWidth - x_root;
	action = 1;
	xmotion = 1;
    }
    if ((x_root >= origx + origWidth - 1) ||
	((xmotion == -1) && (x_root > origx)))
    {
	dragx = origx;
	dragWidth = 1 + x_root - origx;
	action = 1;
	xmotion = -1;
    }

    if (action)
    {
	WIN_ConstrainWindow(scr, tmp_win, &dragWidth, &dragHeight);
	if (xmotion == 1)
	    dragx = origx + origWidth - dragWidth;
	if (ymotion == 1)
	    dragy = origy + origHeight - dragHeight;

	/* update size of the pager_view window */
	if ((scr->mwm_pager != NULL) &&
	    (dragx < scr->mwm_pager->frame_x + scr->mwm_pager->frame_width) &&
	    (dragx + dragWidth > scr->mwm_pager->frame_x) &&
	    (dragy < scr->mwm_pager->frame_y + scr->mwm_pager->frame_height) &&
	    (dragy + dragHeight > scr->mwm_pager->frame_y) &&
	    ((!(scr->flags & OpaqueResize)) ||
	     ((scr->flags & OpaqueResize) && (!(tmp_win->flags & MAPPED)))))
	    WIN_DrawOutline(scr, scr->root_win, 0, 0, 0, 0);
	if (scr->mwm_pager)
	{
	    width = scr->mwm_pager->frame_width -
		2 * scr->mwm_pager->boundary_width -
		2 * scr->mwm_pager->matte_width;
	    height = scr->mwm_pager->frame_height -
		scr->mwm_pager->title_height -
		2 * scr->mwm_pager->boundary_width -
		2 * scr->mwm_pager->matte_width;

	    MaxW = scr->virt_x_max + scr->d_width;
	    MaxH = scr->virt_y_max + scr->d_height;

	    if (!(tmp_win->flags & STICKY))
	    {
		/* show the actual window */
		wx = (dragx + scr->virt_x) * (int)width / MaxW;
		wy = (dragy + scr->virt_y) * (int)height / MaxH;
		ww = dragWidth * (int)width / MaxW;
		wh = dragHeight * (int)height / MaxH;

		if ((last_w - ww >= 2) || (last_w - ww <= -2) ||
		    (last_h - wh >= 2) || (last_h - wh <= -2))
		{
		    if (ww < 2)
			ww = 2;
		    if (wh < 2)
			wh = 2;
		    XMoveResizeWindow(dpy, tmp_win->pager_view, wx, wy, ww, wh);
		    last_h = wh;
		    last_w = ww;
		}
	    }
	}

	if ((!(scr->flags & OpaqueResize)) ||
	    ((scr->flags & OpaqueResize) && (!(tmp_win->flags & MAPPED))))
	{
	    WIN_DrawOutline(scr, scr->root_win, dragx - tmp_win->bw, dragy - tmp_win->bw,
		    dragWidth + 2 * tmp_win->bw, dragHeight + 2 * tmp_win->bw);
	}
	else
	{
	    DEC_ConfigureDecorations(scr, tmp_win, dragx - tmp_win->bw,
			    dragy - tmp_win->bw, dragWidth, dragHeight, False);
	}
    }
    if (Mwm.show_feedback & MWM_FEEDBACK_RESIZE)
	display_size(scr, tmp_win, dragWidth, dragHeight, False);
}
示例#15
0
文件: stats.c 项目: dgivone/ccache
/* sum and display the total stats for all cache dirs */
void
stats_summary(struct conf *conf)
{
	int dir, i;
	struct counters *counters = counters_init(STATS_END);

	assert(conf);

	/* add up the stats in each directory */
	for (dir = -1; dir <= 0xF; dir++) {
		char *fname;

		if (dir == -1) {
			fname = format("%s/stats", conf->cache_dir);
		} else {
			fname = format("%s/%1x/stats", conf->cache_dir, dir);
		}

		stats_read(fname, counters);
		free(fname);
	}

	printf("cache directory                     %s\n", conf->cache_dir);
	printf("primary config                      %s\n",
	       primary_config_path ? primary_config_path : "");
	printf("secondary config      (readonly)    %s\n",
	       secondary_config_path ? secondary_config_path : "");

  extern char *primary_config_path;
  extern char *secondary_config_path;
	printf("primary config path                 %s\n", primary_config_path ? primary_config_path : "");
	printf("secondary config path (readonly)    %s\n", secondary_config_path ? secondary_config_path : "");

	/* and display them */
	for (i = 0; stats_info[i].message; i++) {
		enum stats stat = stats_info[i].stat;

		if (stats_info[i].flags & FLAG_NEVER) {
			continue;
		}
		if (counters->data[stat] == 0 && !(stats_info[i].flags & FLAG_ALWAYS)) {
			continue;
		}

		printf("%s ", stats_info[i].message);
		if (stats_info[i].fn) {
			stats_info[i].fn(counters->data[stat]);
			printf("\n");
		} else {
			printf("%8u\n", counters->data[stat]);
		}
	}

	if (conf->max_files != 0) {
		printf("max files                       %8u\n", conf->max_files);
	}
	if (conf->max_size != 0) {
		printf("max cache size                  ");
		display_size(conf->max_size);
		printf("\n");
	}

	counters_free(counters);
}
示例#16
0
/*
 * Update extents parameters based on other parameters which affect the size
 * calculation.
 * NOTE: We must do this here because of the dm_percent_t typedef and because we
 * need the vg.
 */
static int _update_extents_params(struct volume_group *vg,
				  struct lvcreate_params *lp,
				  struct lvcreate_cmdline_params *lcp)
{
	uint32_t pv_extent_count;
	struct logical_volume *origin = NULL;
	uint32_t size_rest;
	uint32_t stripesize_extents;
	uint32_t extents;

	if (lcp->size &&
	    !(lp->extents = extents_from_size(vg->cmd, lcp->size,
					       vg->extent_size)))
		return_0;

	if (lp->voriginsize &&
	    !(lp->voriginextents = extents_from_size(vg->cmd, lp->voriginsize,
						      vg->extent_size)))
		return_0;

	/*
	 * Create the pv list before we parse lcp->percent - might be
	 * PERCENT_PVSs
	 */
	if (lcp->pv_count) {
		if (!(lp->pvh = create_pv_list(vg->cmd->mem, vg,
					       lcp->pv_count, lcp->pvs, 1)))
			return_0;
	} else
		lp->pvh = &vg->pvs;

	switch (lcp->percent) {
		case PERCENT_VG:
			extents = percent_of_extents(lp->extents, vg->extent_count, 0);
			break;
		case PERCENT_FREE:
			extents = percent_of_extents(lp->extents, vg->free_count, 0);
			break;
		case PERCENT_PVS:
			if (lcp->pv_count) {
				pv_extent_count = pv_list_extents_free(lp->pvh);
				extents = percent_of_extents(lp->extents, pv_extent_count, 0);
			} else
				extents = percent_of_extents(lp->extents, vg->extent_count, 0);
			break;
		case PERCENT_LV:
			log_error("Please express size as %s%%VG, %%PVS, "
				  "or %%FREE.", (lp->snapshot) ? "%ORIGIN, " : "");
			return 0;
		case PERCENT_ORIGIN:
			if (lp->snapshot && lp->origin &&
			    !(origin = find_lv(vg, lp->origin))) {
				log_error("Couldn't find origin volume '%s'.",
					  lp->origin);
				return 0;
			}
			if (!origin) {
				log_error(INTERNAL_ERROR "Couldn't find origin volume.");
				return 0;
			}
			/* Add whole metadata size estimation */
			extents = cow_max_extents(origin, lp->chunk_size) - origin->le_count +
				percent_of_extents(lp->extents, origin->le_count, 1);
			break;
		case PERCENT_NONE:
			extents = lp->extents;
			break;
		default:
			log_error(INTERNAL_ERROR "Unsupported percent type %u.", lcp->percent);
			return 0;
	}

	if (lcp->percent) {
		/* FIXME Don't do the adjustment for parallel allocation with PERCENT_ORIGIN! */
		lp->approx_alloc = 1;
		log_verbose("Converted %" PRIu32 "%%%s into %" PRIu32 " extents.", lp->extents, get_percent_string(lcp->percent), extents);
		lp->extents = extents;
	}

	if (lp->snapshot && lp->origin && lp->extents) {
		if (!lp->chunk_size) {
			log_error(INTERNAL_ERROR "Missing snapshot chunk size.");
			return 0;
		}

		if (!origin && !(origin = find_lv(vg, lp->origin))) {
			log_error("Couldn't find origin volume '%s'.",
				  lp->origin);
			return 0;
		}

		extents = cow_max_extents(origin, lp->chunk_size);

		if (extents < lp->extents) {
			log_print_unless_silent("Reducing COW size %s down to maximum usable size %s.",
						display_size(vg->cmd, (uint64_t) vg->extent_size * lp->extents),
						display_size(vg->cmd, (uint64_t) vg->extent_size * extents));
			lp->extents = extents;
		}
	}

	if (!(stripesize_extents = lp->stripe_size / vg->extent_size))
		stripesize_extents = 1;

	if ((lcp->percent != PERCENT_NONE) && lp->stripes &&
	    (size_rest = lp->extents % (lp->stripes * stripesize_extents)) &&
	    (vg->free_count < lp->extents - size_rest + (lp->stripes * stripesize_extents))) {
		log_print_unless_silent("Rounding size (%d extents) down to stripe boundary "
					"size (%d extents)", lp->extents,
			  lp->extents - size_rest);
		lp->extents = lp->extents - size_rest;
	}

	if (lp->create_pool) {
		if (!_lvcreate_update_pool_params(vg, lp))
			return_0;

		if (!(lp->poolmetadataextents =
		      extents_from_size(vg->cmd, lp->poolmetadatasize, vg->extent_size)))
			return_0;
		if (lcp->percent == PERCENT_FREE) {
			if (lp->extents <= (2 * lp->poolmetadataextents)) {
				log_error("Not enough space for thin pool creation.");
				return 0;
			}
			/* FIXME: persistent hidden space in VG wanted */
			lp->extents -= (2 * lp->poolmetadataextents);
		}
	}

	return 1;
}
示例#17
0
文件: stats.c 项目: UIKit0/ccache
// Sum and display the total stats for all cache dirs.
void
stats_summary(struct conf *conf)
{
	struct counters *counters = counters_init(STATS_END);

	assert(conf);

	// Add up the stats in each directory.
	for (int dir = -1; dir <= 0xF; dir++) {
		char *fname;

		if (dir == -1) {
			fname = format("%s/stats", conf->cache_dir);
		} else {
			fname = format("%s/%1x/stats", conf->cache_dir, dir);
		}

		stats_read(fname, counters);
		free(fname);
	}

	printf("cache directory                     %s\n", conf->cache_dir);
	printf("primary config                      %s\n",
	       primary_config_path ? primary_config_path : "");
	printf("secondary config      (readonly)    %s\n",
	       secondary_config_path ? secondary_config_path : "");

	// ...and display them.
	for (int i = 0; stats_info[i].message; i++) {
		enum stats stat = stats_info[i].stat;

		if (stats_info[i].flags & FLAG_NEVER) {
			continue;
		}
		if (counters->data[stat] == 0 && !(stats_info[i].flags & FLAG_ALWAYS)) {
			continue;
		}

		printf("%s ", stats_info[i].message);
		if (stats_info[i].fn) {
			stats_info[i].fn(counters->data[stat]);
			printf("\n");
		} else {
			printf("%8u\n", counters->data[stat]);
		}

		if (stat == STATS_TOCACHE) {
			unsigned direct = counters->data[STATS_CACHEHIT_DIR];
			unsigned preprocessed = counters->data[STATS_CACHEHIT_CPP];
			unsigned hit = direct + preprocessed;
			unsigned miss = counters->data[STATS_TOCACHE];
			unsigned total = hit + miss;
			double percent = total > 0 ? (100.0f * hit) / total : 0.0f;
			printf("cache hit rate                    %6.2f %%\n", percent);
		}
	}

	if (conf->max_files != 0) {
		printf("max files                       %8u\n", conf->max_files);
	}
	if (conf->max_size != 0) {
		printf("max cache size                  ");
		display_size(conf->max_size);
		printf("\n");
	}

	counters_free(counters);
}
示例#18
0
static void _count(struct device *dev, int *disks, int *parts)
{
	int c = dev_name(dev)[strlen(dev_name(dev)) - 1];

	if (!isdigit(c))
		(*disks)++;
	else
		(*parts)++;
}

static void _print(struct cmd_context *cmd, const struct device *dev,
		   uint64_t size, const char *what)
{
	log_print("%-*s [%15s] %s", max_len, dev_name(dev),
		  display_size(cmd, size), what ? : "");
}

static int _check_device(struct cmd_context *cmd, struct device *dev)
{
	char buffer;
	uint64_t size;

	if (!dev_open(dev)) {
		return 0;
	}
	if (!dev_read(dev, UINT64_C(0), (size_t) 1, &buffer)) {
		dev_close(dev);
		return 0;
	}
	if (!dev_get_size(dev, &size)) {