FatParser::~FatParser() { if (mFragArray) FreeByteBuffer((PGPUInt8 *) mFragArray); if (mDataBuf) FreeByteBuffer((PGPUInt8 *) mDataBuf); }
DualErr FatParser::ExpandFragArray() { DualErr derr; PFileFrag temp; // Get memory for more fragments. derr = GetByteBuffer( (mSizeFragArray + kFPFragArrayChunkSize) * sizeof(FileFrag), (PGPUInt8 **) &temp); if (derr.IsntError()) { // Copy the old fragments to the new memory. pgpCopyMemory(mFragArray, temp, mSizeFragArray*sizeof(FileFrag)); // Delete the old memory. FreeByteBuffer((PGPUInt8 *) mFragArray); mFragArray = temp; mSizeFragArray += kFPFragArrayChunkSize; } return derr; }
void Volume::CleanUpMountedVars() { pgpAssert(Mounted()); pgpAssertAddrValid(mBBlock, PGPUInt8); mMountState = kVol_Unmounted; FreeByteBuffer(mBBlock); mDrive = kInvalidDrive; mBBlock = NULL; mPDcb = NULL; }
DualErr Volume::ClearBlocks(PGPUInt32 startBlock, PGPUInt32 endBlock) { DualErr derr; PGPBoolean allocedBlanks = FALSE; PGPUInt8 *blanks; PGPUInt32 blocksBuf; pgpAssert(Mounted()); pgpAssert(LockedForFormat()); // Allocate our block buffer. derr = CreateReasonableWriteBuffer(endBlock - startBlock, &blanks, &blocksBuf); allocedBlanks = derr.IsntError(); // Clear the blocks. if (derr.IsntError()) { PGPUInt32 blocksThisTime; pgpClearMemory(blanks, blocksBuf*kDefaultBlockSize); for (PGPUInt32 i = startBlock; i <= endBlock; i += blocksBuf) { blocksThisTime = min(blocksBuf, endBlock - i + 1); derr = Write(blanks, i, blocksThisTime); if (derr.IsError()) { break; } } } // Free our block buffer. if (allocedBlanks) FreeByteBuffer(blanks); return derr; }
PGPdisk::~PGPdisk() { if (Mounted()) Unmount(TRUE); if (NULL!=(int)(mContextB)) { mContextB->~CipherContext(); mContextB = NULL; } if (NULL!=(int)(mContextA)) { mContextA->~CipherContext(); mContextA = NULL; } if (NULL!=(int)(mDataBuf)) { FreeByteBuffer(mDataBuf); mDataBuf = NULL; } }
char *ExternalBlastTool :: GetJobFilename (const char * const prefix_s, const char * const suffix_s) { char *job_filename_s = NULL; char *job_id_s = GetUUIDAsString (bt_job_p -> bsj_job.sj_id); if (job_id_s) { char *file_stem_s = NULL; if (ebt_working_directory_s) { file_stem_s = MakeFilename (ebt_working_directory_s, job_id_s); } else { file_stem_s = job_id_s; } if (file_stem_s) { ByteBuffer *buffer_p = AllocateByteBuffer (1024); if (buffer_p) { bool success_flag = false; if (prefix_s) { success_flag = AppendStringsToByteBuffer (buffer_p, prefix_s, file_stem_s, NULL); } else { success_flag = AppendStringToByteBuffer (buffer_p, file_stem_s); } if (success_flag && suffix_s) { success_flag = AppendStringToByteBuffer (buffer_p, suffix_s); } if (success_flag) { job_filename_s = DetachByteBufferData (buffer_p); } else { FreeByteBuffer (buffer_p); } } /* if (buffer_p) */ FreeCopiedString (file_stem_s); } /* if (file_stem_s) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get file stem for \"%s\"", job_id_s); } FreeUUIDString (job_id_s); } /* if (job_id_s) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get uuid string for %s", bt_job_p -> bsj_job.sj_name_s); } return job_filename_s; }
bool ExternalBlastTool :: ParseParameters (ParameterSet *params_p, BlastAppParameters *app_params_p) { bool success_flag = false; SharedType value; memset (&value, 0, sizeof (SharedType)); if (GetParameterValueFromParameterSet (params_p, BS_TASK.npt_name_s, &value, true)) { if (AddBlastArgsPair ("task", value.st_string_value_s)) { ArgsProcessor *args_processor_p = GetArgsProcessor (); if (GetAndAddBlastArgs (params_p, BS_MAX_SEQUENCES.npt_name_s, false, args_processor_p)) { if (bt_job_p -> bsj_job.sj_name_s) { if (AddBlastArgsPair ("db", bt_job_p -> bsj_job.sj_name_s)) { if (ParseBlastAppParameters (app_params_p, bt_service_data_p, params_p, args_processor_p)) { /* Expect threshold */ if (GetAndAddBlastArgs (params_p, BS_EXPECT_THRESHOLD.npt_name_s, false, args_processor_p)) { /* Output Format * If we have a BlastFormatter then the output is always set to 11 which is ASN and * from that we can convert into any other format using a BlastFormatter tool */ memset (&value, 0, sizeof (SharedType)); if (GetParameterValueFromParameterSet (params_p, BS_OUTPUT_FORMAT.npt_name_s, &value, true)) { bt_output_format = value.st_ulong_value; if (bt_service_data_p -> bsd_formatter_p) { success_flag = AddBlastArgsPair (BS_OUTPUT_FORMAT.npt_name_s, BS_DEFAULT_OUTPUT_FORMAT_S); } else { char *value_s = NULL; /* * If we are producing grassroots mark up, get the results * in json file format as that is the format that we will * convert from. */ if (value.st_ulong_value == BOF_GRASSROOTS) { value.st_ulong_value = BOF_SINGLE_FILE_JSON_BLAST; } value_s = ConvertIntegerToString (bt_output_format); if (value_s) { success_flag = AddBlastArgsPair (BS_OUTPUT_FORMAT.npt_name_s, value_s); FreeCopiedString (value_s); } /* if (value_s) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to convert output format \"" UINT32_FMT "\" to string", bt_output_format); } } } /* if (GetParameterValueFromParameterSet (params_p, TAG_BLAST_OUTPUT_FORMAT, &value, true)) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get output format"); } if (success_flag) { /* Query Location */ if (GetParameterValueFromParameterSet (params_p, BS_SUBRANGE_FROM.npt_name_s, &value, true)) { uint32 from = value.st_ulong_value; if (GetParameterValueFromParameterSet (params_p, BS_SUBRANGE_TO.npt_name_s, &value, true)) { uint32 to = value.st_ulong_value; if ((from != 0) && (to != 0)) { ByteBuffer *buffer_p = AllocateByteBuffer (1024); if (buffer_p) { char *from_s = ConvertIntegerToString (from); if (from_s) { char *to_s = ConvertIntegerToString (to); if (to_s) { if (AppendStringsToByteBuffer (buffer_p, from_s, "-", to_s, NULL)) { const char *query_loc_s = GetByteBufferData (buffer_p); if (!AddBlastArgsPair ("query_loc", query_loc_s)) { success_flag = false; } } FreeCopiedString (to_s); } /* if (to_s) */ FreeCopiedString (from_s); } /* if (from_s) */ FreeByteBuffer (buffer_p); } /* if (buffer_p) */ } /* if ((from != 0) && (to != 0)) */ } /* if (GetParameterValueFromParameterSet (params_p, TAG_BLAST_SUBRANGE_TO, &to, true)) */ } /* if (GetParameterValueFromParameterSet (params_p, TAG_BLAST_SUBRANGE_FROM, &value, true)) */ } /* if (success_flag) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to set output format"); } } /* if (AddBlastArgsPairFromIntegerParameter (params_p, TAG_BLAST_EXPECT_THRESHOLD, "-evalue", true)) */ } /* if (bt_app_params_p -> ParseParametersToByteBuffer (bt_service_data_p, params_p, ebt_buffer_p)) */ } /* if (AddBlastArgsPair ("-db", bt_job_p -> sj_name_s))*/ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to set database name"); } } /* if (bt_job_p -> sj_name_s) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get job name"); } } /* if (AddABlastrgsPair ("-num_alignments", "5")) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to add num_alignments parameter"); } } /* if (AddBlastArgsPair ("-task", BS_TASK.npt_name_s)) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to add task parameter"); } } /* if (GetParameterValueFromParameterSet (params_p, BS_TASK.npt_name_s, &value, true)) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get task parameter value"); } return success_flag; }
DualErr Volume::Format() { DualErr derr; FatData fat; PGPBoolean allocedBlockBuf, lockedForFormat; PGPUInt8 *blockBuf; PGPUInt64 megsDisk; pgpAssert(Mounted()); pgpAssert(!LockedForReadWrite() || !LockedForFormat()); allocedBlockBuf = lockedForFormat = FALSE; megsDisk = (GetTotalBlocks() * kDefaultBlockSize) / kBytesPerMeg; // Can only format drives with standard block sizes. if (GetBlockSize() != kDefaultBlockSize) derr = DualErr(kPGDMinorError_CantFormatDrive); // Too big for format? if (derr.IsntError()) { if (GetBlockSize() > kMaxBlocksDiskWeFormat) derr = DualErr(kPGDMinorError_DiskTooBigToFormat); } // Get block buffer. if (derr.IsntError()) { derr = GetByteBuffer(kDefaultBlockSize, &blockBuf); allocedBlockBuf = derr.IsntError(); } // Lock the volume for format. if (derr.IsntError()) { derr = LockVolumeForFormat(); lockedForFormat = derr.IsntError(); } if (derr.IsntError()) { // Initialize FAT data. fat.fdFsId = kFS_FAT16; if (megsDisk < 2) { fat.fdFsId = kFS_FAT12; } else if ((megsDisk >= kMinFat32Megs) && IsWin95OSR2CompatibleMachine()) { fat.fdFsId = kFS_FAT32; } InitFatData(&fat, GetBlockSize()); derr = ClearBlocks(0, fat.fdFirstSecData); } // Write out the FAT data structures. if (derr.IsntError()) { BigFatBootFSInfo bfInfo; BootSector12 bb12; BootSector16 bb16; BootSector32 bb32; PGPUInt32 fat16Sig; PGPUInt64 pos; pgpAssert(sizeof(bb12) == kDefaultBlockSize); pgpAssert(sizeof(bb16) == kDefaultBlockSize); pgpAssert(sizeof(bb32) == kDefaultBlockSize); pgpClearMemory(blockBuf, kDefaultBlockSize); pos = 0; switch (fat.fdFsId) { case kFS_FAT12: // Init the boot block. InitFAT12BootBlock(GetBlockSize(), &fat, &bb12); // Write the boot block. derr = Write((PGPUInt8 *) &bb12, pos, 1); // Write the first FAT. if (derr.IsntError()) { pgpCopyMemory((PGPUInt8 *) &kFat12Sig, blockBuf, sizeof(kFat12Sig)); pos += fat.fdReservedSecs; derr = Write(blockBuf, pos, 1); } // Write the second FAT. if (derr.IsntError()) { pos += fat.fdFatSize; derr = Write(blockBuf, pos, 1); } break; case kFS_FAT16: // Init the boot block. InitFAT16BootBlock(GetBlockSize(), &fat, &bb16); // Decide on a FAT signature. fat16Sig = (megsDisk < 16 ? kUnder16MbFat16Sig : kOver16MbFat16Sig); // Write the boot block. derr = Write((PGPUInt8 *) &bb16, pos, 1); // Write the first FAT. if (derr.IsntError()) { pgpCopyMemory((PGPUInt8 *) &fat16Sig, blockBuf, sizeof(fat16Sig)); pos += fat.fdReservedSecs; derr = Write(blockBuf, pos, 1); } // Write the second FAT. if (derr.IsntError()) { pos += fat.fdFatSize; derr = Write(blockBuf, pos, 1); } break; case kFS_FAT32: // Init the boot block. InitFAT32BootBlock(GetBlockSize(), &fat, &bb32, &bfInfo); // Write the boot block. derr = Write((PGPUInt8 *) &bb32, pos, 1); // Write the BigFatBootInfo structure. if (derr.IsntError()) { pgpCopyMemory((PGPUInt8 *) &bfInfo, blockBuf, sizeof(bfInfo)); pos += bb32.bsFsInfoSec; derr = Write(blockBuf, pos, 1); } if (derr.IsntError()) { PGPUInt32 threeClusts[3]; threeClusts[0] = kFat32Clust1; threeClusts[1] = kFat32Clust2; threeClusts[2] = kFat32Clust3; pgpClearMemory(blockBuf, kDefaultBlockSize); pgpCopyMemory((PGPUInt8 *) &threeClusts, blockBuf, sizeof(threeClusts)); // Write the first FAT. pos = fat.fdReservedSecs; derr = Write(blockBuf, pos, 1); // Write the second FAT. if (derr.IsntError()) { pos += fat.fdFatSize; derr = Write(blockBuf, pos, 1); } } break; default: pgpAssert(FALSE); break; } } // Unlock the volume. if (lockedForFormat) { UnlockVolume(); } // Free our block buffer. if (allocedBlockBuf) { FreeByteBuffer(blockBuf); } return derr; }
TempFile *TempFile :: GetTempFile (const char *working_dir_s, const uuid_t id, const char * const suffix_s) { TempFile *file_p = NULL; ByteBuffer *buffer_p = AllocateByteBuffer (1024); bool success_flag = false; if (buffer_p) { if (working_dir_s) { if (AppendStringToByteBuffer (buffer_p, working_dir_s)) { size_t l = strlen (working_dir_s); char c = GetFileSeparatorChar (); if (* (working_dir_s + (l - 1)) != c) { if (AppendToByteBuffer (buffer_p, &c, 1)) { success_flag = true; } } else { success_flag = true; } } /* if (AppendStringToByteBuffer (buffer_p, ebt_working_directory_s)) */ } /* if (ebt_working_directory_s) */ else { success_flag = true; } if (success_flag) { char uuid_s [UUID_STRING_BUFFER_SIZE]; ConvertUUIDToString (id, uuid_s); success_flag = false; if (AppendStringsToByteBuffer (buffer_p, uuid_s, suffix_s, NULL)) { const char *full_filename_s = GetByteBufferData (buffer_p); file_p = TempFile :: GetTempFile (full_filename_s, false); if (file_p) { file_p -> Close (); } else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get temp file \"%s\"", full_filename_s); } } /* if (AppendStringsToByteBuffer (buffer_p, uuid_s, suffix_s, NULL)) */ } /* if (success_flag) */ FreeByteBuffer (buffer_p); } /* if (buffer_p) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get buffer for temp filename"); } return file_p; }