Example #1
0
static flash_entry_header_t *find_entry(flash_file_token_t token)
{
	for (int s = 0; sector_map[s].address; s++) {

		h_magic_t *pmagic = (h_magic_t *) sector_map[s].address;
		h_magic_t *pe = pmagic + (sector_map[s].size / sizeof(h_magic_t)) - 1;

		/* Hunt for Magic Signature */
cont:

		while (pmagic != pe && !valid_magic(pmagic)) {
			pmagic++;
		}

		/* Did we reach the end
		 * if so try the next sector */

		if (pmagic == pe) { continue; }

		/* Found a magic So assume it is a file header */

		flash_entry_header_t *pf = (flash_entry_header_t *) pmagic;

		/* Test the CRC */

		if (pf->crc == crc32(entry_crc_start(pf), entry_crc_length(pf))) {

			/* Good CRC is it the one we are looking for ?*/

			if (valid_entry(pf) && pf->file_token.t == token.t) {

				return pf;

			} else {

				/* Not the one we wanted but we can trust the size */

				pf = next_entry(pf);
				pmagic = (h_magic_t *) pf;

				/* If the next one is erased */

				if (blank_entry(pf)) {
					continue;
				}
			}

			goto cont;

		} else {

			/* in valid CRC so keep looking */

			pmagic++;
		}
	}

	return NULL;
}
void test_deleting_an_existing_order_decrements_count()
{
    fh_shr_lkp_tbl_t *table = valid_table();
    fh_shr_lkp_ord_t *entry;

    FH_TEST_ASSERT_EQUAL((int)fh_shr_lkp_ord_add(table, valid_entry(), &entry), (int)FH_OK);
    FH_TEST_ASSERT_EQUAL(table->count, 1);
    FH_TEST_ASSERT_EQUAL((int)fh_shr_lkp_ord_del(table, valid_key(), &entry), (int)FH_OK);
    FH_TEST_ASSERT_EQUAL(table->count, 0);
}
void test_fetch_returns_same_pointer_as_add()
{
    fh_shr_lkp_ord_t *addentry, *getentry;
    fh_shr_lkp_tbl_t *table = valid_table();

    FH_TEST_ASSERT_EQUAL((int)fh_shr_lkp_ord_add(table, valid_entry(), &addentry), (int)FH_OK);
    FH_TEST_ASSERT_EQUAL((int)fh_shr_lkp_ord_get(table, valid_key(), &getentry), (int)FH_OK);
    FH_TEST_ASSERT_LEQUAL((unsigned long)addentry, (unsigned long)getentry);

}
void test_order_is_not_fetchable_after_delete()
{
    fh_shr_lkp_tbl_t *table = valid_table();
    fh_shr_lkp_ord_t *entry;

    FH_TEST_ASSERT_EQUAL((int)fh_shr_lkp_ord_add(table, valid_entry(), &entry), (int)FH_OK);
    FH_TEST_ASSERT_EQUAL(table->count, 1);
    FH_TEST_ASSERT_EQUAL((int)fh_shr_lkp_ord_del(table, valid_key(), &entry), (int)FH_OK);
    FH_TEST_ASSERT_EQUAL(table->count, 0);
    FH_TEST_ASSERT_EQUAL((int)fh_shr_lkp_ord_get(table, valid_key(), &entry), (int)FH_ERR_NOTFOUND);
}
Example #5
0
/*
 * Parent vectors: skip all non-valid entries
 */
void print_parents(FILE *f, use_vector_t *v) {
  uint32_t i, n;
  composite_t *p;

  n = v->last;
  for (i=0; i<n; i++) {
    p = v->data[i];
    if (valid_entry(p)) {
      fputs("  ", f);
      print_composite(f, p);
      fputc('\n', f);
    }
  }
}
Example #6
0
bool symbol_table::new_function(const string& name, const string& ret_type,
                                const vector<func_arg>& args, string& sign)
{
    function_desc item(this, name, ret_type, args);
    sign = item.signature();
    
    func_entry entry = find_func_entry(sign);
    if (valid_entry(entry)) {
        return entry->second.ret_type() == ret_type;
    }
    
    item.entry(-1);
    functions_[item.signature()] = item;
    return true;
}
Example #7
0
void print_parents_details(FILE *f, use_vector_t *v) {
  uint32_t i, n;
  composite_t *p;

  n = v->last;
  for (i=0; i<n; i++) {
    p = v->data[i];
    if (valid_entry(p)) {
      fputs("  ", f);
      print_composite(f, p);
      fputc('\n', f);
    } else if (marked_entry(p)) {
      fputs("  ", f);
      print_composite(f, unmark_entry(p));
      fputs(" [hidden]\n", f);
    }
  }
}
void test_modified_entry_persists_after_refetching()
{
    fh_shr_lkp_ord_t        *tblentry;
    fh_shr_lkp_tbl_t        *table = valid_table();
    fh_shr_lkp_ord_t        *entry = valid_entry();

    FH_TEST_ASSERT_EQUAL((int)fh_shr_lkp_ord_add(table, entry, &tblentry), (int)FH_OK);
    FH_TEST_ASSERT_EQUAL((int)fh_shr_lkp_ord_get(table, valid_key(), &tblentry), (int)FH_OK);

    tblentry->shares = 200;
    FH_TEST_ASSERT_EQUAL((int)fh_shr_lkp_ord_get(table, valid_key(), &tblentry), (int)FH_OK);

    FH_TEST_ASSERT_LEQUAL(tblentry->order_no, entry->order_no);
    FH_TEST_ASSERT_LEQUAL(tblentry->price, entry->price);
    FH_TEST_ASSERT_EQUAL(tblentry->shares, 200);
    FH_TEST_ASSERT_EQUAL(tblentry->buy_sell_ind, entry->buy_sell_ind);
    FH_TEST_ASSERT_STREQUAL(tblentry->stock, entry->stock);

    FH_TEST_ASSERT_EQUAL(table->count, 1);
}
static gboolean _save(GtkTreeModel *model, GtkTreePath *path,
                      GtkTreeIter *iter, gpointer data)
{
  gchar *question, *answer, *choice, *pixmap;
  gchar *tmp = NULL;
  xmlNodePtr root, node;

  gtk_tree_model_get (model, iter,
                      QUESTION_COLUMN, &question,
                      ANSWER_COLUMN, &answer,
                      CHOICE_COLUMN, &choice,
                      PIXMAP_COLUMN, &pixmap,
                      -1);

  if(valid_entry(question, answer, choice, pixmap))
    {
      gchar *str = choice;
      gchar choices[(MAX_PROPOSAL * 2)+1];
      int i;
      choices[0] = '\0';
      for (i = 0; i < g_utf8_strlen(choice, -1); i++) {
	gunichar unichar_letter = g_utf8_get_char(str);
	gchar outbuf[6];
	outbuf[g_unichar_to_utf8 ( unichar_letter, outbuf)] = '\0';
	str = g_utf8_next_char(str);
	g_strlcat(choices, "/", MAX_PROPOSAL * 2);
	g_strlcat(choices, outbuf, MAX_PROPOSAL * 2);
      }
      tmp = g_strdup_printf("%s/%s%s",
			    answer, question, choices);
      root =(xmlNodePtr)data;
      node = xmlNewChild(root, NULL, BAD_CAST "Board", NULL);
      xmlNewChild(node, NULL,BAD_CAST "pixmapfile", BAD_CAST pixmap);
      xmlNewChild(node, NULL, BAD_CAST "data", BAD_CAST tmp);
    }
  g_free(tmp);
  g_free(question);
  g_free(answer);
  g_free(choice);
  return FALSE;
}
Example #10
0
static gboolean _check_errors(GtkTreeModel *model, GtkTreePath *path,
			      GtkTreeIter *iter, gpointer data)
{
  gchar *question, *answer, *choice, *pixmap;
  gboolean *has_error = (gboolean*)data;

  gtk_tree_model_get (model, iter,
                      QUESTION_COLUMN, &question,
                      ANSWER_COLUMN, &answer,
                      CHOICE_COLUMN, &choice,
                      PIXMAP_COLUMN, &pixmap,
                      -1);

  if( ! valid_entry(question, answer, choice, pixmap))
    {
      *has_error = TRUE;
      /* Don't check more errors */
      return TRUE;
    }

  return FALSE;
}
Example #11
0
static gboolean
_check_errors(GtkTreeModel *model, GtkTreePath *path,
	      GtkTreeIter *iter, gpointer data)
{
  Level level;
  gboolean *has_error = (gboolean*)data;

  gtk_tree_model_get (model, iter,
                      LEVEL_COLUMN, &level.level,
                      QUESTION_COLUMN, &level.questions,
                      ANSWER_COLUMN, &level.answers,
                      -1);

  if( ! valid_entry( &level ) )
    {
      *has_error = TRUE;
      /* Don't check more errors */
      return TRUE;
    }

  return FALSE;
}
Example #12
0
uint8_t	FileNameRecovery::deletedFileNames(uint8_t * tab,
					   uint64_t content_addr,
					   Node * parent,
					   Directory * inode_dir,
					   DirEntry * dir)
{
  DirEntry *	del_dirent = new DirEntry;
  std::string	name;
  Node *	new_node = NULL;
  inodes_t *	_inter = new (inodes_t);
  uint8_t	valid = 0, tmp;

  for (uint64_t pos = content_addr;
       pos < (dir->entry_length() + content_addr - dir->next() - 12); )
    {

      del_dirent->setDir((dir_entry_v2 *)(tab + pos));
      tmp = valid_entry(del_dirent);

      valid = (valid == 2 ? valid : tmp);
      if (!tmp)
	{
	  if (inode_dir->i_list()->find(del_dirent->inode_value()))
	    {
	      new_node = inode_dir->createNewNode(0, parent,
						  setDirName(del_dirent, tab, pos),
						  _inter);
	      pos += del_dirent->next();
	      new_node->setDeleted();
	      continue ;
	    }
	  if (!(name = setDirName(del_dirent, tab, pos)).empty())
	    {
	      Directory * inode_d = new Directory(inode_dir);

#ifdef DIR_DEBUG
	      if (name.compare(std::string("os-prober.VzowBI")) == 0)
		std::cout << "matched deleted" << std::endl;
	      std::cout << "\tdel file : " << name << "\tcontent_addr : "
			<< content_addr << std::endl;
#endif

	      if ((new_node = retrieve_inode(inode_d, del_dirent, parent, name,
					     _inter)))
		{
		  if (((_inter->file_mode & __IFMT) == __IFDIR)
		      && (del_dirent->file_type_v2() == DirEntry::_DIRECTORY))
		    {
		      if (!inode_dir->isAllocated(dir->inode_value(), _journal->extfs()->vfile()))
			{
			  new_node->setDeleted();
			  Directory * new_dir = new Directory(inode_dir);
			  new_dir->dirContent(new_node, _inter, __addr,
					      del_dirent->inode_value());
			  delete new_dir;
			}
		    }
		}
	      delete inode_d;
	    }

	  pos += del_dirent->next();
	  new_node = NULL;
	}
      else
	pos += 4;
      if (pos >= inode_dir->SB()->block_size() 
	  || pos >= (dir->entry_length() + content_addr))
	break ;
    }
  delete _inter;
  delete del_dirent;
  return valid;
}
fh_shr_cfg_tbl_t *valid_config()
{
    static fh_shr_cfg_tbl_t config = {
        .name       = "dummy_config",
        .enabled    = 1,
        .size       = 100
    };

    return &config;
}

fh_shr_lkp_tbl_t *valid_table()
{
    static fh_shr_lkp_tbl_t table;

    fh_shr_lkp_ord_init(valid_config(), &table);
    return &table;
}

fh_shr_lkp_ord_t *valid_entry()
{
    static fh_shr_lkp_ord_t entry = {
        .order_no       = 1,
        .price          = 1005000,
        .shares         = 100,
        .buy_sell_ind   = 'B',
        .stock          = "AAPL",
        .sym_entry      = NULL,
        .context        = NULL
    };

    return &entry;
}

fh_shr_lkp_ord_key_t *valid_key()
{
    static fh_shr_lkp_ord_key_t key = {
        .order_no       = 1
    };

    return &key;
}

void test_count_responds_to_entry_insertion()
{
    fh_shr_lkp_tbl_t *table = valid_table();
    fh_shr_lkp_ord_t *tblentry;

    FH_TEST_ASSERT_EQUAL((int)fh_shr_lkp_ord_add(table, valid_entry(), &tblentry), (int)FH_OK);
    FH_TEST_ASSERT_EQUAL(table->count, 1);
}

void test_get_after_insertion_yields_correct_values()
{
    fh_shr_lkp_ord_t        *tblentry;
    fh_shr_lkp_tbl_t        *table = valid_table();
    fh_shr_lkp_ord_t        *entry = valid_entry();

    FH_TEST_ASSERT_EQUAL((int)fh_shr_lkp_ord_add(table, entry, &tblentry), (int)FH_OK);
    FH_TEST_ASSERT_EQUAL((int)fh_shr_lkp_ord_get(table, valid_key(), &tblentry), (int)FH_OK);

    FH_TEST_ASSERT_LEQUAL(tblentry->order_no, entry->order_no);
    FH_TEST_ASSERT_LEQUAL(tblentry->price, entry->price);
    FH_TEST_ASSERT_EQUAL(tblentry->shares, entry->shares);
    FH_TEST_ASSERT_EQUAL(tblentry->buy_sell_ind, entry->buy_sell_ind);
    FH_TEST_ASSERT_STREQUAL(tblentry->stock, entry->stock);

    FH_TEST_ASSERT_EQUAL(table->count, 1);
}

void test_retrieving_entry_with_freed_key_works()
{
    fh_shr_lkp_ord_key_t    *key;
    fh_shr_lkp_ord_t        *entry;
    fh_shr_lkp_tbl_t        *table = valid_table();

    key = (fh_shr_lkp_ord_key_t *)malloc(sizeof(fh_shr_lkp_ord_key_t));
    memcpy(key, valid_key(), sizeof(fh_shr_lkp_ord_key_t));

    FH_TEST_ASSERT_EQUAL((int)fh_shr_lkp_ord_add(table, valid_entry(), &entry), (int)FH_OK);
    free(key);
    FH_TEST_ASSERT_EQUAL((int)fh_shr_lkp_ord_get(table, valid_key(), &entry), (int)FH_OK);

    FH_TEST_ASSERT_EQUAL(table->count, 1);
}
Example #14
0
void item_list::execute()
{
  const std::string keys = "\x1B \nabcdefghijklmnopqrstuvwxyz<>?";
  char key = 0;
  bool done = false;

  while (!done)
  {
    print();
    key = wait_for_key(keys);

    if (char_in(key, "\x1B \n"))
    {
      if (m_examine_mode)
      {
        m_examine_mode = false;
      }
      else
      {
        break;
      }
    }

    if (key == '<')
    {
      if (m_page > 0)
      {
        m_page--;
      }
    }
    else if (key == '>')
    {
      if (m_page == 0 && m_items.size() > PAGE_SIZE)
      {
        m_page++;
      }
    }
    else if (key == '?')
    {
      m_examine_mode = !m_examine_mode;
    }
    else if (valid_entry(key))
    {
      if (!m_examine_mode)
      {
        done = handle_item(get_entry(key).item);
      }
      else
      {
        item_t* item_to_describe = get_entry(key).item;
        describe(item_to_describe);
      }
    }
  }

  if (m_action == ZAP)
  {
    if (key == '\x1B' || key == ' ' || key == '\n')
    {
      // Pop wand selection state.
      statestack_pop();
    }
  }

  // Always cancel if escape;
  if (key == '\x1B')
  {
    m_chosen_items.clear();
    return;
  }

  if (m_action == DROP)
  {
    handle_dropped();
  }
}