コード例 #1
0
ファイル: lessfsck.c プロジェクト: crass/lessfs
void printhash(char *msg, unsigned char *bhash)
{
    char *ascii_hash = NULL;
    int n;
    char *p1, *p2;

    for (n = 0; n < config->hashlen ; n++) {
        p1 = as_sprintf("%02X", bhash[n]);
        if (n == 0) {
            ascii_hash = s_strdup(p1);
        } else {
            p2 = s_strdup(ascii_hash);
            free(ascii_hash);
            ascii_hash = as_sprintf("%s%s", p2, p1);
            free(p2);
        }
        free(p1);
    }
    printf("%s : %s\n", msg, ascii_hash);
    free(ascii_hash);
}
コード例 #2
0
ファイル: lessfsck.c プロジェクト: crass/lessfs
int lost_mkdir(const char *path)
{
    unsigned long long inode=0;
    char *rdir;
    char *pdir;
    int res;

    FUNC;
    inode=get_next_inode();
    write_file_ent(path, inode, S_IFDIR | 0755, NULL, 0);
    rdir = as_sprintf("%s/.", path);
    inode=get_next_inode();
    write_file_ent(rdir, inode, S_IFDIR | 0755, NULL, 0);
    free(rdir);
    rdir = as_sprintf("%s/..", path);
    inode=get_next_inode();
    write_file_ent(rdir, inode, S_IFDIR | 0755, NULL, 0);
    free(rdir);
    /* Change ctime and mtime of the parentdir Posix std posix behavior */
    pdir = s_dirname((char *) path);
    res = update_parent_time(pdir,1);
    free(pdir);
    return (res);
}
コード例 #3
0
ファイル: btier_sysfs.c プロジェクト: borland667/btier
static ssize_t tier_attr_migration_policy_show(struct tier_device *dev,
					       char *buf)
{
	char *msg = NULL;
	char *msg2;
	int i;
	int res;

	for (i = 0; i < dev->attached_devices; i++) {
		if (!msg) {
			msg2 =
			    as_sprintf
			    ("%7s %20s %15s %15s\n%7u %20s %15u %15u\n", "tier",
			     "device", "max_age", "hit_collecttime", i,
			     dev->backdev[i]->fds->f_dentry->d_name.name,
			     dev->backdev[i]->devmagic->dtapolicy.max_age,
			     dev->backdev[i]->devmagic->dtapolicy.
			     hit_collecttime);
		} else {
			msg2 =
			    as_sprintf("%s%7u %20s %15u %15u\n", msg,
				       i,
				       dev->backdev[i]->fds->f_dentry->
				       d_name.name,
				       dev->backdev[i]->devmagic->dtapolicy.
				       max_age,
				       dev->backdev[i]->devmagic->dtapolicy.
				       hit_collecttime);
		}
		kfree(msg);
		msg = msg2;
	}
	res = sprintf(buf, "%s\n", msg);
	kfree(msg);
	return res;
}
コード例 #4
0
ファイル: btier_sysfs.c プロジェクト: borland667/btier
static ssize_t tier_attr_device_usage_show(struct tier_device *dev, char *buf)
{
	unsigned int i = 0;
	int res = 0;
	u64 allocated;
	unsigned int lcount = dev->attached_devices + 1;
	u64 devblocks;

	const char **lines = NULL;
	char *line;
	char *msg;
	lines = kzalloc(lcount * sizeof(char *), GFP_KERNEL);
	if (!lines)
		return -ENOMEM;

	line =
	    as_sprintf("%7s %20s %15s %15s %15s %15s %15s %15s\n", "TIER",
		       "DEVICE", "SIZE MB", "ALLOCATED MB", "AVERAGE READS",
		       "AVERAGE WRITES", "TOTAL_READS", "TOTAL_WRITES");
	if (!line) {
		kfree(lines);
		return -ENOMEM;
	}
	lines[0] = line;
	for (i = 0; i < dev->attached_devices; i++) {
		allocated = allocated_on_device(dev, i);
		if (dev->inerror)
			goto end_error;
		allocated >>= BLKBITS;
		devblocks =
		    (dev->backdev[i]->endofdata -
		     dev->backdev[i]->startofdata) >> BLKBITS;
		dev->backdev[i]->devmagic->average_reads =
		    dev->backdev[i]->devmagic->total_reads / devblocks;
		dev->backdev[i]->devmagic->average_writes =
		    dev->backdev[i]->devmagic->total_writes / devblocks;
		line =
		    as_sprintf
		    ("%7u %20s %15llu %15llu %15u %15u %15llu %15llu\n", i,
		     dev->backdev[i]->fds->f_dentry->d_name.name, devblocks,
		     allocated, dev->backdev[i]->devmagic->average_reads,
		     dev->backdev[i]->devmagic->average_writes,
		     dev->backdev[i]->devmagic->total_reads,
		     dev->backdev[i]->devmagic->total_writes);
		lines[i + 1] = line;
	}
	msg = as_strarrcat(lines, i + 1);
	if (!msg) {
		res = -ENOMEM;
		goto end_error;
	}
	while (i) {
		kfree((char *)lines[--i]);
	}
	res = snprintf(buf, 1023, "%s\n", msg);
	kfree(msg);
end_error:
	kfree(lines);
	kfree(line);
	return res;
}
コード例 #5
0
ファイル: btier_sysfs.c プロジェクト: borland667/btier
static ssize_t tier_attr_internals_show(struct tier_device *dev,
                                               char *buf)
{
        char *iotype;
        char *iopending;
        char *qlock;
        char *aiowq;
        char *discard;
#ifndef MAX_PERFORMANCE
        char *debug_state;
#endif
        int res = 0;
       
        if (atomic_read(&dev->migrate) == MIGRATION_IO) 
            iotype = as_sprintf("iotype (normal or migration) : migration_io\n");
        else if (atomic_read(&dev->wqlock))
            iotype = as_sprintf("iotype (normal or migration) : normal_io\n");
        else
            iotype = as_sprintf("iotype (normal or migration) : no activity\n");
        iopending =  as_sprintf("async random ios pending     : %i\n", atomic_read(&dev->aio_pending));
        if ( mutex_is_locked(&dev->qlock))
             qlock = as_sprintf("main mutex                   : locked\n");
        else qlock = as_sprintf("main mutex                   : unlocked\n");
        if (waitqueue_active(&dev->aio_event)) 
             aiowq = as_sprintf("waiting on asynchrounous io  : True\n");
        else 
             aiowq = as_sprintf("waiting on asynchrounous io  : False\n");
#ifndef MAX_PERFORMANCE
        spin_lock(&dev->dbg_lock);
        if (dev->debug_state & DISCARD)
           discard = as_sprintf("discard request is pending   : True\n");
        else 
           discard = as_sprintf("discard request is pending   : False\n");
        debug_state = as_sprintf("debug state                  : %i\n", dev->debug_state);
        spin_unlock(&dev->dbg_lock);
        res = sprintf(buf, "%s%s%s%s%s%s", iotype, iopending, qlock, aiowq, discard, debug_state);
#else
        res = sprintf(buf, "%s%s%s%s", iotype, iopending, qlock, aiowq);
#endif
        kfree(iotype);
        kfree(iopending);
        kfree(qlock);
        kfree(aiowq);
#ifndef MAX_PERFORMANCE
        kfree(discard);
        kfree(debug_state);
#endif
        return res;
}