pmt: initial 3.0.2 update

This commit is contained in:
2024-12-14 10:25:23 +03:00
parent 686ef38598
commit 7f8090bb1f
1292 changed files with 500876 additions and 2823 deletions

View File

@@ -0,0 +1,127 @@
/* By YZBruh */
/**
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <mntent.h>
#include <malloc.h>
ssize_t getrandom(void* buf, size_t buflen, unsigned int flags) {
if (!buf || buflen == 0) {
errno = EINVAL;
return -1;
}
const char* device = (flags & 1) ? "/dev/random" : "/dev/urandom";
int fd = open(device, O_RDONLY);
if (fd < 0) {
perror("Failed to open random device");
return -1;
}
ssize_t total_read = 0;
while (total_read < (ssize_t)buflen) {
ssize_t bytes_read = read(fd, (char*)buf + total_read, buflen - total_read);
if (bytes_read < 0) {
if (errno == EINTR) continue;
perror("Failed to read random data");
close(fd);
return -1;
}
total_read += bytes_read;
}
close(fd);
return total_read;
}
int getentropy(void* buf, size_t buflen) {
if (!buf || buflen == 0 || buflen > 256) {
errno = EINVAL;
return -1;
}
int fd = open("/dev/urandom", O_RDONLY);
if (fd < 0) {
perror("Failed to open /dev/urandom");
return -1;
}
ssize_t total_read = 0;
while (total_read < (ssize_t)buflen) {
ssize_t bytes_read = read(fd, (char*)buf + total_read, buflen - total_read);
if (bytes_read < 0) {
if (errno == EINTR) continue;
perror("Failed to read random data");
close(fd);
return -1;
}
total_read += bytes_read;
}
close(fd);
return 0;
}
char* _Nullable hasmntopt(const struct mntent* mnt, const char* opt) {
if (!mnt || !opt) return NULL;
char* options = mnt->mnt_opts;
size_t opt_len = strlen(opt);
while (*options) {
char *comma = strchr(options, ',');
size_t len = comma ? (size_t)(comma - options) : strlen(options);
if (len == opt_len && strncmp(options, opt, len) == 0)
return (char*)options;
if (!comma) break;
options = comma + 1;
}
return NULL;
}
void* _Nullable reallocarray(void* ptr, size_t count, size_t size) {
if (count == 0 || size == 0) {
free(ptr);
return NULL;
}
if (count > SIZE_MAX / size) return NULL;
size_t total_size = count * size;
void* new_ptr = realloc(ptr, total_size);
if (new_ptr == NULL) return NULL;
return new_ptr;
}
#ifdef __cplusplus
}
#endif
/* end of code */

View File

@@ -7,7 +7,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,8 +16,8 @@
* limitations under the License.
*/
#define INC_MAIN_LIBS
#define INC_STRINGKEYS
#define INC_MAIN_LIBS 1
#define INC_STRINGKEYS 1
#include <PartitionManager/PartitionManager.h>
@@ -26,67 +26,67 @@ using namespace PartitionManager;
/* it's prints standart logs */
void PartitionManager::DisplayLog(LogLevel LogPriority, const char* _Nonnull fmt, ...)
{
va_list args;
va_start(args, fmt);
va_list args;
va_start(args, fmt);
if (!Config.SilentEnabled)
{
switch (LogPriority)
{
case LOG_LEVEL_ERROR:
fprintf(stderr, "%s: ", Strings::ExecutingName.c_str());
vfprintf(stderr, fmt, args);
break;
case LOG_LEVEL_WARN:
fprintf(stdout, "%s: ", Display::UsingDispString->warn);
vfprintf(stdout, fmt, args);
break;
case LOG_LEVEL_FATAL:
fprintf(stderr, "%s: ", Display::UsingDispString->fatal);
vfprintf(stderr, fmt, args);
break;
case LOG_LEVEL_DEBUG:
vfprintf(stdout, fmt, args);
break;
}
}
if (!Config.SilentEnabled)
{
switch (LogPriority)
{
case LOG_LEVEL_ERROR:
fprintf(stderr, "%s: ", Strings::ExecutingName.c_str());
vfprintf(stderr, fmt, args);
break;
case LOG_LEVEL_WARN:
fprintf(stdout, "%s: ", Display::UsingDispString->warn);
vfprintf(stdout, fmt, args);
break;
case LOG_LEVEL_FATAL:
fprintf(stderr, "%s: ", Display::UsingDispString->fatal);
vfprintf(stderr, fmt, args);
break;
case LOG_LEVEL_DEBUG:
vfprintf(stdout, fmt, args);
break;
}
}
if (LogPriority == LOG_LEVEL_ERROR) exit(1);
else if (LogPriority == LOG_LEVEL_FATAL) abort();
if (LogPriority == LOG_LEVEL_ERROR) exit(1);
else if (LogPriority == LOG_LEVEL_FATAL) abort();
va_end(args);
va_end(args);
}
/* it's prints verbose logs */
void PartitionManager::DisplayVerboseLog(LogLevel LogPriority, const char* func, const int& line, const char* _Nonnull fmt, ...)
{
va_list args;
va_start(args, fmt);
va_list args;
va_start(args, fmt);
if (Config.VerboseMode)
{
switch (LogPriority)
{
case LOG_LEVEL_ERROR:
fprintf(stderr, "<E> [%s() Line<%d>]: ", func, line);
vfprintf(stderr, fmt, args);
break;
case LOG_LEVEL_WARN:
fprintf(stdout, "<W> [%s() Line<%d>]: ", func, line);
vfprintf(stdout, fmt, args);
break;
case LOG_LEVEL_FATAL:
fprintf(stderr, "<F> [%s() Line<%d>]: ", func, line);
vfprintf(stderr, fmt, args);
break;
case LOG_LEVEL_DEBUG:
fprintf(stdout, "<D> [%s() Line<%d>]: ", func, line);
vfprintf(stdout, fmt, args);
break;
}
}
if (Config.VerboseMode)
{
switch (LogPriority)
{
case LOG_LEVEL_ERROR:
fprintf(stderr, "<E> [%s() Line<%d>]: ", func, line);
vfprintf(stderr, fmt, args);
break;
case LOG_LEVEL_WARN:
fprintf(stdout, "<W> [%s() Line<%d>]: ", func, line);
vfprintf(stdout, fmt, args);
break;
case LOG_LEVEL_FATAL:
fprintf(stderr, "<F> [%s() Line<%d>]: ", func, line);
vfprintf(stderr, fmt, args);
break;
case LOG_LEVEL_DEBUG:
fprintf(stdout, "<D> [%s() Line<%d>]: ", func, line);
vfprintf(stdout, fmt, args);
break;
}
}
va_end(args);
va_end(args);
}
/**

View File

@@ -7,7 +7,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,8 +16,8 @@
* limitations under the License.
*/
#define INC_MAIN_LIBS
#define INC_STAT
#define INC_MAIN_LIBS 1
#define INC_STAT 1
#include <PartitionManager/PartitionManager.h>
@@ -31,21 +31,22 @@
*/
int PartitionManager::GetState(const string& filepath, const string& stype)
{
struct stat GetStat;
VLOGD("Checking `%s' with 'stat <sys/stat.h>'...\n", filepath.c_str());
struct stat GetStat;
VLOGD("Checking `%s' with 'stat <sys/stat.h>'...\n", filepath.c_str());
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;
else if (stype == "blk")
return (S_ISBLK(GetStat.st_mode)) ? 0 : -1;
else if (stype == "link")
return (S_ISLNK(GetStat.st_mode)) ? 0 : -1;
else return 3;
if (stat(filepath.c_str(), &GetStat) != 0) return 1;
if (stype == "none") return 0;
if (stype == "dir")
return (S_ISDIR(GetStat.st_mode)) ? 0 : -1;
else if (stype == "file")
return (S_ISREG(GetStat.st_mode)) ? 0 : -1;
else if (stype == "blk")
return (S_ISBLK(GetStat.st_mode)) ? 0 : -1;
else if (stype == "link")
return (S_ISLNK(GetStat.st_mode)) ? 0 : -1;
else return 3;
return 2; /* it's a dummy value */
return 2; /* it's a dummy value */
}
/* end of code */

View File

@@ -7,7 +7,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,9 +16,9 @@
* limitations under the License.
*/
#define INC_MAIN_LIBS
#define INC_STRINGKEYS
#define HELP
#define INC_MAIN_LIBS 1
#define INC_STRINGKEYS 1
#define HELP_CPP 1
#include <PartitionManager/PartitionManager.h>
#include <PartitionManager/HelpFn.h>
@@ -30,45 +30,46 @@ struct langdb_docs* Display::UsingDocDispString = nullptr;
static void
PrepareLangconfDocs(void)
{
if (Strings::CurrentLanguage == "en")
Display::UsingDocDispString = &Display::LangDocEn;
else if (Strings::CurrentLanguage == "tr")
Display::UsingDocDispString = &Display::LangDocTr;
if (Strings::CurrentLanguage == "en")
Display::UsingDocDispString = &Display::LangDocEn;
else if (Strings::CurrentLanguage == "tr")
Display::UsingDocDispString = &Display::LangDocTr;
}
void PartitionManager::DisplayHelp(void)
{
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);
LOGD(" %s: %s %s\n\n", Display::UsingDocDispString->or_str, Strings::ExecutingName.c_str(), Display::UsingDocDispString->docs_strs_l4);
LOGD("%s:\n", Display::UsingDocDispString->docs_strs_l5);
LOGD(" -l, --logical %s\n", Display::UsingDocDispString->docs_strs_l6);
LOGD(" -P, --search-path %s\n", Display::UsingDocDispString->docs_strs_l7);
LOGD(" -p, --list %s\n", Display::UsingDocDispString->docs_strs_l8);
LOGD(" -s, --silent %s\n", Display::UsingDocDispString->docs_strs_l9);
LOGD(" -f, --force %s\n", Display::UsingDocDispString->docs_strs_l10);
LOGD(" -V, --verbose %s\n", Display::UsingDocDispString->docs_strs_l11);
LOGD(" -S, --set-lang %s\n", Display::UsingDocDispString->docs_strs_l12);
LOGD(" -v, --version %s\n", Display::UsingDocDispString->docs_strs_l13);
LOGD(" --help %s\n\n", Display::UsingDocDispString->docs_strs_l14);
LOGD("%s:\n", Display::UsingDocDispString->docs_strs_l15);
LOGD(" --only-size %s\n", Display::UsingDocDispString->docs_strs_l16);
LOGD(" --as-byte %s\n", Display::UsingDocDispString->docs_strs_l17);
LOGD(" --as-kilobyte %s\n", Display::UsingDocDispString->docs_strs_l18);
LOGD(" --as-megabyte %s\n", Display::UsingDocDispString->docs_strs_l19);
LOGD(" --as-gigabyte %s\n\n", Display::UsingDocDispString->docs_strs_l20);
LOGD("%s:\n", Display::UsingDocDispString->docs_strs_l21);
LOGD(" %s backup boot_a -P /dev/block/platform/bootdevice/by-name\n", Strings::ExecutingName.c_str());
LOGD(" %s flash boot_a /sdcard/twrp/boot.img -c /dev/block/platform/bootdevice/by-name\n", Strings::ExecutingName.c_str());
LOGD(" %s format system_a ext4 --logical\n", Strings::ExecutingName.c_str());
LOGD(" %s -P /dev/block/platform/bootdevice/by-name --list\n", Strings::ExecutingName.c_str());
LOGD(" %s partition-size boot --as-byte\n", Strings::ExecutingName.c_str());
LOGD(" %s partition-size system --only-size --as-gigabyte --logical\n\n", Strings::ExecutingName.c_str());
LOGD("%s <t.me/ShawkTeam | Topics | pmt>\n", Display::UsingDocDispString->docs_strs_l22);
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);
LOGD(" %s: %s %s\n", Display::UsingDocDispString->or_str, Strings::ExecutingName.c_str(), Display::UsingDocDispString->docs_strs_l4);
LOGD(" %s: %s %s\n\n", Display::UsingDocDispString->or_str, Strings::ExecutingName.c_str(), Display::UsingDocDispString->docs_strs_l5);
LOGD("%s:\n", Display::UsingDocDispString->docs_strs_l6);
LOGD(" -l, --logical %s\n", Display::UsingDocDispString->docs_strs_l7);
LOGD(" -P, --search-path %s\n", Display::UsingDocDispString->docs_strs_l8);
LOGD(" -p, --list %s\n", Display::UsingDocDispString->docs_strs_l9);
LOGD(" -s, --silent %s\n", Display::UsingDocDispString->docs_strs_l10);
LOGD(" -f, --force %s\n", Display::UsingDocDispString->docs_strs_l11);
LOGD(" -V, --verbose %s\n", Display::UsingDocDispString->docs_strs_l12);
LOGD(" -S, --set-lang %s\n", Display::UsingDocDispString->docs_strs_l13);
LOGD(" -v, --version %s\n", Display::UsingDocDispString->docs_strs_l14);
LOGD(" --help %s\n\n", Display::UsingDocDispString->docs_strs_l15);
LOGD("%s:\n", Display::UsingDocDispString->docs_strs_l16);
LOGD(" --only-size %s\n", Display::UsingDocDispString->docs_strs_l17);
LOGD(" --as-byte %s\n", Display::UsingDocDispString->docs_strs_l18);
LOGD(" --as-kilobyte %s\n", Display::UsingDocDispString->docs_strs_l19);
LOGD(" --as-megabyte %s\n", Display::UsingDocDispString->docs_strs_l20);
LOGD(" --as-gigabyte %s\n\n", Display::UsingDocDispString->docs_strs_l21);
LOGD("%s:\n", Display::UsingDocDispString->docs_strs_l22);
LOGD(" %s backup boot_a -P /dev/block/platform/bootdevice/by-name\n", Strings::ExecutingName.c_str());
LOGD(" %s flash boot_a /sdcard/twrp/boot.img -c /dev/block/platform/bootdevice/by-name\n", Strings::ExecutingName.c_str());
LOGD(" %s format system_a ext4 --logical\n", Strings::ExecutingName.c_str());
LOGD(" %s -P /dev/block/platform/bootdevice/by-name --list\n", Strings::ExecutingName.c_str());
LOGD(" %s partition-size boot --as-byte\n", Strings::ExecutingName.c_str());
LOGD(" %s partition-size system --only-size --as-gigabyte --logical\n\n", Strings::ExecutingName.c_str());
LOGD("%s <t.me/ShawkTeam | Topics | pmt>\n", Display::UsingDocDispString->docs_strs_l23);
}
/* end of code */

View File

@@ -7,7 +7,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,12 +16,13 @@
* limitations under the License.
*/
#define INC_MAIN_LIBS
#define INC_DEBUGERS
#define INC_STAT
#define INC_STRINGKEYS
#define INC_MAIN_LIBS 1
#define INC_DEBUGERS 1
#define INC_STAT 1
#define INC_STRINGKEYS 1
#include <PartitionManager/PartitionManager.h>
#include <PartitionManager/LanguageConfigs.h>
using namespace PartitionManager;
@@ -31,153 +32,147 @@ using namespace PartitionManager;
#define PMTLANG_CONF "/sdcard/.pmtlang.conf"
#define PMT_SW_POINT "/sdcard/.pmtlangsw"
struct langdb_general* Display::UsingDispString = nullptr;
static fstream langconf;
string supp_langs[] = {
"en",
"tr",
""
};
static fstream LanguageConfigFile;
static bool LanguageApplied = false;
static int StructSize = static_cast<int>(sizeof(LanguageConfig) / sizeof(LanguageConfig[0]));
static bool
InternalStorageDirFound(void)
{
return (GetState(INTERNAL_STORAGE_DIR, "dir") == 0) ? true : false;
return (GetState(INTERNAL_STORAGE_DIR, "dir") == 0) ? true : false;
}
static bool
LanguageControl(const string& lang)
static inline void
LoadLanguageAs(const string& Name, struct langdb_general* &Language)
{
for (int i = 0; !supp_langs[i].empty(); i++)
{
if (lang == supp_langs[i])
return true;
}
if (LanguageConfigFile.is_open())
LanguageConfigFile.close();
return false;
VLOGD("Load language as '%s'...\n", Name.c_str());
Display::UsingDispString = Language;
Strings::CurrentLanguage = Name;
LanguageApplied = true;
}
static inline bool
LanguageIsSupport(const string& Name)
{
for (int i = 0; (i < StructSize && !LanguageConfig[i].Name.empty()); i++)
if (Name == LanguageConfig[i].Name) return true;
return false;
}
static int
IfLanguageIsSupport_Load(const string& Name)
{
for (int i = 0; i < StructSize; i++) {
if (Name == LanguageConfig[i].Name) {
VLOGD("'Name' ('%s') is '%s'.\n", Name.c_str(), LanguageConfig[i].Name.c_str());
LoadLanguageAs(LanguageConfig[i].Name, LanguageConfig[i].LanguageStructure);
return 0;
}
}
return -1;
}
bool PartitionManager::LoadLanguage(void)
{
string lang_fpr = "en";
langconf.close();
string TargetLanguage = "en";
LanguageConfigFile.close();
VLOGD("Checking install type...\n");
if (GetState(TERMUX_PMT_MANDOC) == 0)
Config.InstalledOnTermux = true;
VLOGD("Checking install type...\n");
if (GetState(TERMUX_PMT_MANDOC) == 0)
Config.InstalledOnTermux = true;
VLOGD("Checking internal storage dir: `%s'\n", INTERNAL_STORAGE_DIR);
if (!InternalStorageDirFound())
LOGE("PartitionManagerLanguageTools: İnternal storage directory (`%s') not found or accessible.\n", INTERNAL_STORAGE_DIR);
VLOGD("Checking internal storage dir: `%s'\n", INTERNAL_STORAGE_DIR);
if (!InternalStorageDirFound())
LOGE("PartitionManagerLanguageTools: İnternal storage directory (`%s') not found or accessible.\n", INTERNAL_STORAGE_DIR);
VLOGD("Trying to open `%s' with 'open <fstream>'\n", PMTLANG_CONF);
langconf.open(PMTLANG_CONF, ios::in | ios::out);
VLOGD("Trying to open `%s' with 'open <fstream>'\n", PMTLANG_CONF);
LanguageConfigFile.open(PMTLANG_CONF, ios::in | ios::out);
VLOGD("Checking status: `%s'...\n", PMTLANG_CONF);
if (!langconf.is_open())
{
langconf.open(PMTLANG_CONF, ios::out | ios::trunc);
VLOGD("Checking status: `%s'...\n", PMTLANG_CONF);
if (!LanguageConfigFile.is_open()) {
LanguageConfigFile.open(PMTLANG_CONF, ios::out | ios::trunc);
VLOGD("Calling SetLanguage()...\n");
SetLanguage("en", 1);
Display::UsingDispString = &Display::LangEn;
Strings::CurrentLanguage = "en";
VLOGD("Calling SetLanguage()...\n");
SetLanguage(LanguageConfig[0].Name, 1);
LoadLanguageAs(LanguageConfig[0].Name, LanguageConfig[0].LanguageStructure); // english - "en"
if (langconf.is_open())
langconf.close();
return true;
} else {
VLOGD("Reading `%s'\n", PMTLANG_CONF);
while (getline(LanguageConfigFile, TargetLanguage))
IfLanguageIsSupport_Load(TargetLanguage);
return true;
}
else
{
VLOGD("Reading `%s'\n", PMTLANG_CONF);
while (getline(langconf, lang_fpr))
{
if (lang_fpr == "en")
goto SetEn;
else if (lang_fpr == "tr")
goto SetTr;
else
{
VLOGD("Calling SetLanguage()\n");
SetLanguage("en", 1);
VLOGD("Re-calling LoadLanguage()\n");
PartitionManager::LoadLanguage();
return true;
}
}
if (!LanguageApplied) {
VLOGD("Calling SetLanguage()\n");
SetLanguage(LanguageConfig[0].Name, 1);
LoadLanguageAs(LanguageConfig[0].Name, LanguageConfig[0].LanguageStructure); // english - "en"
return true;
}
}
if (!getline(langconf, lang_fpr))
{
VLOGD("Calling SetLanguage()\n");
SetLanguage("en", 1);
VLOGD("Re-calling LoadLanguage()\n");
PartitionManager::LoadLanguage();
return true;
}
}
if (LanguageApplied) return true;
SetEn:
langconf.close();
Display::UsingDispString = &Display::LangEn;
Strings::CurrentLanguage = "en";
VLOGD("Loaded \"en\"\n");
return true;
SetTr:
langconf.close();
Display::UsingDispString = &Display::LangTr;
Strings::CurrentLanguage = "tr";
VLOGD("Loaded \"tr\"\n");
return true;
return false;
return false;
}
void PartitionManager::SetLanguage(const string& lang, ushort_t null_conf_stat)
void PartitionManager::SetLanguage(const string& Language, ushort_t NullConfigState)
{
VLOGD("Checking speficed language (from input).\n");
if (!LanguageControl(lang))
LOGE("Unknown language: %s.\n", lang.c_str());
VLOGD("Checking speficed language (from input).\n");
if (!LanguageIsSupport(Language))
LOGE("Unknown language: %s.\n", Language.c_str());
langconf.close();
LanguageConfigFile.close();
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);
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);
VLOGD("Trying to open `%s' with 'open <fstream>'\n", PMTLANG_CONF);
langconf.open(PMTLANG_CONF, ios::out | ios::trunc);
VLOGD("Trying to open `%s' with 'open <fstream>'\n", PMTLANG_CONF);
LanguageConfigFile.open(PMTLANG_CONF, ios::out | ios::trunc);
if (!langconf.is_open())
LOGE("PartitionManagerLanguageTools: Cannot open/write config file!!!\n");
if (!LanguageConfigFile.is_open())
LOGE("PartitionManagerLanguageTools: Cannot open/write config file!!!\n");
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");
else
langconf.close();
VLOGD("Write \"%s\" to `%s' with 'std <iostream>'\n", Language.c_str(), PMTLANG_CONF);
LanguageConfigFile << Language;
if (!LanguageConfigFile)
LOGE("PartitionManagerLanguageTools: Couldn't write config!!!\n");
else
LanguageConfigFile.close();
if (null_conf_stat != 1)
{
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();
}
if (NullConfigState != 1) {
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();
}
}
void DisplaySupportedLanguages(void)
{
VLOGD("Listing supported languages...\n");
LOGD("List of supported languages: \n");
for (int i = 0; i < StructSize; i++)
LOGD(" - %s (%s)\n",
LanguageConfig[i].ExName,
LanguageConfig[i].Name);
}
bool PartitionManager::CleanSWPoint(void)
{
if (GetState(PMT_SW_POINT) == 0)
{
VLOGD("Removing (force) `%s' with 'remove <unistd.h>'\n", PMT_SW_POINT);
remove(PMT_SW_POINT);
return true;
}
if (GetState(PMT_SW_POINT) == 0) {
VLOGD("Removing (force) `%s' with 'remove <unistd.h>'\n", PMT_SW_POINT);
remove(PMT_SW_POINT);
return true;
}
return false;
return false;
}
/* end of code */

View File

@@ -7,7 +7,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,8 +16,8 @@
* limitations under the License.
*/
#define INC_MAIN_LIBS
#define INC_STRINGKEYS
#define INC_MAIN_LIBS 1
#define INC_STRINGKEYS 1
#include <PartitionManager/PartitionManager.h>
@@ -25,221 +25,237 @@ namespace PartitionManager {
namespace Display {
struct langdb_general LangEn = {
.lang_by_s = "YZBruh & r0manas",
.language = "English",
.lang_prefix = "en",
.not_logical = "This device does not have logical partitions!",
.not_file = "is not a file.",
.not_dir = "is not a directory.",
.not_in_dev = "Nothing found in /dev. Use force mode to avoid this error.",
.not_open = "Couldn't open",
.not_block = "The specified partition is not recognized as a block device. Use force mode to avoid this error.",
.not_read = "Couldn't read",
.not_readdir = "Couldn't read directory",
.not_write = "Couldn't write",
.not_gen = "Couldn't generate",
.no_root = "Root access could not be detected! Please run this with root permissions.",
.expected_backup_arg = "Expected backup argument 2 (1 of them are not mandatory), retrieved",
.expected_flash_arg = "Expected flash argument 2, retrieved",
.expected_format_arg = "Expected format argument 2, retrieved",
.expected_partsz_arg = "Expacted partition-size argument 2, retrieved",
.missing_operand = "Missing operand",
.multiple_wiewers = "Multiple viewers can't be used on the same line.",
.symbol_rule = "When specifying arguments for an option, ensure they do not begin with '-'. Each argument must correspond correctly to its respective option.",
.req_part_name = "Partition name required.",
.part_not_found = "Partition not found! Maybe a logical partition?",
.unsupported_fs = "Formatter: unsupported filesystem",
.cannot_stat = "Cannot stat",
.ffile_more_part = "Flash file size exceeds partition capacity. Use force mode to avoid this error (not recommended, riscy!).",
.cannot_get_bsz = "Failed to retrieve partition block size.",
.format_fail = "Formatting failed! There is a possibility of data damage.",
.fail_get_psize = "Cannot get partition size",
.depr_backup_opt = "These options for the backup are unavailable.",
.depr_flash_opt = "These options for the flash are unavailable.",
.depr_format_opt = "These options for the format are unavailable.",
.depr_Vlicense_opt = "Deprecated because it was unnecessary.",
.depr_ch_list_opt = "Use -p argument for listing partitions.",
.depr_ch_sp_opt = "Use -P (--search-path) argument instead of -c (--context).",
.not_spec_opt = "Specify the necessary arguments, not option",
.some_spec = "You may have indicated options, but they don't work much unless you speficy a main transaction",
.logical_warn = "This device uses logical partitions.",
.ab_warn = "This device uses A/B partition style.",
.out_not_spec = "Output file name not specified. Using created name",
.no_found_on_process = "The file that was processed was not found. Something wen wrong...",
.please_rerun = "Please rerun the command.",
.part_disk_sz = "Partition (backup) size",
.flash_file_sz = "Flash file size",
.part_disk_sz_fail = "Failed to retrieve partition disk size.",
.flash_file_sz_fail = "Failed to retrieve flash file size.",
.unknown_opr = "Unknown operand",
.req_an_arg = "option requires an argument",
.list_of_general = "List of general partitions",
.list_of_logc = "List of logical partitions",
.success_backup = "Backup successful. Output",
.success_flash = "Flash successful",
.success_format = "Format successful",
.formatting = "Formatting",
.warn = "WARNING",
.fatal = "FATAL ERROR",
.is_requires_arg = "requires an argument",
.only_partsz_args = "Flags can be used only in partition size view were identified. But target not this",
.unknw_arg = "unknown option",
.switching_lang = "Switching language...",
.welcome = "language!",
.welcome_ = "Welcome to ",
.for_more = "for more information",
.s_and_v = "Silent and verbose mode cannot be used together!",
.try_h = "Try",
.usage_head = "Usage",
.depr_opt_str = "DEPRECATED OPTION",
.switched_opt_str = "SWITCHED OPTION",
.not_changed_opt = "not changed",
.compiler_str = "compiler",
.version_str = "version",
.bin_str = "binary",
.part_name = "Partition name",
.part_type = "Partition is dynamic",
.fs_str = "Filesystem",
.unknw_str = "unknown",
.by_str = "By",
.yes = "true",
.no = "false"
.lang_by_s = "YZBruh & r0manas",
.language = "English",
.lang_prefix = "en",
.not_logical = "This device does not have logical partitions!",
.not_file = "is not a file.",
.not_dir = "is not a directory.",
.not_in_dev = "Nothing found in /dev. Use force mode to avoid this error.",
.not_open = "Couldn't open",
.not_block = "The specified partition is not recognized as a block device. Use force mode to avoid this error.",
.not_read = "Couldn't read",
.not_readdir = "Couldn't read directory",
.not_write = "Couldn't write",
.not_gen = "Couldn't generate",
.no_root = "Root access could not be detected! Please run this with root permissions.",
.expected_backup_arg = "Expected backup argument 2 (1 of them are not mandatory), retrieved",
.expected_flash_arg = "Expected flash argument 2, retrieved",
.expected_format_arg = "Expected format argument 2, retrieved",
.expected_partsz_arg = "Expected partition-size argument 1, retrieved",
.expected_partutil_arg = "Expected part-util argument 1, retrieved",
.missing_operand = "Missing operand",
.multiple_wiewers = "Multiple viewers can't be used on the same line.",
.symbol_rule = "When specifying arguments for an option, ensure they do not begin with '-'. Each argument must correspond correctly to its respective option.",
.req_part_name = "Partition name required.",
.part_not_found = "Partition not found! Maybe a logical partition?",
.unsupported_fs = "Formatter: unsupported filesystem",
.cannot_stat = "Cannot stat",
.ffile_more_part = "Flash file size exceeds partition capacity. Use force mode to avoid this error (not recommended, riscy!).",
.cannot_get_bsz = "Failed to retrieve partition block size.",
.format_fail = "Formatting failed! There is a possibility of data damage.",
.fail_get_psize = "Cannot get partition size",
.depr_backup_opt = "These options for the backup are unavailable.",
.depr_flash_opt = "These options for the flash are unavailable.",
.depr_format_opt = "These options for the format are unavailable.",
.depr_Vlicense_opt = "Deprecated because it was unnecessary.",
.depr_ch_list_opt = "Use -p argument for listing partitions.",
.depr_ch_sp_opt = "Use -P (--search-path) argument instead of -c (--context).",
.not_spec_opt = "Specify the necessary arguments, not option",
.some_spec = "You may have indicated options, but they don't work much unless you speficy a main transaction",
.logical_warn = "This device uses logical partitions.",
.ab_warn = "This device uses A/B partition style.",
.out_not_spec = "Output file name not specified. Using created name",
.no_found_on_process = "The file that was processed was not found. Something wen wrong...",
.please_rerun = "Please rerun the command.",
.part_disk_sz = "Partition (backup) size",
.flash_file_sz = "Flash file size",
.part_disk_sz_fail = "Failed to retrieve partition disk size.",
.flash_file_sz_fail = "Failed to retrieve flash file size.",
.cannot_find_any_defdevice = "Couldn't find any default device",
.cannot_find_device = "Device not founded",
.found_defdevice = "Founded a default device",
.not_spec_device_on_args = "Device is not speficed in arguments. Searching default devices (by pmt)",
.starting_parted = "Starting parted",
.exited_with = "Exited parted with exit code",
.unknown_opr = "Unknown operand",
.req_an_arg = "option requires an argument",
.list_of_general = "List of general partitions",
.list_of_logc = "List of logical partitions",
.success_backup = "Backup successful. Output",
.success_flash = "Flash successful",
.success_format = "Format successful",
.formatting = "Formatting",
.warn = "WARNING",
.fatal = "FATAL ERROR",
.is_requires_arg = "requires an argument",
.only_partsz_args = "Flags can be used only in partition size view were identified. But target not this",
.unknw_arg = "unknown option",
.switching_lang = "Switching language...",
.welcome = "language!",
.welcome_ = "Welcome to ",
.for_more = "for more information",
.s_and_v = "Silent and verbose mode cannot be used together!",
.try_h = "Try",
.usage_head = "Usage",
.depr_opt_str = "DEPRECATED OPTION",
.switched_opt_str = "SWITCHED OPTION",
.not_changed_opt = "not changed",
.compiler_str = "compiler",
.version_str = "version",
.bin_str = "binary",
.part_name = "Partition name",
.part_type = "Partition is dynamic",
.fs_str = "Filesystem",
.unknw_str = "unknown",
.by_str = "By",
.yes = "true",
.no = "false"
};
struct langdb_general LangTr = {
.lang_by_s = "YZBruh",
.language = "Türkçe",
.lang_prefix = "tr",
.not_logical = "Bu cihaz mantıksal (logical) bölümlere sahip değil!",
.not_file = "Bu bir dosya değil",
.not_dir = "Bu bir dizin değil",
.not_in_dev = "Bu bir şakamı? Bunun /dev dizini ile bir ilgisi yok (içermiyor). Bu hatayla karşılaşmak istemiyorsanız zorlama (force) modu kullanın.",
.not_open = "ılamıyor",
.not_block = "Belirtilen bölüm bir blok değil. Yani aslında bu bir bölüm bile değil (disk). Bu hatayı almak için şanslı olmak gerek..! Bu hatayla karşılaşmak istemiyorsanız zorlama (force) modu kullanın.",
.not_read = "Veri okunamıyor",
.not_readdir = "Dizin verisi okunamıyor",
.not_write = "Veri yazılamıyor",
.not_gen = "Oluşturulamıyor",
.no_root = "Root erişimi tespit edilemedi! Lütfen root erişimi ile çalıştırın.",
.expected_backup_arg = "Beklenen yedekleme argümanı 2 (bir tanesi zorunlu değil), alınan",
.expected_flash_arg = "Beklenen flaş argümanı 2, alınan",
.expected_format_arg = "Beklenen format argümanı 2, alınan",
.expected_partsz_arg = "Beklenen partition-size argümanı 1, alınan",
.missing_operand = "İşlem belirtilmedi",
.multiple_wiewers = "Birden fazla görüntüleme işlemi yapan fonksiyonlar bir arada kullanılamaz. Aynı anda sadece bir tanesi kullanılabilir.",
.symbol_rule = "Bir seçeneğin argümanını verirken argüman önüne '-' sembolü getirilemez. Sembolü kaldırın ve tekrar deneyin.",
.req_part_name = "Bölüm adı gereklidir.",
.part_not_found = "Bölüm bulunamadı! Belki mantıksal (logical) bir bölümdür?",
.unsupported_fs = "Formatlayıcı: desteklenmeyen dosya sistemi:",
.cannot_stat = "Durumu tespit edilemedi",
.ffile_more_part = "Flaşlanacak dosyanın boyutu mevcut bölüm boyutundan fazla. Bu hatayla karşılaşmak istemiyorsanız zorlama (force) modu kullanın (bunu yapmanız asla önerilmez).",
.cannot_get_bsz = "Bölüm blok boyutu tespit edilemedi!",
.format_fail = "Formatlama başarısız oldu. Bazı şeyler zarar görmüş olabilir!",
.fail_get_psize = "Bölüm boyutu alınamadı",
.depr_backup_opt = "Yedek için artık bu seçeneği kullanamazsınız.",
.depr_flash_opt = "Flaşlama için artık bu seçeneği kullanamazsınız.",
.depr_format_opt = "Formatlama için artıi bu seçeneği kullanamazsınız.",
.depr_Vlicense_opt = "Gereksiz seçeneklere bellek yok!",
.depr_ch_list_opt = "Listeleme için -p seçeneğini kullanabilirsiniz.",
.depr_ch_sp_opt = "Özel arama dizini belirtmek için -P (--search-path) seçeneğini kullanabilirsiniz.",
.logical_warn = "Bu cihaz mantıksal (logical) bölümlere sahip.",
.not_spec_opt = "Seçenek değil, şuan gerekli argümanları verin",
.some_spec = "Seçenek belirtmiş olabilirsiniz fakat, ana işlem belirtmedikçe pek işe yaramazlar",
.ab_warn = "Bu cihazın bazı bölümleri A/B kullanıyor.",
.out_not_spec = "Çıktı dosya adı belirtilmedi. Oluşturulan çıktı adı",
.no_found_on_process = "İşlenmekte olan dosya bulunamadı. Bir şeyler yanlış...",
.please_rerun = "Lütfen yeniden çalıştırın",
.part_disk_sz = "Bölümün (yedek) boyutu",
.flash_file_sz = "Flaşlanacak dosyanın boyutu",
.flash_file_sz_fail = "Uyarı: flaşlanacak dosyanın boyutu tespit edilemedi.",
.part_disk_sz_fail = "Uyarı: bölüm boyutunun boyutu tespit edilemedi.",
.unknown_opr = "Bilinmeyen işlem",
.req_an_arg = "bu seçenek argüman gerektirir",
.list_of_general = "Genel bölümlerin listesi",
.list_of_logc = "Mantıksal (logical) bölümlerin listesi",
.success_backup = "Başarılı. Çıktı",
.success_flash = "Başarılı.",
.success_format = "Formatlama başarılı",
.formatting = "Formatlanıyor",
.warn = "UYARI",
.fatal = "KRİTİK HATA",
.is_requires_arg = "bir argüman gereklidir",
.only_partsz_args = "Sadece bölüm boyutu görüntülemesinde kullanılabilecek bayraklar tespit edildi. Ama hedef bu değil",
.unknw_arg = "bilinmeyen seçenek",
.switching_lang = "Dil değiştiriliyor...",
.welcome = "diline hoş geldiniz!",
.welcome_ = NULL,
.for_more = "komutunu kullanabilirsiniz",
.s_and_v = "Sessiz ve ayrıntılı günlüklenme aynı anda kullanılamaz!",
.try_h = "Daha fazla bilgi",
.usage_head = "Kullanımı",
.depr_opt_str = "KALDIRILMIŞ SEÇENEK",
.switched_opt_str = "DEĞİŞTİRİLMİŞ SEÇENEK",
.not_changed_opt = "değiştirilmedi",
.compiler_str = "derleyicisi",
.version_str = "versiyon",
.bin_str = "yapı",
.part_name = "Bölüm adı",
.part_type = "Dinamik bölüm",
.fs_str = "Dosya sistemi",
.unknw_str = "bilinmeyen",
.by_str = "Çeviriyi yapan(lar):",
.yes = "evet",
.no = "hayır"
.lang_by_s = "YZBruh",
.language = "Türkçe",
.lang_prefix = "tr",
.not_logical = "Bu cihaz mantıksal (logical) bölümlere sahip değil!",
.not_file = "Bu bir dosya değil",
.not_dir = "Bu bir dizin değil",
.not_in_dev = "Bu bir şakamı? Bunun /dev dizini ile bir ilgisi yok (içermiyor). Bu hatayla karşılaşmak istemiyorsanız zorlama (force) modu kullanın.",
.not_open = "ılamıyor",
.not_block = "Belirtilen bölüm bir blok değil. Yani aslında bu bir bölüm bile değil (disk). Bu hatayı almak için şanslı olmak gerek..! Bu hatayla karşılaşmak istemiyorsanız zorlama (force) modu kullanın.",
.not_read = "Veri okunamıyor",
.not_readdir = "Dizin verisi okunamıyor",
.not_write = "Veri yazılamıyor",
.not_gen = "Oluşturulamıyor",
.no_root = "Root erişimi tespit edilemedi! Lütfen root erişimi ile çalıştırın.",
.expected_backup_arg = "Beklenen yedekleme argümanı 2 (bir tanesi zorunlu değil), alınan",
.expected_flash_arg = "Beklenen flaş argümanı 2, alınan",
.expected_format_arg = "Beklenen format argümanı 2, alınan",
.expected_partsz_arg = "Beklenen partition-size argümanı 1, alınan",
.expected_partutil_arg = "Beklenen part-util argümanı 1, alınan",
.missing_operand = "İşlem belirtilmedi",
.multiple_wiewers = "Birden fazla görüntüleme işlemi yapan fonksiyonlar bir arada kullanılamaz. Aynı anda sadece bir tanesi kullanılabilir.",
.symbol_rule = "Bir seçeneğin argümanını verirken argüman önüne '-' sembolü getirilemez. Sembolü kaldırın ve tekrar deneyin.",
.req_part_name = "Bölüm adı gereklidir.",
.part_not_found = "Bölüm bulunamadı! Belki mantıksal (logical) bir bölümdür?",
.unsupported_fs = "Formatlayıcı: desteklenmeyen dosya sistemi:",
.cannot_stat = "Durumu tespit edilemedi",
.ffile_more_part = "Flaşlanacak dosyanın boyutu mevcut bölüm boyutundan fazla. Bu hatayla karşılaşmak istemiyorsanız zorlama (force) modu kullanın (bunu yapmanız asla önerilmez).",
.cannot_get_bsz = "Bölüm blok boyutu tespit edilemedi!",
.format_fail = "Formatlama başarısız oldu. Bazı şeyler zarar görmüş olabilir!",
.fail_get_psize = "Bölüm boyutu alınamadı",
.depr_backup_opt = "Yedek için artık bu seçeneği kullanamazsınız.",
.depr_flash_opt = "Flaşlama için artık bu seçeneği kullanamazsınız.",
.depr_format_opt = "Formatlama için artıi bu seçeneği kullanamazsınız.",
.depr_Vlicense_opt = "Gereksiz seçeneklere bellek yok!",
.depr_ch_list_opt = "Listeleme için -p seçeneğini kullanabilirsiniz.",
.depr_ch_sp_opt = "Özel arama dizini belirtmek için -P (--search-path) seçeneğini kullanabilirsiniz.",
.logical_warn = "Bu cihaz mantıksal (logical) bölümlere sahip.",
.not_spec_opt = "Seçenek değil, şuan gerekli argümanları verin",
.some_spec = "Seçenek belirtmiş olabilirsiniz fakat, ana işlem belirtmedikçe pek işe yaramazlar",
.ab_warn = "Bu cihazın bazı bölümleri A/B kullanıyor.",
.out_not_spec = "Çıktı dosya adı belirtilmedi. Oluşturulan çıktı adı",
.no_found_on_process = "İşlenmekte olan dosya bulunamadı. Bir şeyler yanlış...",
.please_rerun = "Lütfen yeniden çalıştırın",
.part_disk_sz = "Bölümün (yedek) boyutu",
.flash_file_sz = "Flaşlanacak dosyanın boyutu",
.flash_file_sz_fail = "Uyarı: flaşlanacak dosyanın boyutu tespit edilemedi.",
.part_disk_sz_fail = "Uyarı: bölüm boyutunun boyutu tespit edilemedi.",
.found_defdevice = "Varsayılan bir cihaz bulundu",
.cannot_find_any_defdevice = "Herhangi bir varsayılan cihaz bulunamadı",
.cannot_find_device = "Cihaz bulunamadı",
.not_spec_device_on_args = "Cihaz argümanlarda belirtilmedi. Varsayılan cihazlar aranıyor (pmt tarafından tanımlanan cihazlar)",
.starting_parted = "Parted başlatılıyor",
.exited_with = "Parted çıkış kodu",
.unknown_opr = "Bilinmeyen işlem",
.req_an_arg = "bu seçenek argüman gerektirir",
.list_of_general = "Genel bölümlerin listesi",
.list_of_logc = "Mantıksal (logical) bölümlerin listesi",
.success_backup = "Başarılı. Çıktı",
.success_flash = "Başarılı.",
.success_format = "Formatlama başarılı",
.formatting = "Formatlanıyor",
.warn = "UYARI",
.fatal = "KRİTİK HATA",
.is_requires_arg = "bir argüman gereklidir",
.only_partsz_args = "Sadece bölüm boyutu görüntülemesinde kullanılabilecek bayraklar tespit edildi. Ama hedef bu değil",
.unknw_arg = "bilinmeyen seçenek",
.switching_lang = "Dil değiştiriliyor...",
.welcome = "diline hoş geldiniz!",
.welcome_ = NULL,
.for_more = "komutunu kullanabilirsiniz",
.s_and_v = "Sessiz ve ayrıntılı günlüklenme aynı anda kullanılamaz!",
.try_h = "Daha fazla bilgi",
.usage_head = "Kullanımı",
.depr_opt_str = "KALDIRILMIŞ SEÇENEK",
.switched_opt_str = "DEĞİŞTİRİLMİŞ SEÇENEK",
.not_changed_opt = "değiştirilmedi",
.compiler_str = "derleyicisi",
.version_str = "versiyon",
.bin_str = "yapı",
.part_name = "Bölüm adı",
.part_type = "Dinamik bölüm",
.fs_str = "Dosya sistemi",
.unknw_str = "bilinmeyen",
.by_str = "Çeviriyi yapan(lar):",
.yes = "evet",
.no = "hayır"
};
struct langdb_docs LangDocEn = {
.docs_strs_l1 = "[OPTIONS] backup PARTITION [OUTPUT] [OPTIONS]...",
.docs_strs_l2 = "[OPTIONS] flash PARTITION FILE [OPTIONS]...",
.docs_strs_l3 = "[OPTIONS] format PARTITION FILE_SYSTEM[ext/2/3/4] [OPTIONS]...",
.docs_strs_l4 = "[OPTIONS] partition-size PARTITION [OPTIONS]...",
.docs_strs_l5 = "Options",
.docs_strs_l6 = "It is meant to determine whether the target partition is logical.",
.docs_strs_l7 = "It is meant to specify a custom partition search path. Only normal partitions (default: /dev/block/by-name).",
.docs_strs_l8 = "List partitions.",
.docs_strs_l9 = "Information and warning messages are silenced in normal work.",
.docs_strs_l10 = "Force mode. Some things are ignored.",
.docs_strs_l11 = "Verbose mode. Print detailed informations etc.",
.docs_strs_l12 = "Set current language.",
.docs_strs_l13 = "See version.",
.docs_strs_l14 = "See this help message.",
.docs_strs_l15 = "partition-size flags",
.docs_strs_l16 = "Only the size is displayed, the partition name etc is not displayed.",
.docs_strs_l17 = "Display size as byte.",
.docs_strs_l18 = "Display size as kilobyte.",
.docs_strs_l19 = "Display size as megabyte.",
.docs_strs_l20 = "Display size as gigabyte.",
.docs_strs_l21 = "Examples",
.docs_strs_l22 = "Report bugs and suggestions to",
.or_str = "or",
.usage_docstr = "Usage"
.docs_strs_l1 = "[OPTIONS] start-parted [DEVICE]...",
.docs_strs_l2 = "[OPTIONS] backup PARTITION [OUTPUT] [OPTIONS]...",
.docs_strs_l3 = "[OPTIONS] flash PARTITION FILE [OPTIONS]...",
.docs_strs_l4 = "[OPTIONS] format PARTITION FILE_SYSTEM[ext/2/3/4] [OPTIONS]...",
.docs_strs_l5 = "[OPTIONS] partition-size PARTITION [OPTIONS]...",
.docs_strs_l6 = "Options",
.docs_strs_l7 = "It is meant to determine whether the target partition is logical.",
.docs_strs_l8 = "It is meant to specify a custom partition search path. Only normal partitions (default: /dev/block/by-name).",
.docs_strs_l9 = "List partitions.",
.docs_strs_l10 = "Information and warning messages are silenced in normal work.",
.docs_strs_l11 = "Force mode. Some things are ignored.",
.docs_strs_l12 = "Verbose mode. Print detailed informations etc.",
.docs_strs_l13 = "Set current language.",
.docs_strs_l14 = "See version.",
.docs_strs_l15 = "See this help message.",
.docs_strs_l16 = "partition-size flags",
.docs_strs_l17 = "Only the size is displayed, the partition name etc is not displayed.",
.docs_strs_l18 = "Display size as byte.",
.docs_strs_l19 = "Display size as kilobyte.",
.docs_strs_l20 = "Display size as megabyte.",
.docs_strs_l21 = "Display size as gigabyte.",
.docs_strs_l22 = "Examples",
.docs_strs_l23 = "Report bugs and suggestions to",
.or_str = "or",
.usage_docstr = "Usage"
};
struct langdb_docs LangDocTr = {
.docs_strs_l1 = "[SEÇENEKLER] backup BÖLÜM [ÇIKTI] [SEÇENEKLER]...",
.docs_strs_l2 = "[SEÇENEKLER] flash BÖLÜM DOSYA [SEÇENEKLER]...",
.docs_strs_l3 = "[SEÇENEKLER] format BÖLÜM DOSYA_SİSTEMİ[ext/2/3/4] [SEÇENEKLER]...",
.docs_strs_l4 = "[SEÇENEKLER] partition-size BÖLÜM [SEÇENEKLER]...",
.docs_strs_l5 = "Seçenekler",
.docs_strs_l6 = "Mantıksal (logical) bölüm ile işlem yapın.",
.docs_strs_l7 = "Özel bir bölüm arama dizini belirtin. Sadece normal bölümler içindir (Varsayılan: /dev/block/by-name).",
.docs_strs_l8 = "Bölümler listelenir.",
.docs_strs_l9 = "Bilgi ve uyarı mesajları susturulur.",
.docs_strs_l10 = "Zorlama modu. Bazı şeyler göz ardı edilir.",
.docs_strs_l11 = "Ayrıntılı bilgi modu. Daha fazla bilgi mesajı verilir.",
.docs_strs_l12 = "Mevcut dili ayarlayın.",
.docs_strs_l13 = "Sürümü görüntüleyin.",
.docs_strs_l14 = "Bu yardım mesajını görüntüleyin.",
.docs_strs_l15 = "partition-size bayrakları",
.docs_strs_l16 = "Boyut görüntülenirken bölüm adı vb gibi bilgiler verilmez, sadece boyut görüntülenir.",
.docs_strs_l17 = "Boyutu bayt olarak görüntüleyin.",
.docs_strs_l18 = "Boyutu kilobayt olarak görüntüleyin.",
.docs_strs_l19 = "Boyutu megabyte olarak görüntüleyin.",
.docs_strs_l20 = "Boyutu gigabayt olarak görüntüleyin.",
.docs_strs_l21 = "Örnekler",
.docs_strs_l22 = "Sorunları ve önerileri şuraya bildirin:",
.or_str = "yada",
.usage_docstr = "Kullanımı"
.docs_strs_l1 = "[SEÇENEKLER] start-parted [CİHAZ]...",
.docs_strs_l2 = "[SEÇENEKLER] backup BÖLÜM [ÇIKTI] [SEÇENEKLER]...",
.docs_strs_l3 = "[SEÇENEKLER] flash BÖLÜM DOSYA [SEÇENEKLER]...",
.docs_strs_l4 = "[SEÇENEKLER] format BÖLÜM DOSYA_SİSTEMİ[ext/2/3/4] [SEÇENEKLER]...",
.docs_strs_l5 = "[SEÇENEKLER] partition-size BÖLÜM [SEÇENEKLER]...",
.docs_strs_l6 = "Seçenekler",
.docs_strs_l7 = "Mantıksal (logical) bölüm ile işlem yapın.",
.docs_strs_l8 = "Özel bir bölüm arama dizini belirtin. Sadece normal bölümler içindir (Varsayılan: /dev/block/by-name).",
.docs_strs_l9 = "Bölümler listelenir.",
.docs_strs_l10 = "Bilgi ve uyarı mesajları susturulur.",
.docs_strs_l11 = "Zorlama modu. Bazı şeyler göz ardı edilir.",
.docs_strs_l12 = "Ayrıntılı bilgi modu. Daha fazla bilgi mesajı verilir.",
.docs_strs_l13 = "Mevcut dili ayarlayın.",
.docs_strs_l14 = "Sürümü görüntüleyin.",
.docs_strs_l15 = "Bu yardım mesajını görüntüleyin.",
.docs_strs_l16 = "partition-size bayrakları",
.docs_strs_l17 = "Boyut görüntülenirken bölüm adı vb gibi bilgiler verilmez, sadece boyut görüntülenir.",
.docs_strs_l18 = "Boyutu bayt olarak görüntüleyin.",
.docs_strs_l19 = "Boyutu kilobayt olarak görüntüleyin.",
.docs_strs_l20 = "Boyutu megabyte olarak görüntüleyin.",
.docs_strs_l21 = "Boyutu gigabayt olarak görüntüleyin.",
.docs_strs_l22 = "Örnekler",
.docs_strs_l23 = "Sorunları ve önerileri şuraya bildirin:",
.or_str = "yada",
.usage_docstr = "Kullanımı"
};
} /* namespace Display */

View File

@@ -7,7 +7,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,10 +16,10 @@
* limitations under the License.
*/
#define INC_MAIN_LIBS
#define INC_DEBUGERS
#define INC_DIRENT
#define INC_STRINGKEYS
#define INC_MAIN_LIBS 1
#define INC_DEBUGERS 1
#define INC_DIRENT 1
#define INC_STRINGKEYS 1
#include <PartitionManager/PartitionManager.h>
@@ -33,108 +33,108 @@ static DIR* Directory;
static int
ListDir(const string& TargetDir, const bool ListTargetDir = false)
{
static int count;
struct dirent **List;
bool ListParts = (ListTargetDir) ? true : false;
static int count;
struct dirent **List;
bool ListParts = (ListTargetDir) ? true : false;
Directory = nullptr;
Directory = opendir(TargetDir.c_str());
Directory = nullptr;
Directory = opendir(TargetDir.c_str());
if (ListParts)
{
count = scandir(TargetDir.c_str(), &List, nullptr, alphasort);
if (ListParts)
{
count = scandir(TargetDir.c_str(), &List, nullptr, alphasort);
if (count < 0)
LOGE("%s: `%s': %s\n",
Display::UsingDispString->not_readdir,
TargetDir.c_str(),
strqerror());
if (count < 0)
LOGE("%s: `%s': %s\n",
Display::UsingDispString->not_readdir,
TargetDir.c_str(),
strqerror());
for (int i = 0; i < count; i++)
{
if (List[i]->d_name[0] != '.'
&& strncmp(List[i]->d_name, "com.", 4) != 0
&& strcmp(List[i]->d_name, "by-uuid") != 0
&& strcmp(List[i]->d_name, "userdata") != 0)
LOGD(" - [ %-16s ]\n", List[i]->d_name);
for (int i = 0; i < count; i++)
{
if (List[i]->d_name[0] != '.'
&& strncmp(List[i]->d_name, "com.", 4) != 0
&& strcmp(List[i]->d_name, "by-uuid") != 0
&& strcmp(List[i]->d_name, "userdata") != 0)
LOGD(" - [ %-16s ]\n", List[i]->d_name);
free(List[i]);
}
free(List[i]);
}
free(List);
List = nullptr;
free(List);
List = nullptr;
goto directory;
}
goto directory;
}
directory:
if (Directory != nullptr)
{
closedir(Directory);
return 0;
}
else
return -1;
if (Directory != nullptr)
{
closedir(Directory);
return 0;
}
else
return -1;
return 2;
return 2;
}
/* list existing partitions */
int PartitionManager::ListPartitions(void)
{
VLOGD("Selecting search path...\n");
string AccessDir = (Config.UseCustomSearchPath) ? Strings::CustomSearchPath : CUR_DEV_SP;
VLOGD("Selecting search path...\n");
string AccessDir = (Config.UseCustomSearchPath) ? Strings::CustomSearchPath : CUR_DEV_SP;
VLOGD("Trying to access `%s'...\n", AccessDir.c_str());
if (ListDir(AccessDir) != 0)
{
if (!Config.ForceMode)
LOGE("%s: `%s': %s\n",
Display::UsingDispString->not_open,
AccessDir.c_str(),
strqerror());
else
return 1;
}
else
{
LOGD("%s:\n", Display::UsingDispString->list_of_general);
ListDir(AccessDir, true);
}
VLOGD("Trying to access `%s'...\n", AccessDir.c_str());
if (ListDir(AccessDir) != 0)
{
if (!Config.ForceMode)
LOGE("%s: `%s': %s\n",
Display::UsingDispString->not_open,
AccessDir.c_str(),
strqerror());
else
return 1;
}
else
{
LOGD("%s:\n", Display::UsingDispString->list_of_general);
ListDir(AccessDir, true);
}
if (Config.UsesLogical)
{
VLOGD("Checking for listing `%s'...\n", LGC_DEV_SP);
if (Config.UsesLogical)
{
VLOGD("Checking for listing `%s'...\n", LGC_DEV_SP);
if (ListDir(LGC_DEV_SP) != 0)
LOGE("%s: `%s': %s\n",
Display::UsingDispString->not_open,
LGC_DEV_SP,
strqerror());
else
{
LOGD("\n%s:\n", Display::UsingDispString->list_of_logc);
ListDir(LGC_DEV_SP, true);
}
}
if (ListDir(LGC_DEV_SP) != 0)
LOGE("%s: `%s': %s\n",
Display::UsingDispString->not_open,
LGC_DEV_SP,
strqerror());
else
{
LOGD("\n%s:\n", Display::UsingDispString->list_of_logc);
ListDir(LGC_DEV_SP, true);
}
}
VLOGD("(if have) warnings are printed...\n");
VLOGD("(if have) warnings are printed...\n");
if (Config.UsesLogical)
{
LOGD("\n");
LOGW("%s\n", Display::UsingDispString->logical_warn);
}
if (Config.UsesLogical)
{
LOGD("\n");
LOGW("%s\n", Display::UsingDispString->logical_warn);
}
if (Config.UsesSlots)
{
if (!Config.UsesLogical)
LOGD("\n");
if (Config.UsesSlots)
{
if (!Config.UsesLogical)
LOGD("\n");
LOGW("%s\n", Display::UsingDispString->ab_warn);
}
LOGW("%s\n", Display::UsingDispString->ab_warn);
}
return 0;
return 0;
}
/* end of code */

View File

@@ -0,0 +1,137 @@
/* By YZBruh */
/**
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define INC_MAIN_LIBS 1
#define INC_STRINGKEYS 1
#define INC_DEBUGERS 1
#define INC_PTHREAD 1
/* using by new devices */
#define DEFAULT_DEVICE_NEW "/dev/block/sda"
/* using by old devices */
#define DEFAULT_DEVICE_OLD "/dev/block/mmcblk0"
/**
* These macros will be added/deleted/modified
* according to user feedback.
*/
#include <PartitionManager/PartitionManager.h>
#include <PartitionManager/Parted.h>
static bool started = false, o_ended = false;
static int ret = 0;
static pthread_mutex_t plock = PTHREAD_MUTEX_INITIALIZER;
extern "C" void* __start_parted(void* dummy_arg);
extern "C" void* __watch_parted(void* dummy_arg);
bool PartitionManager::SearchDevice(const string& DevicePath)
{
VLOGD("Check '%s'.\n", DevicePath.c_str());
if (PartitionManager::GetState(DevicePath, "none") != 0) {
VLOGD("Cannot find '%s'.\n", DevicePath.c_str());
return false;
} else VLOGD("Founded: '%s'.\n", DevicePath.c_str());
return true;
}
bool PartitionManager::SearchDefaultDevices(void)
{
VLOGD("Searching '%s'.\n", DEFAULT_DEVICE_NEW);
if (PartitionManager::SearchDevice(DEFAULT_DEVICE_NEW)) {
PartitionManager::Strings::Device = DEFAULT_DEVICE_NEW;
return true;
}
VLOGD("Searching '%s'.\n", DEFAULT_DEVICE_NEW);
if (PartitionManager::SearchDevice(DEFAULT_DEVICE_OLD)) {
PartitionManager::Strings::Device = DEFAULT_DEVICE_OLD;
return true;
}
return false;
}
void* __watch_parted(void* dummy_arg)
{
while (1) {
pthread_mutex_lock(&plock);
if (started) {
if (o_ended) {
pthread_mutex_unlock(&plock);
return NULL;
}
if (set_ret) {
LOGD("%s: %d.\n",
PartitionManager::Display::UsingDispString->exited_with,
parted_ret);
pthread_mutex_unlock(&plock);
return NULL;
}
} else {
VLOGD("Parted is still not started...\n");
sleep(1);
}
pthread_mutex_unlock(&plock);
usleep(1000);
}
}
void* __start_parted(void* dummy_arg)
{
VLOGD("Generating arguments...\n");
char* arguments[] = {
"parted-pmt",
(char*)PartitionManager::Strings::Device.c_str(),
};
LOGD("%s...\n", PartitionManager::Display::UsingDispString->starting_parted);
VLOGD("Calling parted_main...\n");
pthread_mutex_lock(&plock);
started = true;
pthread_mutex_unlock(&plock);
ret = parted_main(2, arguments);
pthread_mutex_lock(&plock);
o_ended = true;
pthread_mutex_unlock(&plock);
sleep(1);
return NULL;
}
int PartitionManager::StartParted(void)
{
pthread_t t1, t2;
pthread_create(&t1, NULL, __start_parted, NULL);
pthread_create(&t2, NULL, __watch_parted, NULL);
pthread_join(t1, NULL);
pthread_join(t2, NULL);
return ret;
}
/* end of code */

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,7 +16,7 @@
* limitations under the License.
*/
#define INC_MAIN_LIBS
#define INC_MAIN_LIBS 1
#include <PartitionManager/PartitionManager.h>
#include <sys/system_properties.h>
@@ -24,51 +24,51 @@
static int
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);
char val[PROP_VALUE_MAX];
int len = __system_property_get(property, val);
VLOGD("Get property value: '%s'\n", property);
if (len > 0)
{
VLOGD("%s=%s\n", property, val);
VLOGD("Get property value: '%s'\n", property);
if (len > 0)
{
VLOGD("%s=%s\n", property, val);
VLOGD("Comparing '%s' property value '%s'\n", property, val1);
if (strcmp(val, val1) == 0)
{
VLOGD("'%s' is '%s'. Stop (0).\n", property, val1);
return 0;
}
else
{
VLOGE("'%s' property is not '%s'. Comparing desired value 2 (if speficed).\n", property, val1);
VLOGD("Comparing '%s' property value '%s'\n", property, val1);
if (strcmp(val, val1) == 0)
{
VLOGD("'%s' is '%s'. Stop (0).\n", property, val1);
return 0;
}
else
{
VLOGE("'%s' property is not '%s'. Comparing desired value 2 (if speficed).\n", property, val1);
if (val2 != nullptr)
{
if (strcmp(val, val2) == 0)
{
VLOGD("'%s' is '%s'.Stop (0).\n", property, val2);
return 0;
}
else
{
VLOGE("'%s' is not '%s'. Stop (1).\n", property, val2);
return 1;
}
}
else
{
VLOGE("'%s' is not '%s'. Stop (1).\n", property, val1);
return 1;
}
}
}
else
{
VLOGE("Cannot get property '%s'. No such property or empty. Stop (1).\n", property);
return 1;
}
if (val2 != nullptr)
{
if (strcmp(val, val2) == 0)
{
VLOGD("'%s' is '%s'.Stop (0).\n", property, val2);
return 0;
}
else
{
VLOGE("'%s' is not '%s'. Stop (1).\n", property, val2);
return 1;
}
}
else
{
VLOGE("'%s' is not '%s'. Stop (1).\n", property, val1);
return 1;
}
}
}
else
{
VLOGE("Cannot get property '%s'. No such property or empty. Stop (1).\n", property);
return 1;
}
return 2;
return 2;
}
using namespace PartitionManager;
@@ -76,17 +76,17 @@ using namespace PartitionManager;
/* check parts */
void PartitionManager::CheckDevPoint(void)
{
/* true = ab | false = a only */
Config.UsesSlots = (GetProperty("ro.boot.slot_suffix", "_a", "_b") == 0 || GetProperty("ro.boot.slot", "_a", "_b") == 0) ? true : false;
/* true = ab | false = a only */
Config.UsesSlots = (GetProperty("ro.boot.slot_suffix", "_a", "_b") == 0 || GetProperty("ro.boot.slot", "_a", "_b") == 0) ? true : false;
if (Config.UsesSlots)
VLOGW("1 warning generated: A/B partitions status.\n");
if (Config.UsesSlots)
VLOGW("1 warning generated: A/B partitions status.\n");
/* true = logical | false = normal */
Config.UsesLogical = (GetProperty("ro.boot.dynamic_partitions", "true") == 0) ? true : false;
/* true = logical | false = normal */
Config.UsesLogical = (GetProperty("ro.boot.dynamic_partitions", "true") == 0) ? true : false;
if (Config.UsesLogical)
VLOGW("1 warning generated: logical partitions status.\n");
if (Config.UsesLogical)
VLOGW("1 warning generated: logical partitions status.\n");
}
/* end of code */

View File

@@ -7,7 +7,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,22 +16,22 @@
* limitations under the License.
*/
#define INC_MAIN_LIBS
#define INC_DEBUGERS
#define INC_STRINGKEYS
#define INC_MAIN_LIBS 1
#define INC_DEBUGERS 1
#define INC_STRINGKEYS 1
#include <PartitionManager/PartitionManager.h>
/* root checker function */
void PartitionManager::CheckRoot(void)
{
VLOGD("Trying to get UID with 'getuid <unistd.h>'\n");
VLOGD("Trying to get UID with 'getuid <unistd.h>'\n");
if (getuid() != 0)
{
VLOGE("You are not superuser!\n");
LOGE("%s\n", PartitionManager::Display::UsingDispString->no_root);
}
if (getuid() != 0)
{
VLOGE("You are not superuser!\n");
LOGE("%s\n", PartitionManager::Display::UsingDispString->no_root);
}
}
/* end of code */

View File

@@ -7,7 +7,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,12 +16,12 @@
* limitations under the License.
*/
#define INC_MAIN_LIBS
#define INC_STAT
#define INC_LIBGEN
#define INC_DEBUGERS
#define INC_TOOLS_REQS
#define INC_STRINGKEYS
#define INC_MAIN_LIBS 1
#define INC_STAT 1
#define INC_LIBGEN 1
#define INC_DEBUGERS 1
#define INC_TOOLS_REQS 1
#define INC_STRINGKEYS 1
#include <PartitionManager/PartitionManager.h>
#include <PartitionManager/PartSizeMacros.h>
@@ -36,70 +36,69 @@ namespace PartitionManager {
* it is meant to calculate the size of the quickly given file.
* its purpose is for rapid processing
*/
static long long
static inline long long
CalculateSizeLongLong(const string& fp)
{
VLOGD("Calculating file size: `%s'\n", fp.c_str());
VLOGD("Calculating file size: `%s'\n", fp.c_str());
VLOGD("Reading `%s' with 'ifstream <fstream>'\n", fp.c_str());
ifstream file(fp, ios::binary | ios::ate);
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());
return (!file) ? -1 : static_cast<long long>(file.tellg());
}
/**
* error that the partition is not found.
* It's for quick action.
*/
static void
static inline void
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
static inline void
SearchPartition(const string& fp)
{
VLOGD("Calling GetState()...\n");
static int op = GetState(fp, "blk");
VLOGD("Calling GetState()...\n");
static int op = GetState(fp, "blk");
if (op == 1)
PartitionNotFound(basename(fp.c_str()));
else if (op == -1 && !Config.ForceMode)
LOGE("%s\n", Display::UsingDispString->not_block);
if (op == 1)
PartitionNotFound(basename(fp.c_str()));
else if (op == -1 && !Config.ForceMode)
LOGE("%s\n", Display::UsingDispString->not_block);
}
static void
PrintInfo(const ushort_t& pcode, const double& psz, const double& fsz)
{
LOGD("##########################################\n");
LOGD("# --> %s: %s\n",
Display::UsingDispString->part_name,
Strings::TargetPartition.c_str());
LOGD("# --> %s: %s\n",
Display::UsingDispString->part_type,
(Config.UseLogical) ? Display::UsingDispString->yes : Display::UsingDispString->no);
LOGD("##########################################\n");
LOGD("# --> %s: %s\n",
Display::UsingDispString->part_name,
Strings::TargetPartition.c_str());
LOGD("# --> %s: %s\n",
Display::UsingDispString->part_type,
(Config.UseLogical) ? Display::UsingDispString->yes : Display::UsingDispString->no);
if (psz != -1)
LOGD("# --> %s: %.2fMB\n",
Display::UsingDispString->part_disk_sz,
psz);
else
LOGD("# --> %s: %s\n",
Display::UsingDispString->warn,
Display::UsingDispString->part_disk_sz_fail);
if (psz != -1)
LOGD("# --> %s: %.2fMB\n",
Display::UsingDispString->part_disk_sz,
psz);
else
LOGD("# --> %s: %s\n",
Display::UsingDispString->warn,
Display::UsingDispString->part_disk_sz_fail);
if (pcode == 3)
{
if (fsz != -1)
LOGD("# --> %s: %.2fMB\n",
Display::UsingDispString->flash_file_sz,
fsz);
else
LOGW("# --> %s: %s\n",
Display::UsingDispString->warn,
Display::UsingDispString->flash_file_sz_fail);
}
if (pcode == 3) {
if (fsz != -1)
LOGD("# --> %s: %.2fMB\n",
Display::UsingDispString->flash_file_sz,
fsz);
else
LOGW("# --> %s: %s\n",
Display::UsingDispString->warn,
Display::UsingDispString->flash_file_sz_fail);
}
LOGD("##########################################\n");
LOGD("##########################################\n");
}
template <typename T>
@@ -109,48 +108,47 @@ IsDoubleOf1024(T size) { return size % (T)1024 == 0; }
static void
ReadAndWrite(const string& FNameForMsg, const int& bfsize)
{
long long copiedData = 0;
char buffer[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);
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());
if (targetF.fail() || targetF.bad())
LOGF("%s: %s: %s\n",
Display::UsingDispString->not_write,
FNameForMsg.c_str(),
strqerror());
copiedData += readed_data;
}
copiedData += readed_data;
}
}
static void
OpenSourceFile(const string& fp)
{
VLOGD("Trying to open `%s' with 'open <fstream>'.\n", fp.c_str());
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());
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());
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());
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 PartitionManager */
@@ -159,172 +157,159 @@ using namespace PartitionManager;
int PartitionManager::PartitionManagerMain(const ushort_t& progress_code)
{
/* Some required variables */
string accessPrefix, opName;
/* Some required variables */
string accessPrefix, opName;
if (Config.UseLogical)
accessPrefix = "/dev/block/mapper/" + Strings::TargetPartition;
else
accessPrefix = (Config.UseCustomSearchPath) ? (Strings::CustomSearchPath) + ("/") + (Strings::TargetPartition) : ("/dev/block/by-name/") + (Strings::TargetPartition);
if (Config.UseLogical)
accessPrefix = "/dev/block/mapper/" + Strings::TargetPartition;
else
accessPrefix = (Config.UseCustomSearchPath) ? (Strings::CustomSearchPath) + ("/") + (Strings::TargetPartition) : ("/dev/block/by-name/") + (Strings::TargetPartition);
VLOGD("Calling SearchPartition() for searching partition (path); `%s'\n", accessPrefix.c_str());
SearchPartition(accessPrefix);
VLOGD("Calling SearchPartition() for searching partition (path); `%s'\n", accessPrefix.c_str());
SearchPartition(accessPrefix);
Count = (long long)(CalculateSizeLongLong(accessPrefix) + ((1024 * 1024) * 4));
const int BFSIZE = (IsDoubleOf1024(CalculateSizeLongLong(accessPrefix))) ? 1024 : 1;
double FlashFileSize = 0;
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>(CalculateSizeLongLong(accessPrefix)) / (1024 * 1024));
if (!Strings::TargetFlashFile.empty())
FlashFileSize = (double)(static_cast<double>(CalculateSizeLongLong(Strings::TargetFlashFile)) / (1024 * 1024));
double PartitionSize = (double)(static_cast<double>(CalculateSizeLongLong(accessPrefix)) / (1024 * 1024));
if (!Strings::TargetFlashFile.empty())
FlashFileSize = (double)(static_cast<double>(CalculateSizeLongLong(Strings::TargetFlashFile)) / (1024 * 1024));
if (progress_code != 4) PrintInfo(progress_code, PartitionSize, FlashFileSize);
if (progress_code != 4) PrintInfo(progress_code, PartitionSize, FlashFileSize);
if (progress_code == 1)
{
OpenSourceFile(accessPrefix);
if (progress_code == 1) {
OpenSourceFile(accessPrefix);
/* determine output */
if (Strings::OutputName == Strings::TargetPartition)
{
opName = Strings::OutputName + ".img";
VLOGW("Output not speficed. Selecting automaticly.\n");
LOGW("%s: %s\n",
Display::UsingDispString->out_not_spec,
opName.c_str());
}
else
opName = Strings::OutputName;
/* determine output */
if (Strings::OutputName == Strings::TargetPartition) {
opName = Strings::OutputName + ".img";
VLOGW("Output not speficed. Selecting automaticly.\n");
LOGW("%s: %s\n",
Display::UsingDispString->out_not_spec,
opName.c_str());
} else
opName = Strings::OutputName;
VLOGD("Checking output status...\n");
if (GetState(opName) == 0)
LOGE("'%s': File exits.\n", opName.c_str());
VLOGD("Checking output status...\n");
if (GetState(opName) == 0)
LOGE("'%s': File exits.\n", opName.c_str());
OpenTargetFile(opName);
OpenTargetFile(opName);
VLOGD("Read (partition) and write (output) 'read, write <fstream>'\n");
ReadAndWrite(opName.c_str(), BFSIZE);
VLOGD("Read (partition) and write (output) 'read, write <fstream>'\n");
ReadAndWrite(opName.c_str(), BFSIZE);
/* close files */
sourceF.close();
targetF.close();
/* close files */
sourceF.close();
targetF.close();
LOGD("%s: %s\n",
Display::UsingDispString->success_backup,
opName.c_str());
}
else if (progress_code == 2)
{
if (PartitionSize != -1 && FlashFileSize != -1)
{
if (FlashFileSize > PartitionSize && !Config.ForceMode)
LOGE("%s\n", Display::UsingDispString->ffile_more_part);
}
LOGD("%s: %s\n",
Display::UsingDispString->success_backup,
opName.c_str());
} else if (progress_code == 2) {
if (PartitionSize != -1 && FlashFileSize != -1) {
if (FlashFileSize > PartitionSize && !Config.ForceMode)
LOGE("%s\n", Display::UsingDispString->ffile_more_part);
}
OpenSourceFile(Strings::TargetFlashFile);
OpenTargetFile(accessPrefix);
OpenSourceFile(Strings::TargetFlashFile);
OpenTargetFile(accessPrefix);
VLOGD("Read (flash file) and write (partition) 'read, write <fstream>'\n");
ReadAndWrite(accessPrefix.c_str(), BFSIZE);
VLOGD("Read (flash file) and write (partition) 'read, write <fstream>'\n");
ReadAndWrite(accessPrefix.c_str(), BFSIZE);
sourceF.close();
targetF.close();
sourceF.close();
targetF.close();
LOGD("%s.\n", Display::UsingDispString->success_flash);
}
else if (progress_code == 3)
{
/* get target partition block size */
VLOGD("Getting block size '%s' with 'statfs <sys/vfs.h>'\n", accessPrefix.c_str());
LOGD("%s.\n", Display::UsingDispString->success_flash);
} else if (progress_code == 3) {
/* get target partition block size */
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);
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("Generating mke2fs argument list...\n");
char bsize[25] = "";
/* generate mke2fs argument list */
VLOGD("Generating mke2fs argument list...\n");
char bsize[25] = "";
#ifdef __LP64__
sprintf(bsize, "%lu", file_sys_inf.f_bsize);
sprintf(bsize, "%lu", file_sys_inf.f_bsize);
#else
sprintf(bsize, "%u", file_sys_inf.f_bsize);
sprintf(bsize, "%u", file_sys_inf.f_bsize);
#endif
char* arguments[] = {
"mke2fs-static",
"-Fq",
"-t",
(char*)Strings::TargetFormatFS.c_str(),
"-b",
(char*)bsize,
(char*)accessPrefix.c_str(),
};
char* arguments[] = {
"mke2fs-static",
"-Fq",
"-t",
(char*)Strings::TargetFormatFS.c_str(),
"-b",
(char*)bsize,
(char*)accessPrefix.c_str(),
};
LOGD("%s: `%s'. %s: %s\n",
Display::UsingDispString->formatting,
accessPrefix.c_str(),
Display::UsingDispString->fs_str,
Strings::TargetFormatFS.c_str());
LOGD("%s: `%s'. %s: %s\n",
Display::UsingDispString->formatting,
accessPrefix.c_str(),
Display::UsingDispString->fs_str,
Strings::TargetFormatFS.c_str());
/* run mke2fs */
VLOGD("Calling mke2fs_main...\n");
if (mke2fs_main(sizeof(arguments), arguments) != 0)
LOGF("%s\n", Display::UsingDispString->format_fail);
/* run mke2fs */
VLOGD("Calling mke2fs_main...\n");
if (mke2fs_main(sizeof(arguments), arguments) != 0)
LOGF("%s\n", Display::UsingDispString->format_fail);
LOGD("%s.\n", Display::UsingDispString->success_format);
}
else if (progress_code == 4)
{
VLOGD("Getting size of '%s' (long long)\n", accessPrefix.c_str());
long long psize = (long long)CalculateSizeLongLong(accessPrefix);
LOGD("%s.\n", Display::UsingDispString->success_format);
} else if (progress_code == 4) {
VLOGD("Getting size of '%s' (long long)\n", accessPrefix.c_str());
long long psize = (long long)CalculateSizeLongLong(accessPrefix);
if (psize == -1)
{
VLOGE("Cannot get partition size!\n");
LOGE("%s: %s\n",
Display::UsingDispString->fail_get_psize,
strqerror());
}
if (psize == -1) {
VLOGE("Cannot get partition size!\n");
LOGE("%s: %s\n",
Display::UsingDispString->fail_get_psize,
strqerror());
}
static char* SizeType;
static char Holder[50];
static char* SizeType;
static char Holder[50];
if (!Config.OnlyViewSize)
{
sprintf(Holder, "%s: ", Strings::TargetPartition.c_str());
if (!Config.OnlyViewSize) {
sprintf(Holder, "%s: ", Strings::TargetPartition.c_str());
if (Integers::PartSizeViewType == VIEW_AS_BYTE) SizeType = "B";
else if (Integers::PartSizeViewType == VIEW_AS_KIB) SizeType = "KB";
else if (Integers::PartSizeViewType == VIEW_AS_MIB) SizeType = "MB";
else if (Integers::PartSizeViewType == VIEW_AS_GIB) SizeType = "GB";
}
else
SizeType = "";
if (Integers::PartSizeViewType == VIEW_AS_BYTE) SizeType = "B";
else if (Integers::PartSizeViewType == VIEW_AS_KIB) SizeType = "KB";
else if (Integers::PartSizeViewType == VIEW_AS_MIB) SizeType = "MB";
else if (Integers::PartSizeViewType == VIEW_AS_GIB) SizeType = "GB";
} else
SizeType = "";
VLOGD("Displaying partition size...\n");
VLOGD("Displaying partition size...\n");
if (Integers::PartSizeViewType == VIEW_AS_BYTE)
LOGD("%s%llu%s\n",
Holder,
(long long)psize,
SizeType);
else if (Integers::PartSizeViewType == VIEW_AS_KIB)
LOGD("%s%lu%s\n",
Holder,
(long)(psize / 1024),
SizeType);
else if (Integers::PartSizeViewType == VIEW_AS_MIB)
LOGD("%s%.2f%s\n",
Holder,
(double)(static_cast<double>(psize) / (1024 * 1024)),
SizeType);
else if (Integers::PartSizeViewType == VIEW_AS_GIB)
LOGD("%s%.2f%s\n",
Holder,
(double)(static_cast<double>(psize) / (1024 * 1024 * 1024)),
SizeType);
}
if (Integers::PartSizeViewType == VIEW_AS_BYTE)
LOGD("%s%llu%s\n",
Holder,
(long long)psize,
SizeType);
else if (Integers::PartSizeViewType == VIEW_AS_KIB)
LOGD("%s%lu%s\n",
Holder,
(long)(psize / 1024),
SizeType);
else if (Integers::PartSizeViewType == VIEW_AS_MIB)
LOGD("%s%.2f%s\n",
Holder,
(double)(static_cast<double>(psize) / (1024 * 1024)),
SizeType);
else if (Integers::PartSizeViewType == VIEW_AS_GIB)
LOGD("%s%.2f%s\n",
Holder,
(double)(static_cast<double>(psize) / (1024 * 1024 * 1024)),
SizeType);
}
return 0;
return 0;
}
/* end of code */

View File

@@ -7,7 +7,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,9 +16,9 @@
* limitations under the License.
*/
#define INC_MAIN_LIBS
#define INC_STRINGKEYS
#define VERSIONING
#define INC_MAIN_LIBS 1
#define INC_STRINGKEYS 1
#define VERSION_CPP 1
#include <PartitionManager/PartitionManager.h>
#include <PartitionManager/VersionFnVars.h>
@@ -27,33 +27,34 @@ using namespace PartitionManager;
void PartitionManager::DisplayVersion(void)
{
VLOGD("Printing main info...\n");
LOGD("%s %s %d.%d.%d (%d%d%d / C++) ",
Strings::ExecutingName.c_str(),
Display::UsingDispString->version_str,
PMT_MAJOR,
PMT_MINOR,
PMT_PATCHLEVEL,
PMT_MAJOR,
PMT_MINOR,
PMT_PATCHLEVEL);
VLOGD("Printing main info...\n");
LOGD("%s %s %d.%d.%d (%d%d%d / C++) ",
Strings::ExecutingName.c_str(),
Display::UsingDispString->version_str,
PMT_MAJOR,
PMT_MINOR,
PMT_PATCHLEVEL,
PMT_MAJOR,
PMT_MINOR,
PMT_PATCHLEVEL);
#ifdef __LP64__
LOGD("64-bit %s\n", Display::UsingDispString->bin_str);
LOGD("64-bit %s\n", Display::UsingDispString->bin_str);
#else
LOGD("32-bit %s\n", Display::UsingDispString->bin_str);
LOGD("32-bit %s\n", Display::UsingDispString->bin_str);
#endif
LOGD("mke2fs %s %s (%s)\n",
Display::UsingDispString->version_str,
E2FSPROGS_VERSION_PRIVATE,
E2FSPROGS_DATE);
LOGD("libext2fs %s %s (%s / %s)\n",
Display::UsingDispString->version_str,
E2FSPROGS_VERSION_PRIVATE,
EXT2FS_LIB_VERSION_PRIVATE,
E2FSPROGS_DATE);
LOGD("\n%s\n", __NDK_CXX_VERSION__);
LOGD("mke2fs %s %s (%s)\n",
Display::UsingDispString->version_str,
E2FSPROGS_VERSION_PRIVATE,
E2FSPROGS_DATE);
LOGD("libext2fs %s %s (%s / %s)\n",
Display::UsingDispString->version_str,
E2FSPROGS_VERSION_PRIVATE,
EXT2FS_LIB_VERSION_PRIVATE,
E2FSPROGS_DATE);
LOGD("\n%s\n", __NDK_CXX_VERSION__);
}
/* end of code */