kfusd/kfusd.c
static void fusd_status_build_binary(fusd_statcontext_t *fs)
{
	int buf_size = 512;
	char *buf = KMALLOC(buf_size, GFP_KERNEL);
	int len = 0, i = 0;
	struct list_head *tmp;
	fusd_status_t *s;

	if (buf == NULL) {
		RDEBUG(1, "out of memory!");
		return;
	}

	down(&fusd_devlist_sem);

	list_for_each(tmp, &fusd_devlist_head)
	{
		fusd_dev_t *d = list_entry(tmp, fusd_dev_t, devlist);

		if (!d)
			continue;

		/* Possibly expand the buffer if we need more space */
		if (maybe_expand_buffer(&buf, &buf_size, len, sizeof(fusd_status_t)) < 0)
			goto out;

		s = &((fusd_status_t *) buf)[i];

		/* construct this status entry */
		memset(s, 0, sizeof(fusd_status_t));
		strncpy(s->name, NAME(d), FUSD_MAX_NAME_LENGTH);
		s->zombie = d->zombie;
		s->pid = d->pid;
		s->num_open = d->num_files;

		i++;
		len += sizeof(fusd_status_t);
	}

out:
	fs->last_version_seen = last_version;
	up(&fusd_devlist_sem);

	if (fs->curr_status)
		KFREE(fs->curr_status);

	fs->curr_status = buf;
	fs->curr_status_len = len;
	fs->need_new_status = 0;
}
/* Build the binary version of status */
Build the binary version of status
Build the binary version of status
static void fusd_status_build_binary(fusd_statcontext_t *fs)
{
	int buf_size = 512;
	char *buf = KMALLOC(buf_size, GFP_KERNEL);
	int len = 0, i = 0;
	struct list_head *tmp;
	fusd_status_t *s;
	if (buf == NULL) {
		RDEBUG(1, "out of memory!");
		return;
	}
	down(&fusd_devlist_sem);
	list_for_each(tmp, &fusd_devlist_head)
	{
		fusd_dev_t *d = list_entry(tmp, fusd_dev_t, devlist);
		if (!d)
			continue;
		if (maybe_expand_buffer(&buf, &buf_size, len, sizeof(fusd_status_t)) < 0)
			goto out;
		s = &((fusd_status_t *) buf)[i];
		memset(s, 0, sizeof(fusd_status_t));
		strncpy(s->name, NAME(d), FUSD_MAX_NAME_LENGTH);
		s->zombie = d->zombie;
		s->pid = d->pid;
		s->num_open = d->num_files;
		i++;
		len += sizeof(fusd_status_t);
	}
out:
	fs->last_version_seen = last_version;
	up(&fusd_devlist_sem);
	if (fs->curr_status)
		KFREE(fs->curr_status);
	fs->curr_status = buf;
	fs->curr_status_len = len;
	fs->need_new_status = 0;
}
static void fusd_status_build_binary ( fusd_statcontext_t * fs ) { int buf_size = 512 ; char * buf = KMALLOC ( buf_size , GFP_KERNEL ) ; int len = 0 , i = 0 ; struct list_head * tmp ; fusd_status_t * s ; if ( buf == NULL ) { RDEBUG ( 1 , " " ) ; return ; } down ( & fusd_devlist_sem ) ; list_for_each ( tmp , & fusd_devlist_head ) { fusd_dev_t * d = list_entry ( tmp , fusd_dev_t , devlist ) ; if ( ! d ) continue ; if ( maybe_expand_buffer ( & buf , & buf_size , len , sizeof ( fusd_status_t ) ) < 0 ) goto out ; s = & ( ( fusd_status_t * ) buf ) [ i ] ; memset ( s , 0 , sizeof ( fusd_status_t ) ) ; strncpy ( s -> name , NAME ( d ) , FUSD_MAX_NAME_LENGTH ) ; s -> zombie = d -> zombie ; s -> pid = d -> pid ; s -> num_open = d -> num_files ; i ++ ; len += sizeof ( fusd_status_t ) ; } out : fs -> last_version_seen = last_version ; up ( & fusd_devlist_sem ) ; if ( fs -> curr_status ) KFREE ( fs -> curr_status ) ; fs -> curr_status = buf ; fs -> curr_status_len = len ; fs -> need_new_status = 0 ; }
Build the binary version of status
Build the binary version of status
/* Possibly expand the buffer if we need more space */ /* construct this status entry */