Ejemplo n.º 1
0
void write_buffer(void)
{
  if(write_func == NULL)
    return;
  
  if(overlapped == 0)
    write_func(buffer, pointer);
  else
    {
      write_func(current_buffer, BUFFER_SIZE - pointer);
      write_func(buffer, pointer);
    }
}
Ejemplo n.º 2
0
void rtk_write_bootinfo_to_flash(unsigned int bootinfo_addr,BOOTINFO_P bootinfo_ram_p, 
	                     void (*write_func)(unsigned int ,unsigned int ,unsigned char*) )
{
#if 0
	printk("rtk_read_bootinfo_from_flash \n");
	printk("header=%2x%2x%2x%2x len=%x\n",bootinfo_ram_p->header.tag[0],bootinfo_ram_p->header.tag[1]
		,bootinfo_ram_p->header.tag[2],bootinfo_ram_p->header.tag[3],bootinfo_ram_p->header.len);

	printk("bank=%d , cnt=%d,maxcnt=%d , val=%8x \n",bootinfo_ram_p->data.field.bootbank,bootinfo_ram_p->data.field.bootcnt,
		bootinfo_ram_p->data.field.bootmaxcnt,bootinfo_ram_p->data.val);
#endif	
	//flash(spi...etc) need flash write api
	write_func(bootinfo_addr,sizeof(BOOTINFO_T),(char *)bootinfo_ram_p);
}
Ejemplo n.º 3
0
/*---------------------------------------------------------------------------*/
void    pci_w8  (usys bus_num, usys dev_num, usys func_num, usys addr,
                 u8   val)
{
    usys data ;
    read_func (get_addr (bus_num, dev_num, func_num, addr), &data) ;

    /* Zero out the correct byte */
    data &= ~(0xff << (addr % 4) * 8) ;

    /* Write the needed value to correct byte */
    data |= val << (addr % 4) * 8 ;

    /* Write back the value */
    write_func (get_addr (bus_num, dev_num, func_num, addr), data) ;

} /* End of Function pci_w8  () */
Ejemplo n.º 4
0
void    pci_w16 (usys bus_num, usys dev_num, usys func_num, usys addr,
                 u16  val)
{
    usys data ;

    /* Read the Current Value */
    read_func (get_addr (bus_num, dev_num, func_num, addr), &data) ;

    /* Zero out the correct 16 bits */
    data &= ~(0xffff << (addr % 4) * 8) ;

    /* Write the needed value to correct byte */
    data |= val << (addr % 4) * 8 ;

    write_func (get_addr (bus_num, dev_num, func_num, addr), data) ;

} /* End of Function pci_w16 () */
Ejemplo n.º 5
0
int main(int argc, char ** argv)
{
	int loops = 100;

	if (argc > 1)
		loops = atoi(argv[1]);

	printf("Create root file\n");
	write_func();

	printf("Read root file in %d loops\n", loops);
	for (int i = 0; i < loops; ++i)
	{
		loop_read_func();

		bar(i);
	}
}
enum ff_result ff_write_stream_buffer_flush(struct ff_write_stream_buffer *buffer)
{
	ff_write_stream_func write_func;
	void *write_func_ctx;
	char *buffer_buf;
	int total_bytes_written = 0;
	int bytes_to_write;
	enum ff_result result = FF_FAILURE;

	ff_assert(buffer->capacity > 0);
	ff_assert(buffer->start_pos >= 0);
	ff_assert(buffer->start_pos <= buffer->capacity);

	write_func = buffer->write_func;
	write_func_ctx = buffer->write_func_ctx;
	buffer_buf = buffer->buf;

	bytes_to_write = buffer->start_pos;
	while (bytes_to_write > 0)
	{
		int bytes_written;

		bytes_written = write_func(write_func_ctx, buffer_buf + total_bytes_written, bytes_to_write);
		if (bytes_written == -1)
		{
			ff_log_debug(L"error while flushing %d bytes from the buffer=%p. See previous messages for more info", bytes_to_write, buffer);
			goto end;
		}
		ff_assert(bytes_written > 0);
		ff_assert(bytes_written <= bytes_to_write);

		bytes_to_write -= bytes_written;
		total_bytes_written += bytes_written;
	}
	buffer->start_pos = 0;
	result = FF_SUCCESS;

end:
	return result;
}
Ejemplo n.º 7
0
/*
 * does fragmented write
 */
static int do_write(int fd, buf_t *msg, unsigned int mtu,
		            ssize_t (*write_func)(int, const void *, size_t))
{
	int actual = -1;
	int size;

	/* Send and fragment if necessary  */
	while (msg->data_size) {
		if (msg->data_size > mtu)
			size = mtu;
		else
			size = msg->data_size;
		DEBUG(1, "sending %d bytes\n", size);

		actual = write_func(fd, msg->data, size);
		if (actual <= 0)
			return actual;

		/* Hide sent data */
		buf_remove_begin(msg, actual);
	}

	return actual;
}
Ejemplo n.º 8
0
void put_chars(char *chars, unsigned int size, gboolean crlf_auto)
{
  char *characters;

  int pos;
  GString *buffer_tmp;
  gchar *in_buffer;

  buffer_tmp =  g_string_new(chars);
	  
  /* If the auto CR LF mode on, read the buffer to add \r before \n */ 

  if(crlf_auto)
    {
      in_buffer=buffer_tmp->str;
      
      in_buffer += size;
      for(pos=size; pos>0; pos--)
	{
	  in_buffer--;
	  
	  if(*in_buffer=='\n' && *(in_buffer-1) != '\r') 
	    {
	      g_string_insert_c(buffer_tmp, pos-1, '\r');
	      size += 1;
	    }

	  if(*in_buffer=='\r' && *(in_buffer+1) != '\n') 
	    {
	      g_string_insert_c(buffer_tmp, pos, '\n');
	      size += 1;
	    }
	}
      chars = buffer_tmp->str;
    }

  if(buffer == NULL)
    {
      i18n_printf(_("ERROR : Buffer is not initialized !\n"));
      return;
    }
  
  if(size > BUFFER_SIZE)
    {
      characters = chars + (size - BUFFER_SIZE);
      size = BUFFER_SIZE;
    }
  else
    characters = chars;

  if((size + pointer) >= BUFFER_SIZE)
    {
      memcpy(current_buffer, characters, BUFFER_SIZE - pointer);
      chars = characters + BUFFER_SIZE - pointer;
      pointer = size - (BUFFER_SIZE - pointer);
      memcpy(buffer, chars, pointer);
      current_buffer = buffer + pointer;
      overlapped = 1;
    }
  else
    {
      memcpy(current_buffer, characters, size);
      pointer += size;
      current_buffer += size;
    }
  
  if(write_func != NULL)
    write_func(characters, size);

  g_string_free(buffer_tmp, 1);
}
Ejemplo n.º 9
0
/****** spool/utilities/spool_default_validate_func() ****************
*  NAME
*     spool_default_validate_func() -- validate objects
*
*  SYNOPSIS
*     bool
*     spool_default_validate_func(lList **answer_list, 
*                               const lListElem *type, 
*                               const lListElem *rule, 
*                               const lListElem *object, 
*                               const char *key, 
*                               const sge_object_type object_type) 
*
*  FUNCTION
*     Verifies an object.
*
*  INPUTS
*     lList **answer_list - to return error messages
*     const lListElem *type           - object type description
*     const lListElem *rule           - rule to use
*     const lListElem *object         - object to validate
*     const sge_object_type object_type - object type
*
*  RESULT
*     bool - true on success, else false
*
*  NOTES
*     This function should not be called directly, it is called by the
*     spooling framework.
*
*  SEE ALSO
*******************************************************************************/
bool spool_default_validate_func(lList **answer_list, 
                          const lListElem *type, 
                          const lListElem *rule,
                          lListElem *object,
                          const sge_object_type object_type)
{
   bool ret = true;

   DENTER(TOP_LAYER, "spool_default_validate_func");

   switch(object_type) {
      case SGE_TYPE_ADMINHOST:
      case SGE_TYPE_EXECHOST:
      case SGE_TYPE_SUBMITHOST:
         {
            int cl_ret;
            int key_nm = object_type_get_key_nm(object_type);
            char *old_name = strdup(lGetHost(object, key_nm));

            /* try hostname resolving */
            if (strcmp(old_name, SGE_GLOBAL_NAME) != 0) {
               cl_ret = sge_resolve_host(object, key_nm);

               /* if hostname resolving failed: create error */
               if (cl_ret != CL_RETVAL_OK) {
                  if (cl_ret != CL_RETVAL_GETHOSTNAME_ERROR) {
                     answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                                             ANSWER_QUALITY_ERROR, 
                                             MSG_SPOOL_CANTRESOLVEHOSTNAME_SS, 
                                             old_name, cl_get_error_text(ret)); 
                     ret = false;
                  } else {
                     answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                                             ANSWER_QUALITY_WARNING, 
                                             MSG_SPOOL_CANTRESOLVEHOSTNAME_SS, 
                                             old_name, cl_get_error_text(ret));
                  }
               } else {
                  /* if hostname resolving changed hostname: spool */
                  const char *new_name;
                  new_name = lGetHost(object, key_nm);
                  if (strcmp(old_name, new_name) != 0) {
                     spooling_write_func write_func = 
                             (spooling_write_func)lGetRef(rule, SPR_write_func);
                     spooling_delete_func delete_func = 
                             (spooling_delete_func)lGetRef(rule, SPR_delete_func);
                     write_func(answer_list, type, rule, object, new_name, 
                                object_type);
                     delete_func(answer_list, type, rule, old_name, object_type);
                  }
               }
            }

            sge_free(&old_name);

            if (object_type == SGE_TYPE_EXECHOST && ret) {
               lListElem *load_value;
               lList *master_centry_list = *object_type_get_master_list(SGE_TYPE_CENTRY);

               /* all spooled load values are static, therefore we tag them here */
               for_each(load_value, lGetList(object, EH_load_list)) {
                  lSetBool(load_value, HL_static, true);
               }

               /* necessary to init double values of consumable configuration */
               centry_list_fill_request(lGetList(object, EH_consumable_config_list), 
                     NULL, master_centry_list, true, false, true);
               /* necessary to setup actual list of exechost */
               debit_host_consumable(NULL, object, master_centry_list, 0, true, NULL);

               if (ensure_attrib_available(NULL, object, 
                                           EH_consumable_config_list)) {
                  ret = false;
               }
            }
         }
Ejemplo n.º 10
0
void put_chars(char *chars, unsigned int size, gboolean crlf_auto)
{
    char *characters;
 
    /* If the auto CR LF mode on, read the buffer to add \r before \n */ 
    if(crlf_auto)
    {
	/* BUFFER_RECEPTION*2 for worst case scenario, all \n or \r chars */
	char out_buffer[BUFFER_RECEPTION*2];
	int i, out_size = 0;
      
	for (i=0; i<size; i++)
        {
	    if (chars[i] == '\r')
            {
		/* If the previous character was a CR too, insert a newline */
		if (cr_received)
                {
		    out_buffer[out_size] = '\n';
		    out_size++;
                }
		cr_received = 1;
            }
	    else
            {
		if (chars[i] == '\n')
                {
		    /* If we get a newline without a CR first, insert a CR */
		    if (!cr_received)
                    {
			out_buffer[out_size] = '\r';
			out_size++;
                    }
                }
		else
                {
		    /* If we receive a normal char, and the previous one was a
		       CR insert a newline */
		    if (cr_received)
                    {
			out_buffer[out_size] = '\n';
			out_size++;
                    }
                }
		cr_received = 0;
            }
	    out_buffer[out_size] = chars[i];
	    out_size++;
        }
	chars = out_buffer;
	size = out_size;
    }

    if(buffer == NULL)
    {
	i18n_printf(_("ERROR : Buffer is not initialized !\n"));
	return;
    }
   
    if(size > BUFFER_SIZE)
    {
	characters = chars + (size - BUFFER_SIZE);
	size = BUFFER_SIZE;
    }
    else
	characters = chars;
 
    if((size + pointer) >= BUFFER_SIZE)
    {
	memcpy(current_buffer, characters, BUFFER_SIZE - pointer);
	chars = characters + BUFFER_SIZE - pointer;
	pointer = size - (BUFFER_SIZE - pointer);
	memcpy(buffer, chars, pointer);
	current_buffer = buffer + pointer;
	overlapped = 1;
    }
    else
    {
	memcpy(current_buffer, characters, size);
	pointer += size;
	current_buffer += size;
    }
   
    if(write_func != NULL)
	write_func(characters, size);
}
Ejemplo n.º 11
0
void    pci_w32 (usys bus_num, usys dev_num, usys func_num, usys addr,
                 u32  val)
{
    write_func (get_addr (bus_num, dev_num, func_num, addr), val) ;
} /* End of Function pci_w32 () */
Ejemplo n.º 12
0
void corefile_write_custom(CoreFile *c, write_callback_func *write_func, tell_callback_func *ftell_func, void *user_file_obj)
{
//	write_func(user_file_obj, "slicksnot", 9);
	const int num_notes = 1;
	int pad_i;
	int hdr_offset = 0;
	bool rc;
	Elf32_Ehdr ehdr;

	int thread_notes_size = c->threads.count * sizeof(CoreNote_Regs);

	// compute how much header space we need...
	int hdr_size = 0
		+sizeof(Elf32_Ehdr)
		+sizeof(Elf32_Phdr)					// NOTE hdr
		+sizeof(Elf32_Phdr)*c->segments.count
		+thread_notes_size
		+sizeof(c->corenote_zoog);
	int rounded_hdr_size = (hdr_size + 0xfff) & ~0xfff;
	int pad_size = rounded_hdr_size - hdr_size;

	// ...so that we can plan on laying data segments down after that.
	int seg_file_offset = rounded_hdr_size;

	ehdr.e_ident[EI_MAG0] = ELFMAG0;
	ehdr.e_ident[EI_MAG1] = ELFMAG1;
	ehdr.e_ident[EI_MAG2] = ELFMAG2;
	ehdr.e_ident[EI_MAG3] = ELFMAG3;
	ehdr.e_ident[EI_CLASS] = ELFCLASS32;
	ehdr.e_ident[EI_DATA] = ELFDATA2LSB;
	ehdr.e_ident[EI_VERSION] = EV_CURRENT;
	ehdr.e_ident[EI_OSABI] = ELFOSABI_NONE;
	ehdr.e_ident[EI_ABIVERSION] = 0;

	for (pad_i=EI_PAD; pad_i<EI_NIDENT; pad_i++)
	{
		ehdr.e_ident[pad_i] = 0;
	}
	ehdr.e_type = ET_CORE;
	ehdr.e_machine = EM_386;
	ehdr.e_version = EV_CURRENT;
	ehdr.e_entry = 0;
	ehdr.e_phoff = sizeof(ehdr);
	ehdr.e_shoff = 0;
	ehdr.e_flags = 0;
	ehdr.e_ehsize = sizeof(ehdr);
	ehdr.e_phentsize = sizeof(Elf32_Phdr);
	ehdr.e_phnum = (Elf32_Half) (num_notes + c->segments.count);
	ehdr.e_shentsize = 0;
	ehdr.e_shnum = 0;
	ehdr.e_shstrndx = 0;

	rc = write_func(user_file_obj, &ehdr, sizeof(ehdr));
	lite_assert(rc);
	hdr_offset += sizeof(ehdr);

	// write CoreNotes Phdr
	{
		lite_assert(c->corenote_zoog.bootblock_addr != 0x0);

		Elf32_Phdr phdr;
		phdr.p_type = PT_NOTE;
		phdr.p_flags = 0;
		phdr.p_offset = hdr_offset + sizeof(Elf32_Phdr)*ehdr.e_phnum;
		phdr.p_vaddr = 0;
		phdr.p_paddr = 0;
		phdr.p_filesz = thread_notes_size + sizeof(c->corenote_zoog);
		phdr.p_memsz = 0;
		phdr.p_align = 0;

		rc = (*write_func)(user_file_obj, &phdr, sizeof(phdr));
		lite_assert(rc);
		hdr_offset += sizeof(phdr);
	}

	LinkedListIterator lli;
	for (ll_start(&c->segments, &lli);
		ll_has_more(&lli);
		ll_advance(&lli))
	{
		CoreSegment *seg = (CoreSegment *) ll_read(&lli);

		Elf32_Phdr phdr;
		lite_assert((seg->size & 0xfff) == 0);

		phdr.p_type = PT_LOAD;
		phdr.p_flags = PF_X|PF_W|PF_R;
		phdr.p_offset = seg_file_offset;
		phdr.p_vaddr = (uint32_t) seg->vaddr;
		phdr.p_paddr = 0;
		phdr.p_filesz = seg->size;
		phdr.p_memsz = seg->size;
		phdr.p_align = 0x1000;

		rc = (*write_func)(user_file_obj, &phdr, sizeof(phdr));
		lite_assert(rc);
		hdr_offset += sizeof(phdr);

		seg_file_offset += phdr.p_filesz;
		lite_assert(ftell_func==NULL || hdr_offset == (*ftell_func)(user_file_obj));
	}

	// write the PT_NOTEs that contains the register & zoog symbol info
	{
		LinkedListIterator lli;
		for (ll_start(&c->threads, &lli);
			ll_has_more(&lli);
			ll_advance(&lli))
		{
			CoreNote_Regs *corenote_regs = (CoreNote_Regs *) ll_read(&lli);

			rc = (*write_func)(user_file_obj, corenote_regs, sizeof(*corenote_regs));
			lite_assert(rc);
			hdr_offset += sizeof(*corenote_regs);
		}
		rc = (*write_func)(user_file_obj, &c->corenote_zoog, sizeof(c->corenote_zoog));
		lite_assert(rc);
		hdr_offset += sizeof(c->corenote_zoog);
	}

	lite_assert(pad_size>=0);

	lite_assert(pad_size < 0x1000);
	char pad_zeros[0x1000];
	lite_memset(pad_zeros, 0, sizeof(pad_zeros));
	rc = (*write_func)(user_file_obj, &pad_zeros, pad_size);
	lite_assert(rc);
	lite_assert(ftell_func==NULL || rounded_hdr_size == (*ftell_func)(user_file_obj));
	seg_file_offset = rounded_hdr_size;

	for (ll_start(&c->segments, &lli);
		ll_has_more(&lli);
		ll_advance(&lli))
	{
		CoreSegment *seg = (CoreSegment *) ll_read(&lli);

		rc = (*write_func)(user_file_obj, seg->bytes, seg->size);
		lite_assert(rc);
		seg_file_offset += seg->size;
		lite_assert(ftell_func==NULL || seg_file_offset == (*ftell_func)(user_file_obj));
	}
}
Ejemplo n.º 13
0
enum ff_result ff_write_stream_buffer_write(struct ff_write_stream_buffer *buffer, const void *buf, int len)
{
	ff_write_stream_func write_func;
	void *write_func_ctx;
	char *buffer_buf;
	char *char_buf;
	int buffer_capacity;
	enum ff_result result = FF_FAILURE;

	ff_assert(buffer->capacity > 0);
	ff_assert(len >= 0);

	write_func = buffer->write_func;
	write_func_ctx = buffer->write_func_ctx;
	buffer_buf = buffer->buf;
	buffer_capacity = buffer->capacity;

	char_buf = (char *) buf;
	while (len > 0)
	{
		int bytes_written;
		int free_bytes_cnt;

		ff_assert(buffer->start_pos >= 0);
		ff_assert(buffer->start_pos <= buffer_capacity);

		if (buffer_capacity == buffer->start_pos)
		{
			/* the buffer is full, so flush its contents to the underlying stream */
			result = ff_write_stream_buffer_flush(buffer);
			if (result != FF_SUCCESS)
			{
				goto end;
			}
			ff_assert(buffer->start_pos == 0);

			/* write data directly from the char_buf to the underlying stream
			 * until len is greater than buffer capacity. This allows to avoid superflous
			 * copying of data into the buffer before flushing it to the underlying stream.
			 */
			while (len >= buffer_capacity)
			{
				bytes_written = write_func(write_func_ctx, char_buf, len);
				if (bytes_written == -1)
				{
					ff_log_debug(L"error while writing data from the char_buf=%p with len=%d from buffer=%p. See previous messges for more info", char_buf, len, buffer);
					goto end;
				}
				ff_assert(bytes_written > 0);
				ff_assert(bytes_written <= len);
				char_buf += bytes_written;
				len -= bytes_written;
			}
			if (len == 0)
			{
				/* all requested data has been written directly to the underlying stream */
				break;
			}
		}
		ff_assert(buffer->start_pos < buffer_capacity);

		/* there is the room in the buffer for data. Copy it to the buffer */
		free_bytes_cnt = buffer_capacity - buffer->start_pos;
		ff_assert(free_bytes_cnt > 0);
		bytes_written = (free_bytes_cnt > len) ? len : free_bytes_cnt;
		memcpy(buffer_buf + buffer->start_pos, char_buf, bytes_written);

		buffer->start_pos += bytes_written;
		char_buf += bytes_written;
		len -= bytes_written;
	}
	result = FF_SUCCESS;

end:
	return result;
}