int switch_storage(STORAGE_T old_storage, STORAGE_T new_storage)
{
	aplogd_logfile_max = aplogd_get_filesize(new_storage);
	aplogd_close_output();
	if (aplogd_output_setup(new_storage)<0){
		ALOGE("aplogd_output_setup in %s failed.",g_output_path[new_storage]);
		aplogd_output_setup(old_storage);
		return old_storage;
	}
	return new_storage;
}
int aplogd_rambuf_output(int index)
{
	int ret_val = 0;
	int need_written = 0;
	int size_written = 0;

	/* From here on out we can only manipulate the output list */

	VPRINT("output index:%d\n", index );
	need_written=aplogd_rambuf_bytes_filled(index);
	VPRINT("need_written=%d.\n",need_written);
	if(!aplogd_io_array[index].input_buf_base || !(need_written >0))
	{
		return -1;
	}
	if (aplogd_io_array[index].output_fd < 0)
	{
		WPRINT("output fd hasn't been initialized.\n");
		aplogd_io_array[index].input_buf = aplogd_io_array[index].input_buf_base;
		ret_val = -1;
		return ret_val;
	}

	while(need_written >0) {
		size_written = write(aplogd_io_array[index].output_fd, (void*)aplogd_io_array[index].input_buf_base, need_written);
		if (size_written < 0 )
		{
			EPRINT("output write: size_written=%d, errno=%d\n", size_written, errno);
			if (ENOSPC == errno)
				aplogd_close_output();
			if (EBADF == errno)
				aplogd_io_array[index].output_fd=-1;
			ret_val=-1;
			return ret_val;
		}
		need_written -= size_written;
		total_write_size+=size_written;
	}
	aplogd_io_array[index].input_buf = aplogd_io_array[index].input_buf_base;
        if (total_write_size >=aplogd_logfile_max)
        {
		ALOGI("aplogd_logfile_max=%d, total_write_size=%d\n",aplogd_logfile_max, total_write_size);
		aplogd_close_output();
		aplogd_io_backupall(g_current_storage);
		aplogd_output_setup(g_current_storage);
		total_write_size=0;
        }
	return ret_val;
}