aesd-char-driver/aesd-circular-buffer.c
struct aesd_buffer_entry *aesd_circular_buffer_find_entry_offset_for_fpos(struct aesd_circular_buffer *buffer,
			size_t char_offset, size_t *entry_offset_byte_rtn )
{
    /**
    * TODO: implement per description
    */
	size_t buff_size_total = 0;
	size_t bytes_con_total = 0; 
	size_t search_buff_size = 0; 
	size_t prev_index_size = 0;
	size_t pres_index_size = 0;
	size_t out_index = buffer->out_offs; 
	uint8_t i = 0;     
	uint8_t j = 0; 
	for(j = 0; j < AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED; j++) //itereate through the circular buffer
	{
		buff_size_total = buff_size_total + buffer->entry[j].size;
		// #ifdef __KERNEL__
		// 	printk("\n total buffer size is :  %d \n", buff_size_total);
		// #else
		// 	printf("\n total buffer size is :    %d \n", buff_size_total);
		// #endif
	}

	if(char_offset >= buff_size_total) //check for valid offset 
		return NULL;

	while(i < AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED)
	{
		// #ifdef __KERNEL__
		// 	printk("out index is :%d\n", out_index);
		// #else
		// 	printf("out index is :%d\n", out_index);
		// #endif
		pres_index_size = buffer->entry[out_index].size;

		if(char_offset < pres_index_size)
		{
			*entry_offset_byte_rtn = char_offset;
			return &buffer->entry[out_index]; //return the address 
		}
		else if (char_offset == pres_index_size)
		{
			size_t temp = 0;
			if(out_index == AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED -1)
				temp = 0;
			else
				temp = out_index + 1;
			return &buffer->entry[temp]; //return the address
		}
		else 
			if(char_offset > pres_index_size)
			char_offset = char_offset - buffer->entry[out_index].size;
		
		bytes_con_total = bytes_con_total + pres_index_size;
		if(out_index == AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED -1)
		{
			out_index = 0; //set out_index =0
		}
		else
		{
			out_index++; //Increment out_index
		}
		
		i++;
	}
    return NULL;
}
/**
 * @param buffer the buffer to search for corresponding offset.  Any necessary locking must be performed by caller.
 * @param char_offset the position to search for in the buffer list, describing the zero referenced
 *      character index if all buffer strings were concatenated end to end
 * @param entry_offset_byte_rtn is a pointer specifying a location to store the byte of the returned
 *      aesd_buffer_entry
 *      buffptr member corresponding to char_offset.  This value is only set when a matching char_offset
 *      is found in aesd_buffer.
 *
 * @return the struct aesd_buffer_entry structure representing the position described by char_offset, or
 * NULL if this position is not available in the buffer (not enough data is written).
 */
@param buffer the buffer to search for corresponding offset.  Any necessary locking must be performed by caller.
@param char_offset the position to search for in the buffer list, describing the zero referenced
character index if all buffer strings were concatenated end to end
@param entry_offset_byte_rtn is a pointer specifying a location to store the byte of the returned
aesd_buffer_entry
buffptr member corresponding to char_offset.  This value is only set when a matching char_offset
is found in aesd_buffer.

@return the struct aesd_buffer_entry structure representing the position described by char_offset, or
NULL if this position is not available in the buffer (not enough data is written).
@param buffer the buffer to search for corresponding offset . Any necessary locking must be performed by caller . @param char_offset the position to search for in the buffer list describing the zero referenced character index if all buffer strings were concatenated end to end @param entry_offset_byte_rtn is a pointer specifying a location to store the byte of the returned aesd_buffer_entry buffptr member corresponding to char_offset . This value is only set when a matching char_offset is found in aesd_buffer . @return the struct aesd_buffer_entry structure representing the position described by char_offset or NULL if this position is not available in the buffer ( not enough data is written ) .
struct aesd_buffer_entry *aesd_circular_buffer_find_entry_offset_for_fpos(struct aesd_circular_buffer *buffer,
			size_t char_offset, size_t *entry_offset_byte_rtn )
{
	size_t buff_size_total = 0;
	size_t bytes_con_total = 0; 
	size_t search_buff_size = 0; 
	size_t prev_index_size = 0;
	size_t pres_index_size = 0;
	size_t out_index = buffer->out_offs; 
	uint8_t i = 0;     
	uint8_t j = 0; 
	for(j = 0; j < AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED; j++) 
	{
		buff_size_total = buff_size_total + buffer->entry[j].size;
	}
	if(char_offset >= buff_size_total) 
		return NULL;
	while(i < AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED)
	{
		pres_index_size = buffer->entry[out_index].size;
		if(char_offset < pres_index_size)
		{
			*entry_offset_byte_rtn = char_offset;
			return &buffer->entry[out_index]; 
		}
		else if (char_offset == pres_index_size)
		{
			size_t temp = 0;
			if(out_index == AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED -1)
				temp = 0;
			else
				temp = out_index + 1;
			return &buffer->entry[temp]; 
		}
		else 
			if(char_offset > pres_index_size)
			char_offset = char_offset - buffer->entry[out_index].size;
		bytes_con_total = bytes_con_total + pres_index_size;
		if(out_index == AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED -1)
		{
			out_index = 0; 
		}
		else
		{
			out_index++; 
		}
		i++;
	}
    return NULL;
}
struct aesd_buffer_entry * aesd_circular_buffer_find_entry_offset_for_fpos ( struct aesd_circular_buffer * buffer , size_t char_offset , size_t * entry_offset_byte_rtn ) { size_t buff_size_total = 0 ; size_t bytes_con_total = 0 ; size_t search_buff_size = 0 ; size_t prev_index_size = 0 ; size_t pres_index_size = 0 ; size_t out_index = buffer -> out_offs ; uint8_t i = 0 ; uint8_t j = 0 ; for ( j = 0 ; j < AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED ; j ++ ) { buff_size_total = buff_size_total + buffer -> entry [ j ] . size ; } if ( char_offset >= buff_size_total ) return NULL ; while ( i < AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED ) { pres_index_size = buffer -> entry [ out_index ] . size ; if ( char_offset < pres_index_size ) { * entry_offset_byte_rtn = char_offset ; return & buffer -> entry [ out_index ] ; } else if ( char_offset == pres_index_size ) { size_t temp = 0 ; if ( out_index == AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED - 1 ) temp = 0 ; else temp = out_index + 1 ; return & buffer -> entry [ temp ] ; } else if ( char_offset > pres_index_size ) char_offset = char_offset - buffer -> entry [ out_index ] . size ; bytes_con_total = bytes_con_total + pres_index_size ; if ( out_index == AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED - 1 ) { out_index = 0 ; } else { out_index ++ ; } i ++ ; } return NULL ; }
@param buffer the buffer to search for corresponding offset.
@param buffer the buffer to search for corresponding offset .
/**
    * TODO: implement per description
    */ //itereate through the circular buffer // #ifdef __KERNEL__ // 	printk("\n total buffer size is :  %d \n", buff_size_total); // #else // 	printf("\n total buffer size is :    %d \n", buff_size_total); // #endif //check for valid offset  // #ifdef __KERNEL__ // 	printk("out index is :%d\n", out_index); // #else // 	printf("out index is :%d\n", out_index); // #endif //return the address  //return the address //set out_index =0 //Increment out_index