Пример #1
0
void G_Formation::remove_soldier(const G_SoldierInfo *info) noexcept {
    assert(info->is_hero());
    if (remove_object(info->id())) {
        the_data()->_formation_opts.emplace_back();
        to_opt(the_data()->_formation_opts.back());
    }
}
Пример #2
0
/*! \brief callback for an object that has been destroyed
 *
 *  \param [in] object the object that has been destroyed
 *  \param [in] state
 */
static void
object_weakref_cb (OBJECT *object, GschemFindTextState *state)
{
  g_return_if_fail (state != NULL);

  remove_object (state, object);
}
Пример #3
0
void GuiListbox::clear() {
    size_t sz = entries.size();
    for (size_t i = 0; i < sz; i++) {
        remove_object(entries[i]);
    }
    entries.clear();
}
Пример #4
0
stored_object *create_object(size_t size)
{
    stored_object *obj = malloc(sizeof(stored_object));
    uint32_t page_id;

    // initialize to stored_object struct with size and initial pages
    obj->id = current_id++;
    obj->size = 0;
    obj->pages = NULL;

    // add the new object to the objects' hashtable
    HASH_ADD_INT(objects_table, id, obj); 

    while(size > obj->size)
    {
        if (GET_NEW_PAGE(VICTIM_OVERALL, EMPTY_TABLE_ENTRY_NB, &page_id) == FAIL)
        {
            // cleanup just in case we managed to do anything up until now
            remove_object(obj);
            return NULL;
        }

        if(!add_page(obj, page_id))
            return NULL;
        
        // mark new page as valid and used
        UPDATE_NEW_PAGE_MAPPING_NO_LOGICAL(page_id);
    }

    return obj;
}
Пример #5
0
void GuiListbox::remove_entry(int index) {
    int sz = static_cast<int>(entries.size());
    if (index >=0 && index < sz) {
        remove_object(entries[index]);
        entries.erase(entries.begin() + index);
    }
}
Пример #6
0
/*
 * Free obj from whatever list it is on in preperation of deleting it or
 * moving it elsewhere.  This will perform all high-level consequences
 * involved with removing the item.  E.g. if the object is in the hero's
 * inventory and confers heat resistance, the hero will lose it.
 *
 * Object positions:
 *	OBJ_FREE	not on any list
 *	OBJ_FLOOR	fobj, level.locations[][] chains (use remove_object)
 *	OBJ_CONTAINED	cobj chain of container object
 *	OBJ_INVENT	hero's invent chain (use freeinv)
 *	OBJ_MINVENT	monster's invent chain
 *	OBJ_MIGRATING	migrating chain
 *	OBJ_BURIED	level.buriedobjs chain
 *	OBJ_ONBILL	on billobjs chain
 */
void
obj_extract_self(struct obj *obj)
{
    switch (obj->where) {
    case OBJ_FREE:
        break;
    case OBJ_FLOOR:
        remove_object(obj);
        break;
    case OBJ_CONTAINED:
        extract_nobj(obj, &obj->ocontainer->cobj);
        container_weight(obj->ocontainer);
        break;
    case OBJ_INVENT:
        freeinv(obj);
        break;
    case OBJ_MINVENT:
        extract_nobj(obj, &obj->ocarry->minvent);
        break;
    case OBJ_MIGRATING:
        extract_nobj(obj, &migrating_objs);
        break;
    case OBJ_BURIED:
        extract_nobj(obj, &level.buriedobjlist);
        break;
    case OBJ_ONBILL:
        extract_nobj(obj, &billobjs);
        break;
    default:
        panic("obj_extract_self");
        break;
    }
}
Пример #7
0
void G_Formation::change_soldier(const G_SoldierInfo *old_info, const G_SoldierInfo *new_info) noexcept {
    assert(old_info->is_hero() == new_info->is_hero());

    if (old_info->is_hero()) {
        ptr<G_FormationItem> old_item = remove_object(old_info->id());
        if (!old_item) {
            return;
        }
        G_FormationItem *new_item = probe_object(new_info->id(), new_info);
        if (new_item) {
            new_item->_soldier = old_item->_soldier;
            new_item->_x = old_item->_x;
            new_item->_y = old_item->_y;
        }
    }
    else {
        bool found = false;
        for (G_FormationItem *item : objects()) {
            if (item->_soldier == old_info) {
                item->_soldier = new_info;
                found = true;
            }
        }
        if (!found) {
            return;
        }
    }
    the_data()->_formation_opts.emplace_back();
    to_opt(the_data()->_formation_opts.back());
}
Пример #8
0
/*
 *  set_bc()
 *
 *  The hero is either about to go blind or already blind and just punished.
 *  Set up the ball and chain variables so that the ball and chain are "felt".
 */
void
set_bc(int already_blind)
{
    int ball_on_floor = !carried(uball);

    u.bc_order = bc_order();    /* get the order */
    u.bc_felt = ball_on_floor ? BC_BALL | BC_CHAIN : BC_CHAIN;  /* felt */

    if (already_blind || Engulfed) {
        u.cglyph = u.bglyph = level->locations[u.ux][u.uy].mem_obj;
        return;
    }

    /* 
     *  Since we can still see, remove the ball&chain and get the glyph that
     *  would be beneath them.  Then put the ball&chain back.  This is pretty
     *  disgusting, but it will work.
     */
    remove_object(uchain);
    if (ball_on_floor)
        remove_object(uball);

    newsym(uchain->ox, uchain->oy);
    u.cglyph = level->locations[uchain->ox][uchain->oy].mem_obj;

    if (u.bc_order == BCPOS_DIFFER) {   /* different locations */
        place_object(uchain, level, uchain->ox, uchain->oy);
        newsym(uchain->ox, uchain->oy);
        if (ball_on_floor) {
            newsym(uball->ox, uball->oy);       /* see under ball */
            u.bglyph = level->locations[uball->ox][uball->oy].mem_obj;
            place_object(uball, level, uball->ox, uball->oy);
            newsym(uball->ox, uball->oy);       /* restore ball */
        }
    } else {
        u.bglyph = u.cglyph;
        if (u.bc_order == BCPOS_CHAIN) {
            place_object(uball, level, uball->ox, uball->oy);
            place_object(uchain, level, uchain->ox, uchain->oy);
        } else {
            place_object(uchain, level, uchain->ox, uchain->oy);
            place_object(uball, level, uball->ox, uball->oy);
        }
        newsym(uball->ox, uball->oy);
    }
}
Пример #9
0
static void move_gold(struct obj *gold, int vroom) {
    signed char nx, ny;

    remove_object(gold);
    newsym(gold->ox, gold->oy);
    nx = rooms[vroom].lx + rn2(2);
    ny = rooms[vroom].ly + rn2(2);
    place_object(gold, nx, ny);
    stackobj(gold);
    newsym(nx, ny);
}
Пример #10
0
int _FTL_OBJ_DELETE(object_id_t object_id)
{
    stored_object *object;
    
    object = lookup_object(object_id);
    
    // object not found
    if (object == NULL)
        return FAIL;

    return remove_object(object);
}
Пример #11
0
/*
 * Function name: stop
 * Description  : Here all commands the player gives comes.
 * Argument     : string str - The command line argument.
 * Returns      : int 1/0    - success/failure.
 */
int
stop(string str)
{
    /* Only paralyze our environment */
    if (environment() != this_player())
    {
        return 0;
    }

    /* Some commands may always be issued. */
    if (member_array(query_verb(), CMDPARSE_PARALYZE_ALLOWED) != -1)
    {
        return 0;
    }

    /* If there is a verb stopping the paralyze, check it. */
    if (stringp(stop_verb) &&
	(query_verb() == stop_verb))
    {
        /* If a stop_fun is defined it MUST return 1 in order not stop the
         * paralyze.
         */
        if (objectp(stop_object) &&
            call_other(stop_object, stop_fun, str))
        {
            return 1;
        }

	if (stringp(stop_message))
        {
            this_player()->catch_msg(stop_message);
        }

        remove_object();
        return 1;
    }

    /* We allow VBFC, so here we may use catch_msg(). */
    if (stringp(fail_message))
    {
        this_player()->catch_msg(fail_message);
    }

    /* Only paralyze mortals. */
    if (!this_player()->query_wiz_level())
    {
        return 1;
    }

    write("Since you are a wizard this paralyze won't affect you.\n");
    return 0;
}
Пример #12
0
/*
 * Function name: stop_paralyze
 * Description  : This function is called if the paralyze shall stop due to 
 *		  the time running out.
 */
void
stop_paralyze()
{
    if (!objectp(environment()))
    {
        remove_object();
        return;
    }

    set_this_player(environment());

    if (objectp(stop_object) && stringp(stop_fun) &&
        (stop_object != this_object()))
    {
        call_other(stop_object, stop_fun, environment());
    }
    else if (strlen(stop_message))
    {
        environment()->catch_msg(stop_message);
    }

    remove_object();
}
Пример #13
0
static int sqlfs_rmdir(const char *path)
{
  int err = 0;
  GError *terr = NULL;

  remove_object(path, &terr);

  if (terr != NULL)
    err = -EFAULT;

  if (terr != NULL)
    g_error_free(terr);

  return err;
}
void
dmz::NetModuleIdentityMapBasic::receive_message (
      const Message &Msg,
      const UInt32 MessageSendHandle,
      const UInt32 TargetObserverHandle,
      const Data *InData,
      Data *outData) {

   if (Msg.is_of_type (_removeObjMsg)) {

      const Handle ObjectHandle (_handleConverter.to_handle (InData));

      if (ObjectHandle) { remove_object (ObjectHandle); }
   }
}
Пример #15
0
void theme::modify(const config &cfg)
{
	std::map<std::string,std::string> title_stash;
	std::vector<theme::menu>::iterator m;
	for (m = menus_.begin(); m != menus_.end(); ++m) {
		if (!m->title().empty() && !m->get_id().empty())
			title_stash[m->get_id()] = m->title();
	}

	std::vector<theme::action>::iterator a;
	for (a = actions_.begin(); a != actions_.end(); ++a) {
		if (!a->title().empty() && !a->get_id().empty())
			title_stash[a->get_id()] = a->title();
	}

	// Change existing theme objects.
	for(const config &c : cfg.child_range("change"))
	{
		std::string id = c["id"];
		std::string ref_id = c["ref"];
		theme::object &element = find_element(id);
		if (element.get_id() == id)
			set_object_location(element, c["rect"], ref_id);
	}

	// Add new theme objects.
	for(const config &c : cfg.child_range("add")) {
		add_object(c);
	}

	// Remove existent theme objects.
	for(const config &c : cfg.child_range("remove")) {
		remove_object(c["id"]);
	}

	for (m = menus_.begin(); m != menus_.end(); ++m) {
		if (title_stash.find(m->get_id()) != title_stash.end())
			m->set_title(title_stash[m->get_id()]);
	}
	for (a = actions_.begin(); a != actions_.end(); ++a) {
		if (title_stash.find(a->get_id()) != title_stash.end())
			a->set_title(title_stash[a->get_id()]);
	}
}
Пример #16
0
static int sqlfs_unlink(const char *path)
{
  int err = 0;
  GError *terr = NULL;
  remove_object(path, &terr);
  if (terr != NULL) {
    if (terr->code == EENOTFOUND) {
      err = -ENOENT;
    }
    else {
      err = -EFAULT;
    }
  }
  
  if (terr != NULL)
    g_error_free(terr);
  
  return err;
}
Пример #17
0
/*prototipo: int drop_bucket(char *idBucket,char *dirName,char *srvrName)
 *objetivo: Remove um Bucket, do Servidor e Diretório especificados por
 *parametros em conjunto com o identificador do Bucket*/
int ss_drop_bucket(char *idBucket,char *dirName,char *srvName) {

	// conecta no pool/servidor
	state = set_server(cluster, srvName,&ioctx);
	if(state >= 0){
		//seta o diretorio
		state = set_directory(dirName,&ioctx);
		
		/* remove o bucket do Diretorio
		   se a operacao falhar error > 0*/
		state = remove_object(ioctx,idBucket);
	}
	else
		fprintf(stderr,"[drop_bucket/iceph.c] Servidor não localizado!\n");
	
	destroy_ioctx(&ioctx);
	
	return ((state >= 0)? 0 : 1);
}
Пример #18
0
void cull_leftovers(PVFS_fs_id cur_fs,
		    struct handlelist *hl_all,
		    PVFS_BMI_addr_t *addr_array,
		    PVFS_credentials *creds)
{
    int ret;
    int server_idx;
    PVFS_handle handle;

    /* recall that return_handle removes from list */
    while (handlelist_return_handle(hl_all,
				    &handle,
				    &server_idx) == 0)
    {
	PVFS_object_ref handle_ref;
	PVFS_sysresp_getattr getattr_resp;

	handle_ref.handle = handle;
	handle_ref.fs_id  = cur_fs;

	ret = PVFS_sys_getattr(handle_ref,
			       PVFS_ATTR_SYS_ALL_NOHINT,
			       creds,
			       &getattr_resp, NULL);
	if (ret) {
	    printf("warning: problem calling getattr on %llu\n",
		   llu(handle));
	    getattr_resp.attr.objtype = 0;
	}

	/* metafile and directory handles should have been removed
	 * in the previous pass.
	 */
	assert(getattr_resp.attr.objtype != PVFS_TYPE_METAFILE);
	assert(getattr_resp.attr.objtype != PVFS_TYPE_DIRECTORY);

	ret = remove_object(handle_ref,
			    getattr_resp.attr.objtype,
			    creds);
	assert(ret == 0);
    }
}
Пример #19
0
void theme::modify(const config* cfg){
	std::map<std::string,std::string> title_stash;
	std::vector<theme::menu>::iterator m;
	for (m = menus_.begin(); m != menus_.end(); ++m) {
		if (!m->title().empty() && !m->get_id().empty())
			title_stash[m->get_id()] = m->title();
	}

	{
		// changes to existing theme objects
		const config::child_list& c = cfg->get_children("change");
		for(config::child_list::const_iterator j = c.begin(); j != c.end(); ++j) {
			std::string id = (**j)["id"];
			std::string ref_id = (**j)["ref"];
			theme::object& element = find_element(id);
			if (element.get_id() == id){
				set_object_location(element, (**j)["rect"], ref_id);
			}
		}
	}
	// adding new theme objects
	{
		const config::child_list& c = cfg->get_children("add");
		for(config::child_list::const_iterator j = c.begin(); j != c.end(); ++j) {
			add_object(**j);
		}
	}
	// removing existent theme objects
	{
		const config::child_list& c = cfg->get_children("remove");
		for(config::child_list::const_iterator j = c.begin(); j != c.end(); ++j) {
			remove_object((**j)["id"]);
		}
	}
	for (m = menus_.begin(); m != menus_.end(); ++m) {
		if (title_stash.find(m->get_id()) != title_stash.end())
			m->set_title(title_stash[m->get_id()]);
	}
}
Пример #20
0
bool iol2opc_IDL::read(yarp::os::ConnectionReader& connection) {
  yarp::os::idl::WireReader reader(connection);
  reader.expectAccept();
  if (!reader.readListHeader()) { reader.fail(); return false; }
  yarp::os::ConstString tag = reader.readTag();
  bool direct = (tag=="__direct__");
  if (direct) tag = reader.readTag();
  while (!reader.isError()) {
    // TODO: use quick lookup, this is just a test
    if (tag == "train_object") {
      std::string name;
      if (!reader.readString(name)) {
        reader.fail();
        return false;
      }
      bool _return;
      _return = train_object(name);
      yarp::os::idl::WireWriter writer(reader);
      if (!writer.isNull()) {
        if (!writer.writeListHeader(1)) return false;
        if (!writer.writeBool(_return)) return false;
      }
      reader.accept();
      return true;
    }
    if (tag == "remove_object") {
      std::string name;
      if (!reader.readString(name)) {
        reader.fail();
        return false;
      }
      bool _return;
      _return = remove_object(name);
      yarp::os::idl::WireWriter writer(reader);
      if (!writer.isNull()) {
        if (!writer.writeListHeader(1)) return false;
        if (!writer.writeBool(_return)) return false;
      }
      reader.accept();
      return true;
    }
    if (tag == "remove_all") {
      bool _return;
      _return = remove_all();
      yarp::os::idl::WireWriter writer(reader);
      if (!writer.isNull()) {
        if (!writer.writeListHeader(1)) return false;
        if (!writer.writeBool(_return)) return false;
      }
      reader.accept();
      return true;
    }
    if (tag == "change_name") {
      std::string old_name;
      std::string new_name;
      if (!reader.readString(old_name)) {
        reader.fail();
        return false;
      }
      if (!reader.readString(new_name)) {
        reader.fail();
        return false;
      }
      bool _return;
      _return = change_name(old_name,new_name);
      yarp::os::idl::WireWriter writer(reader);
      if (!writer.isNull()) {
        if (!writer.writeListHeader(1)) return false;
        if (!writer.writeBool(_return)) return false;
      }
      reader.accept();
      return true;
    }
    if (tag == "help") {
      std::string functionName;
      if (!reader.readString(functionName)) {
        functionName = "--all";
      }
      std::vector<std::string> _return=help(functionName);
      yarp::os::idl::WireWriter writer(reader);
        if (!writer.isNull()) {
          if (!writer.writeListHeader(2)) return false;
          if (!writer.writeTag("many",1, 0)) return false;
          if (!writer.writeListBegin(BOTTLE_TAG_INT, static_cast<uint32_t>(_return.size()))) return false;
          std::vector<std::string> ::iterator _iterHelp;
          for (_iterHelp = _return.begin(); _iterHelp != _return.end(); ++_iterHelp)
          {
            if (!writer.writeString(*_iterHelp)) return false;
           }
          if (!writer.writeListEnd()) return false;
        }
      reader.accept();
      return true;
    }
    if (reader.noMore()) { reader.fail(); return false; }
    yarp::os::ConstString next_tag = reader.readTag();
    if (next_tag=="") break;
    tag = tag + "_" + next_tag;
  }
  return false;
}
Пример #21
0
int descend(PVFS_fs_id cur_fs,
	    struct handlelist *hl,
	    struct handlelist *alt_hl,
	    PVFS_object_ref dir_ref,
	    PVFS_credentials *creds)
{
    int i, count;
    PVFS_ds_position token; 
    PVFS_sysresp_readdir readdir_resp;
    PVFS_sysresp_getattr getattr_resp;
    PVFS_object_ref entry_ref = {0, 0};

    count = 64;

    token = 0;
    do {
        memset(&readdir_resp, 0, sizeof(PVFS_sysresp_readdir));
        PVFS_sys_readdir(dir_ref,
                         (!token ? PVFS_READDIR_START : token),
                         count,
                         creds,
                         &readdir_resp, NULL);

        for (i = 0; i < readdir_resp.pvfs_dirent_outcount; i++)
        {
            int server_idx = 0, ret, in_main_list = 0, in_alt_list = 0;
            char *cur_file;
            PVFS_handle cur_handle;

            cur_handle = readdir_resp.dirent_array[i].handle;
            cur_file   = readdir_resp.dirent_array[i].d_name;

            entry_ref.handle = cur_handle;
            entry_ref.fs_id  = cur_fs;

            if (handlelist_find_handle(hl, cur_handle, &server_idx) == 0)
            {
                in_main_list = 1;
            }
            if (!in_main_list &&
                alt_hl &&
                handlelist_find_handle(alt_hl,
                                       cur_handle,
                                       &server_idx) == 0)
            {
                in_alt_list = 1;
            }
            if (!in_main_list && !in_alt_list) {
                ret = remove_directory_entry(dir_ref,
                                             entry_ref,
                                             cur_file,
                                             creds);
                assert(ret == 0);

                continue;
            }

            ret = PVFS_sys_getattr(entry_ref,
                                   PVFS_ATTR_SYS_ALL_NOHINT,
                                   creds,
                                   &getattr_resp, NULL);
            if (ret != 0) {
                ret = remove_directory_entry(dir_ref,
                                             entry_ref,
                                             cur_file,
                                             creds);
                assert(ret == 0);
                /* handle removed from list below */
            }
            else
            {
                switch (getattr_resp.attr.objtype)
                {
                    case PVFS_TYPE_METAFILE:
                        if (verify_datafiles(cur_fs,
                                             hl,
                                             alt_hl,
                                             entry_ref,
                                             getattr_resp.attr.dfile_count,
                                             creds) < 0)
                        {
                            /* not recoverable; remove */
                            printf("* File %s (%llu) is not recoverable.\n",
                                   cur_file,
                                   llu(cur_handle));

                            /* verify_datafiles() removed the datafiles */
                            ret = remove_object(entry_ref,
                                                getattr_resp.attr.objtype,
                                                creds);
                            assert(ret == 0);

                            ret = remove_directory_entry(dir_ref,
                                                         entry_ref,
                                                         cur_file,
                                                         creds);
                            assert(ret == 0);
                        }
                        
                        break;
                    case PVFS_TYPE_DIRECTORY:
                        ret = match_dirdata(hl,
                                            alt_hl,
                                            entry_ref,
                                            creds);
                        if (ret != 0)
                        {
                            printf("* Directory %s (%llu) is missing DirData.\n",
                                   cur_file,
                                   llu(cur_handle));

                            ret = remove_object(entry_ref,
                                                getattr_resp.attr.objtype,
                                                creds);
                            assert(ret == 0);

                            ret = remove_directory_entry(dir_ref,
                                                         entry_ref,
                                                         cur_file,
                                                         creds);
                            break;
                        }

                        if (in_main_list) {
                            ret = descend(cur_fs,
                                          hl,
                                          alt_hl,
                                          entry_ref,
                                          creds);
                            assert(ret == 0);
                        }
                        break;
                    case PVFS_TYPE_SYMLINK:
                        /* nothing to do */
                        break;
                    default:
                        /* whatever this is, blow it away now. */
                        ret = remove_object(entry_ref,
                                            getattr_resp.attr.objtype,
                                            creds);
                        assert(ret == 0);
                        
                        ret = remove_directory_entry(dir_ref,
                                                     entry_ref,
                                                     cur_file,
                                                     creds);
                        assert(ret == 0);
                        break;
                }
            }

            /* remove from appropriate handle list */
            if (in_alt_list) {
                handlelist_remove_handle(alt_hl, cur_handle, server_idx);
            }
            else if (in_main_list) {
                handlelist_remove_handle(hl, cur_handle, server_idx);
            }
        }
        token = readdir_resp.token;
        if (readdir_resp.pvfs_dirent_outcount)
        {
            free(readdir_resp.dirent_array);
            readdir_resp.dirent_array = NULL;
        }
    } while (readdir_resp.pvfs_dirent_outcount == count);

    if (readdir_resp.pvfs_dirent_outcount)
    {
        free(readdir_resp.dirent_array);
        readdir_resp.dirent_array = NULL;
    }
    return 0;
}
Пример #22
0
struct handlelist *find_sub_trees(PVFS_fs_id cur_fs,
				  struct handlelist *hl_all,
				  PVFS_BMI_addr_t *addr_array,
				  PVFS_credentials *creds)
{
    int ret;
    int server_idx;
    PVFS_handle handle;
    struct handlelist *alt_hl;

    /* TODO: DON'T DIRECTLY USE THESE MEMBERS... */
    alt_hl = handlelist_initialize(hl_all->size_array,
				   hl_all->server_ct);

    /* make a pass working on directories first */
    /* Q: do we want to try to figure out who the root of the tree
     *    really is?  that could be tricky.  we could build this though.
     */
    while (handlelist_return_handle(hl_all,
				    &handle,
				    &server_idx) == 0)
    {
	PVFS_object_ref handle_ref;
	PVFS_sysresp_getattr getattr_resp;

	handle_ref.handle = handle;
	handle_ref.fs_id  = cur_fs;

	ret = PVFS_sys_getattr(handle_ref,
			       PVFS_ATTR_SYS_ALL_NOHINT,
			       creds,
			       &getattr_resp, NULL);
	if (ret) {
	    /* remove anything we can't get attributes on */
	    ret = remove_object(handle_ref,
				0,
				creds);
	    continue;
	}

	switch (getattr_resp.attr.objtype)
	{
	    case PVFS_TYPE_METAFILE:
		/* just hold onto this for now */
		handlelist_add_handle(alt_hl, handle, server_idx);
		break;
	    case PVFS_TYPE_DIRECTORY:
		/* add to directory list */
		printf("# looking for dirdata match to %llu.\n", llu(handle));

		descend(cur_fs,
			hl_all,
			alt_hl,
			handle_ref,
			creds);

		handlelist_add_handle(alt_hl, handle, server_idx);
		break;
	    case PVFS_TYPE_DATAFILE:
		/* save for later */
		handlelist_add_handle(alt_hl, handle, server_idx);
		break;
	    case PVFS_TYPE_DIRDATA:
		handlelist_add_handle(alt_hl, handle, server_idx);
		break;
	    case PVFS_TYPE_SYMLINK:
		handlelist_add_handle(alt_hl, handle, server_idx);
		break;
	    default:
		ret = remove_object(handle_ref,
				    getattr_resp.attr.objtype,
				    creds);
		assert(ret == 0);
		break;
	}

    }

    return alt_hl;
}
Пример #23
0
struct handlelist *fill_lost_and_found(PVFS_fs_id cur_fs,
				       struct handlelist *hl_all,
				       PVFS_BMI_addr_t *addr_array,
				       PVFS_credentials *creds)
{
    int ret;
    int server_idx;
    PVFS_handle handle;
    struct handlelist *alt_hl;
    static char filename[64] = "lostfile.";
    static char dirname[64] = "lostdir.";

    /* TODO: DON'T DIRECTLY USE THESE MEMBERS... */
    alt_hl = handlelist_initialize(hl_all->size_array,
				   hl_all->server_ct);

    /* recall that return_handle removes from list */
    while (handlelist_return_handle(hl_all,
				    &handle,
				    &server_idx) == 0)
    {
	PVFS_object_ref handle_ref;
	PVFS_sysresp_getattr getattr_resp;

	handle_ref.handle = handle;
	handle_ref.fs_id  = cur_fs;

	ret = PVFS_sys_getattr(handle_ref,
			       PVFS_ATTR_SYS_ALL_NOHINT,
			       creds,
			       &getattr_resp, NULL);
	if (ret) {
	    printf("warning: problem calling getattr on %llu; assuming datafile for now.\n",
		   llu(handle));
	    getattr_resp.attr.objtype = PVFS_TYPE_DATAFILE;
	}

	switch (getattr_resp.attr.objtype)
	{
	    case PVFS_TYPE_METAFILE:
		printf("# trying to salvage %s %lld.\n",
		       get_type_str(getattr_resp.attr.objtype),
		       llu(handle));
		if (verify_datafiles(cur_fs,
				     hl_all,
				     alt_hl,
				     handle_ref, 
				     getattr_resp.attr.dfile_count,
				     creds) != 0)
		{
		    ret = remove_object(handle_ref,
					getattr_resp.attr.objtype,
					creds);
		    assert(ret == 0);
		}
		else
		{
		    sprintf(filename + 9, "%llu", llu(handle));
		    ret = create_dirent(laf_ref,
					filename,
					handle,
					creds);
                    assert(ret == 0);
		}
		break;
	    case PVFS_TYPE_DIRECTORY:
                /* assumption: we will often suceed in creating a new entry,
                 * but if the file system is messed up we may not be able to
                 * find dirdata, so match_dirdata before create_dirent */
		if (match_dirdata(hl_all,
				    alt_hl,
				    handle_ref,
				    creds)  != 0)
                {
                    ret = remove_object(handle_ref, 
                            getattr_resp.attr.objtype,
                            creds);
                    assert(ret == 0);
                }

		sprintf(dirname + 8, "%llu", llu(handle));
		ret = create_dirent(laf_ref,
				    dirname,
				    handle,
				    creds);
                if (ret != 0)
                {
                    ret = remove_object(handle_ref,
                            getattr_resp.attr.objtype,
                            creds);
                }

		break;
	    case PVFS_TYPE_DATAFILE:
#if 0
		printf("# saving %llu (datafile) for later.\n", llu(handle));
#endif
		handlelist_add_handle(alt_hl, handle, server_idx);
		break;
	    case PVFS_TYPE_DIRDATA:
#if 0
		printf("# saving %llu (dirdata) for later.\n", llu(handle));
#endif
		handlelist_add_handle(alt_hl, handle, server_idx);
		break;
	    case PVFS_TYPE_SYMLINK:
	    default:
		/* delete on handle -- unknown type */
		printf("* delete handle %llu (unknown type).\n",
		       llu(handle));
		break;
	}

    }

    return alt_hl;
}
Пример #24
0
/*
 *  move_bc()
 *
 *  Move the ball and chain.  This is called twice for every move.  The first
 *  time to pick up the ball and chain before the move, the second time to
 *  place the ball and chain after the move.  If the ball is carried, this
 *  function should never have BC_BALL as part of its control.
 *
 *  Should not be called while swallowed.
 */
void
move_bc(int before, int control, xchar ballx, xchar bally, xchar chainx,
        xchar chainy)
{
    if (Blind) {
        /* 
         *  The hero is blind.  Time to work hard.  The ball and chain that
         *  are attached to the hero are very special.  The hero knows that
         *  they are attached, so when they move, the hero knows that they
         *  aren't at the last position remembered.  This is complicated
         *  by the fact that the hero can "feel" the surrounding locations
         *  at any time, hence, making one or both of them show up again.
         *  So, we have to keep track of which is felt at any one time and
         *  act accordingly.
         */
        if (!before) {
            if ((control & BC_CHAIN) && (control & BC_BALL)) {
                /* 
                 *  Both ball and chain moved.  If felt, drop glyph.
                 */
                if (u.bc_felt & BC_BALL)
                    level->locations[uball->ox][uball->oy].mem_obj = u.bglyph;
                if (u.bc_felt & BC_CHAIN)
                    level->locations[uchain->ox][uchain->oy].mem_obj = u.cglyph;
                u.bc_felt = 0;

                /* Pick up mem_obj at new location. */
                u.bglyph = level->locations[ballx][bally].mem_obj;
                u.cglyph = level->locations[chainx][chainy].mem_obj;

                movobj(uball, ballx, bally);
                movobj(uchain, chainx, chainy);
            } else if (control & BC_BALL) {
                if (u.bc_felt & BC_BALL) {
                    if (u.bc_order == BCPOS_DIFFER) {   /* ball by itself */
                        level->locations[uball->ox][uball->oy].mem_obj =
                            u.bglyph;
                    } else if (u.bc_order == BCPOS_BALL) {
                        if (u.bc_felt & BC_CHAIN) {    /* know chain is there */
                            map_object(uchain, 0, TRUE);
                        } else {
                            level->locations[uball->ox][uball->oy].mem_obj =
                                u.bglyph;
                        }
                    }
                    u.bc_felt &= ~BC_BALL;      /* no longer feel the ball */
                }

                /* Pick up mem_obj at new position. */
                u.bglyph = (ballx != chainx ||
                            bally != chainy) ?
                    level->locations[ballx][bally].mem_obj : u.cglyph;

                movobj(uball, ballx, bally);
            } else if (control & BC_CHAIN) {
                if (u.bc_felt & BC_CHAIN) {
                    if (u.bc_order == BCPOS_DIFFER) {
                        level->locations[uchain->ox][uchain->oy].mem_obj =
                            u.cglyph;
                    } else if (u.bc_order == BCPOS_CHAIN) {
                        if (u.bc_felt & BC_BALL) {
                            map_object(uball, 0, TRUE);
                        } else {
                            level->locations[uchain->ox][uchain->oy].mem_obj =
                                u.cglyph;
                        }
                    }
                    u.bc_felt &= ~BC_CHAIN;
                }
                /* Pick up mem_obj at new position. */
                u.cglyph = (ballx != chainx ||
                            bally != chainy) ?
                    level->locations[chainx][chainy].mem_obj : u.bglyph;

                movobj(uchain, chainx, chainy);
            }

            u.bc_order = bc_order();    /* reset the order */
        }

    } else {
        /* 
         *  The hero is not blind.  To make this work correctly, we need to
         *  pick up the ball and chain before the hero moves, then put them
         *  in their new positions after the hero moves.
         */
        if (before) {
            if (!control) {
                /* 
                 * Neither ball nor chain is moving, so remember which was
                 * on top until !before.  Use the variable u.bc_order
                 * since it is only valid when blind.
                 */
                u.bc_order = bc_order();
            }

            remove_object(uchain);
            newsym(uchain->ox, uchain->oy);
            if (!carried(uball)) {
                remove_object(uball);
                newsym(uball->ox, uball->oy);
            }
        } else {
            int on_floor = !carried(uball);

            if ((control & BC_CHAIN) ||
                (!control && u.bc_order == BCPOS_CHAIN)) {
                /* If the chain moved or nothing moved & chain on top. */
                if (on_floor)
                    place_object(uball, level, ballx, bally);
                place_object(uchain, level, chainx, chainy); /* chain on top */
            } else {
                place_object(uchain, level, chainx, chainy);
                if (on_floor)
                    place_object(uball, level, ballx, bally);
                /* ball on top */
            }
            newsym(chainx, chainy);
            if (on_floor)
                newsym(ballx, bally);
        }
    }
}