Пример #1
0
static int fmt_fld(fmtfn_t fn,void* arg,
		   char* wbuf, int w, int sign,
		   int width,int precision,int fmt,int* count)
{
    char prefix[8];
    char* pp = prefix;
    int pw   = 0;
    int len;

    /* format the prefix */
    if ((sign || (fmt & (FMTF_sgn|FMTF_blk)))
	&& (fmt & FMTC_MASK) == FMTC_d) {
	if (sign < 0)
	    *pp++ = '-';
	else if ((fmt & FMTF_sgn))
	    *pp++ = '+';
	else if (fmt & FMTF_blk)
	    *pp++ = ' ';
    }

    if ((fmt & FMTF_alt)) {
	switch((fmt & FMTC_MASK)) {
	case FMTC_X: *pp++ = '0'; *pp++ = 'X'; break;
	case FMTC_x: *pp++ = '0'; *pp++ = 'x'; break;
	case FMTC_o: *pp++ = '0'; if (precision>1) precision--; break;
	}
    }

    pw = pp-prefix;
    len = ((w < precision) ? precision : w) + pw;

    if (fmt & FMTF_adj) { /* left adjust */
	if (pw)
	    FMT(fn,arg,prefix,pw,*count);
	if (w < precision)
	    ZEROS(fn,arg,precision-w,*count);
	FMT(fn,arg, wbuf, w, *count);
	if (len < width)
	    BLANKS(fn,arg,width-len,*count);
    }
    else if ((fmt & FMTF_pad) && (precision<0)) { /* pad zeros */
	if (pw)
	    FMT(fn,arg, prefix, pw, *count);
	if (w < precision)
	    ZEROS(fn, arg, precision-w, *count);
	if (len < width)
	    ZEROS(fn,arg,width-len,*count);
	FMT(fn,arg,wbuf,w,*count);
    }
    else {
	if (len < width)
	    BLANKS(fn,arg,width-len,*count);
	if (pw)
	    FMT(fn,arg,prefix,pw,*count);
	if (w < precision)
	    ZEROS(fn,arg,precision-w,*count);
	FMT(fn,arg,wbuf,w,*count);
    }
    return 0;
}
Пример #2
0
/**
 * count_free:
 * Counts the number of zero bits pointed to by a bitmap.
 * The structures that contain the bitmap are pointed to by map
 * but are (likely) not contiguous, so we have to chunk through
 * by blocks.
 */
static unsigned long count_free(struct buffer_head **map,
				unsigned numblocks)
{
  unsigned sum = 0, remaining;
  struct buffer_head *bh;
  __u8 *p;

  /* 
   * This code assumes that the bitmap takes up an even number of blocks.
   */
  while (numblocks--) {
    /* sanity check: all map entries should be defined */
    if (!(bh=*map++)) return 0;
    p = bh->b_data;
    remaining = bh->b_size;
    /* for each buffer_head, scan through the bytes (chars) and count zeros */
    while (remaining--) sum += ZEROS(*p++);
  }
  return(sum);
}