Beispiel #1
0
db_result_t
storage_get_index(index_t *index, relation_t *rel, attribute_t *attr)
{
  char filename[INDEX_NAME_LENGTH];
  int fd;
  int r;
  struct index_record record;
  db_result_t result;

  merge_strings(filename, rel->name, INDEX_NAME_SUFFIX);

  fd = cfs_open(filename, CFS_READ);
  if(fd < 0) {
    return DB_STORAGE_ERROR;
  }

  for(result = DB_STORAGE_ERROR;;) {
    r = cfs_read(fd, &record, sizeof(record));
    if(r < sizeof(record)) {
      break;
    }
    if(strcmp(attr->name, record.attribute_name) == 0) {
      PRINTF("DB: Found the index record for %s.%s: type %d, filename %s\n",
	rel->name, attr->name, record.type, record.file_name);
      index->type = record.type;
      memcpy(index->descriptor_file, record.file_name,
	     sizeof(index->descriptor_file));
      result = DB_OK;
    }
  }

  cfs_close(fd);

  return result;
}
Beispiel #2
0
db_result_t
storage_put_index(index_t *index)
{
  char filename[INDEX_NAME_LENGTH];
  int fd;
  int r;
  struct index_record record;
  db_result_t result;

  merge_strings(filename, index->rel->name, INDEX_NAME_SUFFIX);

  fd = cfs_open(filename, CFS_WRITE | CFS_APPEND);
  if(fd < 0) {
    return DB_STORAGE_ERROR;
  }

  strcpy(record.attribute_name, index->attr->name);
  memcpy(record.file_name, index->descriptor_file, sizeof(record.file_name));
  record.type = index->type;

  result = DB_OK;
  r = cfs_write(fd, &record, sizeof(record));
  if(r < sizeof(record)) {
    result = DB_STORAGE_ERROR;
  } else {
    PRINTF("DB: Wrote an index record for %s.%s, type %d\n",
      index->rel->name, index->attr->name, record.type);
  }

  cfs_close(fd);

  return result;
}
void
garmin_read_a000_a001 ( garmin_unit * garmin )
{
  garmin_packet          p;
  garmin_product *       r;
  garmin_extended_data * e;
  int                    done = 0;
  int                    pos;
  int                    size;
  int                    i;
  int                    j;
  uint8                  tag;
  uint16                 data;
  uint16 *               datatypes;

  /* Send the product request */
  
  garmin_packetize(&p,L000_Pid_Product_Rqst,0,NULL);
  garmin_write(garmin,&p);

  /* Read the response. */
  
  while ( !done && garmin_read(garmin,&p) > 0 ) {
    switch ( garmin_packet_id(&p) ) {
    case L000_Pid_Product_Data:
      r = &garmin->product;
      /* product ID, software version, product description, additional data. */
      r->product_id = get_uint16(p.packet.data);
      r->software_version = get_sint16(p.packet.data+2);
      pos = 4;
      if ( r->product_description != NULL ) {
	free(r->product_description);
      }
      r->product_description = get_string(&p,&pos);      
      r->additional_data = merge_strings(r->additional_data,
					 get_strings(&p,&pos));
      break;
      
    case L000_Pid_Ext_Product_Data:
      e = &garmin->extended;
      /* These strings should be ignored, but we save them anyway. */
      pos = 0;
      e->ext_data = merge_strings(e->ext_data,get_strings(&p,&pos));
      break;

    case L000_Pid_Protocol_Array:
      /* This is the A001 protocol, initiated by the device. */
      size = garmin_packet_size(&p) / 3;
      datatypes = calloc(size,sizeof(uint16));
      for ( i = 0; i < size; i++ ) {
	tag  = p.packet.data[3*i];
	data = get_uint16(p.packet.data + 3*i + 1);	
	switch ( tag ) {
	case Tag_Phys_Prot_Id:  
	  garmin->protocol.physical = data;
	  break;
	case Tag_Link_Prot_Id:
	  garmin->protocol.link = data;
	  break;
	case Tag_Appl_Prot_Id:
	  memset(datatypes,0,size * sizeof(uint16));
	  for ( j = i+1; p.packet.data[3*j] == Tag_Data_Type_Id; j++ ) {
	    datatypes[j-i-1] = get_uint16(p.packet.data + 3*j + 1);
	  }
	  garmin_assign_protocol(garmin,data,datatypes);
	  break;
	case Tag_Data_Type_Id:
	  /* Skip, since we should already have handled them. */
	default:
	  break;
	}
      }
      free(datatypes);
      done = 1;
      break;

    default:
      /* Ignore any other packets sent from the device. */
      break;
    }
  }
}