pmt: initial 2.9.6 release [source]
This commit is contained in:
@@ -27,8 +27,10 @@
|
||||
#include <PartitionManager/PartSizeMacros.h>
|
||||
#include <PartitionManager/FileSystemUtils.h>
|
||||
|
||||
static fstream sourceF, targetF;
|
||||
static long long Count;
|
||||
|
||||
namespace PartitionManager {
|
||||
namespace Functions {
|
||||
|
||||
/**
|
||||
* it is meant to calculate the size of the quickly given file.
|
||||
@@ -37,9 +39,9 @@ namespace Functions {
|
||||
static long long
|
||||
CalculateSizeLongLong(const string& fp)
|
||||
{
|
||||
VLOGD("CalculateSizeLongLong: calculating file size: `%s'\n", fp.c_str());
|
||||
VLOGD("Calculating file size: `%s'\n", fp.c_str());
|
||||
|
||||
VLOGD("CalculateSizeLongLong: reading `%s' with 'ifstream <fstream>'\n", fp.c_str());
|
||||
VLOGD("Reading `%s' with 'ifstream <fstream>'\n", fp.c_str());
|
||||
ifstream file(fp, ios::binary | ios::ate);
|
||||
|
||||
return (!file) ? -1 : static_cast<long long>(file.tellg());
|
||||
@@ -50,23 +52,23 @@ CalculateSizeLongLong(const string& fp)
|
||||
* It's for quick action.
|
||||
*/
|
||||
static void
|
||||
PartitionNotFound(const char* p) { LOGE("%s: %s\n", p, Display::UsingDispString->part_not_found); }
|
||||
PartitionNotFound(const string& part) { LOGE("%s: %s\n", part.c_str(), Display::UsingDispString->part_not_found); }
|
||||
|
||||
/* the partitions are meant to quickly find. */
|
||||
static void
|
||||
SearchPartition(const string& fp)
|
||||
{
|
||||
VLOGD("SearchPartition: calling GetState()...\n");
|
||||
VLOGD("Calling GetState()...\n");
|
||||
static int op = GetState(fp, "blk");
|
||||
|
||||
if (op == 1)
|
||||
PartitionNotFound(basename(fp.c_str()));
|
||||
else if (op == -1 && !Booleans::ForceMode)
|
||||
else if (op == -1 && !Config.ForceMode)
|
||||
LOGE("%s\n", Display::UsingDispString->not_block);
|
||||
}
|
||||
|
||||
static void
|
||||
PrintInfo(ushort_t pcode, double psz, double fsz)
|
||||
PrintInfo(const ushort_t& pcode, const double& psz, const double& fsz)
|
||||
{
|
||||
LOGD("##########################################\n");
|
||||
LOGD("# --> %s: %s\n",
|
||||
@@ -74,7 +76,7 @@ PrintInfo(ushort_t pcode, double psz, double fsz)
|
||||
Strings::TargetPartition.c_str());
|
||||
LOGD("# --> %s: %s\n",
|
||||
Display::UsingDispString->part_type,
|
||||
(Booleans::UseLogical) ? Display::UsingDispString->yes : Display::UsingDispString->no);
|
||||
(Config.UseLogical) ? Display::UsingDispString->yes : Display::UsingDispString->no);
|
||||
|
||||
if (psz != -1)
|
||||
LOGD("# --> %s: %.2fMB\n",
|
||||
@@ -100,63 +102,93 @@ PrintInfo(ushort_t pcode, double psz, double fsz)
|
||||
LOGD("##########################################\n");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static bool
|
||||
IsDoubleOf1024(float size)
|
||||
{
|
||||
float num = size / 1024;
|
||||
char str[35];
|
||||
sprintf(str, "%f", num);
|
||||
IsDoubleOf1024(T size) { return size % (T)1024 == 0; }
|
||||
|
||||
return (strstr(str, ".000000") != nullptr) ? true : false;
|
||||
static void
|
||||
ReadAndWrite(const string& FNameForMsg, const int& bfsize)
|
||||
{
|
||||
long long copiedData = 0;
|
||||
char buffer[bfsize];
|
||||
|
||||
while (sourceF.read(buffer, bfsize) && copiedData < Count)
|
||||
{
|
||||
streamsize readed_data = sourceF.gcount();
|
||||
targetF.write(buffer, readed_data);
|
||||
|
||||
if (targetF.fail() || targetF.bad())
|
||||
LOGF("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_write,
|
||||
FNameForMsg.c_str(),
|
||||
strqerror());
|
||||
|
||||
copiedData += readed_data;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
OpenSourceFile(const string& fp)
|
||||
{
|
||||
VLOGD("Trying to open `%s' with 'open <fstream>'.\n", fp.c_str());
|
||||
|
||||
sourceF.open(fp, ios::binary | ios::in);
|
||||
if (!sourceF.is_open())
|
||||
LOGE("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_read,
|
||||
fp.c_str(),
|
||||
strqerror());
|
||||
}
|
||||
|
||||
static void
|
||||
OpenTargetFile(const string& fp)
|
||||
{
|
||||
VLOGD("Trying to open `%s' with 'open <fstream>'.\n", fp.c_str());
|
||||
|
||||
targetF.open(fp, ios::binary | ios::out);
|
||||
if (!targetF.is_open())
|
||||
LOGE("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_gen,
|
||||
fp.c_str(),
|
||||
strqerror());
|
||||
}
|
||||
|
||||
} /* namespace Functions */
|
||||
} /* namespace PartitionManager */
|
||||
|
||||
using namespace PartitionManager;
|
||||
|
||||
int Functions::Start(ushort_t progress_code)
|
||||
int PartitionManager::PartitionManagerMain(const ushort_t& progress_code)
|
||||
{
|
||||
/* Some required variables */
|
||||
fstream sourceF, targetF;
|
||||
string accessPrefix, opName;
|
||||
long long copiedData = 0;
|
||||
bool IsFirstProcessOnTarget = true;
|
||||
|
||||
if (Booleans::UseLogical)
|
||||
if (Config.UseLogical)
|
||||
accessPrefix = "/dev/block/mapper/" + Strings::TargetPartition;
|
||||
else
|
||||
accessPrefix = (Booleans::UseCustomSearchPath) ? (Strings::CustomSearchPath) + ("/") + (Strings::TargetPartition) : ("/dev/block/by-name/") + (Strings::TargetPartition);
|
||||
accessPrefix = (Config.UseCustomSearchPath) ? (Strings::CustomSearchPath) + ("/") + (Strings::TargetPartition) : ("/dev/block/by-name/") + (Strings::TargetPartition);
|
||||
|
||||
VLOGD("PartitionManager: calling SearchPartition() for searching partition (path); `%s'\n", accessPrefix.c_str());
|
||||
Functions::SearchPartition(accessPrefix);
|
||||
VLOGD("Calling SearchPartition() for searching partition (path); `%s'\n", accessPrefix.c_str());
|
||||
SearchPartition(accessPrefix);
|
||||
|
||||
static long long count = (long long)(CalculateSizeLongLong(accessPrefix) + ((1024 * 1024) * 4));
|
||||
const int BFSIZE = (Functions::IsDoubleOf1024((float)Functions::CalculateSizeLongLong(accessPrefix))) ? 1024 : 1;
|
||||
char buffer[BFSIZE];
|
||||
Count = (long long)(CalculateSizeLongLong(accessPrefix) + ((1024 * 1024) * 4));
|
||||
const int BFSIZE = (IsDoubleOf1024(CalculateSizeLongLong(accessPrefix))) ? 1024 : 1;
|
||||
double FlashFileSize = 0;
|
||||
|
||||
double PartitionSize = (double)(static_cast<double>(Functions::CalculateSizeLongLong(accessPrefix)) / (1024 * 1024));
|
||||
double PartitionSize = (double)(static_cast<double>(CalculateSizeLongLong(accessPrefix)) / (1024 * 1024));
|
||||
if (!Strings::TargetFlashFile.empty())
|
||||
FlashFileSize = (double)(static_cast<double>(Functions::CalculateSizeLongLong(Strings::TargetFlashFile)) / (1024 * 1024));
|
||||
FlashFileSize = (double)(static_cast<double>(CalculateSizeLongLong(Strings::TargetFlashFile)) / (1024 * 1024));
|
||||
|
||||
if (progress_code != 4) PrintInfo(progress_code, PartitionSize, FlashFileSize);
|
||||
|
||||
if (progress_code == 1)
|
||||
{
|
||||
VLOGD("PartitionManager: trying to open `%s' with 'open <fstream>'.\n", accessPrefix.c_str());
|
||||
sourceF.open(accessPrefix, ios::binary | ios::in);
|
||||
if (!sourceF.is_open())
|
||||
LOGE("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_read,
|
||||
accessPrefix.c_str(),
|
||||
strqerror());
|
||||
OpenSourceFile(accessPrefix);
|
||||
|
||||
/* determine output */
|
||||
if (Strings::OutputName == Strings::TargetPartition)
|
||||
{
|
||||
opName = Strings::OutputName + ".img";
|
||||
VLOGW("PartitionManager: output not speficed. Selecting automaticly.\n");
|
||||
VLOGW("Output not speficed. Selecting automaticly.\n");
|
||||
LOGW("%s: %s\n",
|
||||
Display::UsingDispString->out_not_spec,
|
||||
opName.c_str());
|
||||
@@ -168,37 +200,10 @@ int Functions::Start(ushort_t progress_code)
|
||||
if (GetState(opName) == 0)
|
||||
LOGE("'%s': File exits.\n", opName.c_str());
|
||||
|
||||
VLOGD("PartitionManager: trying to open `%s' with 'open <fstream>'.\n", opName.c_str());
|
||||
targetF.open(opName, ios::binary | ios::out);
|
||||
if (!targetF.is_open())
|
||||
LOGE("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_gen,
|
||||
opName.c_str(),
|
||||
strqerror());
|
||||
OpenTargetFile(opName);
|
||||
|
||||
VLOGD("PartitionManager: read (partition) and write (output) 'read, write <fstream>'\n");
|
||||
/* start writing */
|
||||
while (sourceF.read(buffer, BFSIZE) && copiedData < count)
|
||||
{
|
||||
if (GetState(opName) != 0 && IsFirstProcessOnTarget)
|
||||
LOGE("%s\n", Display::UsingDispString->no_found_on_process);
|
||||
|
||||
streamsize readed_data = sourceF.gcount();
|
||||
targetF.write(buffer, readed_data);
|
||||
|
||||
if (targetF.fail() || targetF.bad())
|
||||
{
|
||||
if (Functions::GetState(opName) == 0)
|
||||
remove(opName.c_str());
|
||||
LOGF("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_write,
|
||||
opName.c_str(),
|
||||
strqerror());
|
||||
}
|
||||
|
||||
IsFirstProcessOnTarget = false;
|
||||
copiedData += readed_data;
|
||||
}
|
||||
VLOGD("Read (partition) and write (output) 'read, write <fstream>'\n");
|
||||
ReadAndWrite(opName.c_str(), BFSIZE);
|
||||
|
||||
/* close files */
|
||||
sourceF.close();
|
||||
@@ -212,41 +217,15 @@ int Functions::Start(ushort_t progress_code)
|
||||
{
|
||||
if (PartitionSize != -1 && FlashFileSize != -1)
|
||||
{
|
||||
if (FlashFileSize > PartitionSize && !Booleans::ForceMode)
|
||||
if (FlashFileSize > PartitionSize && !Config.ForceMode)
|
||||
LOGE("%s\n", Display::UsingDispString->ffile_more_part);
|
||||
}
|
||||
|
||||
VLOGD("PartitionManager: trying to open `%s' with 'open <fstream>'.\n", Strings::TargetFlashFile.c_str());
|
||||
sourceF.open(Strings::TargetFlashFile, ios::binary | ios::in);
|
||||
if (!sourceF.is_open())
|
||||
LOGF("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_read,
|
||||
Strings::TargetFlashFile.c_str(),
|
||||
strqerror());
|
||||
OpenSourceFile(Strings::TargetFlashFile);
|
||||
OpenTargetFile(accessPrefix);
|
||||
|
||||
VLOGD("PartitionManager: trying to open `%s' with 'open <fstream>'.\n", accessPrefix.c_str());
|
||||
targetF.open(accessPrefix, ios::binary | ios::in | ios::out | ios::trunc);
|
||||
if (!targetF.is_open())
|
||||
LOGF("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_read,
|
||||
accessPrefix.c_str(),
|
||||
strqerror());
|
||||
|
||||
VLOGD("PartitionManager: read (flash file) and write (partition) 'read, write <fstream>'\n");
|
||||
/* start writing */
|
||||
while (sourceF.read(buffer, BFSIZE) && copiedData < count)
|
||||
{
|
||||
streamsize readed_data = sourceF.gcount();
|
||||
targetF.write(buffer, readed_data);
|
||||
|
||||
if (targetF.fail() || targetF.bad())
|
||||
LOGF("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_write,
|
||||
accessPrefix.c_str(),
|
||||
strqerror());
|
||||
|
||||
copiedData += readed_data;
|
||||
}
|
||||
VLOGD("Read (flash file) and write (partition) 'read, write <fstream>'\n");
|
||||
ReadAndWrite(accessPrefix.c_str(), BFSIZE);
|
||||
|
||||
sourceF.close();
|
||||
targetF.close();
|
||||
@@ -256,14 +235,14 @@ int Functions::Start(ushort_t progress_code)
|
||||
else if (progress_code == 3)
|
||||
{
|
||||
/* get target partition block size */
|
||||
VLOGD("PartitionManager: getting block size `%s' with 'statfs <sys/vfs.h>'\n", accessPrefix.c_str());
|
||||
VLOGD("Getting block size '%s' with 'statfs <sys/vfs.h>'\n", accessPrefix.c_str());
|
||||
|
||||
struct statfs file_sys_inf;
|
||||
if (statfs(accessPrefix.c_str(), &file_sys_inf) != 0)
|
||||
LOGE("%s\n", Display::UsingDispString->cannot_get_bsz);
|
||||
|
||||
/* generate mke2fs argument list */
|
||||
VLOGD("PartitionManager: generating mke2fs argument list...\n");
|
||||
VLOGD("Generating mke2fs argument list...\n");
|
||||
char bsize[25] = "";
|
||||
#ifdef __LP64__
|
||||
sprintf(bsize, "%lu", file_sys_inf.f_bsize);
|
||||
@@ -287,7 +266,7 @@ int Functions::Start(ushort_t progress_code)
|
||||
Strings::TargetFormatFS.c_str());
|
||||
|
||||
/* run mke2fs */
|
||||
VLOGD("PartitionManager: calling mke2fs_main...\n");
|
||||
VLOGD("Calling mke2fs_main...\n");
|
||||
if (mke2fs_main(sizeof(arguments), arguments) != 0)
|
||||
LOGF("%s\n", Display::UsingDispString->format_fail);
|
||||
|
||||
@@ -295,12 +274,12 @@ int Functions::Start(ushort_t progress_code)
|
||||
}
|
||||
else if (progress_code == 4)
|
||||
{
|
||||
VLOGD("PartitionManager: getting size of '%s' (long long)\n", accessPrefix.c_str());
|
||||
VLOGD("Getting size of '%s' (long long)\n", accessPrefix.c_str());
|
||||
long long psize = (long long)CalculateSizeLongLong(accessPrefix);
|
||||
|
||||
if (psize == -1)
|
||||
{
|
||||
VLOGE("PartitionManager: cannot get partition size!\n");
|
||||
VLOGE("Cannot get partition size!\n");
|
||||
LOGE("%s: %s\n",
|
||||
Display::UsingDispString->fail_get_psize,
|
||||
strqerror());
|
||||
@@ -309,7 +288,7 @@ int Functions::Start(ushort_t progress_code)
|
||||
static char* SizeType;
|
||||
static char Holder[50];
|
||||
|
||||
if (!Booleans::OnlyViewSize)
|
||||
if (!Config.OnlyViewSize)
|
||||
{
|
||||
sprintf(Holder, "%s: ", Strings::TargetPartition.c_str());
|
||||
|
||||
@@ -321,7 +300,7 @@ int Functions::Start(ushort_t progress_code)
|
||||
else
|
||||
SizeType = "";
|
||||
|
||||
VLOGD("PartitionManager: Displaying partition size...\n");
|
||||
VLOGD("Displaying partition size...\n");
|
||||
|
||||
if (Integers::PartSizeViewType == VIEW_AS_BYTE)
|
||||
LOGD("%s%llu%s\n",
|
||||
|
||||
Reference in New Issue
Block a user