Exemple #1
0
bool CMapzoneData::MapZoneSpawned(CMapzone *mZone)
{
    bool toReturn = false;
    if (!mZone) return false;

    char name[128];
    if ( !ZoneTypeToClass( mZone->GetType(), name ) ) return false;


    CBaseEntity *pEnt = gEntList.FindEntityByClassname(NULL, name);
    while (pEnt)
    {
        if (pEnt->GetAbsOrigin() == *mZone->GetPosition()
            && pEnt->GetAbsAngles() == *mZone->GetRotation()
            && pEnt->WorldAlignMaxs() == *mZone->GetScaleMaxs()
            && pEnt->WorldAlignMins() == *mZone->GetScaleMins())
        {
            DevLog("Already found a %s spawned on the map! Not spawning it from zone file...\n", name);
            toReturn = true;
            break;
        }

        pEnt = gEntList.FindEntityByClassname(pEnt, name);
    }

    return toReturn;
}
Exemple #2
0
void CTimer::PostTime()
{
    if (steamapicontext->SteamHTTP() && steamapicontext->SteamUser() && !m_bWereCheatsActivated)
    {
        //Get required info 
        //MOM_TODO include the extra security measures for beta+
        uint64 steamID = steamapicontext->SteamUser()->GetSteamID().ConvertToUint64();
        const char* map = gpGlobals->mapname.ToCStr();
        int ticks = gpGlobals->tickcount - m_iStartTick;

        TickSet::Tickrate tickRate = TickSet::GetCurrentTickrate();

        //Build URL
        char webURL[512];
        Q_snprintf(webURL, 512, "http://momentum-mod.org/postscore/%llu/%s/%i/%s", steamID, map,
            ticks, tickRate.sType);

        DevLog("Ticks sent to server: %i\n", ticks);

        //Build request
        mom_UTIL.PostTime(webURL);
    }
    else
    {
        Warning("Failed to post scores online: Cannot access STEAM HTTP or Steam User!\n");
    }
}
Exemple #3
0
void
init_transport(xport_state_t *transport)
{
    int clear = 0;
    xport_state_t 	*current = transport;

    if (!(IS_GENERIC_API(transport->library->un->type))) {
        for (; current != (xport_state_t *)0; current = current->next)
            if (clear_transport(current->library, current))
                clear++;

        if (clear) {
            dev_ent_t *un;
            char *lc_mess;

            SANITY_CHECK(transport != (xport_state_t *)0);
            SANITY_CHECK(transport->library != (library_t *)0);
            SANITY_CHECK(transport->library->un != (dev_ent_t *)0);
            un = transport->library->un;
            lc_mess = un->dis_mes[DIS_MES_CRIT];
            memccpy(lc_mess,
                    catgets(catfd, SET, 9077,
                            "needs operator attention"),
                    '\0', DIS_MES_LEN);
            DevLog(DL_ERR(5152));
            DownDevice(un, SAM_STATE_CHANGE);
            exit(1);	/* this kill all threads */
        }
    }
    cond_signal(&transport->condit); /* signal done */
}
Exemple #4
0
void MomentumUtil::PostTimeCallback(HTTPRequestCompleted_t *pCallback, bool bIOFailure)
{
    if (bIOFailure) return;
    uint32 size;
    steamapicontext->SteamHTTP()->GetHTTPResponseBodySize(pCallback->m_hRequest, &size);
    DevLog("Size of body: %u\n", size);
    uint8 *pData = new uint8[size];
    steamapicontext->SteamHTTP()->GetHTTPResponseBodyData(pCallback->m_hRequest, pData, size);
    DevLog("PostTimeCallback response: %s\n", reinterpret_cast<char*>(pData));
    //MOM_TODO: Once the server updates this to contain more info, parse and do more with the response

    // Necesary so TimeDisplay scoreboard knows it has to update;
    IGameEvent *postEvent = gameeventmanager->CreateEvent("runtime_posted");
    if (postEvent)
        gameeventmanager->FireEvent(postEvent);

    //Last but not least, free resources
    steamapicontext->SteamHTTP()->ReleaseHTTPRequest(pCallback->m_hRequest);
}
Exemple #5
0
void MomentumUtil::DownloadCallback(HTTPRequestCompleted_t *pCallback, bool bIOFailure)
{
    if (bIOFailure) return;

    FileHandle_t file;
    //MOM_TODO: Read the MOM_TODO DownloadMap(), we're going to need to save the zone files too
    file = filesystem->Open("testmapdownload.bsp", "w+b", "MOD");
    uint32 size;
    steamapicontext->SteamHTTP()->GetHTTPResponseBodySize(pCallback->m_hRequest, &size);
    DevLog("Size of body: %u\n", size);
    uint8 *pData = new uint8[size];
    steamapicontext->SteamHTTP()->GetHTTPResponseBodyData(pCallback->m_hRequest, pData, size);
    //write the file
    filesystem->Write(pData, size, file);
    //save the file
    filesystem->Close(file);
    DevLog("Successfully written file\n");

    //Free resources
    steamapicontext->SteamHTTP()->ReleaseHTTPRequest(pCallback->m_hRequest);
}
Exemple #6
0
    //This is only called when "map ____" is called, if the user uses changelevel then...
    // \/(o_o)\/
    void GameInit()
    {
        ConVarRef gm("mom_gamemode");
        ConVarRef map("host_map");
        const char *pMapName = map.GetString();
        // This will only happen if the user didn't use the map selector to start a map

        //set gamemode depending on map name
        if (gm.GetInt() == MOMGM_UNKNOWN)
        {
            if (!Q_strnicmp(pMapName, "surf_", strlen("surf_")))
            {
                gm.SetValue(MOMGM_SURF);
                //g_Timer.SetGameMode(MOMGM_SURF);
            }
            else if (!Q_strnicmp(pMapName, "bhop_", strlen("bhop_")))
            {
                DevLog("SETTING THE GAMEMODE!\n");
                gm.SetValue(MOMGM_BHOP);
                //DevLog("GOT TO #2 %i\n", m_iGameMode);

                //g_Timer.SetGameMode(MOMGM_BHOP);
            }
            else if (!Q_strnicmp(pMapName, "kz_", strlen("kz_")))
            {
               DevLog("SETTING THE GAMEMODE!\n");
               gm.SetValue(MOMGM_SCROLL);
            }
            else if (!Q_strcmp(pMapName, "background") || !Q_strcmp(pMapName, "credits"))
            {
                gm.SetValue(MOMGM_ALLOWED);
            }
            else
            {
                gm.SetValue(MOMGM_UNKNOWN);
                //g_Timer.SetGameMode(MOMGM_UNKNOWN);
            }
            
        }
    }
Exemple #7
0
void CMomReplayManager::UnloadPlayback(bool shutdown)
{
    SetPlayingBack(false);

    if (m_pPlaybackReplay)
    {
        if (m_pPlaybackReplay->GetRunEntity() && !shutdown)
            m_pPlaybackReplay->GetRunEntity()->EndRun();

        delete m_pPlaybackReplay;
    }

    m_pPlaybackReplay = nullptr;

    DevLog("Successfully unloaded playback, shutdown: %i\n", shutdown);
}
Exemple #8
0
void
move_drive_error(
    library_t *library,
    uint_t source,
    uint_t dest,
    int *err)
{
    /* Down the drive(s), not the robot */
    int		downed_one = 0;
    drive_state_t	*drive_to_down;
    dev_ent_t	*un = library->un;
    uchar_t		buf[library->ele_dest_len +
                    sizeof (element_status_data_t) + sizeof (element_status_page_t) +
                    50];
    storage_element_t *desc;

    if (drive_to_down = find_element(library->drive, source)) {
        /* The source is a drive */
        down_drive(drive_to_down, SAM_STATE_CHANGE);
        downed_one++;
    } else {
        /*
         * The source is not a drive. Read the storage element of the
         * source. If full then set error to RECOVERED_MEDIA_MOVE. This
         * tells the requester to set the CES_occupied status bit in the
         * catalog entry.
         */
        mutex_unlock(&library->un->io_mutex);
        if (read_element_status(library, STORAGE_ELEMENT, source,
                                1, buf, sizeof (buf)) > 0) {
            desc = (storage_element_t *)(buf +
                                         sizeof (element_status_data_t) +
                                         sizeof (element_status_page_t));
            if (desc->full)
                *err = RECOVERED_MEDIA_MOVE;
        }
        mutex_lock(&library->un->io_mutex);
    }

    if (drive_to_down = find_element(library->drive, dest)) {
        down_drive(drive_to_down, SAM_STATE_CHANGE);
        downed_one++;
    }
    if (downed_one == 0)
        DevLog(DL_ERR(5333), source, dest, 0);
}
Exemple #9
0
//Called upon map load, loads any and all times stored in the <mapname>.tim file
void CTimer::LoadLocalTimes(const char *szMapname)
{
    char timesFilePath[MAX_PATH];
    Q_strcpy(timesFilePath, c_mapDir);
    Q_strcat(timesFilePath, szMapname, MAX_PATH);
    Q_strncat(timesFilePath, c_timesExt, MAX_PATH);
    KeyValues *timesKV = new KeyValues(szMapname);
    if (timesKV->LoadFromFile(filesystem, timesFilePath, "MOD"))
    {
        for (KeyValues *kv = timesKV->GetFirstSubKey(); kv; kv = kv->GetNextKey())
        {
            Time t;
            t.ticks = Q_atoi(kv->GetName());
            t.tickrate = kv->GetFloat("rate");
            t.date = (time_t) kv->GetInt("date");
            localTimes.AddToTail(t);
        }
    }
    else
    {
        DevLog("Failed to load local times; no local file was able to be loaded!\n");
    }
    timesKV->deleteThis();
}
Exemple #10
0
void CMomentumPlayer::Spawn()
{
    SetModel(ENTITY_MODEL);
    SetBodygroup(1, 11);//BODY_PROLATE_ELLIPSE
    // BASECLASS SPAWN MUST BE AFTER SETTING THE MODEL, OTHERWISE A NULL HAPPENS!
    BaseClass::Spawn();
    AddFlag(FL_GODMODE);
    RemoveSolidFlags(FSOLID_NOT_SOLID); // this removes the flag that was added while switching to spectator mode which
                                        // prevented the player from activating triggers
    // do this here because we can't get a local player in the timer class
    ConVarRef gm("mom_gamemode");
    switch (gm.GetInt())
    {
    case MOMGM_BHOP:
    case MOMGM_SURF:
    case MOMGM_UNKNOWN:
    default:
        EnableAutoBhop();
        break;
    case MOMGM_SCROLL:
        DisableAutoBhop();
        break;
    }
    // Reset all bool gameevents
    IGameEvent *runSaveEvent = gameeventmanager->CreateEvent("run_save");
    IGameEvent *runUploadEvent = gameeventmanager->CreateEvent("run_upload");
    IGameEvent *timerStartEvent = gameeventmanager->CreateEvent("timer_state");
    m_RunData.m_bIsInZone = false;
    m_RunData.m_bMapFinished = false;
    m_RunData.m_iCurrentZone = 0;
    m_bHasPracticeMode = false;
    ResetRunStats();
    if (runSaveEvent)
    {
        runSaveEvent->SetBool("run_saved", false);
        gameeventmanager->FireEvent(runSaveEvent);
    }
    if (runUploadEvent)
    {
        runUploadEvent->SetBool("run_posted", false);
        runUploadEvent->SetString("web_msg", "");
        gameeventmanager->FireEvent(runUploadEvent);
    }
    if (timerStartEvent)
    {
        timerStartEvent->SetInt("ent", entindex());
        timerStartEvent->SetBool("is_running", false);
        gameeventmanager->FireEvent(timerStartEvent);
    }
    // Linear/etc map
    g_Timer->DispatchMapInfo();

    RegisterThinkContext("THINK_EVERY_TICK");
    RegisterThinkContext("CURTIME");
    RegisterThinkContext("THINK_AVERAGE_STATS");
    RegisterThinkContext("CURTIME_FOR_START");
    RegisterThinkContext("TWEEN");
    SetContextThink(&CMomentumPlayer::UpdateRunStats, gpGlobals->curtime + gpGlobals->interval_per_tick,
                    "THINK_EVERY_TICK");
    SetContextThink(&CMomentumPlayer::CheckForBhop, gpGlobals->curtime, "CURTIME");
    SetContextThink(&CMomentumPlayer::CalculateAverageStats, gpGlobals->curtime + AVERAGE_STATS_INTERVAL,
                    "THINK_AVERAGE_STATS");
    SetContextThink(&CMomentumPlayer::LimitSpeedInStartZone, gpGlobals->curtime, "CURTIME_FOR_START");
    SetContextThink(&CMomentumPlayer::TweenSlowdownPlayer, gpGlobals->curtime, "TWEEN");

    SetNextThink(gpGlobals->curtime);
    DevLog("Finished spawn!\n");
}
Exemple #11
0
/*
 * -- setup_tapealert - Setup TapeAlert in polling mode.  Disable
 * recovered error check condition mode.  Disable test mode. Set
 * all other flags to the default values listed in the TapeAlert
 * Specification v3.
 */
static void
setup_tapealert(dev_ent_t *un, int fd)
{
	int		resid;		/* bytes not xfered */
#define	LEN 255				/* max page len */
	uchar_t		page[LEN];	/* current page */
	int		i, len, offset; /* page variables */
#define	PERF 0x80			/* performance */
#define	EBF 0x20			/* enable background funcs */
#define	EWASC 0x10			/* excpt warn chk cond */
#define	DEXCPT 0x08			/* polling mode */
#define	TEST 0x04			/* test mode */
#define	LOGERR 0x01			/* logging of errors */
#define	MIRE 0x03			/* tapealert mode */
#define	MIRE_MASK 0x0f			/* mire field */
	sam_extended_sense_t    *sense; /* device sense data ptr */
	uchar_t		 pagechg[LEN];	/* changable page */
	int		 offsetchg;	/* chg page variables */
	uchar_t		 cdb[SAM_CDB_LENGTH];    /* custom cdb */


	/*
	 * Setup TapeAlert mode page in polling mode.
	 */


	memset(page, 0, LEN);
	memset(pagechg, 0, LEN);
	sense = (sam_extended_sense_t *)SHM_REF_ADDR(un->sense);

	/* get current page */
	if (scsi_cmd(fd, un, SCMD_MODE_SENSE, 30, page, LEN, 0x1c,
	    &resid) < 0) {
		DevLog(DL_DEBUG(12009), sense->es_key, sense->es_add_code,
		    sense->es_qual_code);
		goto done;
	}
	len = page[0]+1;
	page[0] = 0;
	offset = page[3];
	page[4+offset] &= 0x7f;


	/* get changeable page */
	memset(cdb, 0, SAM_CDB_LENGTH);
	cdb[0] = SCMD_MODE_SENSE;
	if (IS_ROBOT(un)) {
		cdb[1] = 0x08;
	}
	cdb[2] = 0x40 | 0x1c;
	cdb[4] = LEN;
	if (scsi_cmd(fd, un, SCMD_ISSUE_CDB, 30, cdb, 6, pagechg, LEN,
	    USCSI_READ, &resid) < 0) {
		DevLog(DL_DEBUG(12010), sense->es_key, sense->es_add_code,
		    sense->es_qual_code);
		goto done;
	}
	offsetchg = pagechg[3];


	/*
	 * Change current TapeAlert page settings to polling mode.
	 */


	/* performance */
	if ((pagechg[6+offsetchg] & PERF) == PERF) {
		page[6+offset] &= ~PERF;
	}

	/* enable background functions */
	if ((pagechg[6+offsetchg] & EBF) == EBF) {
		page[6+offset] &= ~EBF;
	}

	/* exception warning reporting */
	if ((pagechg[6+offsetchg] & EWASC) == EWASC) {
		page[6+offset] &= ~EWASC;
	}

	/* disable exception control */
	if ((pagechg[6+offsetchg] & DEXCPT) == DEXCPT) {
		page[6+offset] |= DEXCPT;
	}

	/* test mode */
	if ((pagechg[6+offsetchg] & TEST) == TEST) {
		page[6+offset] &= ~TEST;
	}

	/* log err */
	if ((pagechg[6+offsetchg] & LOGERR) == LOGERR) {
		page[6+offset] &= ~LOGERR;
	}

	/* MIRE - field ignored if DEXCPT is set */
	if ((pagechg[7+offsetchg] & MIRE_MASK) != 0) {
		page[7+offset] &= ~(pagechg[7+offsetchg] & MIRE_MASK);
		page[7+offset] |= (MIRE & pagechg[7+offsetchg]);
		if ((page[7+offset] & MIRE_MASK) != MIRE) {
			page[7+offset] &= ~MIRE_MASK;
		}
	}

	/* interval timer */
	for (i = 0; i < 4; i++) {
		if (pagechg[i+8+offset] != 0) {
			page[i+8+offset] &= ~(pagechg[i+8+offset]);
		}
	}

	/* report count / test flag number */
	for (i = 0; i < 4; i++) {
		if (pagechg[i+12+offset] != 0) {
			page[i+12+offset] &= ~(pagechg[i+12+offset]);
		}
	}

	/* set polling mode and defaults */
	memset(cdb, 0, SAM_CDB_LENGTH);
	cdb[0] = SCMD_MODE_SELECT;
	cdb[1] = 0x10; /* pf bit */
	cdb[4] = len;
	if (scsi_cmd(fd, un, SCMD_ISSUE_CDB, 30, cdb, 6, page, len,
	    USCSI_WRITE, &resid) < 0) {
		DevLog(DL_DEBUG(12011), sense->es_key, sense->es_add_code,
		    sense->es_qual_code);
		goto done;
	}

done:
	/* log run-time settings from current mode page query */
	memset(page, 0, LEN);
	if (scsi_cmd(fd, un, SCMD_MODE_SENSE, 30, page, LEN, 0x1c,
	    &resid) < 0) {
		DevLog(DL_DEBUG(12012), sense->es_key, sense->es_add_code,
		    sense->es_qual_code);
		return;
	}
	offset = page[3];
	if (page[6+offset] != 8 || page[7+offset] != 3) {
		DevLog(DL_DEBUG(12013), page[6+offset], page[7+offset]);
	}
}
Exemple #12
0
/*
 * clean - clean the drive.
 *
 */
void
clean(
	drive_state_t *drive,
	robo_event_t *event)
{
	dev_ent_t	*un;
	int		err, retry;
	uint32_t	access_count, status = 0;
	char	   *d_mess;
	char	   *l_mess;
	struct CatalogEntry ced;
	struct CatalogEntry *ce = &ced;
	library_t	*library;
	move_flags_t    move_flags;

	SANITY_CHECK(drive != (drive_state_t *)0);
	un = drive->un;
	SANITY_CHECK(un != (dev_ent_t *)0);
	library = (library_t *)drive->library;
	SANITY_CHECK(library != (library_t *)0);
	d_mess = drive->un->dis_mes[DIS_MES_NORM];
	l_mess = library->un->dis_mes[DIS_MES_NORM];
	mutex_lock(&drive->mutex);
	if (clear_drive(drive)) {
		mutex_lock(&drive->un->mutex);
		drive->un->status.bits |= DVST_CLEANING;
		mutex_unlock(&drive->un->mutex);
		drive->status.b.cln_inprog = FALSE;
		mutex_unlock(&drive->mutex);
		disp_of_event(library, event, ENOENT);
		return;
	}
	mutex_lock(&drive->un->mutex);
	drive->un->status.bits |= (DVST_REQUESTED | DVST_CLEANING);
	if (drive->un->open_count) {
		clear_driver_idle(drive, drive->open_fd);
		close_unit(drive->un, &drive->open_fd);
		DEC_OPEN(un);
	}
	mutex_unlock(&drive->un->mutex);
	mutex_unlock(&drive->mutex);

	DevLog(DL_ALL(5075));

	memccpy(d_mess, catgets(catfd, SET, 9025, "needs cleaning"),
	    '\0', DIS_MES_LEN);

	ce = CatalogGetCleaningVolume(library->un->eq, &ced);

	if (ce == NULL) {
		memccpy(l_mess,
		    catgets(catfd, SET, 9026,
	    "no cleaning cartridge available"),
		    '\0', DIS_MES_LEN);
		DevLog(DL_ERR(5141));
		SendCustMsg(HERE, 9347);
		mutex_lock(&drive->mutex);
		drive->status.b.cln_inprog = FALSE;
		down_drive(drive, SAM_STATE_CHANGE);
		mutex_lock(&drive->un->mutex);
		drive->un->status.bits &= ~DVST_REQUESTED;
		mutex_unlock(&drive->un->mutex);
		mutex_unlock(&drive->mutex);
		disp_of_event(library, event, EAGAIN);
		return;
	} else {

		status &= ~CES_occupied;
		(void) CatalogSetFieldByLoc(ce->CeEq, ce->CeSlot, ce->CePart,
		    CEF_Status, status, CES_occupied);


	}


	if (library->un->equ_type == DT_3570C) {
		clean_3570(drive, event, ce);
		return;
	}
	mutex_lock(&drive->mutex);

	if (IS_GENERIC_API(library->un->type)) {
		int		local_retry, d_errno, last_derrno = -1;
		api_errs_t	ret;
		char	   *tag = "load on clean";

		local_retry = 3;
		ret = API_ERR_TR;

		while (local_retry > 0) {
			if (aci_load_media(library, drive, ce, &d_errno) == 0)
				break;
			else {
				/* Error return on api call */
				if (d_errno == 0) {
					/*
					 * if call did not happen - error
					 * return but no error
					 */
					local_retry = -1;
					d_errno = EAMUCOMM;
				} else if ((last_derrno == -1) ||
				    (last_derrno != d_errno)) {
					/* Save error if repeated */
					last_derrno = d_errno;
					if (api_valid_error(library->un->type,
					    d_errno, library->un)) {
				/* Indentation for cstyle */
				if (library->un->slot != ROBOT_NO_SLOT) {
					DevLog(DL_DEBUG(6001),
					    library->un->slot, tag, d_errno,
					    d_errno, api_return_message(
					    library->un->type, d_errno));
				} else {
					DevLog(DL_DEBUG(6043), tag, d_errno,
					    d_errno, api_return_message(
					    library->un->type, d_errno));
				}

				local_retry = api_return_retry(
				    library->un->type, d_errno);
				ret = api_return_degree(
				    library->un->type, d_errno);
					} else {
						local_retry = -2;
					}
				}
				if (local_retry > 0) {
					/* delay before retrying */
					local_retry--;
					if (local_retry > 0)
						sleep(api_return_sleep(
						    library->un->type,
						    d_errno));
				}
			}
		}
		if (d_errno != EOK) {
			DevLog(DL_ERR(6036), ce->CeBarCode);
			memccpy(drive->un->dis_mes[DIS_MES_CRIT],
			    catgets(catfd, SET, 9029,
			"unable to load cleaning cartridge, move failed"),
			    '\0', DIS_MES_LEN);

			if (local_retry == -1) {
				/* The call didn't happen */
				DevLog(DL_ERR(6040), tag);
			} else if (local_retry == 0) {
				/* retries exceeded */
				DevLog(DL_ERR(6039), tag);
			} else {
				if (api_valid_error(drive->library->un->type,
				    d_errno, drive->library->un)) {
					if (drive->library->un->slot !=
					    ROBOT_NO_SLOT) {
						DevLog(DL_ERR(6001),
						    drive->library->un->slot,
						    tag, d_errno, d_errno,
						    api_return_message(
						    library->un->type,
						    d_errno));
					} else {
						DevLog(DL_ERR(6043), tag,
						    d_errno, d_errno,
						    api_return_message(
						    library->un->type,
						    d_errno));
					}
				}
			}

			if (ret == API_ERR_DD)
				down_drive(drive, SAM_STATE_CHANGE);
			else if (ret == API_ERR_DM)
				set_bad_media(un);
			else if (ret == API_ERR_DL)
				down_library(library, SAM_STATE_CHANGE);

			drive->status.b.cln_inprog = FALSE;
			mutex_lock(&drive->un->mutex);
			drive->un->status.bits &= ~(DVST_CLEANING |
			    DVST_REQUESTED);
			mutex_unlock(&drive->un->mutex);
			mutex_unlock(&drive->mutex);
			disp_of_event(library, event, EIO);
			return;
		}
	} else {
		move_flags.bits = 0;
		memccpy(d_mess,
		    catgets(catfd, SET, 9009, "waiting for media changer"),
		    '\0', DIS_MES_LEN);
		/*
		 * SPECTRA LOGIC NOTE:  In 3.3.1, the invert argument on this
		 * move was set to one.  This apparently was done for the
		 * spectra-logic robot which overloaded the invert argument
		 * to be the clean argument (See scsi_command case
		 * SCMD_MOVE_MEDIUM).  Unfortunately, the Qualstar robot,
		 * which is mapped to the spectra-logic, implements the
		 * mailbox control for the same bit that spectra-logic uses
		 * as clean.  Confused? Yep.
		 *
		 * Now to add to the confusion. Somewhere in the catalog
		 * rewrite, for reasons lost in the mists of time, the invert
		 * argument was set to zero.  This is inadverentately half
		 * the fix for snap 4966.  It simplifies things, ignoring any
		 * "special" cleaning logic and treating the cleaning tape as
		 * an ordinary load/unload. It seems to work.
		 *
		 * See #ifdef UNKNOWN_SPECTRA_LOGIC below for the other half of
		 * the fix.
		 */
		if (move_media(library, 0, ELEMENT_ADDRESS(library, ce->CeSlot),
		    drive->element, 0, move_flags)) {
			memccpy(drive->un->dis_mes[DIS_MES_CRIT],
			    catgets(catfd, SET, 9029,
			"unable to load cleaning cartridge, move failed"),
			    '\0', DIS_MES_LEN);

			DevLog(DL_ERR(5143));
			down_drive(drive, SAM_STATE_CHANGE);
			drive->status.b.cln_inprog = FALSE;
			mutex_unlock(&drive->mutex);
			disp_of_event(library, event, EIO);
			return;
		}
	}

	mutex_unlock(&drive->mutex);

	/*
	 * Log successful mount of cleaning tape
	 */
	DevLog(DL_ALL(10042), drive->un->eq);
	tapeclean_media(drive->un);

	/*
	 * move_media does not set up the un, so UpdateCatalog can't be
	 * called from here. Using generic_get_media instead of move_media
	 * leaves the drive hung up.
	 */
	status &= ~CES_occupied;
	(void) CatalogSetFieldByLoc(ce->CeEq, ce->CeSlot, ce->CePart,
	    CEF_Status, status, CES_occupied);
	access_count = ce->CeAccess;
	access_count--;
	(void) CatalogSetFieldByLoc(ce->CeEq, ce->CeSlot, ce->CePart,
	    CEF_Access, access_count, 0);
	(void) CatalogSetFieldByLoc(ce->CeEq, ce->CeSlot, ce->CePart,
	    CEF_MountTime, time(NULL), 0);

	retry = 7;
	err = 0;

	if (IS_GENERIC_API(library->un->equ_type)) {
		char	   *tag = "unload for clean";
		int		local_retry, d_errno, last_derrno;
		api_errs_t	ret;
		do {
			memccpy(d_mess,
			    catgets(catfd, SET, 9030,
			    "waiting for cleaning cycle"),
			    '\0', DIS_MES_LEN);
			sleep(3 * 60);	/* wait 3 minutes */
			tapeclean_media(drive->un);
			mutex_lock(&drive->mutex);
			memccpy(d_mess,
			    catgets(catfd, SET, 9031,
			    "attempt to unload cleaning cartridge"),
			    '\0', DIS_MES_LEN);

			local_retry = 3;
			ret = API_ERR_TR;
			last_derrno = -1;

			while (local_retry > 0) {
				/*
				 * vsn is not set, use aci_force_media()
				 * instead of aci_dismount_media()
				 */
				if (aci_force_media(library, drive,
				    &d_errno) == 0)
					break;
				else {
					/* Error return on api call */
					if (d_errno == 0) {
						/*
						 * if call did not happen -
						 * error return but no error
						 */
						local_retry = -1;
						d_errno = EAMUCOMM;
					} else if ((last_derrno == -1) ||
					    (last_derrno != d_errno)) {
						/* Save error if repeated */
						last_derrno = d_errno;
						if (api_valid_error(
						    drive->library->un->type,
						    d_errno,
						    drive->library->un)) {

						if (drive->library->un->slot !=
						    ROBOT_NO_SLOT) {
						DevLog(DL_DEBUG(6001),
						    drive->library->un->slot,
						    tag, d_errno, d_errno,
						    api_return_message(
						    library->un->type,
						    d_errno));
							} else {
						DevLog(DL_DEBUG(6043),
						    tag, d_errno, d_errno,
						    api_return_message(
						    library->un->type,
						    d_errno));
						}

						local_retry = api_return_retry(
						    library->un->type, d_errno);
						ret = api_return_degree(
						    library->un->type, d_errno);
						} else {
							local_retry = -2;
						}
					}
					if (local_retry > 0) {
						/* delay before retrying */
						local_retry--;
						if (local_retry > 0)
							sleep(api_return_sleep(
							    library->un->type,
							    d_errno));
					}
				}
			}
			if (d_errno != EOK) {
				DevLog(DL_ERR(6033), ce->CeBarCode);

				if (local_retry == -1) {
					/* The call didn't happen */
					DevLog(DL_ERR(6040), tag);
				} else if (local_retry == 0) {
					/* retries exceeded */
					DevLog(DL_ERR(6039), tag);
				} else {
					if (api_valid_error(
					    drive->library->un->type,
					    d_errno, drive->library->un))
						if (drive->library->un->slot !=
						    ROBOT_NO_SLOT) {
						DevLog(DL_ERR(6001),
						    drive->library->un->slot,
						    tag, d_errno, d_errno,
						    api_return_message(
						    library->un->type,
						    d_errno));
						} else {
						DevLog(DL_ERR(6043),
						    d_errno, d_errno,
						    api_return_message(
						    library->un->type,
						    d_errno));
						}
				}
				if (ret == API_ERR_DL)
					down_library(library, SAM_STATE_CHANGE);
				else if (ret == API_ERR_DD)
					down_drive(drive, SAM_STATE_CHANGE);
			}
			mutex_unlock(&drive->mutex);
		} while (err != 0 && retry-- != 0);
	} else {
		/*
		 * SPECTRA LOGIC NOTE:  Due to the removal of "special"
		 * cleaning code, we must unload the cleaning tape for all
		 * robot types.
		 *
		 * See the previous SPECTRA LOGIC NOTE:
		 */
#ifdef UNKNOWN_SPECTRA_LOGIC
		if (library->un->equ_type != DT_SPECLOG)
#endif
			do {
				memccpy(d_mess,
				    catgets(catfd, SET, 9030,
				    "wait for cleaning cycle"),
				    '\0', DIS_MES_LEN);
				sleep(3 * 60);	/* wait 3 minutes */
				tapeclean_media(drive->un);
				mutex_lock(&drive->mutex);
				DevLog(DL_DETAIL(5077));
				memccpy(d_mess,
				    catgets(catfd, SET, 9031,
				    "attempt to unload cleaning cartridge"),
				    '\0', DIS_MES_LEN);
				err = move_media(library, 0, drive->element,
				    ELEMENT_ADDRESS(library, ce->CeSlot),
				    0, move_flags);
				if (err) {
					DevLog(DL_ERR(5078), retry);
				} else {
					DevLog(DL_DETAIL(5079));
				}
				mutex_unlock(&drive->mutex);
			} while (err != 0 && retry-- != 0);
	}

	tapeclean_media(drive->un);

	if (err != 0) {
		DevLog(DL_ERR(5080));
		memccpy(drive->un->dis_mes[DIS_MES_CRIT],
		    catgets(catfd, SET, 9032,
		    "unable to unload cleaning cartridge"),
		    '\0', DIS_MES_LEN);
		mutex_lock(&drive->mutex);
		drive->status.b.cln_inprog = FALSE;
		down_drive(drive, SAM_STATE_CHANGE);
		mutex_unlock(&drive->mutex);
		disp_of_event(library, event, EIO);
		return;
	}
	status = CES_occupied;
	if (drive->un->status.b.bad_media) {
		/* cleaning media marked in catalog as bad */
		status |= CES_bad_media;

		/* reset bad media flag */
		drive->un->status.b.bad_media = 0;
	}
	(void) CatalogSetFieldByLoc(library->un->eq, ce->CeSlot, 0,
	    CEF_Status, status, 0);

	DevLog(DL_ALL(5334), access_count);

	if ((status & CES_bad_media) == 0) {
		memccpy(d_mess,
		    catgets(catfd, SET, 9034, "drive has been cleaned"),
		    '\0', DIS_MES_LEN);
	}
	mutex_lock(&drive->mutex);
	drive->status.b.cln_inprog = FALSE;
	mutex_lock(&drive->un->mutex);
	if ((status & CES_bad_media) == 0) {
		/* drive was cleaned */
		drive->un->status.bits &= ~(DVST_CLEANING | DVST_REQUESTED);
	} else {
		/* drive was not cleaned, it needs to still be cleaned */
		drive->un->status.bits &= ~(DVST_REQUESTED);
	}
	mutex_unlock(&drive->un->mutex);
	mutex_unlock(&drive->mutex);
	if (ce->CeAccess == 0 || (status & CES_bad_media)) {
		char	   *MES_9035 = catgets(catfd, SET, 9035,
		    "cleaning cartridge in slot %d has expired");

		char *mess = (char *)malloc_wait(
		    strlen(MES_9035) + 15, 2, 0);
		sprintf(mess, MES_9035, ce->CeSlot);
		memccpy(l_mess, mess, '\0', DIS_MES_LEN);
		free(mess);
		switch (library->un->type) {
		case DT_METD28:
		case DT_DLT2700:
		case DT_GRAUACI:
			DevLog(DL_ERR(5144), ce->CeSlot);
			break;

		default:
			schedule_export(library, ce->CeSlot);
			DevLog(DL_ERR(5145), ce->CeSlot);
			break;
		}
	} else if (tapeclean_drive(drive->un)) {
		memccpy(l_mess,
		    catgets(catfd, SET, 2983, "clean failed"),
		    '\0', DIS_MES_LEN);
		DevLog(DL_ERR(5364));
		mutex_lock(&drive->mutex);
		down_drive(drive, SAM_STATE_CHANGE);
		mutex_unlock(&drive->mutex);
		disp_of_event(library, event, EIO);
		return;
	}
	disp_of_event(library, event, 0);
}
Exemple #13
0
bool CMapzoneData::LoadFromFile(const char *szMapName)
{
    bool toReturn = false;
    char zoneFilePath[MAX_PATH];
    Q_strcpy(zoneFilePath, c_mapPath);
    Q_strcat(zoneFilePath, szMapName, MAX_PATH);
    Q_strncat(zoneFilePath, c_zoneFileEnding, MAX_PATH);
    DevLog("Looking for zone file: %s \n", zoneFilePath);
    KeyValues* zoneKV = new KeyValues(szMapName);
    if (zoneKV->LoadFromFile(filesystem, zoneFilePath, "MOD"))
    {
        // Go through checkpoints
        for (KeyValues *cp = zoneKV->GetFirstSubKey(); cp; cp = cp->GetNextKey())
        {
            // Load position information (will default to 0 if the keys don't exist)
            Vector* pos = new Vector(cp->GetFloat("xPos"), cp->GetFloat("yPos"), cp->GetFloat("zPos"));
            QAngle* rot = new QAngle(cp->GetFloat("xRot"), cp->GetFloat("yRot"), cp->GetFloat("zRot"));
            Vector* scaleMins = new Vector(cp->GetFloat("xScaleMins"), cp->GetFloat("yScaleMins"), cp->GetFloat("zScaleMins"));
            Vector* scaleMaxs = new Vector(cp->GetFloat("xScaleMaxs"), cp->GetFloat("yScaleMaxs"), cp->GetFloat("zScaleMaxs"));

            // Do specific things for different types of checkpoints
            // 0 = start, 1 = checkpoint, 2 = end, 3 = Onehop, 4 = OnehopReset, 5 = Checkpoint_teleport, 6 = Multihop, 7 = stage
            int zoneType = -1;
            int index = -1;
            bool shouldStop = false;
            bool shouldTilt = true;
            float holdTime = 1.0f;
            //int destinationIndex = -1;
            bool limitingspeed = true;
            float maxleavespeed = 290.0f;
            const char * linkedtrigger = NULL;

            if (Q_strcmp(cp->GetName(), "start") == 0)
            {
                zoneType = MOMZONETYPE_START;
                limitingspeed = cp->GetBool("limitingspeed");
                maxleavespeed = cp->GetFloat("leavespeed");
            }
            else if (Q_strcmp(cp->GetName(), "checkpoint") == 0)
            {
                zoneType = MOMZONETYPE_CP;
                index = cp->GetInt("number", -1);
            }
            else if (Q_strcmp(cp->GetName(), "end") == 0)
            {
                zoneType = MOMZONETYPE_STOP;
            }
            else if (Q_strcmp(cp->GetName(), "onehop") == 0)
            {
                zoneType = MOMZONETYPE_ONEHOP;
                shouldStop = cp->GetBool("stop", false);
                shouldTilt = cp->GetBool("resetang", true);
                holdTime = cp->GetFloat("hold", 1);
                //destinationIndex = cp->GetInt("destination", 1);
                linkedtrigger = cp->GetString("destinationname", NULL);
            }
            else if (Q_strcmp(cp->GetName(), "resetonehop") == 0)
            {
                zoneType = MOMZONETYPE_RESETONEHOP;
            }
            else if (Q_strcmp(cp->GetName(), "checkpoint_teleport") == 0)
            {
                zoneType = MOMZONETYPE_CPTELE;
                //destinationIndex = cp->GetInt("destination", -1);
                shouldStop = cp->GetBool("stop", false);
                shouldTilt = cp->GetBool("resetang", true);
                linkedtrigger = cp->GetString("destinationname", NULL);
            }
            else if (Q_strcmp(cp->GetName(), "multihop") == 0)
            {
                zoneType = MOMZONETYPE_MULTIHOP;
                shouldStop = cp->GetBool("stop", false);
                shouldTilt = cp->GetBool("resetang", true);
                holdTime = cp->GetFloat("hold", 1);
                //destinationIndex = cp->GetInt("destination", 1);
                linkedtrigger = cp->GetString("destinationname", NULL);
            }
            else if (Q_strcmp(cp->GetName(), "stage") == 0)
            {
                zoneType = MOMZONETYPE_STAGE;
                index = cp->GetInt("number", 0);
            }
            else
            {
                Warning("Error while reading zone file: Unknown mapzone type %s!\n", cp->GetName());
                continue;
            }

            // Add element
            m_zones.AddToTail(new CMapzone(zoneType, pos, rot, scaleMins, scaleMaxs, index, shouldStop, shouldTilt,
                holdTime, limitingspeed, maxleavespeed, MAKE_STRING(linkedtrigger)));
        }
        DevLog("Successfully loaded map zone file %s!\n", zoneFilePath);
        toReturn = true;
    }
    zoneKV->deleteThis();
    return toReturn;
}
Exemple #14
0
/*
 * audit - start auditing
 *
 *
 */
void
audit(
	drive_state_t *drive,	/* drive state pointer */
	const uint_t slot,		/* slot to audit */
	const int audit_eod)
{				/* flag to find eod during audit */
	int		part, err;
	uint_t	   myslot = 0;
	dev_ent_t	*un;
	sam_defaults_t *defaults;
	struct CatalogEntry ced;
	struct CatalogEntry *ce = &ced;
	int		skip_audit_eod = 0;

	defaults = GetDefaults();

	SANITY_CHECK(drive != (drive_state_t *)0);
	SANITY_CHECK(drive->library != (library_t *)0);
	SANITY_CHECK(drive->library->un != (dev_ent_t *)0);
	SANITY_CHECK(drive->library->un != drive->un);
	un = drive->un;

	if ((slot == ROBOT_NO_SLOT) &&
	    IS_GENERIC_API(drive->library->un->type)) {
		DevLog(DL_ERR(6004));
		return;
	}
	mutex_lock(&drive->mutex);

	if (drive->status.b.full) {
		mutex_lock(&un->mutex);
		un->status.b.requested = TRUE;
		mutex_unlock(&un->mutex);
		if (clear_drive(drive)) {
			mutex_lock(&un->mutex);
			un->status.b.requested = TRUE;
			mutex_unlock(&un->mutex);
			mutex_unlock(&drive->mutex);
			return;
		}
		if (drive->open_fd >= 0) {
			mutex_lock(&un->mutex);
			close_unit(un, &drive->open_fd);
			DEC_OPEN(un);
			mutex_unlock(&un->mutex);
		}
	}
	mutex_unlock(&drive->mutex);

	mutex_lock(&un->mutex);
	un->status.b.requested = TRUE;
	un->status.b.labeled = FALSE;
	un->status.b.ready = FALSE;
	mutex_unlock(&un->mutex);

	if (slot == ROBOT_NO_SLOT) {
		mutex_lock(&drive->library->mutex);
		drive->library->countdown--;
		drive->library->drives_auditing++;
		mutex_unlock(&drive->library->mutex);

		/*
		 * ok not to lock here wait for all drives to clear
		 */
		while (drive->library->countdown > 0)
			sleep(4);
	}
	for (;;) {

		mutex_lock(&drive->mutex);
		if (slot == ROBOT_NO_SLOT) {
			/* get the next slot number (s) */
			mutex_lock(&drive->library->mutex);
			myslot = drive->library->audit_index;
			if (myslot <= drive->library->range.storage_count) {
				drive->library->audit_index++;
				mutex_unlock(&drive->library->mutex);
			} else {
				/* No more slots to audit */
				mutex_unlock(&drive->library->mutex);
				mutex_lock(&drive->library->un->mutex);
				drive->library->un->status.b.mounted = TRUE;
				drive->library->un->status.b.audit = FALSE;
				drive->library->un->status.b.ready = TRUE;
				mutex_unlock(&drive->library->un->mutex);
				if (drive->status.b.full) {
					clear_drive(drive);
					if (drive->open_fd >= 0)
						mutex_lock(&un->mutex);
					close_unit(un, &drive->open_fd);
					mutex_unlock(&un->mutex);
				}
				mutex_lock(&un->mutex);
				un->status.b.requested = FALSE;
				mutex_unlock(&un->mutex);
				mutex_unlock(&drive->mutex);
				return;
			}
		} else {
			/* get specific slot */
			myslot = slot;
		}

		/*
		 * Should we audit this media? (is occupied, not cleaning and
		 * is a sam tape)
		 */
		if (drive->library->status.b.two_sided) {
			part = 1;
		} else {
			part = 0;
		}
		ce = CatalogGetCeByLoc(drive->library->un->eq,
			    myslot, part, &ced);
		if (ce == NULL ||
		    (!(ce->CeStatus & CES_occupied)) ||
		    (ce->CeStatus & CES_cleaning) ||
		    (ce->CeStatus & CES_non_sam)) {

			mutex_unlock(&drive->mutex);
			if (slot != ROBOT_NO_SLOT) {	/* only one slot */
				mutex_lock(&un->mutex);
				un->status.b.requested = FALSE;
				mutex_unlock(&un->mutex);
				return;
			}
			continue;
		}
		/*
		 * The following lines of code get a tape mounted, or if
		 * two-sided media, mounts the "A" side.
		 */
		err = get_media(drive->library, drive, NULL, ce);

		if (err) {
			mutex_lock(&un->mutex);
			un->status.b.requested = FALSE;
			DEC_ACTIVE(un);
			mutex_unlock(&un->mutex);
			mutex_unlock(&drive->mutex);
			return;
		}
		mutex_lock(&un->mutex);
		un->status.b.scanning = TRUE;
		mutex_unlock(&un->mutex);
		if (spin_drive(drive, SPINUP, NOEJECT)) {

			mutex_lock(&drive->un->mutex);
			drive->un->status.b.scanning &= ~DVST_SCANNING;
			drive->un->status.bits &= ~DVST_REQUESTED;
			mutex_unlock(&drive->un->mutex);

			if (un->state > DEV_ON) {
				clear_drive(drive);
				mutex_lock(&un->mutex);
				clear_driver_idle(drive, drive->open_fd);
				DEC_ACTIVE(un);
				close_unit(un, &drive->open_fd);
				mutex_unlock(&un->mutex);
				mutex_unlock(&drive->mutex);
			} else {
				mutex_lock(&un->mutex);
				clear_driver_idle(drive, drive->open_fd);
				DEC_ACTIVE(un);
				close_unit(un, &drive->open_fd);
				mutex_unlock(&un->mutex);
				mutex_unlock(&drive->mutex);
			}
			SendCustMsg(HERE, 9348);
			DevLog(DL_ERR(5218));
			return;
		}
		un->status.bits |= DVST_AUDIT;

		un->mid = ce->CeMid;
		un->status.b.labeled = FALSE;
		un->i.ViPart = ce->CePart;
		scan_a_device(un, drive->open_fd);
		if (drive->status.b.bar_code) {
			(void) CatalogSetStringByLoc(drive->library->un->eq,
			ce->CeSlot, ce->CePart,
			CEF_BarCode, (char *)drive->bar_code);
		}
		/*
		 * If the cleaning light came on while scanning, leave the
		 * audit bit set and unload the drive.
		 */
		if (un->status.bits & DVST_CLEANING) {
			mutex_lock(&un->mutex);
			un->mtime = 0;
			DEC_ACTIVE(un);
			close_unit(un, &drive->open_fd);
			un->status.b.requested = FALSE;
			mutex_unlock(&un->mutex);
			clear_drive(drive);
			mutex_unlock(&drive->mutex);
			return;
		} else {
			un->status.bits &= ~DVST_AUDIT;
		}

		mutex_lock(&un->mutex);
		/*
		 * This next check keeps us from auditing media that is not
		 * really labeled (label lie). I'm not sure why the un->mutex
		 * is held for this.
		 */
		if (!un->status.b.labeled &&
		    (ce->CeStatus & CES_bar_code) &&
		    (defaults->flags & DF_LABEL_BARCODE)) {
			int tmp;

			if (IS_TAPE(un)) {
				tmp = LEN_TAPE_VSN;
			} else {
				tmp = LEN_OPTIC_VSN;
			}
			vsn_from_barcode(un->vsn, ce->CeBarCode, defaults, tmp);
			un->status.b.labeled = TRUE;
			un->space = un->capacity;
			skip_audit_eod = 1;
		}
		if (IS_TAPE(un)) {
			if (un->status.b.labeled &&
			    audit_eod && !skip_audit_eod) {
				DevLog(DL_DETAIL(5074), un->vsn);
				mutex_unlock(&un->mutex);
				mutex_lock(&un->io_mutex);
				tape_append(drive->open_fd, un, NULL);
				mutex_unlock(&un->io_mutex);
				mutex_lock(&un->mutex);
			} else {
				if (!un->status.b.labeled) {
					un->space = un->capacity;
				} else {
					un->space = ce->CeSpace;
				}
			}
		}
		UpdateCatalog(un, 0, CatalogVolumeLoaded);

		/*
		 * Now do the "B" side if this is optical media.
		 * flip_and_scan calls CatalogVolumeLoaded so it is not done
		 * here.
		 */
		if (drive->library->status.b.two_sided && (ce->CePart == 1)) {
			mutex_unlock(&un->mutex);
			if (flip_and_scan(ce->CePart, drive)) {
				clear_drive(drive);
				mutex_lock(&un->mutex);
				un->status.b.requested = FALSE;
				clear_driver_idle(drive, drive->open_fd);
				close_unit(un, &drive->open_fd);
				DEC_ACTIVE(un);
				mutex_unlock(&un->mutex);
				mutex_unlock(&drive->mutex);
				return;
			}
			mutex_unlock(&drive->mutex);
		} else {
			mutex_unlock(&un->mutex);
			mutex_unlock(&drive->mutex);
		}

		mutex_lock(&un->mutex);
		close_unit(un, &drive->open_fd);
		DEC_ACTIVE(un);
		un->status.b.requested = TRUE;
		mutex_unlock(&un->mutex);

		if (slot != ROBOT_NO_SLOT) {	/* only one slot */
			mutex_lock(&un->mutex);
			un->status.b.requested = FALSE;
			mutex_unlock(&un->mutex);
			mutex_lock(&drive->library->un->mutex);
			drive->library->un->status.b.mounted = TRUE;
			mutex_unlock(&drive->library->un->mutex);
			return;
		}
	}
}
Exemple #15
0
static int luasrc_DevLog (lua_State *L) {
  DevLog(luaL_checkstring(L, 1));
  return 0;
}
Exemple #16
0
/*
 * --- get_supports_tapealert - determine if the robot or tape drive supports
 * TapeAlert.
 */
void
get_supports_tapealert(dev_ent_t *un, int fd)
{
	int			local_open = 0;
	int			open_fd;
	sam_extended_sense_t    *sense;
#define	PAGE_LEN 256
	char			page[PAGE_LEN], *page_ptr;
	int			i, page_len, resid;
	boolean_t		unlock_needed = B_FALSE;


	/* Feature check. */
	if ((un->tapealert & TAPEALERT_ENABLED) == 0) {
		return;
	}

	/* Clear previous success flag. */
	un->tapealert &= ~TAPEALERT_SUPPORTED;

	/* Only tape drives and robots. */
	if (un->scsi_type != 1 && un->scsi_type != 8) {
		return;
	}

	/* Local file descriptor open used by fifo command message. */
	if (fd < 0) {
		if ((open_fd = open(un->name, O_RDONLY | O_NONBLOCK)) < 0) {
			if (IS_TAPE(un)) {
					char	*open_name;
					if ((open_fd = open((open_name =
					    samst_devname(un)),
					    O_RDONLY | O_NONBLOCK)) < 0) {
						if (open_name != (char *)
						    un->dt.tp.samst_name)
							free(open_name);
						return;
					} else {
						INC_OPEN(un);
						if (open_name != (char *)
						    un->dt.tp.samst_name)
							free(open_name);
						local_open = TRUE;
					}
			} else {
				DevLog(DL_DEBUG(12014));
				return;
			}
		} else {
			INC_OPEN(un);
			local_open = TRUE;
		}
	} else {
		open_fd = fd;
	}

	/* Look for log sense tapealert page 0x2e */
	sense = (sam_extended_sense_t *)SHM_REF_ADDR(un->sense);
	(void) memset(sense, 0, sizeof (sam_extended_sense_t));

	if (mutex_trylock(&un->io_mutex) == 0) {
		unlock_needed = B_TRUE;
	}

	memset(page, 0, PAGE_LEN);
	if (scsi_cmd(open_fd, un, SCMD_LOG_SENSE, 0, page, 0, 0, 0,
	    PAGE_LEN, &resid) >= 0) {

		page_len = ((PAGE_LEN - resid) >= 4 ? (PAGE_LEN - resid) : 0);
		if (page_len >= 4) {
			page_len = (page[2] << 8) | page[3];
			page_ptr = page + 4;
		}

		for (i = 0; i < page_len; i++) {
			if (page_ptr[i] == 0x2e) {
				/* initialize tapealert data */
				un->tapealert |= TAPEALERT_SUPPORTED;
				un->tapealert_flags = 0;
				un->tapealert_vsn[0] = '\0';
				DevLog(DL_ALL(12001));
				setup_tapealert(un, open_fd);
				break;
			}
		}
	}

	/* query, clear, and report active flags at setup */
	un->tapealert |= TAPEALERT_INIT_QUERY;
	TAPEALERT(open_fd, un);
	un->tapealert &= ~TAPEALERT_INIT_QUERY;

	if (unlock_needed == B_TRUE) {
		mutex_unlock(&un->io_mutex);
	}
	if (local_open) {
		(void) close(open_fd);
		DEC_OPEN(un);
	}
}
Exemple #17
0
/*
 * clean_3570 - attempt to load cleaning tape into 3570.
 */
void
clean_3570(
	drive_state_t *drive,
	robo_event_t *event,
	struct CatalogEntry *ce)
{
	int		retry;
	char	   *dev_name;
	char	   *d_mess = drive->un->dis_mes[DIS_MES_NORM];
	dev_ent_t	*un = drive->un;
	library_t	*library = drive->library;
	move_flags_t    move_flags;

	mutex_lock(&drive->mutex);
	move_flags.bits = 0;
	/*
	 * The 3570 does not return from the move until the cleaning cycle
	 * has completed.
	 */
	memccpy(d_mess, catgets(catfd, SET, 9030, "wait for cleaning cycle"),
	    '\0', DIS_MES_LEN);
	if (generic_get_media(library, drive, event, ce)) {
		memccpy(drive->un->dis_mes[DIS_MES_CRIT],
		    catgets(catfd, SET, 9029,
		    "unable to load cleaning cartridge, move failed"),
		    '\0', DIS_MES_LEN);

		DevLog(DL_ERR(5145), ce->CeSlot);
		down_drive(drive, SAM_STATE_CHANGE);
		drive->status.b.cln_inprog = FALSE;
		mutex_unlock(&drive->mutex);
		disp_of_event(library, event, EIO);
		return;
	}
	mutex_unlock(&drive->mutex);
	sleep(4);
	dev_name = samst_devname(un);
	mutex_lock(&un->mutex);
	drive->open_fd = open_unit(un, dev_name, 10);
	mutex_unlock(&un->mutex);
	free(dev_name);

	un->i.ViEq = un->fseq;
	un->i.ViSlot = un->slot;
	un->i.ViPart = 0;
	un->i.ViFlags = VI_cart;
	UpdateCatalog(drive->un, 0, CatalogVolumeLoaded);

	/* Wait for cleaning to finish */

	retry = 60;
	while (retry--) {
		sam_extended_sense_t *sense = (sam_extended_sense_t *)
		    SHM_REF_ADDR(un->sense);

		mutex_lock(&un->io_mutex);
		memset(sense, 0, sizeof (sam_extended_sense_t));
		if (scsi_cmd(drive->open_fd, un, SCMD_TEST_UNIT_READY, 20) ||
		    sense->es_key != 0) {
			/* If cleaning in progress */
			if (sense->es_key == 0x02 &&
			    sense->es_add_code == 0x30 &&
			    sense->es_qual_code == 0x03) {
				mutex_unlock(&un->io_mutex);
				sleep(30);
				continue;
			}
			if (sense->es_key == 0x06 &&
			    sense->es_add_code == 0x82 &&
			    sense->es_qual_code == 0x83)
				break;

			mutex_unlock(&un->io_mutex);
			sprintf(d_mess, "sense %x, %x, %x", sense->es_key,
			    sense->es_add_code, sense->es_qual_code);
			sleep(10);
		}
	}
	if (retry <= 0)
		DevLog(DL_ERR(5216));

	memccpy(d_mess, catgets(catfd, SET, 9034, "drive has been cleaned"),
	    '\0', DIS_MES_LEN);
	mutex_unlock(&un->io_mutex);
	mutex_lock(&un->mutex);
	close_unit(un, &drive->open_fd);
	mutex_unlock(&un->mutex);
	mutex_lock(&drive->mutex);
	move_flags.bits = 0;
	memccpy(d_mess,
	    catgets(catfd, SET, 9009, "waiting for media changer"),
	    '\0', DIS_MES_LEN);
	if (move_media(library, 0, drive->element, 0xff, 1, move_flags)) {
		memccpy(drive->un->dis_mes[DIS_MES_CRIT],
		    catgets(catfd, SET, 9032,
		    "unable to unload cleaning cartridge"),
		    '\0', DIS_MES_LEN);
		DevLog(DL_ERR(5147));
		drive->status.b.cln_inprog = FALSE;
		down_drive(drive, SAM_STATE_CHANGE);
		mutex_unlock(&drive->mutex);
		disp_of_event(library, event, EIO);
		return;
	}
	if (CatalogVolumeUnloaded(&un->i, "") == -1) {
		DevLog(DL_SYSERR(5336), ce->CeSlot);
	}
	drive->status.b.cln_inprog = FALSE;
	mutex_lock(&drive->un->mutex);
	drive->un->status.bits &= ~(DVST_CLEANING | DVST_REQUESTED);
	un->label_time = 0;
	mutex_unlock(&drive->un->mutex);
	mutex_unlock(&drive->mutex);
	disp_of_event(library, event, 0);
}
Exemple #18
0
void CTriggerTimerStop::StartTouch(CBaseEntity *pOther)
{
    CMomentumPlayer *pPlayer = ToCMOMPlayer(pOther);

    IGameEvent *stageEvent = nullptr;
    // If timer is already stopped, there's nothing to stop (No run state effect to play)
    if (pPlayer)
    {
        g_Timer->SetEndTrigger(this);
        if (g_Timer->IsRunning() && !pPlayer->IsWatchingReplay())
        {
            int zoneNum = pPlayer->m_RunData.m_iCurrentZone;

            // This is needed so we have an ending velocity.
			pPlayer->m_RunStats.SetZoneExitSpeed(zoneNum, pPlayer->GetLocalVelocity().Length(), pPlayer->GetLocalVelocity().Length2D());

            //Check to see if we should calculate the timer offset fix
            if (ContainsPosition(pPlayer->GetPrevOrigin()))
                DevLog("PrevOrigin inside of end trigger, not calculating offset!\n");
            else
            {
                DevLog("Previous origin is NOT inside the trigger, calculating offset...\n");
                g_Timer->CalculateTickIntervalOffset(pPlayer, g_Timer->ZONETYPE_END);
            }

            //This is needed for the final stage
            pPlayer->m_RunStats.SetZoneTime(zoneNum,
                g_Timer->GetCurrentTime() - 
                pPlayer->m_RunStats.GetZoneEnterTime(zoneNum));

            //Ending velocity checks
			float endvel = pPlayer->GetLocalVelocity().Length();
			float endvel2D = pPlayer->GetLocalVelocity().Length2D();

			float finalVel = endvel;
			float finalVel2D = endvel2D;

            if (endvel <= pPlayer->m_RunStats.GetZoneVelocityMax(0, false))
                finalVel = pPlayer->m_RunStats.GetZoneVelocityMax(0, false);

            if (endvel2D <= pPlayer->m_RunStats.GetZoneVelocityMax(0, true))
                finalVel2D = pPlayer->m_RunStats.GetZoneVelocityMax(0, true);

            pPlayer->m_RunStats.SetZoneVelocityMax(0, finalVel, finalVel2D);
            pPlayer->m_RunStats.SetZoneExitSpeed(0, endvel, endvel2D);

            //Stop the timer
            g_Timer->Stop(true);
            pPlayer->m_RunData.m_flRunTime = g_Timer->GetLastRunTime();
            //The map is now finished, show the mapfinished panel
            pPlayer->m_RunData.m_bMapFinished = true;
            pPlayer->m_RunData.m_bTimerRunning = false;
        }

        stageEvent = gameeventmanager->CreateEvent("zone_enter");
        
        pPlayer->m_RunData.m_bIsInZone = true;
    }
    else
    {
        CMomentumReplayGhostEntity *pGhost = dynamic_cast<CMomentumReplayGhostEntity*>(pOther);
        if (pGhost)
        {
            stageEvent = gameeventmanager->CreateEvent("zone_enter");
            pGhost->m_RunData.m_bMapFinished = true;
            pGhost->m_RunData.m_bTimerRunning = false;
            pGhost->m_RunData.m_bIsInZone = true;

            //Needed for hud_comparisons
            IGameEvent *timerStateEvent = gameeventmanager->CreateEvent("timer_state");
            if (timerStateEvent)
            {
                timerStateEvent->SetInt("ent", pGhost->entindex());
                timerStateEvent->SetBool("is_running", false);

                gameeventmanager->FireEvent(timerStateEvent);
            }
            pGhost->StopTimer();
            //MOM_TODO: Maybe play effects if the player is racing against us and lost?
        }
    }

    //Used by speedometer
    if (stageEvent)
    {
        gameeventmanager->FireEvent(stageEvent);
    }

    BaseClass::StartTouch(pOther);
}
Exemple #19
0
/*
 *	init_elements - get status for all elements in the library.
 *
 * exit -
 */
int				/* 0 = all ok !0 = failure */
init_elements(
		library_t *library)
{
	uint16_t	count, start_element;
	uint16_t	avail_drives;
	int		i, err, conlevel = 5;
	size_t	  retry;
	dev_ent_t	*un;
	char	   *drv_tbl;
	mode_sense_t   *mode_sense;
	drive_state_t  *drive;
	xport_state_t  *xport;
	iport_state_t  *import;
	robot_ms_page1d_t *pg1d = NULL;
	robot_ms_page1e_t *pg1e = NULL;
	robot_ms_page1f_t *pg1f = NULL;
	sam_extended_sense_t *sense;

	SANITY_CHECK(library != (library_t *)0);
	un = library->un;
	SANITY_CHECK(un != (dev_ent_t *)0);

	/* Put mode sense data into shared memory. */

	/* LINTED pointer cast may result in improper alignment */
	mode_sense = (mode_sense_t *)SHM_REF_ADDR(un->mode_sense);
	sense = (sam_extended_sense_t *)SHM_REF_ADDR(un->sense);
	SANITY_CHECK(mode_sense != (mode_sense_t *)0);
	SANITY_CHECK(sense != (sam_extended_sense_t *)0);
	(void) memset(mode_sense, 0, sizeof (mode_sense_t));

	mutex_lock(&un->io_mutex);
	pg1d = (robot_ms_page1d_t *)lib_mode_sense(library, 0x1d,
	    (uchar_t *)& mode_sense->u.robot_ms.pg1d,
	    sizeof (robot_ms_page1d_t));
	pg1f = (robot_ms_page1f_t *)lib_mode_sense(library, 0x1f,
	    (uchar_t *)& mode_sense->u.robot_ms.pg1f,
	    sizeof (robot_ms_page1f_t));
	pg1e = (robot_ms_page1e_t *)lib_mode_sense(library, 0x1e,
	    (uchar_t *)& mode_sense->u.robot_ms.pg1e,
	    sizeof (robot_ms_page1e_t));
	mutex_unlock(&un->io_mutex);

	if (pg1d == NULL || pg1f == NULL || pg1e == NULL) {
		DevLog(DL_ERR(5115));
		return (1);
	}
	library->status.b.two_sided = pg1e->transport_sets[0].rotate;
	if (un->type == DT_CYGNET)
		library->status.b.two_sided = 0;

	/* Allocate the drive tables. */
	BE16toH(&pg1d->first_drive, &start_element);
	BE16toH(&pg1d->num_drive, &count);
	library->range.drives_lower = start_element;
	library->range.drives_count = count;
	library->range.drives_upper = start_element + count - 1;

	/*
	 * This code is currently applied to IBM3584 only since the IBM3584
	 * returns a valid status if drive unit is not installed in a
	 * library. ASC/ASCQ:0x82/0x00. May need to add other library types
	 * to this check, check scsi docs.
	 *
	 * If drive is not fully populated and there is an empty slot for the
	 * drive, we don't need to create a redundant drive_thread.
	 */
	avail_drives = count;
	drv_tbl = malloc_wait(count, 2, 0);
	(void) memset(drv_tbl, TRUE, count);
	if (DT_IBM3584 == un->type)
		if ((avail_drives =
		    (uint16_t)populate_drives(library, drv_tbl)) == 0) {
			/*
			 * No drives installed, assum fully populated.
			 */
			DevLog(DL_ERR(5361));
			avail_drives = count;
			(void) memset(drv_tbl, TRUE, count);
		} else if (avail_drives > count) {
			avail_drives = count;
		}
	DevLog(DL_DETAIL(5362), avail_drives);

	/* one for the drive, one for stage and one for the stage helper */
	conlevel += (avail_drives * 3);

	library->drive = (drive_state_t *)malloc_wait(
	    sizeof (drive_state_t), 5, 0);
	library->index = library->drive;
	(void) memset(library->drive, 0, sizeof (drive_state_t));

	/*
	 * For each drive, build the drive state structure, put the init
	 * request on the list and start a thread with a new lwp.
	 */
	for (drive = library->drive, i = 0;
	    i < (int)count && avail_drives > 0; i++) {

		if (drv_tbl[i] == FALSE) {
			continue;
		}
		/* assign element number */
		drive->element = start_element + i;
		drive->library = library;
		/* hold the lock until ready */
		mutex_lock(&drive->mutex);
		drive->new_slot = ROBOT_NO_SLOT;
		drive->open_fd = -1;
		drive->active_count = 1;
		drive->first = (robo_event_t *)malloc_wait(
		    sizeof (robo_event_t), 5, 0);
		(void) memset(drive->first, 0, sizeof (robo_event_t));
		drive->first->type = EVENT_TYPE_INTERNAL;
		drive->first->status.bits = REST_FREEMEM;
		drive->first->request.internal.command = ROBOT_INTRL_INIT;
		if (thr_create(NULL, MD_THR_STK, &drive_thread, (void *) drive,
		    (THR_NEW_LWP | THR_BOUND | THR_DETACHED),
		    &drive->thread)) {
			DevLog(DL_SYSERR(5116));
			drive->status.b.offline = TRUE;
			drive->thread = (thread_t)- 1;
		}
		if (--avail_drives <= 0) {
			break;
		} else {
			/* Allocate next entry */
			drive->next = (drive_state_t *)malloc_wait(
			    sizeof (drive_state_t), 5, 0);
			(void) memset(drive->next, 0, sizeof (drive_state_t));
			drive->next->previous = drive;	/* set back link */
			drive = drive->next;
		}
	}

	drive->next = NULL;	/* no next drive */
	library->drive->previous = NULL;	/* no previous drive */
	free(drv_tbl);

	/* Allocate transport tables */

	BE16toH(&pg1d->first_tport, &start_element);
	BE16toH(&pg1d->num_tport, &count);
	library->range.transport_lower = start_element;
	library->range.transport_count = count;
	library->range.transport_upper = start_element + count - 1;
	library->range.default_transport = 0;
	library->page1f = pg1f;
	conlevel += count;
	library->transports =
	    (xport_state_t *)malloc_wait(sizeof (xport_state_t), 5, 0);
	(void) memset(library->transports, 0, sizeof (xport_state_t));

	for (xport = library->transports, i = 0; i < (int)count; i++) {
		/* assign element number */
		xport->element = start_element + i;
		xport->library = library;

		mutex_lock(&xport->mutex);
		/* start only one transport thread */
		if (i == 0) {
			xport->first =
			    (robo_event_t *)malloc_wait(
			    sizeof (robo_event_t), 5, 0);
			(void) memset(xport->first, 0, sizeof (robo_event_t));
			xport->first->type = EVENT_TYPE_INTERNAL;
			xport->first->status.bits = REST_FREEMEM;
			xport->first->request.internal.command =
			    ROBOT_INTRL_INIT;
			xport->active_count = 1;

			if (thr_create(NULL, SM_THR_STK,
			    &transport_thread, (void *) xport,
			    (THR_NEW_LWP | THR_BOUND | THR_DETACHED),
			    &xport->thread)) {
				DevLog(DL_SYSERR(5117));
				xport->thread = (thread_t)- 1;
			}
		}
		/* Allocate next entry */
		if (i != (count - 1)) {
			xport->next = (xport_state_t *)malloc_wait(
			    sizeof (xport_state_t), 5, 0);
			(void) memset(xport->next, 0, sizeof (xport_state_t));
			xport->next->previous = xport;	/* set back link */
			xport = xport->next;
		}
	}

	/* for the metrum d-360 the last transport is used with import export */
	xport->next = NULL;	/* no next transport */
	library->transports->previous = NULL;

	/* Allocate mailbox (import/export) tables */

	BE16toH(&pg1d->first_mail, &start_element);
	BE16toH(&pg1d->num_mail, &count);
	library->range.ie_lower = start_element;
	library->range.ie_count = count;
	if (count != 0)
		library->range.ie_upper = start_element + count - 1;
	else
		library->range.ie_upper = 0;

	conlevel += 1;		/* only one import/export thread */
	library->import = (iport_state_t *)malloc_wait(
	    sizeof (iport_state_t), 5, 0);
	(void) memset(library->import, 0, sizeof (iport_state_t));

	/* store the transport used in import/export for the metrum D-360 */
	if (un->type == DT_METD28)
		library->import->xport = xport;

	for (import = library->import, i = 0; i < (int)count; i++) {
		SANITY_CHECK(import != (iport_state_t *)0);
		/* assign element number */
		import->element = start_element + i;
		import->library = library;

		mutex_lock(&import->mutex);
		/* Create only one mailbox thread */
		if (i == 0) {
			import->active_count = 1;
			import->first = (robo_event_t *)malloc_wait(
			    sizeof (robo_event_t), 5, 0);
			(void) memset(import->first, 0, sizeof (robo_event_t));
			import->first->type = EVENT_TYPE_INTERNAL;
			import->first->status.bits = REST_FREEMEM;
			import->first->request.internal.command =
			    ROBOT_INTRL_INIT;
			if (thr_create(NULL, SM_THR_STK,
			    &import_thread, (void *) import,
			    (THR_DETACHED | THR_BOUND | THR_NEW_LWP),
			    &import->thread)) {
				DevLog(DL_SYSERR(5118));
				import->thread = (thread_t)- 1;
			}
		}
		if (i != (count - 1)) {	/* Allocate next entry */
			import->next = (iport_state_t *)malloc_wait(
			    sizeof (iport_state_t), 5, 0);
			(void) memset(import->next, 0, sizeof (iport_state_t));
			/* set back link */
			import->next->previous = import;
			import = import->next;
		}
	}

	import->next = NULL;	/* no next mailbox */
	SANITY_CHECK(library->import != (iport_state_t *)0);
	library->import->previous = NULL;

	/* allocate the audit table if needed */

	BE16toH(&pg1d->first_stor, &start_element);
	BE16toH(&pg1d->num_stor, &count);
	library->range.storage_lower = start_element;
	library->range.storage_count = count;
	library->range.storage_upper = start_element + count - 1;

	/* add for the import/export door slots */
	if (un->type == DT_ACL452)
		count += library->range.ie_count;

	DevLog(DL_DETAIL(5220), library->range.drives_count,
	    library->range.transport_count, library->range.storage_count,
	    library->range.ie_count);

	if (thr_setconcurrency(conlevel)) {
		DevLog(DL_SYSERR(5058));
	}
	/*
	 * If the audit table is the wrong length (based on the number of
	 * storage elements returned by mode-sense) or the audit bit is set,
	 * the set up for an audit.
	 */
	if ((library->audit_tab_len == 0) || un->status.b.audit) {
		int		added_more_time = FALSE;
		char	   *l_mess = un->dis_mes[DIS_MES_NORM];

		/*
		 * Audit table does not exist or is the wrong length.  This
		 * is generally a bad thing and  will force an initialize
		 * element scsi command and an audit. Both of these take a
		 * long time.
		 */
		/* tell the outside world */
		un->status.b.audit = TRUE;
		memccpy(l_mess, catgets(catfd, SET, 9022,
		    "initializing elements"),
		    '\0', DIS_MES_LEN);

		mutex_lock(&un->io_mutex);
		retry = 2;
		do {
			/*
			 * Allow 16 seconds for each storage element and 30
			 * seconds of slop.
			 */
			(void) memset(sense, 0, sizeof (sam_extended_sense_t));
			if ((err = scsi_cmd(library->open_fd, un,
			    SCMD_INIT_ELEMENT_STATUS,
			    (count << 4) + 30)) < 0) {
			TAPEALERT_SKEY(library->open_fd, un);
			GENERIC_SCSI_ERROR_PROCESSING(un,
			    library->scsi_err_tab, 0,
			    err, added_more_time, retry,
				/* code for DOWN_EQU */
			    down_library(library, SAM_STATE_CHANGE);
				mutex_unlock(&un->io_mutex);
				return (-1);
				/* MACRO for cstyle */,
				/* code for ILLREQ */
				    mutex_unlock(&un->io_mutex);
				return (-1);
				/* MACRO for cstyle */,
Exemple #20
0
/*
 *	move - move from one element to another
 *
 *	entry -
 *	   library - library_t *
 *	   event - robo_event_t *
 */
int
move(
    library_t *library,
    robo_event_t *event)
{
    dev_ent_t 	*un;
    int 		err = -1, retry, timeout;
    char 		*l_mess = library->un->dis_mes[DIS_MES_NORM];
    char 		*MES_9079 =
        catgets(catfd, SET, 9079, "move from %s to %s %s");
    char 		*mess, *src_mess, *des_mess, *i_mess;
    robot_internal_t 	*cmd = &event->request.internal;
    int 		added_more_time = FALSE;
    sam_extended_sense_t *sense = (sam_extended_sense_t *)
                                  SHM_REF_ADDR(library->un->sense);
    int		movmed_err;

    un = library->un;
    src_mess = element_string(element_type(library, cmd->source));
    des_mess = element_string(element_type(library, cmd->destination1));
    if (cmd->flags.b.invert1)
        i_mess = catgets(catfd, SET, 9084, "invert");
    else
        i_mess = "";

    mess = (char *)malloc_wait(strlen(MES_9079) + strlen(src_mess) +
                               strlen(des_mess) + strlen(i_mess) + 10, 4, 0);
    sprintf(mess, MES_9079, src_mess, des_mess, i_mess);
    memccpy(l_mess, mess, '\0', DIS_MES_LEN);
    free(mess);
    DevLog(DL_DETAIL(5057),
           cmd->source, cmd->flags.b.invert1 ? "invert" : "asis",
           cmd->destination1);

    /*
     * A programming note from DocStore states that you should
     * allow up to 4 minutes for a move.  This is to allow
     * for recovery and retry by the robot.	 If other robots need
     * different time outs, this is the place to put um.
     */
    switch (library->un->type) {
    case DT_DLT2700:
        timeout = 300;
        break;

    case DT_DOCSTOR:
        timeout = 4 * 60;
        break;

    case DT_METD28:
    /* FALLTHROUGH */
    case DT_METD360:
    /* FALLTHROUGH */
    case DT_SPECLOG:
    /* FALLTHROUGH */
    case DT_ATL1500:
    /* FALLTHROUGH */
    case DT_ODI_NEO:
    /* FALLTHROUGH */
    case DT_QUANTUMC4:
    /* FALLTHROUGH */
    case DT_STK97XX:
    /* FALLTHROUGH */
    case DT_FJNMXX:
    /* FALLTHROUGH */
    case DT_SL3000:
    /* FALLTHROUGH */
    case DT_SLPYTHON:
        timeout = 10 * 60;
        break;

    default:
        timeout = 5 * 60;
        break;
    }

    mutex_lock(&library->un->io_mutex);
    retry = 2;
    do {
        time_t start;

        TAPEALERT(library->open_fd, library->un);
        memset(sense, 0, sizeof (sam_extended_sense_t));
        start = time(NULL);
        movmed_err = scsi_cmd(library->open_fd, library->un,
                              SCMD_MOVE_MEDIUM, timeout,
                              cmd->transport, cmd->source, cmd->destination1,
                              (cmd->flags.b.invert1 ? 1 : 0));
        TAPEALERT(library->open_fd, library->un);
        if (movmed_err < 0) {
            DevLog(DL_TIME(5177), cmd->source,
                   cmd->flags.b.invert1 ? "invert" : "asis",
                   cmd->destination1, time(NULL) - start);

            GENERIC_SCSI_ERROR_PROCESSING(library->un,
                                          library->scsi_err_tab, 0,
                                          err, added_more_time, retry,
                                          /* code for DOWN_EQU */
            if (!cmd->flags.b.noerror) {
            err = DOWN_EQU;
            if (sense->es_add_code == 0x40 &&
                        sense->es_qual_code == 0x02) {
                    move_drive_error(library, cmd->source,
                                     cmd->destination1, &err);
                } else {
                    down_library(library, SAM_STATE_CHANGE);
                }
                retry = 1;
                /* MACRO for cstyle */
            }
            break;
            /* MACRO for cstyle */,
Exemple #21
0
void CMomentumPlayer::DisableAutoBhop()
{
    m_bAutoBhop = false;
    DevLog("Disabled autobhop\n");
}
Exemple #22
0
void CMomentumPlayer::EnableAutoBhop()
{
    m_bAutoBhop = true;
    DevLog("Enabled autobhop\n");
}
Exemple #23
0
/*
 *	Main thread.  Sits on the message queue and waits for something to do.
 */
void *
transport_thread(
    void *vxport)
{
    int 		exit_status = 0, err;
    robo_event_t 	*event;
    xport_state_t 	*transport = (xport_state_t *)vxport;
    int 		is_api = IS_GENERIC_API(transport->library->un->type);
    dev_ent_t 	*un = transport->library->un;

    mutex_lock(&transport->mutex);	/* wait for go */
    mutex_unlock(&transport->mutex);

    for (;;) {
        mutex_lock(&transport->list_mutex);
        if (transport->active_count == 0)
            cond_wait(&transport->list_condit,
                      &transport->list_mutex);

        if (transport->active_count == 0) {	/* check to make sure */
            mutex_unlock(&transport->list_mutex);
            continue;
        }
        event = transport->first;
        transport->first = unlink_list(event);
        transport->active_count--;
        mutex_unlock(&transport->list_mutex);
        ETRACE((LOG_NOTICE, "EvTr %#x(%#x) -",
                event, (event->type == EVENT_TYPE_MESS) ?
                event->request.message.command :
                event->request.internal.command));
        err = 0;

        switch (event->type) {
        case EVENT_TYPE_INTERNAL:
            switch (event->request.internal.command) {
            case ROBOT_INTRL_MOVE_MEDIA:
                if (is_api == TRUE) {
                    err = EINVAL;
                    break;
                } else {
                    if (un->state <= DEV_IDLE) {
                        err = move(transport->library,
                                   event);
                    } else {
                        err = EINVAL;
                    }
                }
                break;

            case ROBOT_INTRL_EXCH_MEDIA:
                if (is_api == TRUE) {
                    err = EINVAL;
                    break;
                } else {
                    if (un->state <= DEV_IDLE) {
                        err = exchange(
                                  transport->library, event);
                    } else {
                        err = EINVAL;
                    }
                }
                break;

            case ROBOT_INTRL_INIT:
                init_transport(transport);
                if (is_api == TRUE) {
                    disp_of_event(transport->library,
                                  event, 0);
                }
                break;

            case ROBOT_INTRL_SHUTDOWN:
                transport->thread = (thread_t)- 1;
                thr_exit(&exit_status);
                break;

            case ROBOT_INTRL_LOAD_MEDIA:
                if (is_api == FALSE) {
                    err = EINVAL;
                    break;
                }
                event->next = (robo_event_t *)
                              transport->library;
                err = thr_create(NULL, MD_THR_STK,
                                 api_load_command,
                                 (void *)event, THR_DETACHED, NULL);
                if (err)
                    DevLog(DL_ERR(6038),
                           event->request.internal.command,
                           err);
                break;

            case ROBOT_INTRL_FORCE_MEDIA:
                if (is_api == FALSE) {
                    err = EINVAL;
                    break;
                }
                event->next = (robo_event_t *)
                              transport->library;
                err = thr_create(NULL, MD_THR_STK,
                                 api_force_command,
                                 (void *)event, THR_DETACHED, NULL);
                if (err)
                    DevLog(DL_ERR(6038),
                           event->request.internal.command,
                           err);
                break;

            case ROBOT_INTRL_DISMOUNT_MEDIA:
                if (is_api == FALSE) {
                    err = EINVAL;
                    break;
                }
                event->next = (robo_event_t *)
                              transport->library;
                err = thr_create(NULL, MD_THR_STK,
                                 api_dismount_command,
                                 (void *)event, THR_DETACHED, NULL);
                if (err)
                    DevLog(DL_ERR(6038),
                           event->request.internal.command,
                           err);
                break;

            case ROBOT_INTRL_VIEW_DATABASE:
                if (is_api == FALSE) {
                    err = EINVAL;
                    break;
                }
                event->next = (robo_event_t *)
                              transport->library;
                err = thr_create(NULL, MD_THR_STK,
                                 api_view_command,
                                 (void *)event, THR_DETACHED, NULL);
                if (err)
                    DevLog(DL_ERR(6038),
                           event->request.internal.command,
                           err);
                break;

            case ROBOT_INTRL_DRIVE_ACCESS:
                if (is_api == FALSE) {
                    err = EINVAL;
                    break;
                }
                event->next = (robo_event_t *)
                              transport->library;
                err = thr_create(NULL, MD_THR_STK,
                                 api_drive_access_command,
                                 (void *)event, THR_DETACHED, NULL);
                if (err)
                    DevLog(DL_ERR(6038),
                           event->request.internal.command,
                           err);
                break;

            case ROBOT_INTRL_QUERY_DRIVE:
                if (is_api == FALSE) {
                    err = EINVAL;
                    break;
                }
                event->next = (robo_event_t *)
                              transport->library;
                err = thr_create(NULL, MD_THR_STK,
                                 api_query_drive_command,
                                 (void *)event, THR_DETACHED, NULL);
                if (err)
                    DevLog(DL_ERR(6038),
                           event->request.internal.command,
                           err);
                break;

            case ROBOT_INTRL_GET_SIDE_INFO:
                if (is_api == FALSE) {
                    err = EINVAL;
                    break;
                }
                event->next = (robo_event_t *)
                              transport->library;
                err = thr_create(NULL, MD_THR_STK,
                                 api_getsideinfo_command,
                                 (void *)event, THR_DETACHED, NULL);
                if (err)
                    DevLog(DL_ERR(6038),
                           event->request.internal.command,
                           err);
                break;

            default:
                err = EINVAL;
                break;
            }
            break;

        case EVENT_TYPE_MESS:
            if (event->request.message.magic != MESSAGE_MAGIC) {
                if (DBG_LVL(SAM_DBG_DEBUG))
                    sam_syslog(LOG_DEBUG,
                               "xpt_thr:bad magic: %s:%d.",
                               __FILE__, __LINE__);
                break;
            }
            switch (event->request.message.command) {
            default:
                if (DBG_LVL(SAM_DBG_DEBUG))
                    sam_syslog(LOG_DEBUG,
                               "xpt_thr:msq_bad: %s:%d.",
                               __FILE__, __LINE__);
                err = EINVAL;
                break;
            }

        default:
            if (DBG_LVL(SAM_DBG_DEBUG))
                sam_syslog(LOG_DEBUG,
                           "xpt_thr:event_bad: %s:%d.",
                           __FILE__, __LINE__);
            err = EINVAL;
            break;
        }
        if (is_api == FALSE) {
            disp_of_event(transport->library, event, err);
        } else if (err) {
            /* call disp_of_event only if an error on grau */
            if (err < 0)
                err = errno;
            disp_of_event(transport->library, event, err);
        }
    }
}
Exemple #24
0
/*
 * -- tapealert - tapealert log sense page 0x2e processing
 * Process media changer or tape drive request for tapealert log sense
 * page 0x2e.  An active tapealert never interferes with data
 * transfers.  Active tapealert flags are written to the device log and
 * real-time notification is by a posted tapealert sysevent.  See
 * www.t10.org SSC-2 and SMC-2 for additional tapealert information.
 */
int			/* 0 successful */
tapealert(
	char *src_fn,		/* source filename */
	int src_ln,		/* source file line number */
	int fd,			/* device file descriptor */
	dev_ent_t *un,		/* device */
	uchar_t *logpage,	/* existing tapealert log sense page */
	int logpage_len)	/* existing tapealert log sense page length */
{
#define	CLEAN_NOW		0x80000
#define	CLEAN_PERIODIC		0x100000
#define	EXPIRED_CLEANING_MEDIA	0x200000
#define	INVALID_CLEANING_MEDIA	0x400000
#define	STK_CLEAN_REQUESTED	0x800000
	int			rtn = 1;
	uchar_t			*page;
	uchar_t			*log_param;
#define		PAGE_LEN 256
	uchar_t			tmp_page [PAGE_LEN];
	int 			resid;
	int 			i;
	int			j;
	int			page_len;
	int			param_len;
	int			param_code;
	int 			add_page_len;
	sam_extended_sense_t	*sense;
	sam_extended_sense_t	saved_sense;
	uchar_t			saved_cdb [16];
#define		FLAGS_LEN 64
	int			flags_len;
	uint64_t		flags;
	uchar_t			val;
	int			save_errno = errno;
	uint64_t		seq_no = 0;
	int			supported;
	int			enabled;
	int			init_query;
	int			required;
	int 			requested;
	int			expired;
	int			invalid;


	supported = un->tapealert & TAPEALERT_SUPPORTED;
	enabled = un->tapealert & TAPEALERT_ENABLED;
	init_query = un->tapealert & TAPEALERT_INIT_QUERY;
	if (!(supported && (enabled || init_query))) {
		return (0);
	}

	/*
	 * get device sense pointer.
	 */
	sense = (sam_extended_sense_t *)SHM_REF_ADDR(un->sense);

	/*
	 * Second, process tapealert log sense page.
	 */
	if (logpage == NULL || logpage_len < 4) {
		/* save callers previous cdb and sense */
		memcpy(saved_cdb, un->cdb, SAM_CDB_LENGTH);
		memcpy(&saved_sense, sense, sizeof (sam_extended_sense_t));
		if (scsi_cmd(fd, un, SCMD_LOG_SENSE, 0, tmp_page, 0,
		    0x2e, 0, PAGE_LEN, &resid) < 0) {
			DevLog(DL_DEBUG(12002), sense->es_key,
			    sense->es_add_code, sense->es_qual_code);
			memcpy(un->cdb, saved_cdb, SAM_CDB_LENGTH);
			memcpy(sense, &saved_sense,
			    sizeof (sam_extended_sense_t));
			goto cleanup;
		}
		/* restore callers previous cdb and sense */
		memcpy(un->cdb, saved_cdb, SAM_CDB_LENGTH);
		memcpy(sense, &saved_sense, sizeof (sam_extended_sense_t));

		page = tmp_page;
		page_len = PAGE_LEN - resid;
	} else {
		page = logpage;
		page_len = logpage_len;
	}

	if (page_len < 4) {
		DevLog(DL_DEBUG(12003), page_len);
		goto cleanup;
	}

	if (page [0] != 0x2e) {
		DevLog(DL_DEBUG(12004), page [0]);
		goto cleanup;
	}

	add_page_len = (page [2] << 8) | page [3];
	add_page_len &= 0xffff;
	log_param = page + 4;

	flags = 0;
	flags_len = 0;
	for (i = 0, j = 0; i < FLAGS_LEN && j < add_page_len; i++, j += 5) {

		param_code = (log_param [j] << 8) | log_param [j + 1];
		if (param_code != (i + 1)) {
			if (flags != 0) break;
			goto cleanup;
		}

		param_len = log_param [j + 3];
		param_len &= 0xff;
		if (param_len == 1) {
			val = log_param [j + 4];
			if (i < 64 && val != 0) {
				flags |= ((uint64_t)1 << i);
			}
		} else {
			/*
			 * vendor unique flag length value, quit
			 * processing flags
			 */
			break;
		}

		/*
		 * increment number of valid TapeAlert flags
		 * contained in the 64 bit wide flags variable
		 */
		flags_len++;
	}

	/* check for in-active or already seen */
	if (flags == 0 || (flags == un->tapealert_flags &&
	    strcmp(un->tapealert_vsn, un->vsn) == 0)) {
		rtn = 0;
		goto cleanup;
	}

	/* build active flags filter by vsn */
	if (strcmp(un->tapealert_vsn, un->vsn) == 0) {
		/* check for already seen */
		if ((flags & ~un->tapealert_flags) == 0) {
			rtn = 0;
			goto cleanup;
		}
		/* current vsn, add active flag(s) to filter */
		un->tapealert_flags |= flags;
	} else {
		/* new vsn, initialize flags filter */
		un->tapealert_flags = flags;
	}
	strcpy(un->tapealert_vsn, un->vsn);

	/*
	 * send tapealert sysevent
	 */
	rtn = tapealert_sysevent(src_fn, src_ln, un, flags_len, flags, &seq_no);

	/*
	 * log active flags
	 *
	 * seq_no is zero when sysevent not sent.
	 */
	if (strlen(un->vsn) > 0) {
		DevLog(DL_ALL(12007), un->version, un->eq, un->scsi_type,
		    seq_no, flags_len, flags, un->vsn);
	} else {
		DevLog(DL_ALL(12006), un->version, un->eq, un->scsi_type,
		    seq_no, flags_len, flags);
	}

	if ((un->tapeclean & TAPECLEAN_AUTOCLEAN) &&
	    (un->tapeclean & TAPECLEAN_LOGSENSE)) {
		required = (flags & CLEAN_NOW) ? 1 : 0;
		requested = (flags & CLEAN_PERIODIC) ? 1 : 0;
		expired = (flags & EXPIRED_CLEANING_MEDIA) ? 1 : 0;
		invalid = (flags & INVALID_CLEANING_MEDIA) ? 1 : 0;
		if (un->equ_type == DT_9840 ||
		    un->equ_type == DT_9940 || un->equ_type == DT_TITAN) {
			requested = (flags & STK_CLEAN_REQUESTED) ? 1 : 0;
		}

		/* Map active TapeAlert flags onto SAM-FS status. */
		tapeclean_active(un, required, requested, expired, invalid);
	}

cleanup:

	/*
	 * restore callers errno state
	 */
	errno = save_errno;
	return (rtn);
}
Exemple #25
0
/* --- tapealert_sysevent - send a tapealert sysevent to n event handlers */
static int		/* 0 successful */
tapealert_sysevent(
	char *src_fn,		/* source filename */
	int src_ln,		/* source file line number */
	dev_ent_t *un,		/* device */
	int flags_len,		/* num valid tapealert flags */
	uint64_t flags,		/* tapealert flags */
	uint64_t *seq_no)	/* sysevent sequence number */
{
	int			rtn = 1;
	time_t			tm;
	nvlist_t		*attr_list = NULL;
	sysevent_id_t		eid;
	boolean_t		free_attr_list = B_FALSE;
	char			*str;

	*seq_no = 0;


	/*
	 * build and send sysevent with active tapealert flags
	 */
	if (nvlist_alloc(&attr_list, 0, 0)) {
		DevLog(DL_DEBUG(12008), "alloc", strerror(errno));
		goto done;
	}
	free_attr_list = B_TRUE;

#ifdef DEBUG
	if (nvlist_add_string(attr_list, TAPEALERT_SRC_FILE, src_fn)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_SRC_FILE, strerror(errno));
		goto done;
	}
	if (nvlist_add_int32(attr_list, TAPEALERT_SRC_LINE, src_ln)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_SRC_LINE, strerror(errno));
		goto done;
	}
#endif /* DEBUG */
	if (nvlist_add_string(attr_list, TAPEALERT_VENDOR,
	    (char *)un->vendor_id)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_VENDOR, strerror(errno));
		goto done;
	}
	if (nvlist_add_string(attr_list, TAPEALERT_PRODUCT,
	    (char *)un->product_id)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_PRODUCT, strerror(errno));
		goto done;
	}
	if (nvlist_add_string(attr_list, TAPEALERT_USN, (char *)un->serial)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_USN, strerror(errno));
		goto done;
	}
	if (nvlist_add_string(attr_list, TAPEALERT_REV, (char *)un->revision)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_REV, strerror(errno));
		goto done;
	}
	time(&tm);
	if (nvlist_add_int32(attr_list, TAPEALERT_TOD, tm)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_TOD, strerror(errno));
		goto done;
	}
	if (nvlist_add_int16(attr_list, TAPEALERT_EQ_ORD, un->eq)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_EQ_ORD, strerror(errno));
		goto done;
	}
	if (nvlist_add_string(attr_list, TAPEALERT_NAME, un->name)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_NAME, strerror(errno));
		goto done;
	}
	if (nvlist_add_byte(attr_list, TAPEALERT_VERSION, un->version)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_VERSION, strerror(errno));
		goto done;
	}
	if (nvlist_add_byte(attr_list, TAPEALERT_INQ_TYPE, un->scsi_type)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_INQ_TYPE, strerror(errno));
		goto done;
	}
	if (strlen(str = (char *)un->set) < 1) {
		str = TAPEALERT_EMPTY_STR;
	}
	if (nvlist_add_string(attr_list, TAPEALERT_SET, str)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_SET, strerror(errno));
		goto done;
	}
	if (nvlist_add_int16(attr_list, TAPEALERT_FSEQ, un->fseq)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_FSEQ, strerror(errno));
		goto done;
	}
	if (strlen(str = (char *)un->vsn) < 1) {
		str = TAPEALERT_EMPTY_STR;
	}
	if (nvlist_add_string(attr_list, TAPEALERT_VSN, str)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_VSN, strerror(errno));
		goto done;
	}
	if (nvlist_add_int16(attr_list, TAPEALERT_FLAGS_LEN, flags_len)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_FLAGS_LEN, strerror(errno));
		goto done;
	}
	if (nvlist_add_uint64(attr_list, TAPEALERT_FLAGS, flags)) {
		DevLog(DL_DEBUG(12008), TAPEALERT_FLAGS,
		    strerror(errno));
		goto done;
	}

	/* class, subclass, vendor, publisher, attribute list, event id */
	if (sysevent_post_event(TAPEALERT_SE_CLASS, TAPEALERT_SE_SUBCLASS,
	    TAPEALERT_SE_VENDOR, TAPEALERT_SE_PUBLISHER, attr_list, &eid)
	    != 0) {
		DevLog(DL_DEBUG(12008), TAPEALERT_SE_PUBLISHER,
		    strerror(errno));
		goto done;
	}
	*seq_no = eid.eid_seq;

	/*
	 * tapealert sysevent successfully sent.
	 */
	rtn = 0;

done:
	if (free_attr_list == B_TRUE) {
		nvlist_free(attr_list);
	}

	return (rtn);
}
Exemple #26
0
int main(int argc, char *argv[ ]){
	ClearPrints();
	chdir(CombineStrings("/home/", GetUser()));
	DelFile(output_log);
	DebugLog("--- Begin Android Dev Tools ARGS");
	for(tick = 1; tick < argc; tick++) DebugLog(CombineStrings("ARG: ", argv[tick]));
	DebugLog("");
	DebugLog("--- Begin Android Dev Tools");
	CmdOut("aDev_adb devices > tmp.txt");
	if(IsFileEmpty("tmp.txt")){
		ClearPrints();
		PrintText("--- Proprietary Files Not Found! ---");
		PrintText("Run: \'aDev config\'");
		LineSkip();
		exit(-1);		
	}
	DelFile("tmp.txt");
	if(argc <= 1){
		PrintText("--- Invalid parameters! ---");
		PrintText("Run: \'aDev --help\'");
		LineSkip();
		exit(-1);
	}
	for(tick = 1; tick < argc; tick++){
		if(IsStringEmpty(argv[tick])) continue;
		if(CompareStrings(argv[tick], "--help") || CompareStrings(argv[tick], "-h")){
			PrintHelp();
			exit(0);
		}
		if(CompareStrings(argv[tick], "--version") || CompareStrings(argv[tick], "-v")){
			PrintVersion();
			exit(0);
		}
		else if(CompareStrings(argv[tick], "test")){
			PrintText("aDev was properly installed, enjoy!");
			LineSkip();
			exit(0);
		}
		else if(CompareStrings(argv[tick], "logcat")){
			DevLog(1);
			exit(0);
		}
		else if(CompareStrings(argv[tick], "dmesg")){
			DevLog(2);
			exit(0);
		}
		else if(CompareStrings(argv[tick], "kmsg")){
			DevLog(3);
			exit(0);
		}
		else if(CompareStrings(argv[tick], "screenshot")){
			ScreenShot();
			exit(0);
		}
		else if(CompareStrings(argv[tick], "info")){
			Info();
			exit(0);
		}
		else if(CompareStrings(argv[tick], "adb")){
			text = "aDev_adb ";
			for(tick2 = 1; tick2 < argc; tick2++) if(!CompareStrings(argv[tick2], "adb")) text = CombineStrings(text, CombineStrings(argv[tick2], " "));
			CmdOut(text);
			exit(0);
		}
		else if(CompareStrings(argv[tick], "fastboot")){
			text = "aDev_fastboot ";
			for(tick2 = 1; tick2 < argc; tick2++) if(!CompareStrings(argv[tick2], "fastboot")) text = CombineStrings(text, CombineStrings(argv[tick2], " "));
			CmdOut(text);
			exit(0);
		}
		else{
			for(tick2 = (argc - 1); tick2 < 0; tick2--){
				if(!IsValidArg(argv[tick2])) break;
				if(tick2 == 1) quit();
			}
			if(IsValidArg(argv[tick2])) tick2--;
			if(IsValidArg(argv[tick2])) quit();
			PrintText(CombineStrings("Unknown Parameter: ", argv[tick2]));
			quit();
		}
	}
	return 0;
}