コード例 #1
0
ファイル: optimize.c プロジェクト: enukane/netbsd-src
/*
 * Return the number of nodes reachable by 'p'.
 * All nodes should be initially unmarked.
 */
static int
count_blocks(struct block *p)
{
	if (p == 0 || isMarked(p))
		return 0;
	Mark(p);
	return count_blocks(JT(p)) + count_blocks(JF(p)) + 1;
}
コード例 #2
0
ファイル: mm_to_bcsr.c プロジェクト: alucas/StarPU
static bcsr_t * blocks_to_bcsr(tmp_block_t *block_list, unsigned c, unsigned r)
{
	unsigned nblocks;

	//print_all_blocks(block_list, r, c);

	nblocks = count_blocks(block_list);

	bcsr_t *bcsr = malloc(sizeof(bcsr_t));

	bcsr->nnz_blocks = nblocks;
	bcsr->r = r;
	bcsr->c = c;
	
	unsigned nrows_blocks = count_row_blocks(block_list);
	bcsr->nrows_blocks = nrows_blocks;

	bcsr->val = malloc(nblocks*r*c*sizeof(float));
	bcsr->colind = malloc(nblocks*sizeof(unsigned));
	bcsr->rowptr = calloc((nrows_blocks + 1), sizeof(unsigned));

	fill_bcsr(block_list, c, r, bcsr);

	return bcsr;
}
コード例 #3
0
ファイル: buddy.c プロジェクト: Jiant/buddy
static int total_free() {

  int i, bytecount = 0;

  for (i = 0; i <= MAX_ORDER; i++) {
    bytecount += count_blocks(i) * BLOCKSIZE(i);
  }
  return bytecount;
}
コード例 #4
0
ファイル: mkfs_minix.c プロジェクト: NikhilNJ/screenplay-dx
static int get_size(const char *file)
{
	int fd;
	long size;

	fd = xopen(file, O_RDWR);
	if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
		close(fd);
		return (size * 512);
	}

	size = count_blocks(fd);
	close(fd);
	return size;
}
コード例 #5
0
ファイル: optimize.c プロジェクト: enukane/netbsd-src
/*
 * Allocate memory.  All allocation is done before optimization
 * is begun.  A linear bound on the size of all data structures is computed
 * from the total number of blocks and/or statements.
 */
static void
opt_init(struct block *root)
{
	bpf_u_int32 *p;
	int i, n, max_stmts;

	/*
	 * First, count the blocks, so we can malloc an array to map
	 * block number to block.  Then, put the blocks into the array.
	 */
	unMarkAll();
	n = count_blocks(root);
	blocks = (struct block **)calloc(n, sizeof(*blocks));
	if (blocks == NULL)
		bpf_error("malloc");
	unMarkAll();
	n_blocks = 0;
	number_blks_r(root);

	n_edges = 2 * n_blocks;
	edges = (struct edge **)calloc(n_edges, sizeof(*edges));
	if (edges == NULL)
		bpf_error("malloc");

	/*
	 * The number of levels is bounded by the number of nodes.
	 */
	levels = (struct block **)calloc(n_blocks, sizeof(*levels));
	if (levels == NULL)
		bpf_error("malloc");

	edgewords = n_edges / (8 * sizeof(bpf_u_int32)) + 1;
	nodewords = n_blocks / (8 * sizeof(bpf_u_int32)) + 1;

	/* XXX */
	space = (bpf_u_int32 *)malloc(2 * n_blocks * nodewords * sizeof(*space)
				 + n_edges * edgewords * sizeof(*space));
	if (space == NULL)
		bpf_error("malloc");
	p = space;
	all_dom_sets = p;
	for (i = 0; i < n; ++i) {
		blocks[i]->dom = p;
		p += nodewords;
	}
	all_closure_sets = p;
	for (i = 0; i < n; ++i) {
		blocks[i]->closure = p;
		p += nodewords;
	}
	all_edge_sets = p;
	for (i = 0; i < n; ++i) {
		register struct block *b = blocks[i];

		b->et.edom = p;
		p += edgewords;
		b->ef.edom = p;
		p += edgewords;
		b->et.id = i;
		edges[i] = &b->et;
		b->ef.id = n_blocks + i;
		edges[n_blocks + i] = &b->ef;
		b->et.pred = b;
		b->ef.pred = b;
	}
	max_stmts = 0;
	for (i = 0; i < n; ++i)
		max_stmts += slength(blocks[i]->stmts) + 1;
	/*
	 * We allocate at most 3 value numbers per statement,
	 * so this is an upper bound on the number of valnodes
	 * we'll need.
	 */
	maxval = 3 * max_stmts;
	vmap = (struct vmapinfo *)calloc(maxval, sizeof(*vmap));
	vnode_base = (struct valnode *)calloc(maxval, sizeof(*vnode_base));
	if (vmap == NULL || vnode_base == NULL)
		bpf_error("malloc");
}
コード例 #6
0
ファイル: bfsgen.c プロジェクト: sjrct/drosk
int main(int argc, char ** argv)
{
	FILE * f;
	int i, j = 0, wrotesb = 0;
	char * name;
	char * output = "bfs.iso";
	char * files[BFS_NODE_COUNT];
	bfs_block_t offset = 0, start_block = 0;
	bfs_node_t nodes[BFS_NODE_COUNT];

	/* assert the validity of the bfs system */
	assert(BFS_NODE_COUNT * sizeof(bfs_node_t) == BFS_BLOCK_SIZE);

	/* zero the bfs nodes to start with */
	memset(nodes, 0, sizeof(bfs_node_t) * BFS_NODE_COUNT);

	/* parse the arguments and generate the system */
	for (i = 1; i < argc; i++) {
		if (argv[i][0] == '-') {
			/* parse options */
			switch (argv[i][1]) {
			case 'b':
				start_block = atol(argv[i] + 1);
				break;
			case 'h':
				help();
				return 0;
			case 'o':
				output = argv[i] + 1;
				break;
			}
		} else {
			/* A file has been specified! */
			if ((unsigned)j < BFS_NODE_COUNT) {
				name = strchr(argv[i], '=');

				if (name == NULL) {
					fprintf(stderr, "error: Malformed file specifier '%s'. (no '=' found)\n", argv[i]);
					return EXIT_FAILURE;
				}

				if (name - argv[i] > BFS_NAME_LENGTH) {
					fprintf(stderr, "error: BFS file name cannot exceed %d characters.\n", BFS_NAME_LENGTH);
					return EXIT_FAILURE;
				}

				files[j] = name + 1;
				memcpy(nodes[j].name, argv[i], name - argv[i]);
				nodes[j].block_offset = offset;
				nodes[j].block_count  = count_blocks(files[j]);
				offset += nodes[j].block_count;
				j++;
			} else {
				fprintf(stderr, "error: Too many files to write! (max is %lu)\n", BFS_NODE_COUNT);
				return EXIT_FAILURE;
			}
		}
	}

	/* modify offsets */
	for (i = 0; i < j; i++) {
		nodes[i].block_offset += start_block;
	}

	/* write the bfs system */
	f = fopen(output, "wb");
	if (f == NULL) {
		fprintf(stderr, "error: Could not open '%s' for writing.\n", output);
		return EXIT_FAILURE;
	}

	for (i = 0; i < j; i++) {
		fseek(f, nodes[i].block_offset * BFS_BLOCK_SIZE, SEEK_SET);

		if (strcmp(files[i], SUPERBLOCK_NAME)) {
			write_file(files[i], f);
		} else {
			fwrite(nodes, BFS_BLOCK_SIZE, 1, f);
			wrotesb = 1;
		}
	}

	fclose(f);

	/* check that we wrote the superblock */
	if (!wrotesb) {
		fprintf(stderr, "warning: Superblock never written!\n");
	}

	return 0;
}
コード例 #7
0
int main(int argc, char *argv[]) {
    char * bytes_count_str = NULL;
    char * devname;
    reiserfs_filsys_t fs;
    struct reiserfs_super_block * rs;

    int c;
    int error;

    struct reiserfs_super_block *sb_old;

    unsigned long block_count_new;

    print_banner ("resize_reiserfs");

    while ((c = getopt(argc, argv, "fvcqs:")) != EOF) {
        switch (c) {
        case 's' :
            if (!optarg)
                die("%s: Missing argument to -s option", argv[0]);
            bytes_count_str = optarg;
            break;
        case 'f':
            opt_force = 1;
            break;
        case 'v':
            opt_verbose++;
            break;
        case 'n':
            /* no nowrite option at this moment */
            /* opt_nowrite = 1; */
            break;
        case 'c':
            opt_safe = 1;
            break;
        case 'q':
            opt_verbose = 0;
            break;
        default:
            print_usage_and_exit ();
        }
    }

    if (optind == argc )
        print_usage_and_exit();
    devname = argv[optind];

    fs = reiserfs_open(devname, O_RDONLY, &error, 0);
    if (!fs)
        die ("%s: can not open '%s': %s", argv[0], devname, strerror(error));

    if (no_reiserfs_found (fs)) {
        die ("resize_reiserfs: no reiserfs found on the device");
    }
    if (!spread_bitmaps (fs)) {
        die ("resize_reiserfs: cannot resize reiserfs in old (not spread bitmap) format.\n");
    }

    rs = fs->s_rs;

    if(bytes_count_str) {	/* new fs size is specified by user */
        block_count_new = calc_new_fs_size(rs_block_count(rs), fs->s_blocksize, bytes_count_str);
    } else {		/* use whole device */
        block_count_new = count_blocks(devname, fs->s_blocksize, -1);
    }

    if (is_mounted (devname)) {
        reiserfs_close(fs);
        return resize_fs_online(devname, block_count_new);
    }

    if (rs_state(rs) != REISERFS_VALID_FS)
        die ("%s: the file system isn't in valid state\n", argv[0]);

    if(!valid_offset(fs->s_dev, (loff_t) block_count_new * fs->s_blocksize - 1))
        die ("%s: %s too small", argv[0], devname);

    sb_old = 0;		/* Needed to keep idiot compiler from issuing false warning */
    /* save SB for reporting */
    if(opt_verbose) {
        sb_old = getmem(SB_SIZE);
        memcpy(sb_old, SB_DISK_SUPER_BLOCK(fs), SB_SIZE);
    }

    if (block_count_new == SB_BLOCK_COUNT(fs))
        die ("%s: Calculated fs size is the same as the previous one.", argv[0]);

    if (block_count_new > SB_BLOCK_COUNT(fs))
        expand_fs(fs, block_count_new);
    else
        shrink_fs(fs, block_count_new);

    if(opt_verbose) {
        sb_report(rs, sb_old);
        freemem(sb_old);
    }

    set_state (rs, REISERFS_VALID_FS);
    bwrite_cond(SB_BUFFER_WITH_SB(fs));

    if (opt_verbose) {
        printf("\nSyncing..");
        fflush(stdout);
    }
    reiserfs_close (fs);
    if (opt_verbose)
        printf("done\n");

    return 0;
}
コード例 #8
0
ファイル: load.c プロジェクト: Pankajumn/disambig
int input_load(DB *db, sqlite3* sql_db, char* sql_table){
    int ret;
    struct sqlite_workspace w;
    DB *sdb;
    DBC *cursor;
    DBT pkey;
    memset(&pkey, 0, sizeof(pkey));
    sqlite3_stmt *ppStmt;
    DbRecord recordp;
    DB_BTREE_STAT *stat;
    db_recno_t count=0;
    w.count = &count;
    db_recno_t max = 0;
    char big_block[128];

    if ((ret = db->cursor(db, NULL, &cursor, 0)) != 0) {
		dbenv->err(dbenv, ret, "DB->cursor");
		return (1);
	}
	memset(&(w.key), 0, sizeof(w.key));
	memset(&(w.data), 0, sizeof(w.data));
    
    if(DB_NOTFOUND ==
      (ret = cursor->get(cursor, &(w.key), &(w.data), DB_LAST)))
        w.primary_key = 0;
    else{
        w.primary_key = *(u_int32_t*)(w.data.data);
        w.primary_key++;
    }

    ret = cursor->close(cursor);

    sqlite3_prepare_v2(sql_db, sql_query, -1, &ppStmt, NULL);
    while(SQLITE_ROW == (ret=sqlite3_step(ppStmt))){
        memcpy(&recordp, &DbRecord_base, sizeof(DbRecord));
        build_record(ppStmt, &recordp, &w);
        DbRecord_write(&recordp, db, &w);
        if((count++ % 100000)==0){
            printf("%lu records processed...\n", (ulong)count);
            db->sync(db, 0);
        }
    }
    count = 0;
    sqlite3_finalize(ppStmt);
    

    db->cursor(db, NULL, &cursor, 0);
    cursor->get(cursor, &(w.key), &(w.data), DB_LAST);
    DbRecord_dump(w.data.data);

    db->stat(db, NULL, &stat, 0);
    printf("primary nkeys: %lu\n", (u_long)(stat->bt_nkeys));
    free(stat);

    sqlite_db_secondary_open(db, &sdb, "block_idx", 8*1024, DB_DUPSORT, blocking_callback, compare_uint32);
    sdb->stat(sdb, NULL, &stat, 0);
    printf("block_idx keys: %lu\n", (u_long)(stat->bt_nkeys));
    free(stat);
    sdb->cursor(sdb, NULL, &cursor, 0);
    
    while(DB_NOTFOUND != cursor->pget(cursor, &(w.key), &pkey, &(w.data), DB_NEXT)){
        cursor->count(cursor, &count, 0);
        if (count > max){
            max = count;
            memcpy(big_block, w.key.data, (size_t)w.key.size);
            big_block[w.key.size] = '\0';
        }
    }
    cursor->close(cursor);
    printf("Biggest block: %s\n", big_block);
    printf("%u records.\n", (size_t)max);
    
    count_blocks(sdb);
    sdb->close(sdb, 0);
    

    sqlite_db_secondary_open(db, &sdb, "idx", 8*1024, 0, index_callback, NULL);
    ret = sdb->stat(sdb, NULL, &stat, 0);
    printf("%d\n", ret);
    printf("idx_keys: %lu\n", (u_long)(stat->bt_nkeys));
    free(stat);
    sdb->close(sdb, 0);
    
    return(0);
}
コード例 #9
0
ファイル: msgi_sbp.c プロジェクト: converse2006/MSG
//  =====   INTERNAL FUNCTIONS  =====
static inline unsigned int msgi_count_blocks(unsigned int size)
{
    return count_blocks(size, block_size);        
}