INT cmd_vol (LPTSTR param) { TCHAR szRootPath[] = _T("A:\\"); TCHAR szPath[MAX_PATH]; if (!_tcsncmp(param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_VOL_HELP4); return 0; } nErrorLevel = 0; if (param[0] == _T('\0')) { GetCurrentDirectory(MAX_PATH, szPath); szRootPath[0] = szPath[0]; } else { _tcsupr (param); if (param[1] == _T(':')) { szRootPath[0] = param[0]; } else { error_invalid_drive (); nErrorLevel = 1; return 1; } } if (!IsValidPathName (szRootPath)) { error_invalid_drive (); nErrorLevel = 1; return 1; } /* print the header */ if (!PrintVolumeHeader (szRootPath)) { nErrorLevel = 1; return 1; } return 0; }
static int readDump(afs_uint32 taskId, struct butm_tapeInfo *tapeInfoPtr, struct tapeScanInfo *scanInfoPtr) { int moreTapes = 1; afs_int32 flags, seq; afs_uint32 nbytes = 0; int newDump = 1, newTape = 1; afs_int32 tapePosition; afs_int32 code = 0, tcode; int badscan; struct volumeHeader volHeader, volTrailer; struct budb_tapeEntry tapeEntry; struct budb_volumeEntry volEntry; volEntry.dump = 0; PrintDumpLabel(&scanInfoPtr->dumpLabel); while (moreTapes) { /* While there is a tape to read *//*t */ badscan = 0; while (1) { /* Read each volume on the tape *//*w */ moreTapes = -1; tapePosition = tapeInfoPtr->position; /* remember position */ /* * Skip the volume data */ tcode = scanVolData(taskId, tapeInfoPtr, scanInfoPtr->tapeLabel.structVersion, &volHeader, &volTrailer, &nbytes); if (tcode) { badscan++; if (tcode == TC_ABORTEDBYREQUEST) { /* Aborted */ ERROR_EXIT(tcode); } if (tcode == BUTM_EOD) { moreTapes = 0; /* the end of the dump */ break; } /* Found a volume but it's incomplete. Skip over these */ if (volHeader.volumeID) { TapeLog(0, taskId, tcode, 0, "Warning: volume %s (%u) ignored. Incomplete\n", volHeader.volumeName, volHeader.volumeID); continue; } /* No volume was found. We may have hit the EOT or a * bad-spot. Try to skip over this spot. */ if (badscan < 2) { /* allow 2 errors, then fail */ TapeLog(0, taskId, tcode, 0, "Warning: Error in scanning tape - will try skipping volume\n"); continue; } if (scanInfoPtr->tapeLabel.structVersion >= TAPE_VERSION_4) { TapeLog(0, taskId, tcode, 0, "Warning: Error in scanning tape - end-of-tape inferred\n"); moreTapes = 1; /* then assume next tape */ } else { ErrorLog(0, taskId, tcode, 0, "Error in scanning tape\n"); /* will ask if there is a next tape */ } break; } PrintVolumeHeader(&volHeader); /* If this is not the first volume fragment, make sure it follows * the last volume fragment */ if (volEntry.dump) { if ((volEntry.dump != volHeader.dumpID) || (volEntry.id != volHeader.volumeID) || (volEntry.seq != volHeader.frag - 2) || (strcmp(volEntry.name, volHeader.volumeName))) { TLog(taskId, "Warning: volume %s (%u) ignored. Incomplete - no last fragment\n", volEntry.name, volEntry.id); if (scanInfoPtr->addDbFlag) { tcode = flushSavedEntries(DUMP_FAILED); if (tcode) ERROR_EXIT(tcode); volEntry.dump = 0; } } } /* If this is the first volume fragment, make sure says so */ if (scanInfoPtr->addDbFlag && !volEntry.dump && (volHeader.frag != 1)) { TLog(taskId, "Warning: volume %s (%u) ignored. Incomplete - no first fragment\n", volHeader.volumeName, volHeader.volumeID); } /* Check that this volume belongs to the dump we are scanning */ else if (scanInfoPtr->dumpLabel.dumpid && (volHeader.dumpID != scanInfoPtr->dumpLabel.dumpid)) { TLog(taskId, "Warning: volume %s (%u) ignored. Expected DumpId %u, got %u\n", volHeader.volumeName, volHeader.volumeID, scanInfoPtr->dumpLabel.dumpid, volHeader.dumpID); } /* Passed tests, Now add to the database (if dbadd flag is set) */ else if (scanInfoPtr->addDbFlag) { /* Have enough information to create a dump entry */ if (newDump) { tcode = RcreateDump(scanInfoPtr, &volHeader); if (tcode) { ErrorLog(0, taskId, tcode, 0, "Can't add dump %u to database\n", volHeader.dumpID); ERROR_EXIT(tcode); } newDump = 0; } /* Have enough information to create a tape entry */ if (newTape) { seq = extractTapeSeq(scanInfoPtr->tapeLabel.AFSName); if (seq < 0) ERROR_EXIT(TC_INTERNALERROR); tcode = useTape(&tapeEntry, volHeader.dumpID, TNAME(&scanInfoPtr->tapeLabel), seq, scanInfoPtr->tapeLabel.useCount, scanInfoPtr->dumpLabel.creationTime, scanInfoPtr->dumpLabel.expirationDate, tapepos); if (tcode) { char gotName[BU_MAXTAPELEN + 32]; LABELNAME(gotName, &scanInfoPtr->tapeLabel); ErrorLog(0, taskId, tcode, 0, "Can't add tape %s for dump %u to database\n", gotName, volHeader.dumpID); ERROR_EXIT(tcode); } newTape = 0; } /* Create the volume entry */ flags = ((volHeader.frag == 1) ? BUDB_VOL_FIRSTFRAG : 0); if (!volTrailer.contd) flags |= BUDB_VOL_LASTFRAG; tcode = addVolume(&volEntry, volHeader.dumpID, TNAME(&scanInfoPtr->tapeLabel), volHeader.volumeName, volHeader.volumeID, volHeader.cloneDate, tapePosition, nbytes, (volHeader.frag - 1), flags); if (tcode) { ErrorLog(0, taskId, tcode, 0, "Can't add volume %s (%u) for dump %u to database\n", volHeader.volumeName, volHeader.volumeID, volHeader.dumpID); ERROR_EXIT(tcode); } } if (volTrailer.contd) { /* No need to read the EOD marker, we know there is a next tape */ moreTapes = 1; break; } else { if (scanInfoPtr->addDbFlag) { tcode = flushSavedEntries(DUMP_SUCCESS); if (tcode) ERROR_EXIT(tcode); volEntry.dump = 0; } } } /*w */ if (!newTape) { if (scanInfoPtr->addDbFlag) { tcode = finishTape(&tapeEntry, (tapeInfoPtr->kBytes + (tapeInfoPtr->nBytes ? 1 : 0))); if (tcode) { char gotName[BU_MAXTAPELEN + 32]; LABELNAME(gotName, &scanInfoPtr->tapeLabel); ErrorLog(0, taskId, tcode, 0, "Can't mark tape %s 'completed' for dump %u in database\n", gotName, tapeEntry.dump); ERROR_EXIT(tcode); } } } /* Ask if there is another tape if we can't figure it out */ if (moreTapes == -1) moreTapes = (queryoperator ? Ask("Are there more tapes") : 1); /* Get the next tape label */ if (moreTapes) { char *tapeName; afs_int32 dumpid; unmountTape(taskId, tapeInfoPtr); tapeName = nextTapeLabel(scanInfoPtr->tapeLabel.AFSName); dumpid = scanInfoPtr->tapeLabel.dumpid; tcode = getScanTape(taskId, tapeInfoPtr, tapeName, dumpid, 1, &scanInfoPtr->tapeLabel); if (tcode) ERROR_EXIT(tcode); newTape = 1; } } /*t */ if (!newDump) { if (scanInfoPtr->addDbFlag) { tcode = finishDump(&scanInfoPtr->dumpEntry); if (tcode) { ErrorLog(0, taskId, tcode, 0, "Can't mark dump %u 'completed' in database\n", scanInfoPtr->dumpEntry.id); } tcode = flushSavedEntries(DUMP_SUCCESS); if (tcode) ERROR_EXIT(tcode); } } error_exit: return (code); }