本文整理汇总了C++中wrap函数的典型用法代码示例。如果您正苦于以下问题:C++ wrap函数的具体用法?C++ wrap怎么用?C++ wrap使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wrap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dnssock
dnssock_udp::dnssock_udp (int f, cb_t cb)
: dnssock (false, cb), fd (f)
{
fdcb (fd, selread, wrap (this, &dnssock_udp::rcb));
}
示例2: wrap
VALUE wrap< sf::View >(const sf::View &image )
{
return wrap(const_cast<sf::View*>(&image));
}
示例3: act
void act(gamedata &g, int jx, int jy, bool jb){
// Reset hidden/afterburner status
g.p().hide = false;
g.p().boost = false;
g.p().gunthreat = 0;
switch(g.p().state){
case 0: // OK planes
switch(g.p().land){
case 0: // Stationary on runway
// Check for mission 0 and mission 1 wins
if (((g.mission == 0) || (g.mission == 1)) && (!g.p().drak) &&
(g.p().score >= g.targetscore)){
g.winner = g.p().side;
}
// Start Engine
if (jy == -1){
g.p().s = 0.3*GAME_SPEED*GAME_SPEED;
g.p().land = 1;
if ((g.p().control) > 0){
g.sound.volume(g.p().control-1, 0.0);
g.sound.loop(g.p().control-1, g.p().enginesample);
}
}
break;
case 1: // Taking off plane
if (jy == -1){
g.p().s = dlimit(g.p().s + 0.3*GAME_SPEED*GAME_SPEED, 0.0,
6.0*GAME_SPEED);
}
// Take off plane
if ((jx == -1) && (g.p().s > 2.0*GAME_SPEED) &&
(g.base[g.p().side].planed == 13)){
g.p().d++;
g.p().rotate = g.p().maxrotate;
g.p().land = 2;
}
if ((jx == 1) && (g.p().s > 2.0*GAME_SPEED) &&
(g.base[g.p().side].planed == 5)){
g.p().d--;
g.p().rotate = g.p().maxrotate;
g.p().land = 2;
}
// Off end of runway
if (abs(int(g.p().x - g.base[g.p().side].planex)) >
g.base[g.p().side].runwaylength){
g.p().land = 2;
}
break;
case 2: // flying
// Navigate plane
if ((g.p().rotate == 0) && (jx !=0)){
g.p().d = wrap(g.p().d-jx,1,17);
g.p().rotate = g.p().maxrotate;
}else{
if (g.p().rotate > 0){
g.p().rotate--;
}
}
// Acceleration / Afterburner Controls
{
double acceleration = g.accel[g.p().d] * GAME_SPEED * GAME_SPEED;
if (g.p().burner){
if (jy == -1){
acceleration += 0.3*GAME_SPEED*GAME_SPEED;
g.p().boost = true;
}
if ((g.p().s > 6.0*GAME_SPEED) && (jy != -1)){
acceleration -= 0.3*GAME_SPEED*GAME_SPEED;
}
g.p().s = dlimit(g.p().s + acceleration, 0.0, 12.0*GAME_SPEED);
}else{
g.p().s = dlimit(g.p().s + acceleration, 0.0, 6.0*GAME_SPEED);
}
}
// Stealth Controls
if ((jy == -1) && (jx == 0) && (!jb) && (g.p().stealth)){
g.p().hide = true;
}
// Check for shotfire
if (g.p().shotdelay == 0){
if ((jb) && (g.p().ammo > 0)){
fire_shot(g.p(), g.shot, g.sound, g.xmove, g.ymove);
}
// Check for bombdrop
if ((jy == 1) && (g.p().bombs > 0)){
drop_bomb(g.p(), g.fall, g.sound, g.bombimage);
}
}else{
g.p().shotdelay--;
}
break;
case 3: // Landing plane
if ((((g.p().x - g.base[g.p().side].planex) < 2.0) &&
(g.base[g.p().side].planed == 13)) ||
//.........这里部分代码省略.........
示例4: attribute
inline string attribute(unsigned short type, unsigned short acclaim, int p, int value, int minVal, int maxVal, int step, unit valueUnit) {
string result;
char tempStr[4];
snprintf(tempStr, 4, "%d", value);
if (p & premission_read) {
result += wrap("value")+":"+tempStr;
result += ",";
}
snprintf(tempStr, 4, "%d", minVal);
if (minVal != INT32_MIN)
result += wrap("minValue")+":"+tempStr+",";
snprintf(tempStr, 4, "%d", maxVal);
if (maxVal != INT32_MAX)
result += wrap("maxValue")+":"+tempStr+",";
snprintf(tempStr, 4, "%d", step);
if (step > 0)
result += wrap("minStep")+":"+tempStr+",";
result += wrap("perms")+":";
result += "[";
if (p & premission_read) result += wrap("pr")+",";
if (p & premission_write) result += wrap("pw")+",";
if (p & premission_notify) result += wrap("ev")+",";
result = result.substr(0, result.size()-1);
result += "]";
result += ",";
snprintf(tempStr, 4, "%X", type);
result += wrap("type")+":"+wrap(tempStr);
result += ",";
snprintf(tempStr, 4, "%hd", acclaim);
result += wrap("iid")+":"+tempStr;
result += ",";
switch (valueUnit) {
case unit_arcDegree:
result += wrap("unit")+":"+wrap("arcdegrees")+",";
break;
case unit_celsius:
result += wrap("unit")+":"+wrap("celsius")+",";
break;
case unit_percentage:
result += wrap("unit")+":"+wrap("percentage")+",";
break;
}
result += "\"format\":\"int\"";
return "{"+result+"}";
}
示例5: wrap
void RaceDialog::onSelectNextFace(MyGUI::Widget*)
{
mFaceIndex = wrap(mFaceIndex + 1, mAvailableHeads.size());
updatePreview();
}
示例6: ASSERT
bool DSoundBuf::get_output_buf( char **pBuffer, unsigned *pBufferSize, int iChunksize )
{
ASSERT( !m_bBufferLocked );
iChunksize *= bytes_per_frame();
DWORD iCursorStart, iCursorEnd;
HRESULT result;
/* It's easiest to think of the cursor as a block, starting and ending at
* the two values returned by GetCurrentPosition, that we can't write to. */
result = m_pBuffer->GetCurrentPosition( &iCursorStart, &iCursorEnd );
#ifndef _XBOX
if( result == DSERR_BUFFERLOST )
{
m_pBuffer->Restore();
result = m_pBuffer->GetCurrentPosition( &iCursorStart, &iCursorEnd );
}
if( result != DS_OK )
{
LOG->Warn( hr_ssprintf(result, "DirectSound::GetCurrentPosition failed") );
return false;
}
#endif
memmove( &m_iLastCursors[0][0], &m_iLastCursors[1][0], sizeof(int)*6 );
m_iLastCursors[3][0] = iCursorStart;
m_iLastCursors[3][1] = iCursorEnd;
/* Some cards (Creative AudioPCI) have a no-write area even when not playing. I'm not
* sure what that means, but it breaks the assumption that we can fill the whole writeahead
* when prebuffering. */
if( !m_bPlaying )
iCursorEnd = iCursorStart;
/*
* Some cards (Game Theater XP 7.1 hercwdm.sys 5.12.01.4101 [466688b, 01-10-2003])
* have odd behavior when starting a sound: the start/end cursors go:
*
* 0,0 end cursor forced equal to start above (normal)
* 4608, 1764 end cursor trailing the write cursor; except with old emulated
* WaveOut devices, this shouldn't happen; it indicates that the
* driver expects almost the whole buffer to be filled. Also, the
* play cursor is too far ahead from the last call for the amount
* of actual time passed.
* 704, XXX start cursor moves back to where it should be. I don't have an exact
* end cursor position, but in general from now on it stays about 5kb
* ahead of start (which is where it should be).
*
* The second call is completely wrong; both the start and end cursors are meaningless.
* Detect this: if the end cursor is close behind the start cursor, don't do anything.
* (We can't; we have no idea what the cursors actually are.)
*/
{
int iPrefetch = iCursorEnd - iCursorStart;
wrap( iPrefetch, m_iBufferSize );
if( m_iBufferSize - iPrefetch < 1024*4 )
{
LOG->Trace( "Strange DirectSound cursor ignored: %i..%i", iCursorStart, iCursorEnd );
return false;
}
}
/* Update m_iBufferBytesFilled. */
{
int iFirstByteFilled = m_iWriteCursor - m_iBufferBytesFilled;
wrap( iFirstByteFilled, m_iBufferSize );
/* The number of bytes that have been played since the last time we got here: */
int bytes_played = iCursorStart - iFirstByteFilled;
wrap( bytes_played, m_iBufferSize );
m_iBufferBytesFilled -= bytes_played;
m_iBufferBytesFilled = max( 0, m_iBufferBytesFilled );
if( m_iExtraWriteahead )
{
int used = min( m_iExtraWriteahead, bytes_played );
CString s = ssprintf("used %i of %i (%i..%i)", used, m_iExtraWriteahead, iCursorStart, iCursorEnd );
s += "; last: ";
for( int i = 0; i < 4; ++i )
s += ssprintf( "%i, %i; ", m_iLastCursors[i][0], m_iLastCursors[i][1] );
LOG->Trace("%s", s.c_str());
m_iWriteAhead -= used;
m_iExtraWriteahead -= used;
}
}
CheckWriteahead( iCursorStart, iCursorEnd );
CheckUnderrun( iCursorStart, iCursorEnd );
/* If we already have enough bytes written ahead, stop. */
if( m_iBufferBytesFilled > m_iWriteAhead )
return false;
int iNumBytesEmpty = m_iWriteAhead - m_iBufferBytesFilled;
/* num_bytes_empty is the amount of free buffer space. If it's
//.........这里部分代码省略.........
示例7: prepare_galaxy_for_output
void prepare_galaxy_for_output(int n, struct GALAXY *g, struct GALAXY_OUTPUT *o)
#endif
{
int j,ibin;
#ifndef NO_PROPS_OUTPUTS
o->Type = g->Type;
o->SnapNum = g->SnapNum;
o->CentralMvir = get_virial_mass(Halo[g->HaloNr].FirstHaloInFOFgroup);
o->CentralRvir = get_virial_radius(Halo[g->HaloNr].FirstHaloInFOFgroup);
o->Mvir = g->Mvir;
o->Rvir = g->Rvir;
o->Vvir = g->Vvir;
for(j = 0; j < 3; j++)
{
o->Pos[j] = g->Pos[j];
o->DistanceToCentralGal[j] = wrap(Halo[Halo[g->HaloNr].FirstHaloInFOFgroup].Pos[j] - g->Pos[j],BoxSize);;
}
o->ColdGas = g->ColdGas;
o->DiskMass = g->DiskMass;
o->BulgeMass = g->BulgeMass;
o->HotGas = g->HotGas;
o->BlackHoleMass = g->BlackHoleMass;
#endif
#ifdef COMPUTE_SPECPHOT_PROPERTIES
#ifndef POST_PROCESS_MAGS
#ifdef OUTPUT_REST_MAGS
/* Luminosities are converted into Mags in various bands */
for(j = 0; j < NMAG; j++)
o->Mag[j] = lum_to_mag(g->Lum[j][n]);
#endif
#endif //ndef POST_PROCESS_MAGS
#endif //COMPUTE_SPECPHOT_PROPERTIES
#ifndef LIGHT_OUTPUT
#ifndef NO_PROPS_OUTPUTS
#ifdef GALAXYTREE
o->HaloID = HaloIDs[g->HaloNr].HaloID;
o->Redshift = ZZ[g->SnapNum];
int ii = (int) floor(o->Pos[0] * ScaleFactor);
int jj = (int) floor(o->Pos[1] * ScaleFactor);
int kk = (int) floor(o->Pos[2] * ScaleFactor);
o->PeanoKey = peano_hilbert_key(ii, jj, kk, Hashbits);
o->SubID = calc_big_db_subid_index(g->SnapNum, Halo[g->HaloNr].FileNr, Halo[g->HaloNr].SubhaloIndex);
int tmpfirst = Halo[g->HaloNr].FirstHaloInFOFgroup;
int lenmax = 0;
int next = tmpfirst;
while(next != -1)
{
if(Halo[next].Len > lenmax)
{
lenmax = Halo[next].Len;
tmpfirst = next;
}
next = Halo[next].NextHaloInFOFgroup;
}
o->MMSubID = calc_big_db_subid_index(g->SnapNum, Halo[tmpfirst].FileNr, Halo[tmpfirst].SubhaloIndex);
#endif
o->LookBackTimeToSnap = NumToTime(g->SnapNum)*UnitTime_in_years/Hubble_h;
o->InfallVmax = g->InfallVmax;
o->InfallSnap = g->InfallSnap;
o-> InfallHotGas = g-> InfallHotGas;
o->HotRadius = g->HotRadius;
#ifdef HALOPROPERTIES
o->HaloM_Mean200 = g->HaloM_Mean200;
o->HaloM_Crit200 = g->HaloM_Crit200;
o->HaloM_TopHat = g->HaloM_TopHat;
o->HaloVelDisp = g->HaloVelDisp;
o->HaloVmax = g->HaloVmax;
#endif
o->Len = g->Len;
o->Vmax = g->Vmax;
o->BulgeSize = g->BulgeSize;
o->EjectedMass = g->EjectedMass;
o->BlackHoleGas = g->BlackHoleGas;
for(j = 0; j < 3; j++)
{
o->Vel[j] = g->Vel[j];
#ifdef HALOSPIN
o->HaloSpin[j] = g->HaloSpin[j];
#endif
#ifndef H2_AND_RINGS
o->GasSpin[j] = g->GasSpin[j];
o->StellarSpin[j] = g->StellarSpin[j];
#else
o->DiskSpin[j] = g->DiskSpin[j];
//.........这里部分代码省略.........
示例8: ceilf
void ActorScroller::PositionItemsAndDrawPrimitives( bool bDrawPrimitives )
{
if( m_SubActors.empty() )
return;
float fNumItemsToDraw = m_fNumItemsToDraw;
if( m_quadMask.GetVisible() )
{
// write to z buffer so that top and bottom are clipped
// Draw an extra item; this is the one that will be masked.
fNumItemsToDraw++;
float fPositionFullyOffScreenTop = -(fNumItemsToDraw)/2.f;
float fPositionFullyOffScreenBottom = (fNumItemsToDraw)/2.f;
m_exprTransformFunction.TransformItemCached( m_quadMask, fPositionFullyOffScreenTop, -1, m_iNumItems );
if( bDrawPrimitives ) m_quadMask.Draw();
m_exprTransformFunction.TransformItemCached( m_quadMask, fPositionFullyOffScreenBottom, m_iNumItems, m_iNumItems );
if( bDrawPrimitives ) m_quadMask.Draw();
}
float fFirstItemToDraw = m_fCurrentItem - fNumItemsToDraw/2.f;
float fLastItemToDraw = m_fCurrentItem + fNumItemsToDraw/2.f;
int iFirstItemToDraw = (int) ceilf( fFirstItemToDraw );
int iLastItemToDraw = (int) ceilf( fLastItemToDraw );
if( !m_bLoop )
{
iFirstItemToDraw = clamp( iFirstItemToDraw, 0, m_iNumItems );
iLastItemToDraw = clamp( iLastItemToDraw, 0, m_iNumItems );
}
bool bDelayedDraw = m_bDrawByZPosition && !m_bLoop;
vector<Actor*> subs;
{
// Shift m_SubActors so iFirstItemToDraw is at the beginning.
int iNewFirstIndex = iFirstItemToDraw;
int iDist = iNewFirstIndex - m_iFirstSubActorIndex;
m_iFirstSubActorIndex = iNewFirstIndex;
ShiftSubActors( iDist );
}
int iNumToDraw = iLastItemToDraw - iFirstItemToDraw;
for( int i = 0; i < iNumToDraw; ++i )
{
int iItem = i + iFirstItemToDraw;
float fPosition = iItem - m_fCurrentItem;
int iIndex = i; // index into m_SubActors
if( m_bLoop )
wrap( iIndex, m_SubActors.size() );
else if( iIndex < 0 || iIndex >= (int)m_SubActors.size() )
continue;
// Optimization: Zero out unused parameters so that they don't create new,
// unnecessary entries in the position cache. On scrollers with lots of
// items, especially with Subdivisions > 1, m_exprTransformFunction uses
// too much memory.
if( !m_bFunctionDependsOnPositionOffset )
fPosition = 0;
if( !m_bFunctionDependsOnItemIndex )
iItem = 0;
m_exprTransformFunction.TransformItemCached( *m_SubActors[iIndex], fPosition, iItem, m_iNumItems );
if( bDrawPrimitives )
{
if( bDelayedDraw )
subs.push_back( m_SubActors[iIndex] );
else
m_SubActors[iIndex]->Draw();
}
}
if( bDelayedDraw )
{
ActorUtil::SortByZPosition( subs );
FOREACH( Actor*, subs, a )
(*a)->Draw();
}
}
示例9: _alloc
VALUE _alloc(VALUE self)
{
return wrap(new Ogre::RotationalSpline);
}
示例10: _get
VALUE _get(VALUE self,VALUE index)
{
if(NUM2UINT(index) < _self->getNumPoints())
return wrap(_self->getPoint(NUM2ULONG(index)));
return Qnil;
}
示例11: prepare_galaxy_for_output
/*@brief Copies all the relevant properties from the Galaxy structure
into the Galaxy output structure, some units are corrected.*/
void prepare_galaxy_for_output(int n, struct GALAXY *g, struct GALAXY_OUTPUT *o)
{
int j;
o->Type = g->Type;
o->SnapNum = g->SnapNum;
o->CentralMvir = get_virial_mass(Halo[g->HaloNr].FirstHaloInFOFgroup);
o->Mvir = g->Mvir;
o->Rvir = g->Rvir;
o->Vvir = g->Vvir;
for(j = 0; j < 3; j++)
{
o->Pos[j] = g->Pos[j];
o->DistanceToCentralGal[j] = wrap(Halo[Halo[g->HaloNr].FirstHaloInFOFgroup].Pos[j] - g->Pos[j],BoxSize);;
}
o->ColdGas = g->ColdGas;
o->DiskMass = g->DiskMass;
o->BulgeMass = g->BulgeMass;
o->HotGas = g->HotGas;
o->BlackHoleMass = g->BlackHoleMass;
#ifndef POST_PROCESS_MAGS
#ifdef OUTPUT_REST_MAGS
/* Luminosities are converted into Mags in various bands */
for(j = 0; j < NMAG; j++)
o->Mag[j] = lum_to_mag(g->Lum[j][n]);
#endif
#endif
#ifndef LIGHT_OUTPUT
#ifdef GALAXYTREE
o->HaloID = HaloIDs[g->HaloNr].HaloID;
o->Redshift = ZZ[g->SnapNum];
int ii = (int) floor(o->Pos[0] * ScaleFactor);
int jj = (int) floor(o->Pos[1] * ScaleFactor);
int kk = (int) floor(o->Pos[2] * ScaleFactor);
o->PeanoKey = peano_hilbert_key(ii, jj, kk, Hashbits);
o->SubID = calc_big_db_subid_index(g->SnapNum, Halo[g->HaloNr].FileNr, Halo[g->HaloNr].SubhaloIndex);
int tmpfirst = Halo[g->HaloNr].FirstHaloInFOFgroup;
int lenmax = 0;
int next = tmpfirst;
while(next != -1)
{
if(Halo[next].Len > lenmax)
{
lenmax = Halo[next].Len;
tmpfirst = next;
}
next = Halo[next].NextHaloInFOFgroup;
}
o->MMSubID = calc_big_db_subid_index(g->SnapNum, Halo[tmpfirst].FileNr, Halo[tmpfirst].SubhaloIndex);
#endif
o->LookBackTimeToSnap = NumToTime(g->SnapNum)*UnitTime_in_years/Hubble_h;
o->InfallVmax = g->InfallVmax;
o->InfallSnap = g->InfallSnap;
o->HotRadius = g->HotRadius;
#ifdef HALOPROPERTIES
o->HaloM_Mean200 = g->HaloM_Mean200;
o->HaloM_Crit200 = g->HaloM_Crit200;
o->HaloM_TopHat = g->HaloM_TopHat;
o->HaloVelDisp = g->HaloVelDisp;
o->HaloVmax = g->HaloVmax;
#endif
o->Len = g->Len;
o->Vmax = g->Vmax;
o->BulgeSize = g->BulgeSize;
o->EjectedMass = g->EjectedMass;
o->BlackHoleGas = g->BlackHoleGas;
for(j = 0; j < 3; j++)
{
o->Vel[j] = g->Vel[j];
#ifdef HALOSPIN
o->HaloSpin[j] = g->HaloSpin[j];
#endif
o->GasSpin[j] = g->GasSpin[j];
o->StellarSpin[j] = g->StellarSpin[j];
#ifdef HALOPROPERTIES
o->HaloPos[j] = g->HaloPos[j];
o->HaloVel[j] = g->HaloVel[j];
o->HaloSpin[j] = g->HaloSpin[j];
#endif
}
o->XrayLum = g->XrayLum;
o->GasDiskRadius = g->GasDiskRadius;
//.........这里部分代码省略.........
示例12: _runWizard
VALUE _runWizard(VALUE self,VALUE page)
{
return wrap(_self->RunWizard(wrap<wxWizardPage*>(page)));
}
示例13: main
int
main (int argc, char **argv)
{
pid_t child;
int an;
vec<char *> av;
char *fname = NULL;
char *basename;
enum { BAD, HEADER, CFILE, PYTHON } mode = BAD;
void (*fn) (str) = NULL;
int len;
av.push_back (PATH_CPP);
av.push_back ("-DRPCC");
av.push_back (NULL);
for (an = 1; an < argc; an++) {
char *arg = argv[an];
int arglen = strlen (arg);
if (arg[0] == '-' && (arg[1] == 'D' || arg[1] == 'I'))
av.push_back (arg);
else if (!fname && arglen > 2 && arg[0] != '-'
&& arg[arglen-1] == 'x' && arg[arglen-2] == '.')
fname = arg;
else if (!strcmp (arg, "-h") && mode == BAD)
mode = HEADER;
else if (!strcmp (arg, "-c") && mode == BAD)
mode = CFILE;
else if (!strcmp (arg, "-python") && mode == BAD)
mode = PYTHON;
else if (!strcmp (arg, "-o") && !outfile && ++an < argc)
outfile = argv[an];
else if (!strncmp (arg, "-o", 2) && !outfile && arg[2])
outfile = arg + 2;
else if (!strcmp (arg, "-P") && !idprefix && ++an < argc)
idprefix = argv[an];
else if (!strncmp (arg, "-P", 2) && !idprefix && arg[2])
idprefix = arg + 2;
else
usage ();
}
if (!fname)
usage ();
if (idprefix)
idprefix = idprefix << "_";
av.push_back (fname);
av.push_back (NULL);
if ((basename = strrchr (fname, '/')))
basename++;
else
basename = fname;
len = strlen (basename);
switch (mode) {
case HEADER:
av[2] = "-DRPCC_H";
fn = genheader;
if (!outfile)
outfile = strbuf ("%.*sh", len - 1, basename);
break;
case CFILE:
av[2] = "-DRPCC_C";
fn = gencfile;
if (!outfile)
outfile = strbuf ("%.*sC", len - 1, basename);
break;
case PYTHON:
av[2] = "-DRPCC_P";
fn = genpython;
if (!outfile)
outfile = strbuf ("%.*spy", len - 1, basename);
break;
default:
usage ();
break;
}
child = runcpp (av.base ());
if (outfile != "-") {
if (outfile[0] != '|')
atexit (cleanup);
setstdout ();
}
make_sync (0);
yyparse ();
checkliterals ();
if (outfile != "-" && outfile[0] != '|')
fn (outfile);
else
fn (fname);
#if 0
chldcb (child, wrap (reapcpp));
amain ();
#else
//.........这里部分代码省略.........
示例14: do_one_pass
static int do_one_pass(journal_t *journal,
struct recovery_info *info, enum passtype pass)
{
unsigned int first_commit_ID, next_commit_ID;
unsigned long long next_log_block;
int err, success = 0;
journal_superblock_t * sb;
journal_header_t * tmp;
struct buffer_head * bh;
unsigned int sequence;
int blocktype;
int tag_bytes = journal_tag_bytes(journal);
__u32 crc32_sum = ~0; /* Transactional Checksums */
/*
* First thing is to establish what we expect to find in the log
* (in terms of transaction IDs), and where (in terms of log
* block offsets): query the superblock.
*/
sb = journal->j_superblock;
next_commit_ID = be32_to_cpu(sb->s_sequence);
next_log_block = be32_to_cpu(sb->s_start);
first_commit_ID = next_commit_ID;
if (pass == PASS_SCAN)
info->start_transaction = first_commit_ID;
jbd_debug(1, "Starting recovery pass %d\n", pass);
/*
* Now we walk through the log, transaction by transaction,
* making sure that each transaction has a commit block in the
* expected place. Each complete transaction gets replayed back
* into the main filesystem.
*/
while (1) {
int flags;
char * tagp;
journal_block_tag_t * tag;
struct buffer_head * obh;
struct buffer_head * nbh;
cond_resched();
/* If we already know where to stop the log traversal,
* check right now that we haven't gone past the end of
* the log. */
if (pass != PASS_SCAN)
if (tid_geq(next_commit_ID, info->end_transaction))
break;
jbd_debug(2, "Scanning for sequence ID %u at %llu/%lu\n",
next_commit_ID, next_log_block, journal->j_last);
/* Skip over each chunk of the transaction looking
* either the next descriptor block or the final commit
* record. */
jbd_debug(3, "JBD: checking block %llu\n", next_log_block);
err = jread(&bh, journal, next_log_block);
if (err)
goto failed;
next_log_block++;
wrap(journal, next_log_block);
/* What kind of buffer is it?
*
* If it is a descriptor block, check that it has the
* expected sequence number. Otherwise, we're all done
* here. */
tmp = (journal_header_t *)bh->b_data;
if (tmp->h_magic != cpu_to_be32(JFS_MAGIC_NUMBER)) {
brelse(bh);
break;
}
blocktype = be32_to_cpu(tmp->h_blocktype);
sequence = be32_to_cpu(tmp->h_sequence);
jbd_debug(3, "Found magic %d, sequence %d\n",
blocktype, sequence);
if (sequence != next_commit_ID) {
brelse(bh);
break;
}
/* OK, we have a valid descriptor block which matches
* all of the sequence number checks. What are we going
* to do with it? That depends on the pass... */
switch(blocktype) {
case JFS_DESCRIPTOR_BLOCK:
/* If it is a valid descriptor block, replay it
* in pass REPLAY; if journal_checksums enabled, then
//.........这里部分代码省略.........
示例15: do_one_pass
static int do_one_pass(journal_t *journal,
struct recovery_info *info, enum passtype pass)
{
unsigned int first_commit_ID, next_commit_ID;
unsigned long next_log_block;
int err, success = 0;
journal_superblock_t * sb;
journal_header_t * tmp;
struct buffer_head * bh;
unsigned int sequence;
int blocktype;
/* Precompute the maximum metadata descriptors in a descriptor block */
int MAX_BLOCKS_PER_DESC;
MAX_BLOCKS_PER_DESC = ((journal->j_blocksize-sizeof(journal_header_t))
/ sizeof(journal_block_tag_t));
/*
* First thing is to establish what we expect to find in the log
* (in terms of transaction IDs), and where (in terms of log
* block offsets): query the superblock.
*/
sb = journal->j_superblock;
next_commit_ID = be32_to_cpu(sb->s_sequence);
next_log_block = be32_to_cpu(sb->s_start);
first_commit_ID = next_commit_ID;
if (pass == PASS_SCAN)
info->start_transaction = first_commit_ID;
jbd_debug(1, "Starting recovery pass %d\n", pass);
/*
* Now we walk through the log, transaction by transaction,
* making sure that each transaction has a commit block in the
* expected place. Each complete transaction gets replayed back
* into the main filesystem.
*/
while (1) {
int flags;
char * tagp;
journal_block_tag_t * tag;
struct buffer_head * obh;
struct buffer_head * nbh;
cond_resched();
/* If we already know where to stop the log traversal,
* check right now that we haven't gone past the end of
* the log. */
if (pass != PASS_SCAN)
if (tid_geq(next_commit_ID, info->end_transaction))
break;
jbd_debug(2, "Scanning for sequence ID %u at %lu/%lu\n",
next_commit_ID, next_log_block, journal->j_last);
/* Skip over each chunk of the transaction looking
* either the next descriptor block or the final commit
* record. */
jbd_debug(3, "JBD: checking block %ld\n", next_log_block);
err = jread(&bh, journal, next_log_block);
if (err)
goto failed;
next_log_block++;
wrap(journal, next_log_block);
/* What kind of buffer is it?
*
* If it is a descriptor block, check that it has the
* expected sequence number. Otherwise, we're all done
* here. */
tmp = (journal_header_t *)bh->b_data;
if (tmp->h_magic != cpu_to_be32(JFS_MAGIC_NUMBER)) {
brelse(bh);
break;
}
blocktype = be32_to_cpu(tmp->h_blocktype);
sequence = be32_to_cpu(tmp->h_sequence);
jbd_debug(3, "Found magic %d, sequence %d\n",
blocktype, sequence);
if (sequence != next_commit_ID) {
brelse(bh);
break;
}
/* OK, we have a valid descriptor block which matches
* all of the sequence number checks. What are we going
* to do with it? That depends on the pass... */
switch(blocktype) {
//.........这里部分代码省略.........