pmt: initial 2.9.6 release [source]

This commit is contained in:
2024-10-26 11:03:52 +03:00
parent ce7fcae4a4
commit 638062c42f
43 changed files with 672 additions and 10601 deletions

View File

@@ -24,82 +24,66 @@
using namespace PartitionManager;
/* it's prints standart logs */
void Functions::DisplayLog(LogLevel status, const char* _Nullable fmt, ...)
void PartitionManager::DisplayLog(LogLevel LogPriority, const char* _Nonnull fmt, ...)
{
va_list args;
va_start(args, fmt);
switch (status)
if (!Config.SilentEnabled)
{
switch (LogPriority)
{
case LOG_LEVEL_ERROR:
if (!Booleans::SilentEnabled)
{
fprintf(stderr, "%s: ", Strings::ExecutingName.c_str());
vfprintf(stderr, fmt, args);
}
exit(1);
fprintf(stderr, "%s: ", Strings::ExecutingName.c_str());
vfprintf(stderr, fmt, args);
break;
case LOG_LEVEL_WARN:
if (!Booleans::SilentEnabled)
{
fprintf(stdout, "%s: ", Display::UsingDispString->warn);
vfprintf(stdout, fmt, args);
}
fprintf(stdout, "%s: ", Display::UsingDispString->warn);
vfprintf(stdout, fmt, args);
break;
case LOG_LEVEL_FATAL:
if (!Booleans::SilentEnabled)
{
fprintf(stderr, "%s: ", Display::UsingDispString->fatal);
vfprintf(stderr, fmt, args);
}
abort();
fprintf(stderr, "%s: ", Display::UsingDispString->fatal);
vfprintf(stderr, fmt, args);
break;
case LOG_LEVEL_DEBUG:
if (!Booleans::SilentEnabled)
vfprintf(stdout, fmt, args);
vfprintf(stdout, fmt, args);
break;
}
}
if (LogPriority == LOG_LEVEL_ERROR) exit(1);
else if (LogPriority == LOG_LEVEL_FATAL) abort();
va_end(args);
}
/* it's prints verbose logs */
void Functions::DisplayVerboseLog(LogLevel status, const char* fmt, ...)
void PartitionManager::DisplayVerboseLog(LogLevel LogPriority, const char* func, const int& line, const char* _Nonnull fmt, ...)
{
va_list args;
va_start(args, fmt);
switch (status)
if (Config.VerboseMode)
{
case LOG_LEVEL_ERROR:
if (Booleans::VerboseMode)
{
fprintf(stderr, "E:[stderr]: ");
vfprintf(stderr, fmt, args);
}
switch (LogPriority)
{
case LOG_LEVEL_ERROR:
fprintf(stderr, "<E> [%s() Line<%d>]: ", func, line);
vfprintf(stderr, fmt, args);
break;
case LOG_LEVEL_WARN:
if (Booleans::VerboseMode)
{
fprintf(stdout, "W:[stdout]: ");
vfprintf(stdout, fmt, args);
}
fprintf(stdout, "<W> [%s() Line<%d>]: ", func, line);
vfprintf(stdout, fmt, args);
break;
case LOG_LEVEL_FATAL:
if (Booleans::VerboseMode)
{
fprintf(stderr, "F:[stderr]: ");
vfprintf(stderr, fmt, args);
abort();
}
fprintf(stderr, "<F> [%s() Line<%d>]: ", func, line);
vfprintf(stderr, fmt, args);
break;
case LOG_LEVEL_DEBUG:
if (Booleans::VerboseMode)
{
fprintf(stdout, "D:[stdout]: ");
vfprintf(stdout, fmt, args);
}
fprintf(stdout, "<D> [%s() Line<%d>]: ", func, line);
vfprintf(stdout, fmt, args);
break;
}
}
va_end(args);
@@ -109,6 +93,6 @@ void Functions::DisplayVerboseLog(LogLevel status, const char* fmt, ...)
* Last error is taken from strerror by taking
* the contents of errno or taking a special entry
*/
char* strqerror(int errno_macro) { return strerror(errno_macro); }
char* strqerror(int __qerrno) { return strerror(__qerrno); }
/* end of code */

View File

@@ -29,15 +29,13 @@
* If the desired type is not in -1 value is returned.
* If the search type is unknown, 3 value is returned
*/
int PartitionManager::Functions::GetState(const string& filepath, const string& stype)
int PartitionManager::GetState(const string& filepath, const string& stype)
{
static struct stat GetStat;
struct stat GetStat;
VLOGD("Checking `%s' with 'stat <sys/stat.h>'...\n", filepath.c_str());
VLOGD("GetStat: checking `%s' with 'stat <sys/stat.h>'...\n", filepath.c_str());
if (stat(filepath.c_str(), &GetStat) != 0)
return 1;
if (stype == "dir")
if (stat(filepath.c_str(), &GetStat) != 0) return 1;
if (stype == "dir")
return (S_ISDIR(GetStat.st_mode)) ? 0 : -1;
else if (stype == "file")
return (S_ISREG(GetStat.st_mode)) ? 0 : -1;
@@ -45,10 +43,9 @@ int PartitionManager::Functions::GetState(const string& filepath, const string&
return (S_ISBLK(GetStat.st_mode)) ? 0 : -1;
else if (stype == "link")
return (S_ISLNK(GetStat.st_mode)) ? 0 : -1;
else
return 3;
else return 3;
return 2;
return 2; /* it's a dummy value */
}
/* end of code */

View File

@@ -28,7 +28,7 @@ using namespace PartitionManager;
struct langdb_docs* Display::UsingDocDispString = nullptr;
static void
prepare_langconf_docs(void)
PrepareLangconfDocs(void)
{
if (Strings::CurrentLanguage == "en")
Display::UsingDocDispString = &Display::LangDocEn;
@@ -36,11 +36,11 @@ prepare_langconf_docs(void)
Display::UsingDocDispString = &Display::LangDocTr;
}
void Functions::DisplayHelp(void)
void PartitionManager::DisplayHelp(void)
{
VLOGD("DisplayHelp: Loading language for help messages... Calling prepare_langconf_docs() <local function>...\n");
prepare_langconf_docs();
VLOGD("DisplayHelp: Printing...\n");
VLOGD("Loading language for help messages... Calling PrepareLangconfDocs() <local function>...\n");
PrepareLangconfDocs();
VLOGD("Printing...\n");
LOGD("%s: %s %s\n", Display::UsingDocDispString->usage_docstr, Strings::ExecutingName.c_str(), Display::UsingDocDispString->docs_strs_l1);
LOGD(" %s: %s %s\n", Display::UsingDocDispString->or_str, Strings::ExecutingName.c_str(), Display::UsingDocDispString->docs_strs_l2);
LOGD(" %s: %s %s\n", Display::UsingDocDispString->or_str, Strings::ExecutingName.c_str(), Display::UsingDocDispString->docs_strs_l3);

View File

@@ -42,7 +42,7 @@ string supp_langs[] = {
static bool
InternalStorageDirFound(void)
{
return (Functions::GetState(INTERNAL_STORAGE_DIR, "dir") == 0) ? true : false;
return (GetState(INTERNAL_STORAGE_DIR, "dir") == 0) ? true : false;
}
static bool
@@ -57,29 +57,29 @@ LanguageControl(const string& lang)
return false;
}
bool Functions::LoadLanguage(void)
bool PartitionManager::LoadLanguage(void)
{
string lang_fpr = "en";
langconf.close();
VLOGD("LoadLanguage: checking install type...\n");
if (Functions::GetState(TERMUX_PMT_MANDOC) == 0)
Booleans::InstalledOnTermux = true;
VLOGD("Checking install type...\n");
if (GetState(TERMUX_PMT_MANDOC) == 0)
Config.InstalledOnTermux = true;
VLOGD("LoadLanguage: checking internal storage dir: `%s'\n", INTERNAL_STORAGE_DIR);
VLOGD("Checking internal storage dir: `%s'\n", INTERNAL_STORAGE_DIR);
if (!InternalStorageDirFound())
LOGE("PartitionManagerLoadLanguage: internal storage directory (`%s') not found or accessible.\n", INTERNAL_STORAGE_DIR);
LOGE("PartitionManagerLanguageTools: İnternal storage directory (`%s') not found or accessible.\n", INTERNAL_STORAGE_DIR);
VLOGD("LoadLanguage: trying to open `%s' with 'open <fstream>'\n", PMTLANG_CONF);
VLOGD("Trying to open `%s' with 'open <fstream>'\n", PMTLANG_CONF);
langconf.open(PMTLANG_CONF, ios::in | ios::out);
VLOGD("LoadLanguage: checking status: `%s'...\n", PMTLANG_CONF);
VLOGD("Checking status: `%s'...\n", PMTLANG_CONF);
if (!langconf.is_open())
{
langconf.open(PMTLANG_CONF, ios::out | ios::trunc);
VLOGD("LoadLanguage: calling SetLanguage()...\n");
Functions::SetLanguage("en", 1);
VLOGD("Calling SetLanguage()...\n");
SetLanguage("en", 1);
Display::UsingDispString = &Display::LangEn;
Strings::CurrentLanguage = "en";
@@ -90,7 +90,7 @@ bool Functions::LoadLanguage(void)
}
else
{
VLOGD("LoadLanguage: reading `%s'\n", PMTLANG_CONF);
VLOGD("Reading `%s'\n", PMTLANG_CONF);
while (getline(langconf, lang_fpr))
{
if (lang_fpr == "en")
@@ -99,20 +99,20 @@ bool Functions::LoadLanguage(void)
goto SetTr;
else
{
VLOGD("LoadLanguage: calling SetLanguage()\n");
Functions::SetLanguage("en", 1);
VLOGD("LoadLanguage: re-calling LoadLanguage()\n");
Functions::LoadLanguage();
VLOGD("Calling SetLanguage()\n");
SetLanguage("en", 1);
VLOGD("Re-calling LoadLanguage()\n");
PartitionManager::LoadLanguage();
return true;
}
}
if (!getline(langconf, lang_fpr))
{
VLOGD("LoadLanguage: calling SetLanguage()\n");
Functions::SetLanguage("en", 1);
VLOGD("LoadLanguage: re-calling LoadLanguage()\n");
Functions::LoadLanguage();
VLOGD("Calling SetLanguage()\n");
SetLanguage("en", 1);
VLOGD("Re-calling LoadLanguage()\n");
PartitionManager::LoadLanguage();
return true;
}
}
@@ -121,38 +121,38 @@ SetEn:
langconf.close();
Display::UsingDispString = &Display::LangEn;
Strings::CurrentLanguage = "en";
VLOGD("LoadLanguage: loaded \"en\"\n");
VLOGD("Loaded \"en\"\n");
return true;
SetTr:
langconf.close();
Display::UsingDispString = &Display::LangTr;
Strings::CurrentLanguage = "tr";
VLOGD("LoadLanguage: loaded \"tr\"\n");
VLOGD("Loaded \"tr\"\n");
return true;
return false;
}
void Functions::SetLanguage(const string& lang, unsigned short null_conf_stat)
void PartitionManager::SetLanguage(const string& lang, ushort_t null_conf_stat)
{
VLOGD("SetLanguage: checking speficed language (from input).\n");
VLOGD("Checking speficed language (from input).\n");
if (!LanguageControl(lang))
LOGE("Unknown language: %s.\n", lang.c_str());
langconf.close();
VLOGD("SetLanguage: checking internal storage dir: `%s'\n", INTERNAL_STORAGE_DIR);
VLOGD("Checking internal storage dir: `%s'\n", INTERNAL_STORAGE_DIR);
if (!InternalStorageDirFound())
LOGE("PartitionManagerSetLanguage: internal storage directory (`%s') not found or accessible.\n", INTERNAL_STORAGE_DIR);
LOGE("PartitionManagerSetLanguage: Internal storage directory (`%s') not found or accessible.\n", INTERNAL_STORAGE_DIR);
VLOGD("SetLanguage: trying to open `%s' with 'open <fstream>'\n", PMTLANG_CONF);
VLOGD("Trying to open `%s' with 'open <fstream>'\n", PMTLANG_CONF);
langconf.open(PMTLANG_CONF, ios::out | ios::trunc);
if (!langconf.is_open())
LOGE("PartitionManagerLanguageTools: Cannot open/write config file!!!\n");
VLOGD("SetLanguage: write \"%s\" to `%s' with 'std <iostream>'\n", lang.c_str(), PMTLANG_CONF);
VLOGD("Write \"%s\" to `%s' with 'std <iostream>'\n", lang.c_str(), PMTLANG_CONF);
langconf << lang;
if (!langconf)
LOGE("PartitionManagerLanguageTools: Couldn't write config!!!\n");
@@ -161,23 +161,23 @@ void Functions::SetLanguage(const string& lang, unsigned short null_conf_stat)
if (null_conf_stat != 1)
{
VLOGD("SetLanguage: generating dummy file `%s' with 'ofstream <fstream>'\n", PMT_SW_POINT);
VLOGD("Generating dummy file `%s' with 'ofstream <fstream>'\n", PMT_SW_POINT);
ofstream sw_point(PMT_SW_POINT, ios::trunc);
if (sw_point.is_open())
sw_point.close();
}
}
bool Functions::CleanSWPoint(void)
bool PartitionManager::CleanSWPoint(void)
{
if (Functions::GetState(PMT_SW_POINT) == 0)
if (GetState(PMT_SW_POINT) == 0)
{
VLOGD("CleanSWPoint: removing (force) `%s' with 'remove <unistd.h>'\n", PMT_SW_POINT);
VLOGD("Removing (force) `%s' with 'remove <unistd.h>'\n", PMT_SW_POINT);
remove(PMT_SW_POINT);
return true;
}
else
return false;
return false;
}
/* end of code */

View File

@@ -80,15 +80,15 @@ directory:
}
/* list existing partitions */
int Functions::ListPartitions(void)
int PartitionManager::ListPartitions(void)
{
VLOGD("ListPartitions: selecting search path...\n");
string AccessDir = (Booleans::UseCustomSearchPath) ? Strings::CustomSearchPath : CUR_DEV_SP;
VLOGD("Selecting search path...\n");
string AccessDir = (Config.UseCustomSearchPath) ? Strings::CustomSearchPath : CUR_DEV_SP;
VLOGD("ListPartitions: trying to access `%s'...\n", AccessDir.c_str());
VLOGD("Trying to access `%s'...\n", AccessDir.c_str());
if (ListDir(AccessDir) != 0)
{
if (!Booleans::ForceMode)
if (!Config.ForceMode)
LOGE("%s: `%s': %s\n",
Display::UsingDispString->not_open,
AccessDir.c_str(),
@@ -102,9 +102,9 @@ int Functions::ListPartitions(void)
ListDir(AccessDir, true);
}
if (Booleans::UsesLogical)
if (Config.UsesLogical)
{
VLOGD("ListPartitions: checking for listing `%s'...\n", LGC_DEV_SP);
VLOGD("Checking for listing `%s'...\n", LGC_DEV_SP);
if (ListDir(LGC_DEV_SP) != 0)
LOGE("%s: `%s': %s\n",
@@ -118,17 +118,17 @@ int Functions::ListPartitions(void)
}
}
VLOGD("ListPartitions: (if have) warnings are printed...\n");
VLOGD("(if have) warnings are printed...\n");
if (Booleans::UsesLogical)
if (Config.UsesLogical)
{
LOGD("\n");
LOGW("%s\n", Display::UsingDispString->logical_warn);
}
if (Booleans::UsesSlots)
if (Config.UsesSlots)
{
if (!Booleans::UsesSlots)
if (!Config.UsesLogical)
LOGD("\n");
LOGW("%s\n", Display::UsingDispString->ab_warn);

File diff suppressed because it is too large Load Diff

View File

@@ -22,49 +22,49 @@
#include <sys/system_properties.h>
static int
GetProperty(const char* _Nonnull property, const char* desired_val, const char* desired_val2 = nullptr)
GetProperty(const char* _Nonnull property, const char* _Nonnull val1, const char* _Nullable val2 = nullptr)
{
char val[PROP_VALUE_MAX];
int len = __system_property_get(property, val);
VLOGD("GetProperty: get property value: '%s'\n", property);
VLOGD("Get property value: '%s'\n", property);
if (len > 0)
{
VLOGD("GetProperty: %s=%s\n", property, val);
VLOGD("%s=%s\n", property, val);
VLOGD("GetProperty: comparing '%s' property value '%s'\n", property, desired_val);
if (strcmp(val, desired_val) == 0)
VLOGD("Comparing '%s' property value '%s'\n", property, val1);
if (strcmp(val, val1) == 0)
{
VLOGD("GetProperty: '%s' is '%s'. Stop (0).\n", property, desired_val);
VLOGD("'%s' is '%s'. Stop (0).\n", property, val1);
return 0;
}
else
{
VLOGE("GetProperty: '%s' property is not '%s'. Comparing desired value 2 (if speficed).\n", property, desired_val);
VLOGE("'%s' property is not '%s'. Comparing desired value 2 (if speficed).\n", property, val1);
if (desired_val2 != nullptr)
if (val2 != nullptr)
{
if (strcmp(val, desired_val2) == 0)
if (strcmp(val, val2) == 0)
{
VLOGD("GetProperty: '%s' is '%s'.Stop (0).\n", property, desired_val2);
VLOGD("'%s' is '%s'.Stop (0).\n", property, val2);
return 0;
}
else
{
VLOGE("GetProperty: '%s' is not '%s'. Stop (1).\n", property, desired_val2);
VLOGE("'%s' is not '%s'. Stop (1).\n", property, val2);
return 1;
}
}
else
{
VLOGE("GetProperty: '%s' is not '%s'. Stop (1).\n", property, desired_val);
VLOGE("'%s' is not '%s'. Stop (1).\n", property, val1);
return 1;
}
}
}
else
{
VLOGE("GetProperty: cannot get property '%s'. No such property or empty. Stop (1).\n", property);
VLOGE("Cannot get property '%s'. No such property or empty. Stop (1).\n", property);
return 1;
}
@@ -74,19 +74,19 @@ GetProperty(const char* _Nonnull property, const char* desired_val, const char*
using namespace PartitionManager;
/* check parts */
void Functions::CheckDevPoint(void)
void PartitionManager::CheckDevPoint(void)
{
/* true = ab | false = a only */
Booleans::UsesSlots = (GetProperty("ro.boot.slot_suffix", "_a", "_b") == 0 || GetProperty("ro.boot.slot", "_a", "_b") == 0) ? true : false;
Config.UsesSlots = (GetProperty("ro.boot.slot_suffix", "_a", "_b") == 0 || GetProperty("ro.boot.slot", "_a", "_b") == 0) ? true : false;
if (Booleans::UsesSlots)
VLOGW("CheckDevPoint: 1 warning generated: A/B partitions status.\n");
if (Config.UsesSlots)
VLOGW("1 warning generated: A/B partitions status.\n");
/* true = logical | false = normal */
Booleans::UsesLogical = (GetProperty("ro.boot.dynamic_partitions", "true") == 0) ? true : false;
Config.UsesLogical = (GetProperty("ro.boot.dynamic_partitions", "true") == 0) ? true : false;
if (Booleans::UsesLogical)
VLOGW("CheckDevPoint: 1 warning generated: logical partitions status.\n");
if (Config.UsesLogical)
VLOGW("1 warning generated: logical partitions status.\n");
}
/* end of code */

View File

@@ -23,13 +23,13 @@
#include <PartitionManager/PartitionManager.h>
/* root checker function */
void PartitionManager::Functions::CheckRoot(void)
void PartitionManager::CheckRoot(void)
{
VLOGD("CheckRoot: trying to get UID with 'getuid <unistd.h>'\n");
VLOGD("Trying to get UID with 'getuid <unistd.h>'\n");
if (getuid() != 0)
{
VLOGE("CheckRoot: cannot get UID. Not executed with root!\n");
VLOGE("You are not superuser!\n");
LOGE("%s\n", PartitionManager::Display::UsingDispString->no_root);
}
}

View File

@@ -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",

View File

@@ -25,9 +25,9 @@
using namespace PartitionManager;
void Functions::DisplayVersion(void)
void PartitionManager::DisplayVersion(void)
{
VLOGD("DisplayVersion: printing main info...\n");
VLOGD("Printing main info...\n");
LOGD("%s %s %d.%d.%d (%d%d%d / C++) ",
Strings::ExecutingName.c_str(),
Display::UsingDispString->version_str,
@@ -38,14 +38,10 @@ void Functions::DisplayVersion(void)
PMT_MINOR,
PMT_PATCHLEVEL);
#if __SIZEOF_POINTER__ == 4
LOGD("32-bit %s\n", Display::UsingDispString->bin_str);
#elif __SIZEOF_POINTER__ == 8
#ifdef __LP64__
LOGD("64-bit %s\n", Display::UsingDispString->bin_str);
#else
LOGD("<%s> %s\n",
Display::UsingDispString->unknw_str,
Display::UsingDispString->bin_str);
LOGD("32-bit %s\n", Display::UsingDispString->bin_str);
#endif
LOGD("mke2fs %s %s (%s)\n",