pmt: reformat code
This commit is contained in:
288
.clang-format
Normal file
288
.clang-format
Normal file
@@ -0,0 +1,288 @@
|
|||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
AccessModifierOffset: -2
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignArrayOfStructures: None
|
||||||
|
AlignConsecutiveAssignments:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: true
|
||||||
|
AlignConsecutiveBitFields:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveDeclarations:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: true
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveMacros:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveShortCaseStatements:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCaseArrows: false
|
||||||
|
AlignCaseColons: false
|
||||||
|
AlignConsecutiveTableGenBreakingDAGArgColons:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveTableGenCondOperatorColons:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveTableGenDefinitionColons:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignEscapedNewlines: Right
|
||||||
|
AlignOperands: Align
|
||||||
|
AlignTrailingComments:
|
||||||
|
Kind: Always
|
||||||
|
OverEmptyLines: 0
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowBreakBeforeNoexceptSpecifier: Never
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
AllowShortCaseExpressionOnASingleLine: true
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortCompoundRequirementOnASingleLine: true
|
||||||
|
AllowShortEnumsOnASingleLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AllowShortNamespacesOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AttributeMacros:
|
||||||
|
- __capability
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: BinPack
|
||||||
|
BitFieldColonSpacing: Both
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: false
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: Never
|
||||||
|
AfterEnum: false
|
||||||
|
AfterExternBlock: false
|
||||||
|
AfterFunction: false
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: false
|
||||||
|
AfterUnion: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
BeforeLambdaBody: false
|
||||||
|
BeforeWhile: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: true
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
BreakAdjacentStringLiterals: true
|
||||||
|
BreakAfterAttributes: Leave
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakAfterReturnType: None
|
||||||
|
BreakArrays: true
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeConceptDeclarations: Always
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
BreakBeforeInlineASMColon: OnlyMultiline
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakBinaryOperations: Never
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakFunctionDefinitionParameters: false
|
||||||
|
BreakInheritanceList: BeforeColon
|
||||||
|
BreakStringLiterals: true
|
||||||
|
BreakTemplateDeclarations: MultiLine
|
||||||
|
ColumnLimit: 80
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
DisableFormat: false
|
||||||
|
EmptyLineAfterAccessModifier: Never
|
||||||
|
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
FixNamespaceComments: true
|
||||||
|
ForEachMacros:
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IfMacros:
|
||||||
|
- KJ_IF_MAYBE
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||||
|
Priority: 2
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||||
|
Priority: 3
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 1
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
IncludeIsMainRegex: '(Test)?$'
|
||||||
|
IncludeIsMainSourceRegex: ''
|
||||||
|
IndentAccessModifiers: false
|
||||||
|
IndentCaseBlocks: false
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentExportBlock: true
|
||||||
|
IndentExternBlock: AfterExternBlock
|
||||||
|
IndentGotoLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentRequiresClause: true
|
||||||
|
IndentWidth: 2
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
InsertBraces: false
|
||||||
|
InsertNewlineAtEOF: false
|
||||||
|
InsertTrailingCommas: None
|
||||||
|
IntegerLiteralSeparator:
|
||||||
|
Binary: 0
|
||||||
|
BinaryMinDigits: 0
|
||||||
|
Decimal: 0
|
||||||
|
DecimalMinDigits: 0
|
||||||
|
Hex: 0
|
||||||
|
HexMinDigits: 0
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLines:
|
||||||
|
AtEndOfFile: false
|
||||||
|
AtStartOfBlock: true
|
||||||
|
AtStartOfFile: true
|
||||||
|
KeepFormFeed: false
|
||||||
|
LambdaBodyIndentation: Signature
|
||||||
|
LineEnding: DeriveLF
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MainIncludeChar: Quote
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBinPackProtocolList: Auto
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCBreakBeforeNestedBlockParam: true
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PackConstructorInitializers: BinPack
|
||||||
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 19
|
||||||
|
PenaltyBreakBeforeMemberAccess: 150
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakOpenParenthesis: 0
|
||||||
|
PenaltyBreakScopeResolution: 500
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyIndentedWhitespace: 0
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
|
PointerAlignment: Right
|
||||||
|
PPIndentWidth: -1
|
||||||
|
QualifierAlignment: Leave
|
||||||
|
ReferenceAlignment: Pointer
|
||||||
|
ReflowComments: Always
|
||||||
|
RemoveBracesLLVM: false
|
||||||
|
RemoveEmptyLinesInUnwrappedLines: false
|
||||||
|
RemoveParentheses: Leave
|
||||||
|
RemoveSemicolon: false
|
||||||
|
RequiresClausePosition: OwnLine
|
||||||
|
RequiresExpressionIndentation: OuterScope
|
||||||
|
SeparateDefinitionBlocks: Leave
|
||||||
|
ShortNamespaceLines: 1
|
||||||
|
SkipMacroDefinitionBody: false
|
||||||
|
SortIncludes: CaseSensitive
|
||||||
|
SortJavaStaticImport: Before
|
||||||
|
SortUsingDeclarations: LexicographicNumeric
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterLogicalNot: false
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
SpaceAroundPointerQualifiers: Default
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCaseColon: false
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeJsonColon: false
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeParensOptions:
|
||||||
|
AfterControlStatements: true
|
||||||
|
AfterForeachMacros: true
|
||||||
|
AfterFunctionDefinitionName: false
|
||||||
|
AfterFunctionDeclarationName: false
|
||||||
|
AfterIfMacros: true
|
||||||
|
AfterOverloadedOperator: false
|
||||||
|
AfterPlacementOperator: true
|
||||||
|
AfterRequiresInClause: false
|
||||||
|
AfterRequiresInExpression: false
|
||||||
|
BeforeNonEmptyParentheses: false
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
SpaceInEmptyBlock: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: Never
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInLineCommentPrefix:
|
||||||
|
Minimum: 1
|
||||||
|
Maximum: -1
|
||||||
|
SpacesInParens: Never
|
||||||
|
SpacesInParensOptions:
|
||||||
|
ExceptDoubleParentheses: false
|
||||||
|
InCStyleCasts: false
|
||||||
|
InConditionalStatements: false
|
||||||
|
InEmptyParentheses: false
|
||||||
|
Other: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
Standard: Latest
|
||||||
|
StatementAttributeLikeMacros:
|
||||||
|
- Q_EMIT
|
||||||
|
StatementMacros:
|
||||||
|
- Q_UNUSED
|
||||||
|
- QT_REQUIRE_VERSION
|
||||||
|
TableGenBreakInsideDAGArg: DontBreak
|
||||||
|
TabWidth: 8
|
||||||
|
UseTab: Never
|
||||||
|
VerilogBreakBetweenInstancePorts: true
|
||||||
|
WhitespaceSensitiveMacros:
|
||||||
|
- BOOST_PP_STRINGIZE
|
||||||
|
- CF_SWIFT_NAME
|
||||||
|
- NS_SWIFT_NAME
|
||||||
|
- PP_STRINGIZE
|
||||||
|
- STRINGIZE
|
||||||
|
WrapNamespaceBodyWithEmptyLines: Leave
|
||||||
|
...
|
||||||
|
|
||||||
4700
include/CLI/CLI11.hpp
Executable file → Normal file
4700
include/CLI/CLI11.hpp
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
34
include/PartitionManager/PartitionManager.hpp
Executable file → Normal file
34
include/PartitionManager/PartitionManager.hpp
Executable file → Normal file
@@ -17,11 +17,11 @@
|
|||||||
#ifndef LIBPMT_LIB_HPP
|
#ifndef LIBPMT_LIB_HPP
|
||||||
#define LIBPMT_LIB_HPP
|
#define LIBPMT_LIB_HPP
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <memory>
|
|
||||||
#include <libhelper/lib.hpp>
|
#include <libhelper/lib.hpp>
|
||||||
#include <libpartition_map/lib.hpp>
|
#include <libpartition_map/lib.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
@@ -94,28 +94,32 @@ namespace PartitionManager {
|
|||||||
int Main(int argc, char **argv);
|
int Main(int argc, char **argv);
|
||||||
|
|
||||||
// Print messages if not using quiet mode
|
// Print messages if not using quiet mode
|
||||||
__attribute__((format(printf, 1, 2)))
|
__attribute__((format(printf, 1, 2))) void print(const char *format, ...);
|
||||||
void print(const char *format, ...);
|
__attribute__((format(printf, 1, 2))) void println(const char *format, ...);
|
||||||
__attribute__((format(printf, 1, 2)))
|
|
||||||
void println(const char *format, ...);
|
|
||||||
|
|
||||||
// Format it input and return as std::string
|
// Format it input and return as std::string
|
||||||
__attribute__((format(printf, 1, 2)))
|
__attribute__((format(printf, 1, 2))) std::string format(const char *format,
|
||||||
std::string format(const char *format, ...);
|
...);
|
||||||
|
|
||||||
// If there is a delimiter in the string, CLI::detail::split returns; if not, an empty vector is returned. And checks duplicate arguments.
|
// If there is a delimiter in the string, CLI::detail::split returns; if not, an
|
||||||
std::vector<std::string> splitIfHasDelim(const std::string &s, char delim, bool checkForBadUsage = false);
|
// empty vector is returned. And checks duplicate arguments.
|
||||||
|
std::vector<std::string> splitIfHasDelim(const std::string &s, char delim,
|
||||||
|
bool checkForBadUsage = false);
|
||||||
|
|
||||||
// Process vectors with input strings. Use for [flag(s)]-[other flag(s)] situations
|
// Process vectors with input strings. Use for [flag(s)]-[other flag(s)]
|
||||||
void processCommandLine(std::vector<std::string> &vec1, std::vector<std::string> &vec2, const std::string &s1,
|
// situations
|
||||||
const std::string &s2, char delim, bool checkForBadUsage = false);
|
void processCommandLine(std::vector<std::string> &vec1,
|
||||||
|
std::vector<std::string> &vec2, const std::string &s1,
|
||||||
|
const std::string &s2, char delim,
|
||||||
|
bool checkForBadUsage = false);
|
||||||
|
|
||||||
// Setting ups buffer size
|
// Setting ups buffer size
|
||||||
void setupBufferSize(int &size, const std::string &partition);
|
void setupBufferSize(int &size, const std::string &partition);
|
||||||
|
|
||||||
std::string getLibVersion();
|
std::string getLibVersion();
|
||||||
|
|
||||||
std::string getAppVersion(); // Not Android app version (an Android app is planned!), tells pmt version.
|
std::string getAppVersion(); // Not Android app version (an Android app is
|
||||||
|
// planned!), tells pmt version.
|
||||||
} // namespace PartitionManager
|
} // namespace PartitionManager
|
||||||
|
|
||||||
#endif // #ifndef LIBPMT_LIB_HPP
|
#endif // #ifndef LIBPMT_LIB_HPP
|
||||||
|
|||||||
39
src/FunctionManager.cpp
Executable file → Normal file
39
src/FunctionManager.cpp
Executable file → Normal file
@@ -14,22 +14,24 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <vector>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <PartitionManager/PartitionManager.hpp>
|
#include <vector>
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
std::vector<std::string> splitIfHasDelim(const std::string &s, const char delim, const bool checkForBadUsage) {
|
std::vector<std::string> splitIfHasDelim(const std::string &s, const char delim,
|
||||||
|
const bool checkForBadUsage) {
|
||||||
if (s.find(delim) == std::string::npos) return {};
|
if (s.find(delim) == std::string::npos) return {};
|
||||||
auto vec = CLI::detail::split(s, delim);
|
auto vec = CLI::detail::split(s, delim);
|
||||||
|
|
||||||
if (checkForBadUsage) {
|
if (checkForBadUsage) {
|
||||||
std::unordered_set<std::string> set;
|
std::unordered_set<std::string> set;
|
||||||
for (const auto &str : vec) {
|
for (const auto &str : vec) {
|
||||||
if (set.find(str) != set.end()) throw CLI::ValidationError("Duplicate element in your inputs!");
|
if (set.find(str) != set.end())
|
||||||
|
throw CLI::ValidationError("Duplicate element in your inputs!");
|
||||||
set.insert(str);
|
set.insert(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,13 +41,17 @@ namespace PartitionManager {
|
|||||||
|
|
||||||
void setupBufferSize(int &size, const std::string &partition) {
|
void setupBufferSize(int &size, const std::string &partition) {
|
||||||
if (Variables->PartMap->sizeOf(partition) % size != 0) {
|
if (Variables->PartMap->sizeOf(partition) % size != 0) {
|
||||||
print("%sWARNING%s: Specified buffer size is invalid! Using 1 byte as buffer size.", YELLOW, STYLE_RESET);
|
print("%sWARNING%s: Specified buffer size is invalid! Using 1 byte as "
|
||||||
|
"buffer size.",
|
||||||
|
YELLOW, STYLE_RESET);
|
||||||
size = 1;
|
size = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void processCommandLine(std::vector<std::string> &vec1, std::vector<std::string> &vec2, const std::string &s1,
|
void processCommandLine(std::vector<std::string> &vec1,
|
||||||
const std::string &s2, const char delim, const bool checkForBadUsage) {
|
std::vector<std::string> &vec2, const std::string &s1,
|
||||||
|
const std::string &s2, const char delim,
|
||||||
|
const bool checkForBadUsage) {
|
||||||
vec1 = splitIfHasDelim(s1, delim, checkForBadUsage);
|
vec1 = splitIfHasDelim(s1, delim, checkForBadUsage);
|
||||||
vec2 = splitIfHasDelim(s2, delim, checkForBadUsage);
|
vec2 = splitIfHasDelim(s2, delim, checkForBadUsage);
|
||||||
|
|
||||||
@@ -53,23 +59,30 @@ namespace PartitionManager {
|
|||||||
if (vec2.empty() && !s2.empty()) vec2.push_back(s2);
|
if (vec2.empty() && !s2.empty()) vec2.push_back(s2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void basic_function_manager::registerFunction(std::unique_ptr<basic_function> _func, CLI::App &_app) {
|
void basic_function_manager::registerFunction(
|
||||||
|
std::unique_ptr<basic_function> _func, CLI::App &_app) {
|
||||||
LOGN(PMTF, INFO) << "registering function: " << _func->name() << std::endl;
|
LOGN(PMTF, INFO) << "registering function: " << _func->name() << std::endl;
|
||||||
if (!_func->init(_app)) throw Error("Cannot init function: %s\n", _func->name());
|
if (!_func->init(_app))
|
||||||
|
throw Error("Cannot init function: %s\n", _func->name());
|
||||||
_functions.push_back(std::move(_func));
|
_functions.push_back(std::move(_func));
|
||||||
LOGN(PMTF, INFO) << _functions.back()->name() << " successfully registered." << std::endl;
|
LOGN(PMTF, INFO) << _functions.back()->name() << " successfully registered."
|
||||||
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool basic_function_manager::handleAll() const {
|
bool basic_function_manager::handleAll() const {
|
||||||
LOGN(PMTF, INFO) << "running caught function commands in command-line." << std::endl;
|
LOGN(PMTF, INFO) << "running caught function commands in command-line."
|
||||||
|
<< std::endl;
|
||||||
for (const auto &func : _functions) {
|
for (const auto &func : _functions) {
|
||||||
if (func->isUsed()) {
|
if (func->isUsed()) {
|
||||||
LOGN(PMTF, INFO) << func->name() << " is calling because used in command-line." << std::endl;
|
LOGN(PMTF, INFO) << func->name()
|
||||||
|
<< " is calling because used in command-line."
|
||||||
|
<< std::endl;
|
||||||
return func->run();
|
return func->run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGN(PMTF, INFO) << "not found any used function from command-line." << std::endl;
|
LOGN(PMTF, INFO) << "not found any used function from command-line."
|
||||||
|
<< std::endl;
|
||||||
println("Target progress is not specified. Specify a progress.");
|
println("Target progress is not specified. Specify a progress.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
3
src/Main.cpp
Executable file → Normal file
3
src/Main.cpp
Executable file → Normal file
@@ -16,8 +16,7 @@
|
|||||||
|
|
||||||
#include <PartitionManager/PartitionManager.hpp>
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
|
||||||
// Call integrated main function in library
|
// Call integrated main function in library
|
||||||
Helper::LoggingProperties::setProgramName(PMTE);
|
Helper::LoggingProperties::setProgramName(PMTE);
|
||||||
return PartitionManager::Main(argc, argv);
|
return PartitionManager::Main(argc, argv);
|
||||||
|
|||||||
107
src/PartitionManager.cpp
Executable file → Normal file
107
src/PartitionManager.cpp
Executable file → Normal file
@@ -14,32 +14,33 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include "functions/functions.hpp"
|
||||||
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
#include <cstdarg>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstdarg>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <PartitionManager/PartitionManager.hpp>
|
|
||||||
#include <generated/buildInfo.hpp>
|
#include <generated/buildInfo.hpp>
|
||||||
#include "functions/functions.hpp"
|
#include <string>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
variableProtect protector;
|
variableProtect protector;
|
||||||
auto Variables = new VariableTable();
|
auto Variables = new VariableTable();
|
||||||
|
|
||||||
variableProtect::variableProtect() { Helper::LoggingProperties::setLogFile("/sdcard/Documents/last_pmt_logs.log"); }
|
variableProtect::variableProtect() {
|
||||||
|
Helper::LoggingProperties::setLogFile("/sdcard/Documents/last_pmt_logs.log");
|
||||||
|
}
|
||||||
variableProtect::~variableProtect() { delete _ptr; }
|
variableProtect::~variableProtect() { delete _ptr; }
|
||||||
void variableProtect::setVariablePointer(basic_variables *&_ptr) { this->_ptr = _ptr; }
|
void variableProtect::setVariablePointer(basic_variables *&_ptr) {
|
||||||
|
this->_ptr = _ptr;
|
||||||
|
}
|
||||||
|
|
||||||
basic_variables::~basic_variables() { delete PartMap; }
|
basic_variables::~basic_variables() { delete PartMap; }
|
||||||
basic_variables::basic_variables() : PartMap(new PartitionMap::BuildMap()),
|
basic_variables::basic_variables()
|
||||||
logFile("/sdcard/Documents/last_pmt_logs.log"),
|
: PartMap(new PartitionMap::BuildMap()),
|
||||||
onLogical(false),
|
logFile("/sdcard/Documents/last_pmt_logs.log"), onLogical(false),
|
||||||
quietProcess(false),
|
quietProcess(false), verboseMode(false), viewVersion(false),
|
||||||
verboseMode(false),
|
forceProcess(false) {}
|
||||||
viewVersion(false),
|
|
||||||
forceProcess(false)
|
|
||||||
{}
|
|
||||||
|
|
||||||
int Main(int argc, char **argv) {
|
int Main(int argc, char **argv) {
|
||||||
try {
|
try {
|
||||||
@@ -50,57 +51,84 @@ namespace PartitionManager {
|
|||||||
|
|
||||||
AppMain.fallthrough(true);
|
AppMain.fallthrough(true);
|
||||||
AppMain.set_help_all_flag("--help-all", "Print full help message and exit");
|
AppMain.set_help_all_flag("--help-all", "Print full help message and exit");
|
||||||
AppMain.footer("Partition Manager Tool is written by YZBruh\nThis project licensed under Apache 2.0 license\nReport bugs to https://github.com/ShawkTeam/pmt-renovated/issues");
|
AppMain.footer("Partition Manager Tool is written by YZBruh\nThis project "
|
||||||
AppMain.add_option("-S,--search-path", Variables->searchPath, "Set partition search path")->check(
|
"licensed under "
|
||||||
[&](const std::string &val) {
|
"Apache 2.0 license\nReport "
|
||||||
if (val.find("/block") == std::string::npos) throw CLI::ValidationError(
|
"bugs to https://github.com/ShawkTeam/pmt-renovated/issues");
|
||||||
"Partition search path is unexpected! Couldn't find 'block' in input path!");
|
AppMain
|
||||||
|
.add_option("-S,--search-path", Variables->searchPath,
|
||||||
|
"Set partition search path")
|
||||||
|
->check([&](const std::string &val) {
|
||||||
|
if (val.find("/block") == std::string::npos)
|
||||||
|
throw CLI::ValidationError(
|
||||||
|
"Partition search path is unexpected! Couldn't find "
|
||||||
|
"'block' in input path!");
|
||||||
return std::string();
|
return std::string();
|
||||||
});
|
});
|
||||||
AppMain.add_option("-L,--log-file", Variables->logFile, "Set log file");
|
AppMain.add_option("-L,--log-file", Variables->logFile, "Set log file");
|
||||||
AppMain.add_flag("-f,--force", Variables->forceProcess, "Force process to be processed");
|
AppMain.add_flag("-f,--force", Variables->forceProcess,
|
||||||
AppMain.add_flag("-l,--logical", Variables->onLogical, "Specify that the target partition is dynamic");
|
"Force process to be processed");
|
||||||
|
AppMain.add_flag("-l,--logical", Variables->onLogical,
|
||||||
|
"Specify that the target partition is dynamic");
|
||||||
AppMain.add_flag("-q,--quiet", Variables->quietProcess, "Quiet process");
|
AppMain.add_flag("-q,--quiet", Variables->quietProcess, "Quiet process");
|
||||||
AppMain.add_flag("-V,--verbose", Variables->verboseMode,
|
AppMain.add_flag("-V,--verbose", Variables->verboseMode,
|
||||||
"Detailed information is written on the screen while the transaction is being carried out");
|
"Detailed information is written on the screen while the "
|
||||||
AppMain.add_flag("-v,--version", Variables->viewVersion, "Print version and exit");
|
"transaction is "
|
||||||
|
"being carried out");
|
||||||
|
AppMain.add_flag("-v,--version", Variables->viewVersion,
|
||||||
|
"Print version and exit");
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
println("Usage: %s [OPTIONS] [SUBCOMMAND]\nUse --help for more information.", argv[0]);
|
println(
|
||||||
|
"Usage: %s [OPTIONS] [SUBCOMMAND]\nUse --help for more information.",
|
||||||
|
argv[0]);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
FuncManager.registerFunction(std::make_unique<backupFunction>(), AppMain);
|
FuncManager.registerFunction(std::make_unique<backupFunction>(), AppMain);
|
||||||
FuncManager.registerFunction(std::make_unique<flashFunction>(), AppMain);
|
FuncManager.registerFunction(std::make_unique<flashFunction>(), AppMain);
|
||||||
FuncManager.registerFunction(std::make_unique<eraseFunction>(), AppMain);
|
FuncManager.registerFunction(std::make_unique<eraseFunction>(), AppMain);
|
||||||
FuncManager.registerFunction(std::make_unique<partitionSizeFunction>(), AppMain);
|
FuncManager.registerFunction(std::make_unique<partitionSizeFunction>(),
|
||||||
|
AppMain);
|
||||||
FuncManager.registerFunction(std::make_unique<infoFunction>(), AppMain);
|
FuncManager.registerFunction(std::make_unique<infoFunction>(), AppMain);
|
||||||
FuncManager.registerFunction(std::make_unique<realPathFunction>(), AppMain);
|
FuncManager.registerFunction(std::make_unique<realPathFunction>(), AppMain);
|
||||||
FuncManager.registerFunction(std::make_unique<realLinkPathFunction>(), AppMain);
|
FuncManager.registerFunction(std::make_unique<realLinkPathFunction>(),
|
||||||
|
AppMain);
|
||||||
FuncManager.registerFunction(std::make_unique<typeFunction>(), AppMain);
|
FuncManager.registerFunction(std::make_unique<typeFunction>(), AppMain);
|
||||||
FuncManager.registerFunction(std::make_unique<rebootFunction>(), AppMain);
|
FuncManager.registerFunction(std::make_unique<rebootFunction>(), AppMain);
|
||||||
|
|
||||||
CLI11_PARSE(AppMain, argc, argv);
|
CLI11_PARSE(AppMain, argc, argv);
|
||||||
|
|
||||||
if (Variables->verboseMode) Helper::LoggingProperties::setPrinting(YES);
|
if (Variables->verboseMode) Helper::LoggingProperties::setPrinting(YES);
|
||||||
if (Variables->viewVersion) { println("%s", getAppVersion().data()); return EXIT_SUCCESS; }
|
if (Variables->viewVersion) {
|
||||||
if (!Variables->searchPath.empty()) (*Variables->PartMap)(Variables->searchPath);
|
println("%s", getAppVersion().data());
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
if (!Variables->searchPath.empty())
|
||||||
|
(*Variables->PartMap)(Variables->searchPath);
|
||||||
|
|
||||||
if (!Variables->PartMap && Variables->searchPath.empty())
|
if (!Variables->PartMap && Variables->searchPath.empty())
|
||||||
throw Error("No default search entries were found. Specify a search directory with -S (--search-path)");
|
throw Error("No default search entries were found. Specify a search "
|
||||||
|
"directory with -S "
|
||||||
|
"(--search-path)");
|
||||||
|
|
||||||
if (!Helper::hasSuperUser()) throw Error("Partition Manager Tool is requires super-user privileges!\n");
|
if (!Helper::hasSuperUser())
|
||||||
|
throw Error(
|
||||||
|
"Partition Manager Tool is requires super-user privileges!\n");
|
||||||
|
|
||||||
return FuncManager.handleAll() == true ? EXIT_SUCCESS : EXIT_FAILURE;
|
return FuncManager.handleAll() == true ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
} catch (Helper::Error &error) {
|
} catch (Helper::Error &error) {
|
||||||
// catch Helper::Error
|
// catch Helper::Error
|
||||||
|
|
||||||
if (!Variables->quietProcess) fprintf(stderr, "%s%sERROR(S) OCCURRED:%s\n%s", RED, BOLD, STYLE_RESET, error.what());
|
if (!Variables->quietProcess)
|
||||||
|
fprintf(stderr, "%s%sERROR(S) OCCURRED:%s\n%s", RED, BOLD, STYLE_RESET,
|
||||||
|
error.what());
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} catch (CLI::Error &error) {
|
} catch (CLI::Error &error) {
|
||||||
// catch CLI::Error
|
// catch CLI::Error
|
||||||
|
|
||||||
fprintf(stderr, "%s: %s%sFLAG PARSE ERROR:%s %s\n", argv[0], RED, BOLD, STYLE_RESET, error.what());
|
fprintf(stderr, "%s: %s%sFLAG PARSE ERROR:%s %s\n", argv[0], RED, BOLD,
|
||||||
|
STYLE_RESET, error.what());
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} // try-catch block end
|
} // try-catch block end
|
||||||
}
|
}
|
||||||
@@ -115,7 +143,10 @@ namespace PartitionManager {
|
|||||||
void println(const char *format, ...) {
|
void println(const char *format, ...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
if (!Variables->quietProcess) { vfprintf(stdout, format, args); print("\n"); }
|
if (!Variables->quietProcess) {
|
||||||
|
vfprintf(stdout, format, args);
|
||||||
|
print("\n");
|
||||||
|
}
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,11 +159,7 @@ namespace PartitionManager {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getLibVersion() {
|
std::string getLibVersion() { MKVERSION(PMT); }
|
||||||
MKVERSION(PMT);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string getAppVersion() {
|
std::string getAppVersion() { MKVERSION(PMTE); }
|
||||||
MKVERSION(PMTE);
|
|
||||||
}
|
|
||||||
} // namespace PartitionManager
|
} // namespace PartitionManager
|
||||||
|
|||||||
@@ -14,100 +14,142 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "functions.hpp"
|
||||||
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
#include <cerrno>
|
||||||
|
#include <chrono>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <cerrno>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <chrono>
|
|
||||||
#include <PartitionManager/PartitionManager.hpp>
|
|
||||||
#include <private/android_filesystem_config.h>
|
#include <private/android_filesystem_config.h>
|
||||||
#include "functions.hpp"
|
#include <unistd.h>
|
||||||
|
|
||||||
#define BFUN "backupFunction"
|
#define BFUN "backupFunction"
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
pair backupFunction::runAsync(const std::string &partitionName, const std::string &outputName, int bufferSize) {
|
pair backupFunction::runAsync(const std::string &partitionName,
|
||||||
if (!Variables->PartMap->hasPartition(partitionName)) return {
|
const std::string &outputName, int bufferSize) {
|
||||||
format("Couldn't find partition: %s", partitionName.data()), false
|
if (!Variables->PartMap->hasPartition(partitionName))
|
||||||
};
|
return {format("Couldn't find partition: %s", partitionName.data()), false};
|
||||||
|
|
||||||
LOGN(BFUN, INFO) << "back upping " << partitionName << " as " << outputName << std::endl;
|
LOGN(BFUN, INFO) << "back upping " << partitionName << " as " << outputName
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
if (Variables->onLogical && !Variables->PartMap->isLogical(partitionName)) {
|
if (Variables->onLogical && !Variables->PartMap->isLogical(partitionName)) {
|
||||||
if (Variables->forceProcess)
|
if (Variables->forceProcess)
|
||||||
LOGN(BFUN, WARNING) << "Partition " << partitionName <<
|
LOGN(BFUN, WARNING)
|
||||||
" is exists but not logical. Ignoring (from --force, -f)." << std::endl;
|
<< "Partition " << partitionName
|
||||||
else return {format("Used --logical (-l) flag but is not logical partition: %s", partitionName.data()), false};
|
<< " is exists but not logical. Ignoring (from --force, -f)."
|
||||||
|
<< std::endl;
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
format("Used --logical (-l) flag but is not logical partition: %s",
|
||||||
|
partitionName.data()),
|
||||||
|
false};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Helper::fileIsExists(outputName) && !Variables->forceProcess) return {
|
if (Helper::fileIsExists(outputName) && !Variables->forceProcess)
|
||||||
format("%s is exists. Remove it, or use --force (-f) flag.", outputName.data()), false
|
return {format("%s is exists. Remove it, or use --force (-f) flag.",
|
||||||
};
|
outputName.data()),
|
||||||
|
false};
|
||||||
|
|
||||||
setupBufferSize(bufferSize, partitionName);
|
setupBufferSize(bufferSize, partitionName);
|
||||||
LOGN(BFUN, INFO) << "Using buffer size (for back upping " << partitionName << "): " << bufferSize << std::endl;
|
LOGN(BFUN, INFO) << "Using buffer size (for back upping " << partitionName
|
||||||
|
<< "): " << bufferSize << std::endl;
|
||||||
|
|
||||||
// Automatically close file descriptors and delete allocated memories (arrays)
|
// Automatically close file descriptors and delete allocated memories (arrays)
|
||||||
Helper::garbageCollector collector;
|
Helper::garbageCollector collector;
|
||||||
|
|
||||||
const int pfd = Helper::openAndAddToCloseList(Variables->PartMap->getRealPathOf(partitionName), collector, O_RDONLY);
|
const int pfd = Helper::openAndAddToCloseList(
|
||||||
if (pfd < 0) return {format("Can't open partition: %s: %s", partitionName.data(), strerror(errno)), false};
|
Variables->PartMap->getRealPathOf(partitionName), collector, O_RDONLY);
|
||||||
|
if (pfd < 0)
|
||||||
|
return {format("Can't open partition: %s: %s", partitionName.data(),
|
||||||
|
strerror(errno)),
|
||||||
|
false};
|
||||||
|
|
||||||
const int ffd = Helper::openAndAddToCloseList(outputName, collector, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
const int ffd = Helper::openAndAddToCloseList(
|
||||||
if (ffd < 0) return {format("Can't create/open output file %s: %s", outputName.data(), strerror(errno)), false};
|
outputName, collector, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||||
|
if (ffd < 0)
|
||||||
|
return {format("Can't create/open output file %s: %s", outputName.data(),
|
||||||
|
strerror(errno)),
|
||||||
|
false};
|
||||||
|
|
||||||
LOGN(BFUN, INFO) << "Writing partition " << partitionName << " to file: " << outputName << std::endl;
|
LOGN(BFUN, INFO) << "Writing partition " << partitionName
|
||||||
|
<< " to file: " << outputName << std::endl;
|
||||||
auto *buffer = new char[bufferSize];
|
auto *buffer = new char[bufferSize];
|
||||||
collector.delAfterProgress(buffer);
|
collector.delAfterProgress(buffer);
|
||||||
memset(buffer, 0x00, bufferSize);
|
memset(buffer, 0x00, bufferSize);
|
||||||
|
|
||||||
ssize_t bytesRead;
|
ssize_t bytesRead;
|
||||||
while ((bytesRead = read(pfd, buffer, bufferSize)) > 0) {
|
while ((bytesRead = read(pfd, buffer, bufferSize)) > 0) {
|
||||||
if (const ssize_t bytesWritten = write(ffd, buffer, bytesRead); bytesWritten != bytesRead)
|
if (const ssize_t bytesWritten = write(ffd, buffer, bytesRead);
|
||||||
return {format("Can't write partition to output file %s: %s", outputName.data(), strerror(errno)), false};
|
bytesWritten != bytesRead)
|
||||||
|
return {format("Can't write partition to output file %s: %s",
|
||||||
|
outputName.data(), strerror(errno)),
|
||||||
|
false};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Helper::changeOwner(outputName, AID_EVERYBODY, AID_EVERYBODY))
|
if (!Helper::changeOwner(outputName, AID_EVERYBODY, AID_EVERYBODY))
|
||||||
LOGN(BFUN, WARNING) << "Failed to change owner of output file: " << outputName << ". Access problems maybe occur in non-root mode" << std::endl;
|
LOGN(BFUN, WARNING) << "Failed to change owner of output file: "
|
||||||
|
<< outputName
|
||||||
|
<< ". Access problems maybe occur in non-root mode"
|
||||||
|
<< std::endl;
|
||||||
if (!Helper::changeMode(outputName, 0660))
|
if (!Helper::changeMode(outputName, 0660))
|
||||||
LOGN(BFUN, WARNING) << "Failed to change mode of output file as 660: " << outputName << ". Access problems maybe occur in non-root mode" << std::endl;
|
LOGN(BFUN, WARNING) << "Failed to change mode of output file as 660: "
|
||||||
|
<< outputName
|
||||||
|
<< ". Access problems maybe occur in non-root mode"
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
return {format("%s partition successfully back upped to %s", partitionName.data(), outputName.data()), true};
|
return {format("%s partition successfully back upped to %s",
|
||||||
|
partitionName.data(), outputName.data()),
|
||||||
|
true};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool backupFunction::init(CLI::App &_app) {
|
bool backupFunction::init(CLI::App &_app) {
|
||||||
LOGN(BFUN, INFO) << "Initializing variables of backup function." << std::endl;
|
LOGN(BFUN, INFO) << "Initializing variables of backup function." << std::endl;
|
||||||
cmd = _app.add_subcommand("backup", "Backup partition(s) to file(s)");
|
cmd = _app.add_subcommand("backup", "Backup partition(s) to file(s)");
|
||||||
cmd->add_option("partition(s)", rawPartitions, "Partition name(s)")->required();
|
cmd->add_option("partition(s)", rawPartitions, "Partition name(s)")
|
||||||
cmd->add_option("output(s)", rawOutputNames, "File name(s) (or path(s)) to save the partition image(s)");
|
->required();
|
||||||
cmd->add_option("-O,--output-directory", outputDirectory, "Directory to save the partition image(s)")->check(CLI::ExistingDirectory);
|
cmd->add_option("output(s)", rawOutputNames,
|
||||||
cmd->add_option("-b,--buffer-size", bufferSize, "Buffer size for reading partition(s) and writing to file(s)");
|
"File name(s) (or path(s)) to save the partition image(s)");
|
||||||
|
cmd->add_option("-O,--output-directory", outputDirectory,
|
||||||
|
"Directory to save the partition image(s)")
|
||||||
|
->check(CLI::ExistingDirectory);
|
||||||
|
cmd->add_option(
|
||||||
|
"-b,--buffer-size", bufferSize,
|
||||||
|
"Buffer size for reading partition(s) and writing to file(s)");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool backupFunction::run() {
|
bool backupFunction::run() {
|
||||||
processCommandLine(partitions, outputNames, rawPartitions, rawOutputNames, ',', true);
|
processCommandLine(partitions, outputNames, rawPartitions, rawOutputNames,
|
||||||
|
',', true);
|
||||||
if (!outputNames.empty() && partitions.size() != outputNames.size())
|
if (!outputNames.empty() && partitions.size() != outputNames.size())
|
||||||
throw CLI::ValidationError("You must provide an output name(s) as long as the partition name(s)");
|
throw CLI::ValidationError(
|
||||||
|
"You must provide an output name(s) as long as the partition name(s)");
|
||||||
|
|
||||||
std::vector<std::future<pair>> futures;
|
std::vector<std::future<pair>> futures;
|
||||||
for (size_t i = 0; i < partitions.size(); i++) {
|
for (size_t i = 0; i < partitions.size(); i++) {
|
||||||
std::string partitionName = partitions[i];
|
std::string partitionName = partitions[i];
|
||||||
std::string outputName = outputNames.empty() ? partitionName + ".img" : outputNames[i];
|
std::string outputName =
|
||||||
|
outputNames.empty() ? partitionName + ".img" : outputNames[i];
|
||||||
if (!outputDirectory.empty()) outputName.insert(0, outputDirectory + '/');
|
if (!outputDirectory.empty()) outputName.insert(0, outputDirectory + '/');
|
||||||
|
|
||||||
futures.push_back(std::async(std::launch::async, runAsync, partitionName, outputName, bufferSize));
|
futures.push_back(std::async(std::launch::async, runAsync, partitionName,
|
||||||
LOGN(BFUN, INFO) << "Created thread backup upping " << partitionName << std::endl;
|
outputName, bufferSize));
|
||||||
|
LOGN(BFUN, INFO) << "Created thread backup upping " << partitionName
|
||||||
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string end;
|
std::string end;
|
||||||
bool endResult = true;
|
bool endResult = true;
|
||||||
for (auto &future : futures) {
|
for (auto &future : futures) {
|
||||||
auto [fst, snd] = future.get();
|
auto [fst, snd] = future.get();
|
||||||
if (!snd) { end += fst + '\n'; endResult = false; }
|
if (!snd) {
|
||||||
else println("%s", fst.c_str());
|
end += fst + '\n';
|
||||||
|
endResult = false;
|
||||||
|
} else println("%s", fst.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!endResult) throw Error("%s", end.c_str());
|
if (!endResult) throw Error("%s", end.c_str());
|
||||||
|
|||||||
@@ -14,27 +14,32 @@ Copyright 2025 Yağız Zengin
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "functions.hpp"
|
||||||
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
#include <cerrno>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <cerrno>
|
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <PartitionManager/PartitionManager.hpp>
|
|
||||||
#include "functions.hpp"
|
|
||||||
|
|
||||||
#define EFUN "eraseFunction"
|
#define EFUN "eraseFunction"
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
pair eraseFunction::runAsync(const std::string &partitionName, int bufferSize) {
|
pair eraseFunction::runAsync(const std::string &partitionName, int bufferSize) {
|
||||||
if (!Variables->PartMap->hasPartition(partitionName)) return {
|
if (!Variables->PartMap->hasPartition(partitionName))
|
||||||
format("Couldn't find partition: %s", partitionName.data()), false
|
return {format("Couldn't find partition: %s", partitionName.data()), false};
|
||||||
};
|
|
||||||
|
|
||||||
if (Variables->onLogical && !Variables->PartMap->isLogical(partitionName)) {
|
if (Variables->onLogical && !Variables->PartMap->isLogical(partitionName)) {
|
||||||
if (Variables->forceProcess)
|
if (Variables->forceProcess)
|
||||||
LOGN(EFUN, WARNING) << "Partition " << partitionName <<
|
LOGN(EFUN, WARNING)
|
||||||
" is exists but not logical. Ignoring (from --force, -f)." << std::endl;
|
<< "Partition " << partitionName
|
||||||
else return {format("Used --logical (-l) flag but is not logical partition: %s", partitionName.data()), false};
|
<< " is exists but not logical. Ignoring (from --force, -f)."
|
||||||
|
<< std::endl;
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
format("Used --logical (-l) flag but is not logical partition: %s",
|
||||||
|
partitionName.data()),
|
||||||
|
false};
|
||||||
}
|
}
|
||||||
|
|
||||||
setupBufferSize(bufferSize, partitionName);
|
setupBufferSize(bufferSize, partitionName);
|
||||||
@@ -43,13 +48,21 @@ namespace PartitionManager {
|
|||||||
// Automatically close file descriptors and delete allocated memories (arrays)
|
// Automatically close file descriptors and delete allocated memories (arrays)
|
||||||
Helper::garbageCollector collector;
|
Helper::garbageCollector collector;
|
||||||
|
|
||||||
const int pfd = Helper::openAndAddToCloseList(Variables->PartMap->getRealPathOf(partitionName), collector, O_WRONLY);
|
const int pfd = Helper::openAndAddToCloseList(
|
||||||
if (pfd < 0) return {format("Can't open partition: %s: %s", partitionName.data(), strerror(errno)), false};
|
Variables->PartMap->getRealPathOf(partitionName), collector, O_WRONLY);
|
||||||
|
if (pfd < 0)
|
||||||
|
return {format("Can't open partition: %s: %s", partitionName.data(),
|
||||||
|
strerror(errno)),
|
||||||
|
false};
|
||||||
|
|
||||||
if (!Variables->forceProcess) Helper::confirmPropt(
|
if (!Variables->forceProcess)
|
||||||
"Are you sure you want to continue? This could render your device unusable! Do not continue if you do not know what you are doing!");
|
Helper::confirmPropt(
|
||||||
|
"Are you sure you want to continue? This could render your device "
|
||||||
|
"unusable! Do not continue if you "
|
||||||
|
"do not know what you are doing!");
|
||||||
|
|
||||||
LOGN(EFUN, INFO) << "Writing zero bytes to partition: " << partitionName << std::endl;
|
LOGN(EFUN, INFO) << "Writing zero bytes to partition: " << partitionName
|
||||||
|
<< std::endl;
|
||||||
auto *buffer = new char[bufferSize];
|
auto *buffer = new char[bufferSize];
|
||||||
collector.delAfterProgress(buffer);
|
collector.delAfterProgress(buffer);
|
||||||
memset(buffer, 0x00, bufferSize);
|
memset(buffer, 0x00, bufferSize);
|
||||||
@@ -59,37 +72,49 @@ namespace PartitionManager {
|
|||||||
|
|
||||||
while (bytesWritten < partitionSize) {
|
while (bytesWritten < partitionSize) {
|
||||||
size_t toWrite = sizeof(buffer);
|
size_t toWrite = sizeof(buffer);
|
||||||
if (partitionSize - bytesWritten < sizeof(buffer)) toWrite = partitionSize - bytesWritten;
|
if (partitionSize - bytesWritten < sizeof(buffer))
|
||||||
|
toWrite = partitionSize - bytesWritten;
|
||||||
|
|
||||||
if (const ssize_t result = write(pfd, buffer, toWrite); result == -1)
|
if (const ssize_t result = write(pfd, buffer, toWrite); result == -1)
|
||||||
return {format("Can't write zero bytes to partition: %s: %s", partitionName.data(), strerror(errno)), false};
|
return {format("Can't write zero bytes to partition: %s: %s",
|
||||||
|
partitionName.data(), strerror(errno)),
|
||||||
|
false};
|
||||||
else bytesWritten += result;
|
else bytesWritten += result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {format("Successfully wrote zero bytes to the %s partition\n", partitionName.data()), true};
|
return {format("Successfully wrote zero bytes to the %s partition\n",
|
||||||
|
partitionName.data()),
|
||||||
|
true};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool eraseFunction::init(CLI::App &_app) {
|
bool eraseFunction::init(CLI::App &_app) {
|
||||||
LOGN(EFUN, INFO) << "Initializing variables of erase function." << std::endl;
|
LOGN(EFUN, INFO) << "Initializing variables of erase function." << std::endl;
|
||||||
cmd = _app.add_subcommand("erase", "Writes zero bytes to partition(s)");
|
cmd = _app.add_subcommand("erase", "Writes zero bytes to partition(s)");
|
||||||
cmd->add_option("partition(s)", partitions, "Partition name(s)")->required()->delimiter(',');
|
cmd->add_option("partition(s)", partitions, "Partition name(s)")
|
||||||
cmd->add_option("-b,--buffer-size", bufferSize, "Buffer size for writing zero bytes to partition(s)");
|
->required()
|
||||||
|
->delimiter(',');
|
||||||
|
cmd->add_option("-b,--buffer-size", bufferSize,
|
||||||
|
"Buffer size for writing zero bytes to partition(s)");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool eraseFunction::run() {
|
bool eraseFunction::run() {
|
||||||
std::vector<std::future<pair>> futures;
|
std::vector<std::future<pair>> futures;
|
||||||
for (const auto &partitionName : partitions) {
|
for (const auto &partitionName : partitions) {
|
||||||
futures.push_back(std::async(std::launch::async, runAsync, partitionName, bufferSize));
|
futures.push_back(
|
||||||
LOGN(EFUN, INFO) << "Created thread for writing zero bytes to " << partitionName << std::endl;
|
std::async(std::launch::async, runAsync, partitionName, bufferSize));
|
||||||
|
LOGN(EFUN, INFO) << "Created thread for writing zero bytes to "
|
||||||
|
<< partitionName << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string end;
|
std::string end;
|
||||||
bool endResult = true;
|
bool endResult = true;
|
||||||
for (auto &future : futures) {
|
for (auto &future : futures) {
|
||||||
auto [fst, snd] = future.get();
|
auto [fst, snd] = future.get();
|
||||||
if (!snd) { end += fst + '\n'; endResult = false; }
|
if (!snd) {
|
||||||
else println("%s", fst.c_str());
|
end += fst + '\n';
|
||||||
|
endResult = false;
|
||||||
|
} else println("%s", fst.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!endResult) throw Error("%s", end.c_str());
|
if (!endResult) throw Error("%s", end.c_str());
|
||||||
|
|||||||
@@ -14,32 +14,42 @@ Copyright 2025 Yağız Zengin
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "functions.hpp"
|
||||||
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
#include <cerrno>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <cerrno>
|
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <PartitionManager/PartitionManager.hpp>
|
|
||||||
#include "functions.hpp"
|
|
||||||
|
|
||||||
#define FFUN "flashFunction"
|
#define FFUN "flashFunction"
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
pair flashFunction::runAsync(const std::string &partitionName, const std::string &imageName, int bufferSize) {
|
pair flashFunction::runAsync(const std::string &partitionName,
|
||||||
if (!Helper::fileIsExists(imageName)) return {format("Couldn't find image file: %s", imageName.data()), false};
|
const std::string &imageName, int bufferSize) {
|
||||||
if (!Variables->PartMap->hasPartition(partitionName)) return {format("Couldn't find partition: %s", partitionName.data()), false};
|
if (!Helper::fileIsExists(imageName))
|
||||||
|
return {format("Couldn't find image file: %s", imageName.data()), false};
|
||||||
|
if (!Variables->PartMap->hasPartition(partitionName))
|
||||||
|
return {format("Couldn't find partition: %s", partitionName.data()), false};
|
||||||
if (Helper::fileSize(imageName) > Variables->PartMap->sizeOf(partitionName))
|
if (Helper::fileSize(imageName) > Variables->PartMap->sizeOf(partitionName))
|
||||||
return {format("%s is larger than %s partition size!", imageName.data(), partitionName.data()), false};
|
return {format("%s is larger than %s partition size!", imageName.data(),
|
||||||
|
partitionName.data()),
|
||||||
|
false};
|
||||||
|
|
||||||
LOGN(FFUN, INFO) << "flashing " << imageName << " to " << partitionName << std::endl;
|
LOGN(FFUN, INFO) << "flashing " << imageName << " to " << partitionName
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
if (Variables->onLogical && !Variables->PartMap->isLogical(partitionName)) {
|
if (Variables->onLogical && !Variables->PartMap->isLogical(partitionName)) {
|
||||||
if (Variables->forceProcess)
|
if (Variables->forceProcess)
|
||||||
LOGN(FFUN, WARNING) << "Partition " << partitionName <<
|
LOGN(FFUN, WARNING)
|
||||||
" is exists but not logical. Ignoring (from --force, -f)." << std::endl;
|
<< "Partition " << partitionName
|
||||||
else return {
|
<< " is exists but not logical. Ignoring (from --force, -f)."
|
||||||
format("Used --logical (-l) flag but is not logical partition: %s", partitionName.data()), false
|
<< std::endl;
|
||||||
};
|
else
|
||||||
|
return {
|
||||||
|
format("Used --logical (-l) flag but is not logical partition: %s",
|
||||||
|
partitionName.data()),
|
||||||
|
false};
|
||||||
}
|
}
|
||||||
|
|
||||||
setupBufferSize(bufferSize, imageName);
|
setupBufferSize(bufferSize, imageName);
|
||||||
@@ -49,48 +59,71 @@ namespace PartitionManager {
|
|||||||
Helper::garbageCollector collector;
|
Helper::garbageCollector collector;
|
||||||
|
|
||||||
const int ffd = Helper::openAndAddToCloseList(imageName, collector, O_RDONLY);
|
const int ffd = Helper::openAndAddToCloseList(imageName, collector, O_RDONLY);
|
||||||
if (ffd < 0) return {format("Can't open image file %s: %s", imageName.data(), strerror(errno)), false};
|
if (ffd < 0)
|
||||||
|
return {format("Can't open image file %s: %s", imageName.data(),
|
||||||
|
strerror(errno)),
|
||||||
|
false};
|
||||||
|
|
||||||
const int pfd = Helper::openAndAddToCloseList(Variables->PartMap->getRealPathOf(partitionName), collector, O_RDWR | O_TRUNC);
|
const int pfd = Helper::openAndAddToCloseList(
|
||||||
if (pfd < 0) return {format("Can't open partition: %s: %s", partitionName.data(), strerror(errno)), false};
|
Variables->PartMap->getRealPathOf(partitionName), collector,
|
||||||
|
O_RDWR | O_TRUNC);
|
||||||
|
if (pfd < 0)
|
||||||
|
return {format("Can't open partition: %s: %s", partitionName.data(),
|
||||||
|
strerror(errno)),
|
||||||
|
false};
|
||||||
|
|
||||||
LOGN(FFUN, INFO) << "Writing image " << imageName << " to partition: " << partitionName << std::endl;
|
LOGN(FFUN, INFO) << "Writing image " << imageName
|
||||||
|
<< " to partition: " << partitionName << std::endl;
|
||||||
auto *buffer = new char[bufferSize];
|
auto *buffer = new char[bufferSize];
|
||||||
collector.delAfterProgress(buffer);
|
collector.delAfterProgress(buffer);
|
||||||
memset(buffer, 0x00, bufferSize);
|
memset(buffer, 0x00, bufferSize);
|
||||||
|
|
||||||
ssize_t bytesRead;
|
ssize_t bytesRead;
|
||||||
while ((bytesRead = read(ffd, buffer, bufferSize)) > 0) {
|
while ((bytesRead = read(ffd, buffer, bufferSize)) > 0) {
|
||||||
if (const ssize_t bytesWritten = write(pfd, buffer, bytesRead); bytesWritten != bytesRead)
|
if (const ssize_t bytesWritten = write(pfd, buffer, bytesRead);
|
||||||
return {format("Can't write partition to output file %s: %s", imageName.data(), strerror(errno)), false};
|
bytesWritten != bytesRead)
|
||||||
|
return {format("Can't write partition to output file %s: %s",
|
||||||
|
imageName.data(), strerror(errno)),
|
||||||
|
false};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {format("%s is successfully wrote to %s partition", imageName.data(), partitionName.data()), true};
|
return {format("%s is successfully wrote to %s partition", imageName.data(),
|
||||||
|
partitionName.data()),
|
||||||
|
true};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool flashFunction::init(CLI::App &_app) {
|
bool flashFunction::init(CLI::App &_app) {
|
||||||
LOGN(FFUN, INFO) << "Initializing variables of flash function." << std::endl;
|
LOGN(FFUN, INFO) << "Initializing variables of flash function." << std::endl;
|
||||||
cmd = _app.add_subcommand("flash", "Flash image(s) to partition(s)");
|
cmd = _app.add_subcommand("flash", "Flash image(s) to partition(s)");
|
||||||
cmd->add_option("partition(s)", rawPartitions, "Partition name(s)")->required();
|
cmd->add_option("partition(s)", rawPartitions, "Partition name(s)")
|
||||||
cmd->add_option("imageFile(s)", rawImageNames, "Name(s) of image file(s)")->required();
|
->required();
|
||||||
cmd->add_option("-b,--buffer-size", bufferSize, "Buffer size for reading image(s) and writing to partition(s)");
|
cmd->add_option("imageFile(s)", rawImageNames, "Name(s) of image file(s)")
|
||||||
cmd->add_option("-I,--image-directory", imageDirectory, "Directory to find image(s) and flash to partition(s)");
|
->required();
|
||||||
|
cmd->add_option(
|
||||||
|
"-b,--buffer-size", bufferSize,
|
||||||
|
"Buffer size for reading image(s) and writing to partition(s)");
|
||||||
|
cmd->add_option("-I,--image-directory", imageDirectory,
|
||||||
|
"Directory to find image(s) and flash to partition(s)");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool flashFunction::run() {
|
bool flashFunction::run() {
|
||||||
processCommandLine(partitions, imageNames, rawPartitions, rawImageNames, ',', true);
|
processCommandLine(partitions, imageNames, rawPartitions, rawImageNames, ',',
|
||||||
|
true);
|
||||||
if (partitions.size() != imageNames.size())
|
if (partitions.size() != imageNames.size())
|
||||||
throw CLI::ValidationError("You must provide an image file(s) as long as the partition name(s)");
|
throw CLI::ValidationError(
|
||||||
|
"You must provide an image file(s) as long as the partition name(s)");
|
||||||
|
|
||||||
std::vector<std::future<pair>> futures;
|
std::vector<std::future<pair>> futures;
|
||||||
for (size_t i = 0; i < partitions.size(); i++) {
|
for (size_t i = 0; i < partitions.size(); i++) {
|
||||||
std::string imageName = imageNames[i];
|
std::string imageName = imageNames[i];
|
||||||
if (!imageDirectory.empty()) imageName.insert(0, imageDirectory + '/');
|
if (!imageDirectory.empty()) imageName.insert(0, imageDirectory + '/');
|
||||||
|
|
||||||
futures.push_back(std::async(std::launch::async, runAsync, partitions[i], imageName, bufferSize));
|
futures.push_back(std::async(std::launch::async, runAsync, partitions[i],
|
||||||
LOGN(FFUN, INFO) << "Created thread for flashing image to " << partitions[i] << std::endl;
|
imageName, bufferSize));
|
||||||
|
LOGN(FFUN, INFO) << "Created thread for flashing image to " << partitions[i]
|
||||||
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string end;
|
std::string end;
|
||||||
|
|||||||
@@ -14,26 +14,35 @@ Copyright 2025 Yağız Zengin
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "functions.hpp"
|
||||||
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
#include <cerrno>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <cerrno>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <PartitionManager/PartitionManager.hpp>
|
|
||||||
#include "functions.hpp"
|
|
||||||
|
|
||||||
#define IFUN "infoFunction"
|
#define IFUN "infoFunction"
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
bool infoFunction::init(CLI::App &_app) {
|
bool infoFunction::init(CLI::App &_app) {
|
||||||
LOGN(IFUN, INFO) << "Initializing variables of info printer function." << std::endl;
|
LOGN(IFUN, INFO) << "Initializing variables of info printer function."
|
||||||
cmd = _app.add_subcommand("info", "Tell info(s) of input partition list")->footer(
|
<< std::endl;
|
||||||
"Use get-all or getvar-all as partition name for getting info's of all partitions.");
|
cmd = _app.add_subcommand("info", "Tell info(s) of input partition list")
|
||||||
cmd->add_option("partition(s)", partitions, "Partition name(s).")->required()->delimiter(',');
|
->footer("Use get-all or getvar-all as partition name for getting "
|
||||||
|
"info's of all "
|
||||||
|
"partitions.");
|
||||||
|
cmd->add_option("partition(s)", partitions, "Partition name(s).")
|
||||||
|
->required()
|
||||||
|
->delimiter(',');
|
||||||
cmd->add_flag("-J,--json", jsonFormat,
|
cmd->add_flag("-J,--json", jsonFormat,
|
||||||
"Print info(s) as JSON body. The body of each partition will be written separately");
|
"Print info(s) as JSON body. The body of each partition will "
|
||||||
cmd->add_option("--json-partition-name", jNamePartition, "Speficy partition name element for JSON body");
|
"be written separately");
|
||||||
cmd->add_option("--json-size-name", jNameSize, "Speficy size element name for JSON body");
|
cmd->add_option("--json-partition-name", jNamePartition,
|
||||||
cmd->add_option("--json-logical-name", jNameLogical, "Speficy logical element name for JSON body");
|
"Speficy partition name element for JSON body");
|
||||||
|
cmd->add_option("--json-size-name", jNameSize,
|
||||||
|
"Speficy size element name for JSON body");
|
||||||
|
cmd->add_option("--json-logical-name", jNameLogical,
|
||||||
|
"Speficy logical element name for JSON body");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,10 +50,13 @@ namespace PartitionManager {
|
|||||||
if (partitions.back() == "get-all" || partitions.back() == "getvar-all") {
|
if (partitions.back() == "get-all" || partitions.back() == "getvar-all") {
|
||||||
partitions.clear();
|
partitions.clear();
|
||||||
const auto parts = Variables->PartMap->getPartitionList();
|
const auto parts = Variables->PartMap->getPartitionList();
|
||||||
if (!parts) throw Error("Cannot get list of all partitions! See logs for more information (%s)",
|
if (!parts)
|
||||||
|
throw Error("Cannot get list of all partitions! See logs for more "
|
||||||
|
"information (%s)",
|
||||||
Helper::LoggingProperties::FILE.data());
|
Helper::LoggingProperties::FILE.data());
|
||||||
|
|
||||||
for (const auto &name: *parts) partitions.push_back(name);
|
for (const auto &name : *parts)
|
||||||
|
partitions.push_back(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &partition : partitions) {
|
for (const auto &partition : partitions) {
|
||||||
@@ -53,9 +65,13 @@ namespace PartitionManager {
|
|||||||
|
|
||||||
if (Variables->onLogical && !Variables->PartMap->isLogical(partition)) {
|
if (Variables->onLogical && !Variables->PartMap->isLogical(partition)) {
|
||||||
if (Variables->forceProcess)
|
if (Variables->forceProcess)
|
||||||
LOGN(IFUN, WARNING) << "Partition " << partition <<
|
LOGN(IFUN, WARNING)
|
||||||
" is exists but not logical. Ignoring (from --force, -f)." << std::endl;
|
<< "Partition " << partition
|
||||||
else throw Error("Used --logical (-l) flag but is not logical partition: %s", partition.data());
|
<< " is exists but not logical. Ignoring (from --force, -f)."
|
||||||
|
<< std::endl;
|
||||||
|
else
|
||||||
|
throw Error("Used --logical (-l) flag but is not logical partition: %s",
|
||||||
|
partition.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jsonFormat)
|
if (jsonFormat)
|
||||||
@@ -64,11 +80,8 @@ namespace PartitionManager {
|
|||||||
#else
|
#else
|
||||||
println("{\"%s\": \"%s\", \"%s\": %llu, \"%s\": %s}",
|
println("{\"%s\": \"%s\", \"%s\": %llu, \"%s\": %s}",
|
||||||
#endif
|
#endif
|
||||||
jNamePartition.data(),
|
jNamePartition.data(), partition.data(), jNameSize.data(),
|
||||||
partition.data(),
|
Variables->PartMap->sizeOf(partition), jNameLogical.data(),
|
||||||
jNameSize.data(),
|
|
||||||
Variables->PartMap->sizeOf(partition),
|
|
||||||
jNameLogical.data(),
|
|
||||||
Variables->PartMap->isLogical(partition) ? "true" : "false");
|
Variables->PartMap->isLogical(partition) ? "true" : "false");
|
||||||
else
|
else
|
||||||
#ifdef __LP64__
|
#ifdef __LP64__
|
||||||
@@ -76,8 +89,7 @@ namespace PartitionManager {
|
|||||||
#else
|
#else
|
||||||
println("partition=%s size=%llu isLogical=%s",
|
println("partition=%s size=%llu isLogical=%s",
|
||||||
#endif
|
#endif
|
||||||
partition.data(),
|
partition.data(), Variables->PartMap->sizeOf(partition),
|
||||||
Variables->PartMap->sizeOf(partition),
|
|
||||||
Variables->PartMap->isLogical(partition) ? "true" : "false");
|
Variables->PartMap->isLogical(partition) ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ Copyright 2025 Yağız Zengin
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <PartitionManager/PartitionManager.hpp>
|
|
||||||
#include "functions.hpp"
|
#include "functions.hpp"
|
||||||
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
|
||||||
#define SFUN "partitionSizeFunction"
|
#define SFUN "partitionSizeFunction"
|
||||||
|
|
||||||
@@ -28,14 +28,24 @@ std::string convertTo(const uint64_t size, const std::string &multiple) {
|
|||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
bool partitionSizeFunction::init(CLI::App &_app) {
|
bool partitionSizeFunction::init(CLI::App &_app) {
|
||||||
LOGN(SFUN, INFO) << "Initializing variables of partition size getter function." << std::endl;
|
LOGN(SFUN, INFO)
|
||||||
|
<< "Initializing variables of partition size getter function."
|
||||||
|
<< std::endl;
|
||||||
cmd = _app.add_subcommand("sizeof", "Tell size(s) of input partition list");
|
cmd = _app.add_subcommand("sizeof", "Tell size(s) of input partition list");
|
||||||
cmd->add_option("partition(s)", partitions, "Partition name(s).")->required()->delimiter(',');
|
cmd->add_option("partition(s)", partitions, "Partition name(s).")
|
||||||
cmd->add_flag("--as-byte", asByte, "Tell input size of partition list as byte.");
|
->required()
|
||||||
cmd->add_flag("--as-kilobyte", asKiloBytes, "Tell input size of partition list as kilobyte.");
|
->delimiter(',');
|
||||||
cmd->add_flag("--as-megabyte", asMega, "Tell input size of partition list as megabyte.");
|
cmd->add_flag("--as-byte", asByte,
|
||||||
cmd->add_flag("--as-gigabyte", asGiga, "Tell input size of partition list as gigabyte.");
|
"Tell input size of partition list as byte.");
|
||||||
cmd->add_flag("--only-size", onlySize, "Tell input size of partition list as not printing multiple and partition name.");
|
cmd->add_flag("--as-kilobyte", asKiloBytes,
|
||||||
|
"Tell input size of partition list as kilobyte.");
|
||||||
|
cmd->add_flag("--as-megabyte", asMega,
|
||||||
|
"Tell input size of partition list as megabyte.");
|
||||||
|
cmd->add_flag("--as-gigabyte", asGiga,
|
||||||
|
"Tell input size of partition list as gigabyte.");
|
||||||
|
cmd->add_flag("--only-size", onlySize,
|
||||||
|
"Tell input size of partition list as not printing multiple "
|
||||||
|
"and partition name.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,9 +56,13 @@ namespace PartitionManager {
|
|||||||
|
|
||||||
if (Variables->onLogical && !Variables->PartMap->isLogical(partition)) {
|
if (Variables->onLogical && !Variables->PartMap->isLogical(partition)) {
|
||||||
if (Variables->forceProcess)
|
if (Variables->forceProcess)
|
||||||
LOGN(SFUN, WARNING) << "Partition " << partition <<
|
LOGN(SFUN, WARNING)
|
||||||
" is exists but not logical. Ignoring (from --force, -f)." << std::endl;
|
<< "Partition " << partition
|
||||||
else throw Error("Used --logical (-l) flag but is not logical partition: %s", partition.data());
|
<< " is exists but not logical. Ignoring (from --force, -f)."
|
||||||
|
<< std::endl;
|
||||||
|
else
|
||||||
|
throw Error("Used --logical (-l) flag but is not logical partition: %s",
|
||||||
|
partition.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string multiple = "MB";
|
std::string multiple = "MB";
|
||||||
@@ -58,9 +72,13 @@ namespace PartitionManager {
|
|||||||
if (asGiga) multiple = "GB";
|
if (asGiga) multiple = "GB";
|
||||||
|
|
||||||
if (onlySize)
|
if (onlySize)
|
||||||
println("%s", convertTo(Variables->PartMap->sizeOf(partition), multiple).data());
|
println(
|
||||||
|
"%s",
|
||||||
|
convertTo(Variables->PartMap->sizeOf(partition), multiple).data());
|
||||||
else
|
else
|
||||||
println("%s: %s%s", partition.data(), convertTo(Variables->PartMap->sizeOf(partition), multiple).data(), multiple.data());
|
println("%s: %s%s", partition.data(),
|
||||||
|
convertTo(Variables->PartMap->sizeOf(partition), multiple).data(),
|
||||||
|
multiple.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -14,16 +14,20 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <PartitionManager/PartitionManager.hpp>
|
|
||||||
#include "functions.hpp"
|
#include "functions.hpp"
|
||||||
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
|
||||||
#define RLPFUN "realPathFunction"
|
#define RLPFUN "realPathFunction"
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
bool realLinkPathFunction::init(CLI::App &_app) {
|
bool realLinkPathFunction::init(CLI::App &_app) {
|
||||||
LOGN(RLPFUN, INFO) << "Initializing variables of real link path function." << std::endl;
|
LOGN(RLPFUN, INFO) << "Initializing variables of real link path function."
|
||||||
cmd = _app.add_subcommand("real-linkpath", "Tell real link paths of partition(s)");
|
<< std::endl;
|
||||||
cmd->add_option("partition(s)", partitions, "Partition name(s)")->required()->delimiter(',');
|
cmd = _app.add_subcommand("real-linkpath",
|
||||||
|
"Tell real link paths of partition(s)");
|
||||||
|
cmd->add_option("partition(s)", partitions, "Partition name(s)")
|
||||||
|
->required()
|
||||||
|
->delimiter(',');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,9 +38,13 @@ namespace PartitionManager {
|
|||||||
|
|
||||||
if (Variables->onLogical && !Variables->PartMap->isLogical(partition)) {
|
if (Variables->onLogical && !Variables->PartMap->isLogical(partition)) {
|
||||||
if (Variables->forceProcess)
|
if (Variables->forceProcess)
|
||||||
LOGN(RLPFUN, WARNING) << "Partition " << partition <<
|
LOGN(RLPFUN, WARNING)
|
||||||
" is exists but not logical. Ignoring (from --force, -f)." << std::endl;
|
<< "Partition " << partition
|
||||||
else throw Error("Used --logical (-l) flag but is not logical partition: %s", partition.data());
|
<< " is exists but not logical. Ignoring (from --force, -f)."
|
||||||
|
<< std::endl;
|
||||||
|
else
|
||||||
|
throw Error("Used --logical (-l) flag but is not logical partition: %s",
|
||||||
|
partition.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
println("%s", Variables->PartMap->getRealPathOf(partition).data());
|
println("%s", Variables->PartMap->getRealPathOf(partition).data());
|
||||||
|
|||||||
@@ -14,16 +14,19 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <PartitionManager/PartitionManager.hpp>
|
|
||||||
#include "functions.hpp"
|
#include "functions.hpp"
|
||||||
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
|
||||||
#define RPFUN "realPathFunction"
|
#define RPFUN "realPathFunction"
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
bool realPathFunction::init(CLI::App &_app) {
|
bool realPathFunction::init(CLI::App &_app) {
|
||||||
LOGN(RPFUN, INFO) << "Initializing variables of real path function." << std::endl;
|
LOGN(RPFUN, INFO) << "Initializing variables of real path function."
|
||||||
|
<< std::endl;
|
||||||
cmd = _app.add_subcommand("real-path", "Tell real paths of partition(s)");
|
cmd = _app.add_subcommand("real-path", "Tell real paths of partition(s)");
|
||||||
cmd->add_option("partition(s)", partitions, "Partition name(s)")->required()->delimiter(',');
|
cmd->add_option("partition(s)", partitions, "Partition name(s)")
|
||||||
|
->required()
|
||||||
|
->delimiter(',');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,9 +37,13 @@ namespace PartitionManager {
|
|||||||
|
|
||||||
if (Variables->onLogical && !Variables->PartMap->isLogical(partition)) {
|
if (Variables->onLogical && !Variables->PartMap->isLogical(partition)) {
|
||||||
if (Variables->forceProcess)
|
if (Variables->forceProcess)
|
||||||
LOGN(RPFUN, WARNING) << "Partition " << partition <<
|
LOGN(RPFUN, WARNING)
|
||||||
" is exists but not logical. Ignoring (from --force, -f)." << std::endl;
|
<< "Partition " << partition
|
||||||
else throw Error("Used --logical (-l) flag but is not logical partition: %s", partition.data());
|
<< " is exists but not logical. Ignoring (from --force, -f)."
|
||||||
|
<< std::endl;
|
||||||
|
else
|
||||||
|
throw Error("Used --logical (-l) flag but is not logical partition: %s",
|
||||||
|
partition.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
println("%s", Variables->PartMap->getRealPathOf(partition).data());
|
println("%s", Variables->PartMap->getRealPathOf(partition).data());
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ Copyright 2025 Yağız Zengin
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <PartitionManager/PartitionManager.hpp>
|
|
||||||
#include "functions.hpp"
|
#include "functions.hpp"
|
||||||
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
|
||||||
#define RFUN "rebootFunction"
|
#define RFUN "rebootFunction"
|
||||||
|
|
||||||
@@ -23,12 +23,15 @@ namespace PartitionManager {
|
|||||||
bool rebootFunction::init(CLI::App &_app) {
|
bool rebootFunction::init(CLI::App &_app) {
|
||||||
LOGN(RFUN, INFO) << "Initializing variables of reboot function." << std::endl;
|
LOGN(RFUN, INFO) << "Initializing variables of reboot function." << std::endl;
|
||||||
cmd = _app.add_subcommand("reboot", "Reboots device");
|
cmd = _app.add_subcommand("reboot", "Reboots device");
|
||||||
cmd->add_option("rebootTarget", rebootTarget, "Reboot target (default: normal)");
|
cmd->add_option("rebootTarget", rebootTarget,
|
||||||
|
"Reboot target (default: normal)");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rebootFunction::run() {
|
bool rebootFunction::run() {
|
||||||
LOGN(RFUN, INFO) << "Rebooting device!!! (custom reboot target: " << (rebootTarget.empty() ? "none" : rebootTarget) << std::endl;
|
LOGN(RFUN, INFO) << "Rebooting device!!! (custom reboot target: "
|
||||||
|
<< (rebootTarget.empty() ? "none" : rebootTarget)
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
if (Helper::reboot(rebootTarget)) println("Reboot command was sent");
|
if (Helper::reboot(rebootTarget)) println("Reboot command was sent");
|
||||||
else throw Error("Cannot reboot device");
|
else throw Error("Cannot reboot device");
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <PartitionManager/PartitionManager.hpp>
|
|
||||||
#include "functions.hpp"
|
#include "functions.hpp"
|
||||||
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
|
||||||
#define TFUN "typeFunction"
|
#define TFUN "typeFunction"
|
||||||
|
|
||||||
@@ -23,33 +23,49 @@ namespace PartitionManager {
|
|||||||
bool typeFunction::init(CLI::App &_app) {
|
bool typeFunction::init(CLI::App &_app) {
|
||||||
LOGN(TFUN, INFO) << "Initializing variables of type function." << std::endl;
|
LOGN(TFUN, INFO) << "Initializing variables of type function." << std::endl;
|
||||||
cmd = _app.add_subcommand("type", "Get type of the partition(s) or image(s)");
|
cmd = _app.add_subcommand("type", "Get type of the partition(s) or image(s)");
|
||||||
cmd->add_option("content(s)", contents, "Content(s)")->required()->delimiter(',');
|
cmd->add_option("content(s)", contents, "Content(s)")
|
||||||
cmd->add_option("-b,--buffer-size", bufferSize, "Buffer size for max seek depth");
|
->required()
|
||||||
cmd->add_flag("--only-check-android-magics", onlyCheckAndroidMagics, "Only check Android magic values.");
|
->delimiter(',');
|
||||||
cmd->add_flag("--only-check-filesystem-magics", onlyCheckFileSystemMagics, "Only check filesystem magic values.");
|
cmd->add_option("-b,--buffer-size", bufferSize,
|
||||||
|
"Buffer size for max seek depth");
|
||||||
|
cmd->add_flag("--only-check-android-magics", onlyCheckAndroidMagics,
|
||||||
|
"Only check Android magic values.");
|
||||||
|
cmd->add_flag("--only-check-filesystem-magics", onlyCheckFileSystemMagics,
|
||||||
|
"Only check filesystem magic values.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool typeFunction::run() {
|
bool typeFunction::run() {
|
||||||
std::unordered_map<uint64_t, std::string> magics;
|
std::unordered_map<uint64_t, std::string> magics;
|
||||||
if (onlyCheckAndroidMagics) magics.merge(PartitionMap::Extras::AndroidMagicMap);
|
if (onlyCheckAndroidMagics)
|
||||||
else if (onlyCheckFileSystemMagics) magics.merge(PartitionMap::Extras::FileSystemMagicMap);
|
magics.merge(PartitionMap::Extras::AndroidMagicMap);
|
||||||
|
else if (onlyCheckFileSystemMagics)
|
||||||
|
magics.merge(PartitionMap::Extras::FileSystemMagicMap);
|
||||||
else magics.merge(PartitionMap::Extras::MagicMap);
|
else magics.merge(PartitionMap::Extras::MagicMap);
|
||||||
|
|
||||||
for (const auto &content : contents) {
|
for (const auto &content : contents) {
|
||||||
if (!Variables->PartMap->hasPartition(content) && !Helper::fileIsExists(content))
|
if (!Variables->PartMap->hasPartition(content) &&
|
||||||
throw Error("Couldn't find partition or image file: %s\n", content.data());
|
!Helper::fileIsExists(content))
|
||||||
|
throw Error("Couldn't find partition or image file: %s\n",
|
||||||
|
content.data());
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (const auto &[magic, name] : magics) {
|
for (const auto &[magic, name] : magics) {
|
||||||
if (PartitionMap::Extras::hasMagic(magic, bufferSize, Helper::fileIsExists(content) ? content : Variables->PartMap->getRealPathOf(content))) {
|
if (PartitionMap::Extras::hasMagic(
|
||||||
println("%s contains %s magic (%s)", content.data(), name.data(), PartitionMap::Extras::formatMagic(magic).data());
|
magic, bufferSize,
|
||||||
|
Helper::fileIsExists(content)
|
||||||
|
? content
|
||||||
|
: Variables->PartMap->getRealPathOf(content))) {
|
||||||
|
println("%s contains %s magic (%s)", content.data(), name.data(),
|
||||||
|
PartitionMap::Extras::formatMagic(magic).data());
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) throw Error("Couldn't determine type of %s%s\n", content.data(), content == "userdata" ? " (encrypted file system?)" : "");
|
if (!found)
|
||||||
|
throw Error("Couldn't determine type of %s%s\n", content.data(),
|
||||||
|
content == "userdata" ? " (encrypted file system?)" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
12
src/functions/functions.hpp
Executable file → Normal file
12
src/functions/functions.hpp
Executable file → Normal file
@@ -36,7 +36,8 @@ namespace PartitionManager {
|
|||||||
|
|
||||||
bool init(CLI::App &_app) override;
|
bool init(CLI::App &_app) override;
|
||||||
bool run() override;
|
bool run() override;
|
||||||
static pair runAsync(const std::string &partitionName, const std::string &outputName, int bufferSize);
|
static pair runAsync(const std::string &partitionName,
|
||||||
|
const std::string &outputName, int bufferSize);
|
||||||
|
|
||||||
[[nodiscard]] bool isUsed() const override;
|
[[nodiscard]] bool isUsed() const override;
|
||||||
[[nodiscard]] const char *name() const override;
|
[[nodiscard]] const char *name() const override;
|
||||||
@@ -54,7 +55,8 @@ namespace PartitionManager {
|
|||||||
|
|
||||||
bool init(CLI::App &_app) override;
|
bool init(CLI::App &_app) override;
|
||||||
bool run() override;
|
bool run() override;
|
||||||
static pair runAsync(const std::string &partitionName, const std::string &imageName, int bufferSize);
|
static pair runAsync(const std::string &partitionName,
|
||||||
|
const std::string &imageName, int bufferSize);
|
||||||
|
|
||||||
[[nodiscard]] bool isUsed() const override;
|
[[nodiscard]] bool isUsed() const override;
|
||||||
[[nodiscard]] const char *name() const override;
|
[[nodiscard]] const char *name() const override;
|
||||||
@@ -81,7 +83,8 @@ namespace PartitionManager {
|
|||||||
class partitionSizeFunction final : public FunctionBase {
|
class partitionSizeFunction final : public FunctionBase {
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> partitions;
|
std::vector<std::string> partitions;
|
||||||
bool onlySize = false, asByte = false, asKiloBytes = false, asMega = false, asGiga = false;
|
bool onlySize = false, asByte = false, asKiloBytes = false, asMega = false,
|
||||||
|
asGiga = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CLI::App *cmd = nullptr;
|
CLI::App *cmd = nullptr;
|
||||||
@@ -97,7 +100,8 @@ namespace PartitionManager {
|
|||||||
class infoFunction final : public FunctionBase {
|
class infoFunction final : public FunctionBase {
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> partitions;
|
std::vector<std::string> partitions;
|
||||||
std::string jNamePartition = "name", jNameSize = "size", jNameLogical = "isLogical";
|
std::string jNamePartition = "name", jNameSize = "size",
|
||||||
|
jNameLogical = "isLogical";
|
||||||
bool jsonFormat = false;
|
bool jsonFormat = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
54
srclib/libhelper/include/libhelper/lib.hpp
Executable file → Normal file
54
srclib/libhelper/include/libhelper/lib.hpp
Executable file → Normal file
@@ -18,11 +18,11 @@
|
|||||||
#define LIBHELPER_LIB_HPP
|
#define LIBHELPER_LIB_HPP
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
|
||||||
#include <string_view>
|
|
||||||
#include <sstream>
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#ifndef ONLY_HELPER_MACROS
|
#ifndef ONLY_HELPER_MACROS
|
||||||
|
|
||||||
@@ -49,12 +49,12 @@ namespace Helper {
|
|||||||
int _line;
|
int _line;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Logger(LogLevels level, const char *func, const char *file, const char *name, const char *sfile, int line);
|
Logger(LogLevels level, const char *func, const char *file, const char *name,
|
||||||
|
const char *sfile, int line);
|
||||||
|
|
||||||
~Logger();
|
~Logger();
|
||||||
|
|
||||||
template<typename T>
|
template <typename T> Logger &operator<<(const T &msg) {
|
||||||
Logger &operator<<(const T &msg) {
|
|
||||||
_oss << msg;
|
_oss << msg;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -68,8 +68,7 @@ namespace Helper {
|
|||||||
std::string _message;
|
std::string _message;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
__attribute__((format(printf, 2, 3)))
|
__attribute__((format(printf, 2, 3))) explicit Error(const char *format, ...);
|
||||||
explicit Error(const char *format, ...);
|
|
||||||
|
|
||||||
[[nodiscard]] const char *what() const noexcept override;
|
[[nodiscard]] const char *what() const noexcept override;
|
||||||
};
|
};
|
||||||
@@ -158,9 +157,14 @@ namespace Helper {
|
|||||||
// Library-specif
|
// Library-specif
|
||||||
std::string getLibVersion();
|
std::string getLibVersion();
|
||||||
|
|
||||||
// Open input path with flags and add to integrity list. And return file descriptor
|
// Open input path with flags and add to integrity list. And return file
|
||||||
[[nodiscard]] int openAndAddToCloseList(const std::string_view& path, garbageCollector &collector, int flags, mode_t mode = 0000);
|
// descriptor
|
||||||
[[nodiscard]] FILE* openAndAddToCloseList(const std::string_view& path, garbageCollector &collector, const char* mode);
|
[[nodiscard]] int openAndAddToCloseList(const std::string_view &path,
|
||||||
|
garbageCollector &collector, int flags,
|
||||||
|
mode_t mode = 0000);
|
||||||
|
[[nodiscard]] FILE *openAndAddToCloseList(const std::string_view &path,
|
||||||
|
garbageCollector &collector,
|
||||||
|
const char *mode);
|
||||||
} // namespace Helper
|
} // namespace Helper
|
||||||
|
|
||||||
#endif // #ifndef ONLY_HELPER_MACROS
|
#endif // #ifndef ONLY_HELPER_MACROS
|
||||||
@@ -193,7 +197,8 @@ namespace Helper {
|
|||||||
// ABORT(message), ex: ABORT("memory error!\n")
|
// ABORT(message), ex: ABORT("memory error!\n")
|
||||||
#define ABORT(msg) \
|
#define ABORT(msg) \
|
||||||
do { \
|
do { \
|
||||||
fprintf(stderr, "%s%sCRITICAL ERROR%s: %s\nAborting...\n", BOLD, RED, STYLE_RESET, msg); \
|
fprintf(stderr, "%s%sCRITICAL ERROR%s: %s\nAborting...\n", BOLD, RED, \
|
||||||
|
STYLE_RESET, msg); \
|
||||||
abort(); \
|
abort(); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@@ -213,20 +218,33 @@ namespace Helper {
|
|||||||
fprintf(stdout, "%s%sINFO%s: %s", BOLD, GREEN, STYLE_RESET, msg);
|
fprintf(stdout, "%s%sINFO%s: %s", BOLD, GREEN, STYLE_RESET, msg);
|
||||||
#endif // #ifndef NO_C_TYPE_HANDLERS
|
#endif // #ifndef NO_C_TYPE_HANDLERS
|
||||||
|
|
||||||
#define LOG(level) Helper::Logger(level, __func__, Helper::LoggingProperties::FILE.data(), Helper::LoggingProperties::NAME.data(), __FILE__, __LINE__)
|
#define LOG(level) \
|
||||||
#define LOGN(name, level) Helper::Logger(level, __func__, Helper::LoggingProperties::FILE.data(), name, __FILE__, __LINE__)
|
Helper::Logger(level, __func__, Helper::LoggingProperties::FILE.data(), \
|
||||||
#define LOGNF(name, file, level) Helper::Logger(level, file, name, __FILE__, __LINE__)
|
Helper::LoggingProperties::NAME.data(), __FILE__, __LINE__)
|
||||||
|
#define LOGN(name, level) \
|
||||||
|
Helper::Logger(level, __func__, Helper::LoggingProperties::FILE.data(), \
|
||||||
|
name, __FILE__, __LINE__)
|
||||||
|
#define LOGNF(name, file, level) \
|
||||||
|
Helper::Logger(level, file, name, __FILE__, __LINE__)
|
||||||
|
|
||||||
#define LOG_IF(level, condition) \
|
#define LOG_IF(level, condition) \
|
||||||
if (condition) Helper::Logger(level, __func__, Helper::LoggingProperties::FILE.data(), Helper::LoggingProperties::NAME.data(), __FILE__, __LINE__)
|
if (condition) \
|
||||||
|
Helper::Logger(level, __func__, Helper::LoggingProperties::FILE.data(), \
|
||||||
|
Helper::LoggingProperties::NAME.data(), __FILE__, __LINE__)
|
||||||
#define LOGN_IF(name, level, condition) \
|
#define LOGN_IF(name, level, condition) \
|
||||||
if (condition) Helper::Logger(level, __func__, Helper::LoggingProperties::FILE.data(), name, __FILE__, __LINE__)
|
if (condition) \
|
||||||
|
Helper::Logger(level, __func__, Helper::LoggingProperties::FILE.data(), \
|
||||||
|
name, __FILE__, __LINE__)
|
||||||
#define LOGNF_IF(name, file, level, condition) \
|
#define LOGNF_IF(name, file, level, condition) \
|
||||||
if (condition) Helper::Logger(level, __func__, file, name, __FILE__, __LINE__)
|
if (condition) Helper::Logger(level, __func__, file, name, __FILE__, __LINE__)
|
||||||
|
|
||||||
#define MKVERSION(name) \
|
#define MKVERSION(name) \
|
||||||
char vinfo[512]; \
|
char vinfo[512]; \
|
||||||
sprintf(vinfo, "%s %s [%s %s]\nBuildType: %s\nCMakeVersion: %s\nCompilerVersion: %s\nBuildFlags: %s", name, BUILD_VERSION, BUILD_DATE, BUILD_TIME, BUILD_TYPE, BUILD_CMAKE_VERSION, BUILD_COMPILER_VERSION, BUILD_FLAGS); \
|
sprintf(vinfo, \
|
||||||
|
"%s %s [%s %s]\nBuildType: %s\nCMakeVersion: %s\nCompilerVersion: " \
|
||||||
|
"%s\nBuildFlags: %s", \
|
||||||
|
name, BUILD_VERSION, BUILD_DATE, BUILD_TIME, BUILD_TYPE, \
|
||||||
|
BUILD_CMAKE_VERSION, BUILD_COMPILER_VERSION, BUILD_FLAGS); \
|
||||||
return std::string(vinfo)
|
return std::string(vinfo)
|
||||||
|
|
||||||
#endif // #ifndef LIBHELPER_LIB_HPP
|
#endif // #ifndef LIBHELPER_LIB_HPP
|
||||||
|
|||||||
18
srclib/libhelper/src/Checkers.cpp
Executable file → Normal file
18
srclib/libhelper/src/Checkers.cpp
Executable file → Normal file
@@ -16,15 +16,13 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <libhelper/lib.hpp>
|
#include <libhelper/lib.hpp>
|
||||||
#include <private/android_filesystem_config.h>
|
#include <private/android_filesystem_config.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace Helper {
|
namespace Helper {
|
||||||
bool hasSuperUser() {
|
bool hasSuperUser() { return (getuid() == AID_ROOT); }
|
||||||
return (getuid() == AID_ROOT);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isExists(const std::string_view entry) {
|
bool isExists(const std::string_view entry) {
|
||||||
struct stat st{};
|
struct stat st{};
|
||||||
@@ -53,9 +51,7 @@ namespace Helper {
|
|||||||
return S_ISLNK(st.st_mode);
|
return S_ISLNK(st.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSymbolicLink(const std::string_view entry) {
|
bool isSymbolicLink(const std::string_view entry) { return isLink(entry); }
|
||||||
return isLink(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isHardLink(const std::string_view entry) {
|
bool isHardLink(const std::string_view entry) {
|
||||||
struct stat st{};
|
struct stat st{};
|
||||||
@@ -64,8 +60,10 @@ namespace Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool areLinked(const std::string_view entry1, const std::string_view entry2) {
|
bool areLinked(const std::string_view entry1, const std::string_view entry2) {
|
||||||
const std::string st1 = (isSymbolicLink(entry1)) ? readSymlink(entry1) : std::string(entry1.data());
|
const std::string st1 = (isSymbolicLink(entry1)) ? readSymlink(entry1)
|
||||||
const std::string st2 = (isSymbolicLink(entry2)) ? readSymlink(entry2) : std::string(entry2.data());
|
: std::string(entry1.data());
|
||||||
|
const std::string st2 = (isSymbolicLink(entry2)) ? readSymlink(entry2)
|
||||||
|
: std::string(entry2.data());
|
||||||
|
|
||||||
return (st1 == st2);
|
return (st1 == st2);
|
||||||
}
|
}
|
||||||
|
|||||||
77
srclib/libhelper/src/Classes.cpp
Executable file → Normal file
77
srclib/libhelper/src/Classes.cpp
Executable file → Normal file
@@ -14,17 +14,17 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <exception>
|
#include <cerrno>
|
||||||
#include <sstream>
|
#include <cstdarg>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <unistd.h>
|
#include <exception>
|
||||||
#include <libgen.h>
|
|
||||||
#include <cstdarg>
|
|
||||||
#include <cerrno>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <libgen.h>
|
||||||
#include <libhelper/lib.hpp>
|
#include <libhelper/lib.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace Helper {
|
namespace Helper {
|
||||||
Error::Error(const char *format, ...) {
|
Error::Error(const char *format, ...) {
|
||||||
@@ -37,34 +37,32 @@ namespace Helper {
|
|||||||
LOGN(HELPER, ERROR) << _message << std::endl;
|
LOGN(HELPER, ERROR) << _message << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Error::what() const noexcept {
|
const char *Error::what() const noexcept { return _message.data(); }
|
||||||
return _message.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger::Logger(const LogLevels level, const char *func, const char *file, const char *name, const char *sfile,
|
Logger::Logger(const LogLevels level, const char *func, const char *file,
|
||||||
const int line) : _level(level), _funcname(func), _logFile(file), _program_name(name), _file(sfile),
|
const char *name, const char *sfile, const int line)
|
||||||
_line(line) {
|
: _level(level), _funcname(func), _logFile(file), _program_name(name),
|
||||||
}
|
_file(sfile), _line(line) {}
|
||||||
|
|
||||||
Logger::~Logger() {
|
Logger::~Logger() {
|
||||||
if (LoggingProperties::DISABLE) return;
|
if (LoggingProperties::DISABLE) return;
|
||||||
char str[1024];
|
char str[1024];
|
||||||
snprintf(str, sizeof(str), "<%c> [ <prog %s> <on %s:%d> %s %s] %s(): %s",
|
snprintf(str, sizeof(str), "<%c> [ <prog %s> <on %s:%d> %s %s] %s(): %s",
|
||||||
static_cast<char>(_level),
|
static_cast<char>(_level), _program_name,
|
||||||
_program_name,
|
basename(const_cast<char *>(_file)), _line, currentDate().data(),
|
||||||
basename(const_cast<char *>(_file)),
|
currentTime().data(), _funcname, _oss.str().data());
|
||||||
_line,
|
|
||||||
currentDate().data(),
|
|
||||||
currentTime().data(),
|
|
||||||
_funcname,
|
|
||||||
_oss.str().data());
|
|
||||||
|
|
||||||
if (!isExists(_logFile)) {
|
if (!isExists(_logFile)) {
|
||||||
if (const int fd = open(_logFile, O_WRONLY | O_CREAT, DEFAULT_EXTENDED_FILE_PERMS); fd != -1) close(fd);
|
if (const int fd =
|
||||||
|
open(_logFile, O_WRONLY | O_CREAT, DEFAULT_EXTENDED_FILE_PERMS);
|
||||||
|
fd != -1)
|
||||||
|
close(fd);
|
||||||
else {
|
else {
|
||||||
LoggingProperties::setLogFile("last_logs.log");
|
LoggingProperties::setLogFile("last_logs.log");
|
||||||
LOGN(HELPER, INFO) << "Cannot create log file: " << _logFile << ": " << strerror(errno) <<
|
LOGN(HELPER, INFO) << "Cannot create log file: " << _logFile << ": "
|
||||||
" New logging file: last_logs.log (this file)." << std::endl;
|
<< strerror(errno)
|
||||||
|
<< " New logging file: last_logs.log (this file)."
|
||||||
|
<< std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,8 +71,11 @@ namespace Helper {
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
} else {
|
} else {
|
||||||
LoggingProperties::setLogFile("last_logs.log");
|
LoggingProperties::setLogFile("last_logs.log");
|
||||||
LOGN(HELPER, INFO) << "Cannot write logs to log file: " << _logFile << ": " << strerror(errno) <<
|
LOGN(HELPER, INFO)
|
||||||
" Logging file setting up as: last_logs.log (this file)." << std::endl;
|
<< "Cannot write logs to log file: " << _logFile << ": "
|
||||||
|
<< strerror(errno)
|
||||||
|
<< " Logging file setting up as: last_logs.log (this file)."
|
||||||
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LoggingProperties::PRINT) printf("%s", str);
|
if (LoggingProperties::PRINT) printf("%s", str);
|
||||||
@@ -86,14 +87,24 @@ namespace Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
garbageCollector::~garbageCollector() {
|
garbageCollector::~garbageCollector() {
|
||||||
for (const auto& ptr : _ptrs_c) delete[] ptr;
|
for (const auto &ptr : _ptrs_c)
|
||||||
for (const auto& ptr : _ptrs_u) delete[] ptr;
|
delete[] ptr;
|
||||||
for (const auto& fd : _fds) close(fd);
|
for (const auto &ptr : _ptrs_u)
|
||||||
for (const auto& fp : _fps) fclose(fp);
|
delete[] ptr;
|
||||||
|
for (const auto &fd : _fds)
|
||||||
|
close(fd);
|
||||||
|
for (const auto &fp : _fps)
|
||||||
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbageCollector::delAfterProgress(char* &_ptr) { _ptrs_c.push_back(_ptr); }
|
void garbageCollector::delAfterProgress(char *&_ptr) {
|
||||||
void garbageCollector::delAfterProgress(uint8_t *&_ptr) { _ptrs_u.push_back(_ptr); }
|
_ptrs_c.push_back(_ptr);
|
||||||
void garbageCollector::closeAfterProgress(const int _fd) { _fds.push_back(_fd); }
|
}
|
||||||
|
void garbageCollector::delAfterProgress(uint8_t *&_ptr) {
|
||||||
|
_ptrs_u.push_back(_ptr);
|
||||||
|
}
|
||||||
|
void garbageCollector::closeAfterProgress(const int _fd) {
|
||||||
|
_fds.push_back(_fd);
|
||||||
|
}
|
||||||
void garbageCollector::delAfterProgress(FILE *&_fp) { _fps.push_back(_fp); }
|
void garbageCollector::delAfterProgress(FILE *&_fp) { _fps.push_back(_fp); }
|
||||||
} // namespace Helper
|
} // namespace Helper
|
||||||
|
|||||||
62
srclib/libhelper/src/FileUtil.cpp
Executable file → Normal file
62
srclib/libhelper/src/FileUtil.cpp
Executable file → Normal file
@@ -14,20 +14,21 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <cerrno>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cerrno>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <unistd.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <libhelper/lib.hpp>
|
#include <libhelper/lib.hpp>
|
||||||
|
#include <string>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace Helper {
|
namespace Helper {
|
||||||
bool writeFile(const std::string_view file, const std::string_view text) {
|
bool writeFile(const std::string_view file, const std::string_view text) {
|
||||||
LOGN(HELPER, INFO) << "write \"" << text << "\" to " << file << "requested." << std::endl;
|
LOGN(HELPER, INFO) << "write \"" << text << "\" to " << file << "requested."
|
||||||
|
<< std::endl;
|
||||||
garbageCollector collector;
|
garbageCollector collector;
|
||||||
|
|
||||||
FILE *fp = openAndAddToCloseList(file, collector, "a");
|
FILE *fp = openAndAddToCloseList(file, collector, "a");
|
||||||
@@ -47,20 +48,24 @@ namespace Helper {
|
|||||||
|
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
std::string str;
|
std::string str;
|
||||||
while (fgets(buffer, sizeof(buffer), fp)) str += buffer;
|
while (fgets(buffer, sizeof(buffer), fp))
|
||||||
|
str += buffer;
|
||||||
|
|
||||||
LOGN(HELPER, INFO) << "read " << file << " successfully, read text: \"" << str << "\"" << std::endl;
|
LOGN(HELPER, INFO) << "read " << file << " successfully, read text: \"" << str
|
||||||
|
<< "\"" << std::endl;
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool copyFile(const std::string_view file, const std::string_view dest) {
|
bool copyFile(const std::string_view file, const std::string_view dest) {
|
||||||
LOGN(HELPER, INFO) << "copy " << file << " to " << dest << " requested." << std::endl;
|
LOGN(HELPER, INFO) << "copy " << file << " to " << dest << " requested."
|
||||||
|
<< std::endl;
|
||||||
garbageCollector collector;
|
garbageCollector collector;
|
||||||
|
|
||||||
const int src_fd = openAndAddToCloseList(file.data(), collector, O_RDONLY);
|
const int src_fd = openAndAddToCloseList(file.data(), collector, O_RDONLY);
|
||||||
if (src_fd == -1) return false;
|
if (src_fd == -1) return false;
|
||||||
|
|
||||||
const int dst_fd = openAndAddToCloseList(dest.data(), collector, O_WRONLY | O_CREAT | O_TRUNC, DEFAULT_FILE_PERMS);
|
const int dst_fd = openAndAddToCloseList(
|
||||||
|
dest.data(), collector, O_WRONLY | O_CREAT | O_TRUNC, DEFAULT_FILE_PERMS);
|
||||||
if (dst_fd == -1) return false;
|
if (dst_fd == -1) return false;
|
||||||
|
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
@@ -70,7 +75,8 @@ namespace Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (br == -1) return false;
|
if (br == -1) return false;
|
||||||
LOGN(HELPER, INFO) << "copy " << file << " to " << dest << " successfully." << std::endl;
|
LOGN(HELPER, INFO) << "copy " << file << " to " << dest << " successfully."
|
||||||
|
<< std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +87,8 @@ namespace Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool makeRecursiveDirectory(const std::string_view paths) {
|
bool makeRecursiveDirectory(const std::string_view paths) {
|
||||||
LOGN(HELPER, INFO) << "make recursive directory requested: " << paths << std::endl;
|
LOGN(HELPER, INFO) << "make recursive directory requested: " << paths
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
char tmp[PATH_MAX];
|
char tmp[PATH_MAX];
|
||||||
|
|
||||||
@@ -92,9 +99,7 @@ namespace Helper {
|
|||||||
if (*p == '/') {
|
if (*p == '/') {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
if (access(tmp, F_OK) != 0) {
|
if (access(tmp, F_OK) != 0) {
|
||||||
if (mkdir(tmp, DEFAULT_DIR_PERMS) != 0
|
if (mkdir(tmp, DEFAULT_DIR_PERMS) != 0 && errno != EEXIST) return false;
|
||||||
&& errno != EEXIST)
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
*p = '/';
|
*p = '/';
|
||||||
}
|
}
|
||||||
@@ -117,15 +122,20 @@ namespace Helper {
|
|||||||
if (fd == -1) return false;
|
if (fd == -1) return false;
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
LOGN(HELPER, INFO) << "create file \"" << path << "\" successfull." << std::endl;
|
LOGN(HELPER, INFO) << "create file \"" << path << "\" successfull."
|
||||||
|
<< std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool createSymlink(const std::string_view entry1, const std::string_view entry2) {
|
bool createSymlink(const std::string_view entry1,
|
||||||
LOGN(HELPER, INFO) << "symlink \"" << entry1 << "\" to \"" << entry2 << "\" requested." << std::endl;
|
const std::string_view entry2) {
|
||||||
if (const int ret = symlink(entry1.data(), entry2.data()); ret != 0) return false;
|
LOGN(HELPER, INFO) << "symlink \"" << entry1 << "\" to \"" << entry2
|
||||||
|
<< "\" requested." << std::endl;
|
||||||
|
if (const int ret = symlink(entry1.data(), entry2.data()); ret != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
LOGN(HELPER, INFO) << "\"" << entry1 << "\" symlinked to \"" << entry2 << "\" successfully." << std::endl;
|
LOGN(HELPER, INFO) << "\"" << entry1 << "\" symlinked to \"" << entry2
|
||||||
|
<< "\" successfully." << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,11 +158,11 @@ namespace Helper {
|
|||||||
while ((entry = readdir(dir)) != nullptr) {
|
while ((entry = readdir(dir)) != nullptr) {
|
||||||
char fullpath[PATH_MAX];
|
char fullpath[PATH_MAX];
|
||||||
|
|
||||||
if (strcmp(entry->d_name, ".") == 0
|
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||||
|| strcmp(entry->d_name, "..") == 0)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
snprintf(fullpath, sizeof(fullpath), "%s/%s", directory.data(), entry->d_name);
|
snprintf(fullpath, sizeof(fullpath), "%s/%s", directory.data(),
|
||||||
|
entry->d_name);
|
||||||
|
|
||||||
if (lstat(fullpath, &buf) == -1) {
|
if (lstat(fullpath, &buf) == -1) {
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
@@ -175,7 +185,8 @@ namespace Helper {
|
|||||||
closedir(dir);
|
closedir(dir);
|
||||||
if (rmdir(directory.data()) == -1) return false;
|
if (rmdir(directory.data()) == -1) return false;
|
||||||
|
|
||||||
LOGN(HELPER, INFO) << "\"" << directory << "\" successfully erased." << std::endl;
|
LOGN(HELPER, INFO) << "\"" << directory << "\" successfully erased."
|
||||||
|
<< std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +198,8 @@ namespace Helper {
|
|||||||
if (len == -1) return entry.data();
|
if (len == -1) return entry.data();
|
||||||
|
|
||||||
target[len] = '\0';
|
target[len] = '\0';
|
||||||
LOGN(HELPER, INFO) << "\"" << entry << "\" symlink to \"" << target << "\"" << std::endl;
|
LOGN(HELPER, INFO) << "\"" << entry << "\" symlink to \"" << target << "\""
|
||||||
|
<< std::endl;
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
27
srclib/libhelper/src/Sha256.cpp
Executable file → Normal file
27
srclib/libhelper/src/Sha256.cpp
Executable file → Normal file
@@ -15,36 +15,43 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <libhelper/lib.hpp>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <picosha2.h>
|
#include <picosha2.h>
|
||||||
|
#include <string>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <libhelper/lib.hpp>
|
#include <vector>
|
||||||
|
|
||||||
namespace Helper {
|
namespace Helper {
|
||||||
std::optional<std::string> sha256Of(const std::string_view path) {
|
std::optional<std::string> sha256Of(const std::string_view path) {
|
||||||
LOGN(HELPER, INFO) << "get sha256 of \"" << path <<
|
LOGN(HELPER, INFO)
|
||||||
"\" request. Getting full path (if input is link and exists)." << std::endl;
|
<< "get sha256 of \"" << path
|
||||||
|
<< "\" request. Getting full path (if input is link and exists)."
|
||||||
|
<< std::endl;
|
||||||
std::string fp = (isLink(path)) ? readSymlink(path) : std::string(path);
|
std::string fp = (isLink(path)) ? readSymlink(path) : std::string(path);
|
||||||
|
|
||||||
if (!fileIsExists(fp)) throw Error("Is not exists or not file: %s", fp.data());
|
if (!fileIsExists(fp))
|
||||||
|
throw Error("Is not exists or not file: %s", fp.data());
|
||||||
|
|
||||||
if (const std::ifstream file(fp, std::ios::binary); !file) throw Error("Cannot open file: %s", fp.data());
|
if (const std::ifstream file(fp, std::ios::binary); !file)
|
||||||
|
throw Error("Cannot open file: %s", fp.data());
|
||||||
|
|
||||||
std::vector<unsigned char> hash(picosha2::k_digest_size);
|
std::vector<unsigned char> hash(picosha2::k_digest_size);
|
||||||
picosha2::hash256(fp, hash.begin(), hash.end());
|
picosha2::hash256(fp, hash.begin(), hash.end());
|
||||||
LOGN(HELPER, INFO) << "get sha256 of \"" << path << "\" successfully." << std::endl;
|
LOGN(HELPER, INFO) << "get sha256 of \"" << path << "\" successfully."
|
||||||
|
<< std::endl;
|
||||||
return picosha2::bytes_to_hex_string(hash.begin(), hash.end());
|
return picosha2::bytes_to_hex_string(hash.begin(), hash.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sha256Compare(const std::string_view file1, const std::string_view file2) {
|
bool sha256Compare(const std::string_view file1, const std::string_view file2) {
|
||||||
LOGN(HELPER, INFO) << "comparing sha256 signatures of input files." << std::endl;
|
LOGN(HELPER, INFO) << "comparing sha256 signatures of input files."
|
||||||
|
<< std::endl;
|
||||||
const auto f1 = sha256Of(file1);
|
const auto f1 = sha256Of(file1);
|
||||||
const auto f2 = sha256Of(file2);
|
const auto f2 = sha256Of(file2);
|
||||||
if (f1->empty() || f2->empty()) return false;
|
if (f1->empty() || f2->empty()) return false;
|
||||||
LOGN_IF(HELPER, INFO, *f1 == *f2) << "(): input files is contains same sha256 signature." << std::endl;
|
LOGN_IF(HELPER, INFO, *f1 == *f2)
|
||||||
|
<< "(): input files is contains same sha256 signature." << std::endl;
|
||||||
return (*f1 == *f2);
|
return (*f1 == *f2);
|
||||||
}
|
}
|
||||||
} // namespace Helper
|
} // namespace Helper
|
||||||
|
|||||||
58
srclib/libhelper/src/Utilities.cpp
Executable file → Normal file
58
srclib/libhelper/src/Utilities.cpp
Executable file → Normal file
@@ -14,21 +14,21 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <ctime>
|
||||||
|
#include <cutils/android_reboot.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <generated/buildInfo.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <libhelper/lib.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <cstdio>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <ctime>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <libgen.h>
|
|
||||||
#include <libhelper/lib.hpp>
|
|
||||||
#include <generated/buildInfo.hpp>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/_system_properties.h>
|
#include <sys/_system_properties.h>
|
||||||
#include <cutils/android_reboot.h>
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
// From system/core/libcutils/android_reboot.cpp android16-s2-release
|
// From system/core/libcutils/android_reboot.cpp android16-s2-release
|
||||||
int android_reboot(const unsigned cmd, int /*flags*/, const char *arg) {
|
int android_reboot(const unsigned cmd, int /*flags*/, const char *arg) {
|
||||||
@@ -118,8 +118,7 @@ namespace Helper {
|
|||||||
const time_t t = time(nullptr);
|
const time_t t = time(nullptr);
|
||||||
|
|
||||||
if (const tm *date = localtime(&t))
|
if (const tm *date = localtime(&t))
|
||||||
return std::string(
|
return std::string(std::to_string(date->tm_mday) + "/" +
|
||||||
std::to_string(date->tm_mday) + "/" +
|
|
||||||
std::to_string(date->tm_mon + 1) + "/" +
|
std::to_string(date->tm_mon + 1) + "/" +
|
||||||
std::to_string(date->tm_year + 1900));
|
std::to_string(date->tm_year + 1900));
|
||||||
return "--/--/----";
|
return "--/--/----";
|
||||||
@@ -129,15 +128,15 @@ namespace Helper {
|
|||||||
const time_t t = time(nullptr);
|
const time_t t = time(nullptr);
|
||||||
|
|
||||||
if (const tm *date = localtime(&t))
|
if (const tm *date = localtime(&t))
|
||||||
return std::string(
|
return std::string(std::to_string(date->tm_hour) + ":" +
|
||||||
std::to_string(date->tm_hour) + ":" +
|
|
||||||
std::to_string(date->tm_min) + ":" +
|
std::to_string(date->tm_min) + ":" +
|
||||||
std::to_string(date->tm_sec));
|
std::to_string(date->tm_sec));
|
||||||
return "--:--:--";
|
return "--:--:--";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string runCommandWithOutput(const std::string_view cmd) {
|
std::string runCommandWithOutput(const std::string_view cmd) {
|
||||||
LOGN(HELPER, INFO) << "run command and catch out request: " << cmd << std::endl;
|
LOGN(HELPER, INFO) << "run command and catch out request: " << cmd
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
FILE *pipe = popen(cmd.data(), "r");
|
FILE *pipe = popen(cmd.data(), "r");
|
||||||
if (!pipe) return {};
|
if (!pipe) return {};
|
||||||
@@ -147,7 +146,8 @@ namespace Helper {
|
|||||||
std::string output;
|
std::string output;
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
|
||||||
while (fgets(buffer, sizeof(buffer), pipe_holder.get()) != nullptr) output += buffer;
|
while (fgets(buffer, sizeof(buffer), pipe_holder.get()) != nullptr)
|
||||||
|
output += buffer;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@@ -170,22 +170,29 @@ namespace Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool changeMode(const std::string_view file, const mode_t mode) {
|
bool changeMode(const std::string_view file, const mode_t mode) {
|
||||||
LOGN(HELPER, INFO) << "change mode request: " << file << ". As mode: " << mode << std::endl;
|
LOGN(HELPER, INFO) << "change mode request: " << file << ". As mode: " << mode
|
||||||
|
<< std::endl;
|
||||||
return chmod(file.data(), mode) == 0;
|
return chmod(file.data(), mode) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool changeOwner(const std::string_view file, const uid_t uid, const gid_t gid) {
|
bool changeOwner(const std::string_view file, const uid_t uid,
|
||||||
LOGN(HELPER, INFO) << "change owner request: " << file << ". As owner:group: " << uid << ":" << gid << std::endl;
|
const gid_t gid) {
|
||||||
|
LOGN(HELPER, INFO) << "change owner request: " << file
|
||||||
|
<< ". As owner:group: " << uid << ":" << gid << std::endl;
|
||||||
return chown(file.data(), uid, gid) == 0;
|
return chown(file.data(), uid, gid) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int openAndAddToCloseList(const std::string_view& path, garbageCollector &collector, const int flags, const mode_t mode) {
|
int openAndAddToCloseList(const std::string_view &path,
|
||||||
const int fd = mode == 0 ? open(path.data(), flags) : open(path.data(), flags, mode);
|
garbageCollector &collector, const int flags,
|
||||||
|
const mode_t mode) {
|
||||||
|
const int fd =
|
||||||
|
mode == 0 ? open(path.data(), flags) : open(path.data(), flags, mode);
|
||||||
collector.closeAfterProgress(fd);
|
collector.closeAfterProgress(fd);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* openAndAddToCloseList(const std::string_view& path, garbageCollector &collector, const char* mode) {
|
FILE *openAndAddToCloseList(const std::string_view &path,
|
||||||
|
garbageCollector &collector, const char *mode) {
|
||||||
FILE *fp = fopen(path.data(), mode);
|
FILE *fp = fopen(path.data(), mode);
|
||||||
collector.delAfterProgress(fp);
|
collector.delAfterProgress(fp);
|
||||||
return fp;
|
return fp;
|
||||||
@@ -201,14 +208,13 @@ namespace Helper {
|
|||||||
LOGN(HELPER, INFO) << "reboot request sent!!!" << std::endl;
|
LOGN(HELPER, INFO) << "reboot request sent!!!" << std::endl;
|
||||||
|
|
||||||
unsigned cmd = ANDROID_RB_RESTART2;
|
unsigned cmd = ANDROID_RB_RESTART2;
|
||||||
if (const std::string prop = getProperty("ro.build.version.sdk"); prop != "ERROR") {
|
if (const std::string prop = getProperty("ro.build.version.sdk");
|
||||||
|
prop != "ERROR") {
|
||||||
if (std::stoi(prop) < 26) cmd = ANDROID_RB_RESTART;
|
if (std::stoi(prop) < 26) cmd = ANDROID_RB_RESTART;
|
||||||
}
|
}
|
||||||
|
|
||||||
return android_reboot(cmd, 0, arg.empty() ? nullptr : arg.data()) != -1;
|
return android_reboot(cmd, 0, arg.empty() ? nullptr : arg.data()) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getLibVersion() {
|
std::string getLibVersion() { MKVERSION("libhelper"); }
|
||||||
MKVERSION("libhelper");
|
|
||||||
}
|
|
||||||
} // namespace Helper
|
} // namespace Helper
|
||||||
|
|||||||
115
srclib/libhelper/tests/test.cpp
Executable file → Normal file
115
srclib/libhelper/tests/test.cpp
Executable file → Normal file
@@ -21,72 +21,103 @@
|
|||||||
|
|
||||||
char *TEST_DIR = nullptr;
|
char *TEST_DIR = nullptr;
|
||||||
|
|
||||||
std::string test_path(const char* file)
|
std::string test_path(const char *file) {
|
||||||
{
|
|
||||||
std::string end = std::string(TEST_DIR) + "/" + file;
|
std::string end = std::string(TEST_DIR) + "/" + file;
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
|
||||||
if (argc < 2) return 2;
|
if (argc < 2) return 2;
|
||||||
else TEST_DIR = argv[1];
|
else TEST_DIR = argv[1];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::cout << "Has super user?; " << std::boolalpha << Helper::hasSuperUser() << std::endl;
|
std::cout << "Has super user?; " << std::boolalpha << Helper::hasSuperUser()
|
||||||
std::cout << "file.txt is exists?; " << std::boolalpha << Helper::isExists(test_path("file.txt")) << std::endl;
|
<< std::endl;
|
||||||
std::cout << "'file.txt' file is exists?; " << std::boolalpha << Helper::fileIsExists(test_path("file")) << std::endl;
|
std::cout << "file.txt is exists?; " << std::boolalpha
|
||||||
std::cout << "'dir' directory is exists?; " << std::boolalpha << Helper::directoryIsExists(test_path("dir")) << std::endl;
|
<< Helper::isExists(test_path("file.txt")) << std::endl;
|
||||||
std::cout << "'linkdir' is link?; " << std::boolalpha << Helper::isLink(test_path("linkdir")) << std::endl;
|
std::cout << "'file.txt' file is exists?; " << std::boolalpha
|
||||||
std::cout << "'linkdir' is symlink?; " << std::boolalpha << Helper::isSymbolicLink(test_path("linkdir")) << std::endl;
|
<< Helper::fileIsExists(test_path("file")) << std::endl;
|
||||||
std::cout << "'linkdir' is hardlink?; " << std::boolalpha << Helper::isHardLink(test_path("linkdir")) << std::endl;
|
std::cout << "'dir' directory is exists?; " << std::boolalpha
|
||||||
std::cout << "'linkdir' is symlink to 'dir'?; " << std::boolalpha << Helper::areLinked(test_path("linkdir"), test_path("dir")) << std::endl;
|
<< Helper::directoryIsExists(test_path("dir")) << std::endl;
|
||||||
|
std::cout << "'linkdir' is link?; " << std::boolalpha
|
||||||
|
<< Helper::isLink(test_path("linkdir")) << std::endl;
|
||||||
|
std::cout << "'linkdir' is symlink?; " << std::boolalpha
|
||||||
|
<< Helper::isSymbolicLink(test_path("linkdir")) << std::endl;
|
||||||
|
std::cout << "'linkdir' is hardlink?; " << std::boolalpha
|
||||||
|
<< Helper::isHardLink(test_path("linkdir")) << std::endl;
|
||||||
|
std::cout << "'linkdir' is symlink to 'dir'?; " << std::boolalpha
|
||||||
|
<< Helper::areLinked(test_path("linkdir"), test_path("dir"))
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
if (!Helper::writeFile("file.txt", "hello world"))
|
if (!Helper::writeFile("file.txt", "hello world"))
|
||||||
throw Helper::Error("Cannor write \"hello world\" in 'file.txt'");
|
throw Helper::Error("Cannor write \"hello world\" in 'file.txt'");
|
||||||
else
|
else std::cout << "file.txt writed." << std::endl;
|
||||||
std::cout << "file.txt writed." << std::endl;
|
|
||||||
|
|
||||||
auto content = Helper::readFile("file.txt");
|
auto content = Helper::readFile("file.txt");
|
||||||
if (!content)
|
if (!content) throw Helper::Error("Cannot read 'file.txt'");
|
||||||
throw Helper::Error("Cannot read 'file.txt'");
|
else std::cout << "'file.txt': " << *content << std::endl;
|
||||||
else
|
|
||||||
std::cout << "'file.txt': " << *content << std::endl;
|
|
||||||
|
|
||||||
std::cout << "Making directory 'dir2': " << std::boolalpha << Helper::makeDirectory(test_path("dir2")) << std::endl;
|
std::cout << "Making directory 'dir2': " << std::boolalpha
|
||||||
std::cout << "Making recursive directories 'dir3/x/y': " << std::boolalpha << Helper::makeRecursiveDirectory(test_path("dir3/x/y")) << std::endl;
|
<< Helper::makeDirectory(test_path("dir2")) << std::endl;
|
||||||
std::cout << "Create 'file2.txt': " << std::boolalpha << Helper::createFile(test_path("file2.txt")) << std::endl;
|
std::cout << "Making recursive directories 'dir3/x/y': " << std::boolalpha
|
||||||
std::cout << "Create symlink 'file2.txt' to 'file2lnk.txt': " << std::boolalpha << Helper::createSymlink(test_path("file2.txt"), test_path("file2lnk.txt")) << std::endl;
|
<< Helper::makeRecursiveDirectory(test_path("dir3/x/y"))
|
||||||
std::cout << "Size of 'file2.txt': " << Helper::fileSize(test_path("file2.txt")) << std::endl;
|
<< std::endl;
|
||||||
std::cout << "Erasing 'file.txt': " << std::boolalpha << Helper::eraseEntry(test_path("file.txt")) << std::endl;
|
std::cout << "Create 'file2.txt': " << std::boolalpha
|
||||||
std::cout << "Erasing 'dir2': " << std::boolalpha << Helper::eraseEntry(test_path("dir2")) << std::endl;
|
<< Helper::createFile(test_path("file2.txt")) << std::endl;
|
||||||
std::cout << "Read link of 'file2lnk.txt': " << Helper::readSymlink(test_path("file2lnk.txt")) << std::endl;
|
std::cout << "Create symlink 'file2.txt' to 'file2lnk.txt': "
|
||||||
|
<< std::boolalpha
|
||||||
|
<< Helper::createSymlink(test_path("file2.txt"),
|
||||||
|
test_path("file2lnk.txt"))
|
||||||
|
<< std::endl;
|
||||||
|
std::cout << "Size of 'file2.txt': "
|
||||||
|
<< Helper::fileSize(test_path("file2.txt")) << std::endl;
|
||||||
|
std::cout << "Erasing 'file.txt': " << std::boolalpha
|
||||||
|
<< Helper::eraseEntry(test_path("file.txt")) << std::endl;
|
||||||
|
std::cout << "Erasing 'dir2': " << std::boolalpha
|
||||||
|
<< Helper::eraseEntry(test_path("dir2")) << std::endl;
|
||||||
|
std::cout << "Read link of 'file2lnk.txt': "
|
||||||
|
<< Helper::readSymlink(test_path("file2lnk.txt")) << std::endl;
|
||||||
|
|
||||||
auto sha256 = Helper::sha256Of(test_path("file2.txt"));
|
auto sha256 = Helper::sha256Of(test_path("file2.txt"));
|
||||||
if (!sha256)
|
if (!sha256) throw Helper::Error("Cannot get sha256 of 'file2.txt'");
|
||||||
throw Helper::Error("Cannot get sha256 of 'file2.txt'");
|
else std::cout << "SHA256 of 'file2.txt': " << *sha256 << std::endl;
|
||||||
else
|
|
||||||
std::cout << "SHA256 of 'file2.txt': " << *sha256 << std::endl;
|
|
||||||
|
|
||||||
std::cout << "'file2.txt' and 'file2lnk.txt' same? (SHA256): " << std::boolalpha << Helper::sha256Compare(test_path("file2.txt"), test_path("file2lnk.txt")) << std::endl;
|
std::cout << "'file2.txt' and 'file2lnk.txt' same? (SHA256): "
|
||||||
std::cout << "Copy 'file2.txt' as 'file2cpy.txt': " << std::boolalpha << Helper::copyFile(test_path("file2.txt"), test_path("file2cpy.txt")) << std::endl;
|
<< std::boolalpha
|
||||||
std::cout << "Run command: 'ls': " << std::boolalpha << Helper::runCommand("ls") << std::endl;
|
<< Helper::sha256Compare(test_path("file2.txt"),
|
||||||
|
test_path("file2lnk.txt"))
|
||||||
|
<< std::endl;
|
||||||
|
std::cout << "Copy 'file2.txt' as 'file2cpy.txt': " << std::boolalpha
|
||||||
|
<< Helper::copyFile(test_path("file2.txt"),
|
||||||
|
test_path("file2cpy.txt"))
|
||||||
|
<< std::endl;
|
||||||
|
std::cout << "Run command: 'ls': " << std::boolalpha
|
||||||
|
<< Helper::runCommand("ls") << std::endl;
|
||||||
std::cout << "Spawn confirm propt..." << std::endl;
|
std::cout << "Spawn confirm propt..." << std::endl;
|
||||||
|
|
||||||
bool p = Helper::confirmPropt("Please answer");
|
bool p = Helper::confirmPropt("Please answer");
|
||||||
std::cout << "Result of confirm propt: " << std::boolalpha << p << std::endl;
|
std::cout << "Result of confirm propt: " << std::boolalpha << p
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
std::cout << "Working directory: " << Helper::currentWorkingDirectory() << std::endl;
|
std::cout << "Working directory: " << Helper::currentWorkingDirectory()
|
||||||
|
<< std::endl;
|
||||||
std::cout << "Current date: " << Helper::currentDate() << std::endl;
|
std::cout << "Current date: " << Helper::currentDate() << std::endl;
|
||||||
std::cout << "Current time: " << Helper::currentTime() << std::endl;
|
std::cout << "Current time: " << Helper::currentTime() << std::endl;
|
||||||
std::cout << "Output of 'ls' command: " << Helper::runCommandWithOutput("ls") << std::endl;
|
std::cout << "Output of 'ls' command: "
|
||||||
std::cout << "Basename of " << test_path("file2.txt") << ": " << Helper::pathBasename(test_path("file2.txt")) << std::endl;
|
<< Helper::runCommandWithOutput("ls") << std::endl;
|
||||||
std::cout << "Dirname of " << test_path("file2.txt") << ": " << Helper::pathDirname(test_path("file2.txt")) << std::endl;
|
std::cout << "Basename of " << test_path("file2.txt") << ": "
|
||||||
|
<< Helper::pathBasename(test_path("file2.txt")) << std::endl;
|
||||||
|
std::cout << "Dirname of " << test_path("file2.txt") << ": "
|
||||||
|
<< Helper::pathDirname(test_path("file2.txt")) << std::endl;
|
||||||
|
|
||||||
std::cout << "pathJoin() test 1: " << Helper::pathJoin("mydir", "dir2") << std::endl;
|
std::cout << "pathJoin() test 1: " << Helper::pathJoin("mydir", "dir2")
|
||||||
std::cout << "pathJoin() test 2: " << Helper::pathJoin("mydir/", "dir2") << std::endl;
|
<< std::endl;
|
||||||
std::cout << "pathJoin() test 3: " << Helper::pathJoin("mydir/", "/dir2") << std::endl;
|
std::cout << "pathJoin() test 2: " << Helper::pathJoin("mydir/", "dir2")
|
||||||
std::cout << "pathJoin() test 4: " << Helper::pathJoin("mydir", "/dir2") << std::endl;
|
<< std::endl;
|
||||||
|
std::cout << "pathJoin() test 3: " << Helper::pathJoin("mydir/", "/dir2")
|
||||||
|
<< std::endl;
|
||||||
|
std::cout << "pathJoin() test 4: " << Helper::pathJoin("mydir", "/dir2")
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
std::cout << Helper::getLibVersion() << std::endl;
|
std::cout << Helper::getLibVersion() << std::endl;
|
||||||
|
|
||||||
|
|||||||
36
srclib/libpartition_map/include/libpartition_map/lib.hpp
Executable file → Normal file
36
srclib/libpartition_map/include/libpartition_map/lib.hpp
Executable file → Normal file
@@ -17,16 +17,16 @@
|
|||||||
#ifndef LIBPARTITION_MAP_LIB_HPP
|
#ifndef LIBPARTITION_MAP_LIB_HPP
|
||||||
#define LIBPARTITION_MAP_LIB_HPP
|
#define LIBPARTITION_MAP_LIB_HPP
|
||||||
|
|
||||||
|
#include <cstdint> // for uint64_t
|
||||||
|
#include <exception>
|
||||||
|
#include <libhelper/lib.hpp>
|
||||||
|
#include <list>
|
||||||
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <optional>
|
|
||||||
#include <exception>
|
|
||||||
#include <list>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <memory>
|
|
||||||
#include <utility> // for std::pair
|
#include <utility> // for std::pair
|
||||||
#include <cstdint> // for uint64_t
|
|
||||||
#include <libhelper/lib.hpp>
|
|
||||||
|
|
||||||
namespace PartitionMap {
|
namespace PartitionMap {
|
||||||
struct _entry {
|
struct _entry {
|
||||||
@@ -87,7 +87,8 @@ namespace PartitionMap {
|
|||||||
|
|
||||||
explicit iterator(_entry *p);
|
explicit iterator(_entry *p);
|
||||||
|
|
||||||
auto operator*() const -> std::pair<std::string &, decltype(_entry::props) &>;
|
auto operator*() const
|
||||||
|
-> std::pair<std::string &, decltype(_entry::props) &>;
|
||||||
_entry *operator->() const;
|
_entry *operator->() const;
|
||||||
iterator &operator++();
|
iterator &operator++();
|
||||||
iterator operator++(int);
|
iterator operator++(int);
|
||||||
@@ -101,7 +102,8 @@ namespace PartitionMap {
|
|||||||
|
|
||||||
explicit constant_iterator(const _entry *p);
|
explicit constant_iterator(const _entry *p);
|
||||||
|
|
||||||
auto operator*() const -> std::pair<const std::string &, const decltype(_entry::props) &>;
|
auto operator*() const
|
||||||
|
-> std::pair<const std::string &, const decltype(_entry::props) &>;
|
||||||
const _entry *operator->() const;
|
const _entry *operator->() const;
|
||||||
constant_iterator &operator++();
|
constant_iterator &operator++();
|
||||||
constant_iterator operator++(int);
|
constant_iterator operator++(int);
|
||||||
@@ -156,7 +158,8 @@ namespace PartitionMap {
|
|||||||
* Map_temp_t type. If the partition is not in the
|
* Map_temp_t type. If the partition is not in the
|
||||||
* currently created list, returns std::nullopt.
|
* currently created list, returns std::nullopt.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] std::optional<std::pair<uint64_t, bool> > get(std::string_view name) const;
|
[[nodiscard]] std::optional<std::pair<uint64_t, bool>>
|
||||||
|
get(std::string_view name) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If there is a logical partition(s) in the created
|
* If there is a logical partition(s) in the created
|
||||||
@@ -164,14 +167,16 @@ namespace PartitionMap {
|
|||||||
* data of type std::string). If there is no logical
|
* data of type std::string). If there is no logical
|
||||||
* partition in the created list, it returns std::nullopt.
|
* partition in the created list, it returns std::nullopt.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] std::optional<std::list<std::string> > getLogicalPartitionList() const;
|
[[nodiscard]] std::optional<std::list<std::string>>
|
||||||
|
getLogicalPartitionList() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The physical partitions in the created list are
|
* The physical partitions in the created list are
|
||||||
* returned as std::list type. If there is no content
|
* returned as std::list type. If there is no content
|
||||||
* due to any problem, returns std::nullopt.
|
* due to any problem, returns std::nullopt.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] std::optional<std::list<std::string> > getPhysicalPartitionList() const;
|
[[nodiscard]] std::optional<std::list<std::string>>
|
||||||
|
getPhysicalPartitionList() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The partitions in the created list are returned as std::list
|
* The partitions in the created list are returned as std::list
|
||||||
@@ -251,12 +256,14 @@ namespace PartitionMap {
|
|||||||
* the same (checked only according to the partition
|
* the same (checked only according to the partition
|
||||||
* names), true is returned, otherwise false is returned
|
* names), true is returned, otherwise false is returned
|
||||||
*/
|
*/
|
||||||
friend bool operator==(const basic_partition_map_builder &lhs, const basic_partition_map_builder &rhs);
|
friend bool operator==(const basic_partition_map_builder &lhs,
|
||||||
|
const basic_partition_map_builder &rhs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The opposite logic of the == operator.
|
* The opposite logic of the == operator.
|
||||||
*/
|
*/
|
||||||
friend bool operator!=(const basic_partition_map_builder &lhs, const basic_partition_map_builder &rhs);
|
friend bool operator!=(const basic_partition_map_builder &lhs,
|
||||||
|
const basic_partition_map_builder &rhs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You can check whether the object was created
|
* You can check whether the object was created
|
||||||
@@ -309,7 +316,8 @@ namespace PartitionMap {
|
|||||||
constexpr uint64_t VBMETA_IMAGE = 0x425641;
|
constexpr uint64_t VBMETA_IMAGE = 0x425641;
|
||||||
constexpr uint64_t SUPER_IMAGE = 0x7265797573;
|
constexpr uint64_t SUPER_IMAGE = 0x7265797573;
|
||||||
constexpr uint64_t SPARSE_IMAGE = 0x3AFF26ED;
|
constexpr uint64_t SPARSE_IMAGE = 0x3AFF26ED;
|
||||||
constexpr uint64_t ELF = 0x464C457F; // It makes more sense than between file systems
|
constexpr uint64_t ELF =
|
||||||
|
0x464C457F; // It makes more sense than between file systems
|
||||||
constexpr uint64_t RAW = 0x00000000;
|
constexpr uint64_t RAW = 0x00000000;
|
||||||
} // namespace AndroidMagic
|
} // namespace AndroidMagic
|
||||||
|
|
||||||
|
|||||||
32
srclib/libpartition_map/src/Getters.cpp
Executable file → Normal file
32
srclib/libpartition_map/src/Getters.cpp
Executable file → Normal file
@@ -14,10 +14,10 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <optional>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <libpartition_map/lib.hpp>
|
#include <libpartition_map/lib.hpp>
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace PartitionMap {
|
namespace PartitionMap {
|
||||||
Map_t basic_partition_map_builder::getAll() const {
|
Map_t basic_partition_map_builder::getAll() const {
|
||||||
@@ -25,14 +25,17 @@ namespace PartitionMap {
|
|||||||
return _current_map;
|
return _current_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::pair<uint64_t, bool> > basic_partition_map_builder::get(const std::string_view name) const {
|
std::optional<std::pair<uint64_t, bool>>
|
||||||
|
basic_partition_map_builder::get(const std::string_view name) const {
|
||||||
_map_build_check();
|
_map_build_check();
|
||||||
|
|
||||||
if (!_current_map.find(name)) return std::nullopt;
|
if (!_current_map.find(name)) return std::nullopt;
|
||||||
return std::make_pair(_current_map.get_size(name), _current_map.is_logical(name));
|
return std::make_pair(_current_map.get_size(name),
|
||||||
|
_current_map.is_logical(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::list<std::string> > basic_partition_map_builder::getLogicalPartitionList() const {
|
std::optional<std::list<std::string>>
|
||||||
|
basic_partition_map_builder::getLogicalPartitionList() const {
|
||||||
_map_build_check();
|
_map_build_check();
|
||||||
|
|
||||||
std::list<std::string> logicals;
|
std::list<std::string> logicals;
|
||||||
@@ -43,7 +46,8 @@ namespace PartitionMap {
|
|||||||
return logicals;
|
return logicals;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::list<std::string> > basic_partition_map_builder::getPhysicalPartitionList() const {
|
std::optional<std::list<std::string>>
|
||||||
|
basic_partition_map_builder::getPhysicalPartitionList() const {
|
||||||
_map_build_check();
|
_map_build_check();
|
||||||
|
|
||||||
std::list<std::string> physicals;
|
std::list<std::string> physicals;
|
||||||
@@ -54,32 +58,34 @@ namespace PartitionMap {
|
|||||||
return physicals;
|
return physicals;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::list<std::string> > basic_partition_map_builder::getPartitionList() const {
|
std::optional<std::list<std::string>>
|
||||||
|
basic_partition_map_builder::getPartitionList() const {
|
||||||
_map_build_check();
|
_map_build_check();
|
||||||
|
|
||||||
std::list<std::string> partitions;
|
std::list<std::string> partitions;
|
||||||
for (const auto &[name, props]: _current_map) partitions.push_back(name);
|
for (const auto &[name, props] : _current_map)
|
||||||
|
partitions.push_back(name);
|
||||||
|
|
||||||
if (partitions.empty()) return std::nullopt;
|
if (partitions.empty()) return std::nullopt;
|
||||||
return partitions;
|
return partitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string basic_partition_map_builder::getRealLinkPathOf(const std::string_view name) const {
|
std::string basic_partition_map_builder::getRealLinkPathOf(
|
||||||
|
const std::string_view name) const {
|
||||||
_map_build_check();
|
_map_build_check();
|
||||||
|
|
||||||
if (!_current_map.find(name)) return {};
|
if (!_current_map.find(name)) return {};
|
||||||
return std::string(_workdir + "/" + name.data());
|
return std::string(_workdir + "/" + name.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string basic_partition_map_builder::getRealPathOf(const std::string_view name) const {
|
std::string
|
||||||
|
basic_partition_map_builder::getRealPathOf(const std::string_view name) const {
|
||||||
_map_build_check();
|
_map_build_check();
|
||||||
|
|
||||||
const std::string full = (isLogical(name))
|
const std::string full = (isLogical(name))
|
||||||
? std::string("/dev/block/mapper/") + name.data()
|
? std::string("/dev/block/mapper/") + name.data()
|
||||||
: _workdir + "/" + name.data();
|
: _workdir + "/" + name.data();
|
||||||
if (!_current_map.find(name)
|
if (!_current_map.find(name) || !std::filesystem::is_symlink(full)) return {};
|
||||||
|| !std::filesystem::is_symlink(full))
|
|
||||||
return {};
|
|
||||||
|
|
||||||
return std::filesystem::read_symlink(full);
|
return std::filesystem::read_symlink(full);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <libhelper/lib.hpp>
|
#include <libhelper/lib.hpp>
|
||||||
#include <libpartition_map/lib.hpp>
|
#include <libpartition_map/lib.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "PartitionManager/PartitionManager.hpp"
|
#include "PartitionManager/PartitionManager.hpp"
|
||||||
|
|
||||||
@@ -34,8 +34,7 @@ namespace PartitionMap::Extras {
|
|||||||
{FileSystemMagic::FAT16_FS, "FAT16"},
|
{FileSystemMagic::FAT16_FS, "FAT16"},
|
||||||
{FileSystemMagic::FAT32_FS, "FAT32"},
|
{FileSystemMagic::FAT32_FS, "FAT32"},
|
||||||
{FileSystemMagic::NTFS_FS, "NTFS"},
|
{FileSystemMagic::NTFS_FS, "NTFS"},
|
||||||
{FileSystemMagic::MSDOS_FS, "MSDOS"}
|
{FileSystemMagic::MSDOS_FS, "MSDOS"}};
|
||||||
};
|
|
||||||
|
|
||||||
std::unordered_map<uint64_t, std::string> AndroidMagicMap = {
|
std::unordered_map<uint64_t, std::string> AndroidMagicMap = {
|
||||||
{AndroidMagic::BOOT_IMAGE, "Android Boot Image"},
|
{AndroidMagic::BOOT_IMAGE, "Android Boot Image"},
|
||||||
@@ -46,8 +45,7 @@ namespace PartitionMap::Extras {
|
|||||||
{AndroidMagic::SUPER_IMAGE, "Android Super Image"},
|
{AndroidMagic::SUPER_IMAGE, "Android Super Image"},
|
||||||
{AndroidMagic::SPARSE_IMAGE, "Android Sparse Image"},
|
{AndroidMagic::SPARSE_IMAGE, "Android Sparse Image"},
|
||||||
{AndroidMagic::ELF, "ELF"},
|
{AndroidMagic::ELF, "ELF"},
|
||||||
{AndroidMagic::RAW, "Raw Data"}
|
{AndroidMagic::RAW, "Raw Data"}};
|
||||||
};
|
|
||||||
|
|
||||||
std::unordered_map<uint64_t, std::string> MagicMap = {
|
std::unordered_map<uint64_t, std::string> MagicMap = {
|
||||||
{AndroidMagic::BOOT_IMAGE, "Android Boot Image"},
|
{AndroidMagic::BOOT_IMAGE, "Android Boot Image"},
|
||||||
@@ -67,8 +65,7 @@ namespace PartitionMap::Extras {
|
|||||||
{FileSystemMagic::FAT16_FS, "FAT16"},
|
{FileSystemMagic::FAT16_FS, "FAT16"},
|
||||||
{FileSystemMagic::FAT32_FS, "FAT32"},
|
{FileSystemMagic::FAT32_FS, "FAT32"},
|
||||||
{FileSystemMagic::NTFS_FS, "NTFS"},
|
{FileSystemMagic::NTFS_FS, "NTFS"},
|
||||||
{FileSystemMagic::MSDOS_FS, "MSDOS"}
|
{FileSystemMagic::MSDOS_FS, "MSDOS"}};
|
||||||
};
|
|
||||||
|
|
||||||
size_t getMagicLength(const uint64_t magic) {
|
size_t getMagicLength(const uint64_t magic) {
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
@@ -78,8 +75,11 @@ namespace PartitionMap::Extras {
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasMagic(const uint64_t magic, const ssize_t buf, const std::string &path) {
|
bool hasMagic(const uint64_t magic, const ssize_t buf,
|
||||||
LOGN(MAP, INFO) << "Checking magic of " << path << " with using " << buf << " byte buffer size (has magic 0x" << std::hex << magic << "?)" << std::endl;
|
const std::string &path) {
|
||||||
|
LOGN(MAP, INFO) << "Checking magic of " << path << " with using " << buf
|
||||||
|
<< " byte buffer size (has magic 0x" << std::hex << magic
|
||||||
|
<< "?)" << std::endl;
|
||||||
Helper::garbageCollector collector;
|
Helper::garbageCollector collector;
|
||||||
|
|
||||||
const int fd = Helper::openAndAddToCloseList(path, collector, O_RDONLY);
|
const int fd = Helper::openAndAddToCloseList(path, collector, O_RDONLY);
|
||||||
@@ -100,20 +100,24 @@ namespace PartitionMap::Extras {
|
|||||||
|
|
||||||
for (size_t i = 0; i <= bytesRead - magicLength; i++) {
|
for (size_t i = 0; i <= bytesRead - magicLength; i++) {
|
||||||
uint64_t value = 0;
|
uint64_t value = 0;
|
||||||
for (size_t j = 0; j < magicLength; ++j) value |= static_cast<uint64_t>(buffer[i + j]) << (8 * j);
|
for (size_t j = 0; j < magicLength; ++j)
|
||||||
|
value |= static_cast<uint64_t>(buffer[i + j]) << (8 * j);
|
||||||
if (value == magic) {
|
if (value == magic) {
|
||||||
LOGN(MAP, INFO) << path << " contains 0x" << std::hex << magic << std::endl;
|
LOGN(MAP, INFO) << path << " contains 0x" << std::hex << magic
|
||||||
|
<< std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGN(MAP, INFO) << path << " is not contains 0x" << std::hex << magic << std::endl;
|
LOGN(MAP, INFO) << path << " is not contains 0x" << std::hex << magic
|
||||||
|
<< std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string formatMagic(const uint64_t magic) {
|
std::string formatMagic(const uint64_t magic) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "0x" << std::uppercase << std::hex << std::setw(16) << std::setfill('0') << magic;
|
ss << "0x" << std::uppercase << std::hex << std::setw(16) << std::setfill('0')
|
||||||
|
<< magic;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
} // namespace PartitionMap::Extras
|
} // namespace PartitionMap::Extras
|
||||||
|
|||||||
112
srclib/libpartition_map/src/PartitionMap.cpp
Executable file → Normal file
112
srclib/libpartition_map/src/PartitionMap.cpp
Executable file → Normal file
@@ -14,32 +14,31 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <filesystem>
|
|
||||||
#include <memory>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <cerrno>
|
||||||
|
#include <cstring>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <generated/buildInfo.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <libpartition_map/lib.hpp>
|
||||||
|
#include <linux/fs.h>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <cerrno>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <linux/fs.h>
|
#include <sys/stat.h>
|
||||||
#include <libpartition_map/lib.hpp>
|
|
||||||
#include <generated/buildInfo.hpp>
|
|
||||||
#include <cstring>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
static constexpr std::array<std::string_view, 3> defaultEntryList = {
|
static constexpr std::array<std::string_view, 3> defaultEntryList = {
|
||||||
"/dev/block/by-name",
|
"/dev/block/by-name", "/dev/block/bootdevice/by-name",
|
||||||
"/dev/block/bootdevice/by-name",
|
"/dev/block/platform/bootdevice/by-name"};
|
||||||
"/dev/block/platform/bootdevice/by-name"
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace PartitionMap {
|
namespace PartitionMap {
|
||||||
bool basic_partition_map_builder::_is_real_block_dir(const std::string_view path) {
|
bool basic_partition_map_builder::_is_real_block_dir(
|
||||||
|
const std::string_view path) {
|
||||||
if (path.find("/block/") == std::string::npos) {
|
if (path.find("/block/") == std::string::npos) {
|
||||||
LOGN(MAP, ERROR) << "Path " << path << " is not a real block directory.";
|
LOGN(MAP, ERROR) << "Path " << path << " is not a real block directory.";
|
||||||
return false;
|
return false;
|
||||||
@@ -47,35 +46,43 @@ namespace PartitionMap {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map_t basic_partition_map_builder::_build_map(std::string_view path, bool logical) {
|
Map_t basic_partition_map_builder::_build_map(std::string_view path,
|
||||||
|
bool logical) {
|
||||||
Map_t map;
|
Map_t map;
|
||||||
std::vector<std::filesystem::directory_entry> entries{
|
std::vector<std::filesystem::directory_entry> entries{
|
||||||
std::filesystem::directory_iterator(path), std::filesystem::directory_iterator()
|
std::filesystem::directory_iterator(path),
|
||||||
};
|
std::filesystem::directory_iterator()};
|
||||||
std::sort(entries.begin(), entries.end(), [](const auto &a, const auto &b) {
|
std::sort(entries.begin(), entries.end(), [](const auto &a, const auto &b) {
|
||||||
return a.path().filename() < b.path().filename();
|
return a.path().filename() < b.path().filename();
|
||||||
});
|
});
|
||||||
|
|
||||||
LOGN_IF(MAP, WARNING, entries.empty()) << "" << path <<
|
LOGN_IF(MAP, WARNING, entries.empty())
|
||||||
"is exists but generated vector is empty (std::vector<std::filesystem::directory_entry>)." << std::endl;
|
<< "" << path
|
||||||
|
<< "is exists but generated vector is empty "
|
||||||
|
"(std::vector<std::filesystem::directory_entry>)."
|
||||||
|
<< std::endl;
|
||||||
for (const auto &entry : entries) {
|
for (const auto &entry : entries) {
|
||||||
if (entry.path().filename() != "by-uuid"
|
if (entry.path().filename() != "by-uuid" &&
|
||||||
&& std::string(entry.path()).find("com.") == std::string::npos)
|
std::string(entry.path()).find("com.") == std::string::npos)
|
||||||
map.insert(entry.path().filename().string(), _get_size(entry.path()), logical);
|
map.insert(entry.path().filename().string(), _get_size(entry.path()),
|
||||||
|
logical);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGN(MAP, INFO) << std::boolalpha << "Map generated successfully. is_logical_map=" << logical << std::endl;
|
LOGN(MAP, INFO) << std::boolalpha
|
||||||
|
<< "Map generated successfully. is_logical_map=" << logical
|
||||||
|
<< std::endl;
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
void basic_partition_map_builder::_insert_logicals(Map_t &&logicals) {
|
void basic_partition_map_builder::_insert_logicals(Map_t &&logicals) {
|
||||||
LOGN(MAP, INFO) << "merging created logical partition list to this object's variable." << std::endl;
|
LOGN(MAP, INFO)
|
||||||
|
<< "merging created logical partition list to this object's variable."
|
||||||
|
<< std::endl;
|
||||||
_current_map.merge(logicals);
|
_current_map.merge(logicals);
|
||||||
}
|
}
|
||||||
|
|
||||||
void basic_partition_map_builder::_map_build_check() const {
|
void basic_partition_map_builder::_map_build_check() const {
|
||||||
if (!_map_builded)
|
if (!_map_builded) throw Error("Please build partition map before!");
|
||||||
throw Error("Please build partition map before!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t basic_partition_map_builder::_get_size(const std::string &path) {
|
uint64_t basic_partition_map_builder::_get_size(const std::string &path) {
|
||||||
@@ -84,13 +91,15 @@ namespace PartitionMap {
|
|||||||
|
|
||||||
const int fd = Helper::openAndAddToCloseList(real, collector, O_RDONLY);
|
const int fd = Helper::openAndAddToCloseList(real, collector, O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
LOGN(MAP, ERROR) << "Cannot open " << real << ": " << strerror(errno) << std::endl;
|
LOGN(MAP, ERROR) << "Cannot open " << real << ": " << strerror(errno)
|
||||||
|
<< std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t size = 0;
|
uint64_t size = 0;
|
||||||
if (ioctl(fd, BLKGETSIZE64, &size) != 0) {
|
if (ioctl(fd, BLKGETSIZE64, &size) != 0) {
|
||||||
LOGN(MAP, ERROR) << "ioctl() process failed for " << real << ": " << strerror(errno) << std::endl;
|
LOGN(MAP, ERROR) << "ioctl() process failed for " << real << ": "
|
||||||
|
<< strerror(errno) << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,15 +122,19 @@ namespace PartitionMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_current_map.empty())
|
if (_current_map.empty())
|
||||||
LOGN(MAP, ERROR) << "Cannot build map by any default search entry." << std::endl;
|
LOGN(MAP, ERROR) << "Cannot build map by any default search entry."
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
LOGN(MAP, INFO) << "default constructor successfully ended work." << std::endl;
|
LOGN(MAP, INFO) << "default constructor successfully ended work."
|
||||||
|
<< std::endl;
|
||||||
_insert_logicals(_build_map("/dev/block/mapper", true));
|
_insert_logicals(_build_map("/dev/block/mapper", true));
|
||||||
_map_builded = true;
|
_map_builded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
basic_partition_map_builder::basic_partition_map_builder(const std::string_view path) {
|
basic_partition_map_builder::basic_partition_map_builder(
|
||||||
LOGN(MAP, INFO) << "argument-based constructor called. Starting build." << std::endl;
|
const std::string_view path) {
|
||||||
|
LOGN(MAP, INFO) << "argument-based constructor called. Starting build."
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
if (std::filesystem::exists(path)) {
|
if (std::filesystem::exists(path)) {
|
||||||
if (!_is_real_block_dir(path)) return;
|
if (!_is_real_block_dir(path)) return;
|
||||||
@@ -129,14 +142,17 @@ namespace PartitionMap {
|
|||||||
if (_current_map.empty()) _any_generating_error = true;
|
if (_current_map.empty()) _any_generating_error = true;
|
||||||
else _workdir = path;
|
else _workdir = path;
|
||||||
} else
|
} else
|
||||||
throw Error("Cannot find directory: %s. Cannot build partition map!", path.data());
|
throw Error("Cannot find directory: %s. Cannot build partition map!",
|
||||||
|
path.data());
|
||||||
|
|
||||||
LOGN(MAP, INFO) << "argument-based constructor successfully ended work." << std::endl;
|
LOGN(MAP, INFO) << "argument-based constructor successfully ended work."
|
||||||
|
<< std::endl;
|
||||||
_insert_logicals(_build_map("/dev/block/mapper", true));
|
_insert_logicals(_build_map("/dev/block/mapper", true));
|
||||||
_map_builded = true;
|
_map_builded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool basic_partition_map_builder::hasPartition(const std::string_view name) const {
|
bool basic_partition_map_builder::hasPartition(
|
||||||
|
const std::string_view name) const {
|
||||||
_map_build_check();
|
_map_build_check();
|
||||||
return _current_map.find(name);
|
return _current_map.find(name);
|
||||||
}
|
}
|
||||||
@@ -164,7 +180,8 @@ namespace PartitionMap {
|
|||||||
return false;
|
return false;
|
||||||
} else _workdir = path;
|
} else _workdir = path;
|
||||||
} else
|
} else
|
||||||
throw Error("Cannot find directory: %s. Cannot build partition map!", path.data());
|
throw Error("Cannot find directory: %s. Cannot build partition map!",
|
||||||
|
path.data());
|
||||||
|
|
||||||
LOGN(MAP, INFO) << "read " << path << " successfull." << std::endl;
|
LOGN(MAP, INFO) << "read " << path << " successfull." << std::endl;
|
||||||
_insert_logicals(_build_map("/dev/block/mapper", true));
|
_insert_logicals(_build_map("/dev/block/mapper", true));
|
||||||
@@ -190,7 +207,8 @@ namespace PartitionMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_current_map.empty())
|
if (_current_map.empty())
|
||||||
LOGN(MAP, ERROR) << "Cannot build map by any default search entry." << std::endl;
|
LOGN(MAP, ERROR) << "Cannot build map by any default search entry."
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
LOGN(MAP, INFO) << "read default directories successfull." << std::endl;
|
LOGN(MAP, INFO) << "read default directories successfull." << std::endl;
|
||||||
_insert_logicals(_build_map("/dev/block/mapper", true));
|
_insert_logicals(_build_map("/dev/block/mapper", true));
|
||||||
@@ -203,16 +221,19 @@ namespace PartitionMap {
|
|||||||
return _current_map.empty();
|
return _current_map.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t basic_partition_map_builder::sizeOf(const std::string_view name) const {
|
uint64_t
|
||||||
|
basic_partition_map_builder::sizeOf(const std::string_view name) const {
|
||||||
_map_build_check();
|
_map_build_check();
|
||||||
return _current_map.get_size(name);
|
return _current_map.get_size(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const basic_partition_map_builder &lhs, const basic_partition_map_builder &rhs) {
|
bool operator==(const basic_partition_map_builder &lhs,
|
||||||
|
const basic_partition_map_builder &rhs) {
|
||||||
return lhs._current_map == rhs._current_map;
|
return lhs._current_map == rhs._current_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const basic_partition_map_builder &lhs, const basic_partition_map_builder &rhs) {
|
bool operator!=(const basic_partition_map_builder &lhs,
|
||||||
|
const basic_partition_map_builder &rhs) {
|
||||||
return !(lhs == rhs);
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,11 +246,10 @@ namespace PartitionMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool basic_partition_map_builder::operator()(const std::string_view path) {
|
bool basic_partition_map_builder::operator()(const std::string_view path) {
|
||||||
LOGN(MAP, INFO) << "calling readDirectory() for building map with " << path << std::endl;
|
LOGN(MAP, INFO) << "calling readDirectory() for building map with " << path
|
||||||
|
<< std::endl;
|
||||||
return readDirectory(path);
|
return readDirectory(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getLibVersion() {
|
std::string getLibVersion() { MKVERSION("libpartition_map"); }
|
||||||
MKVERSION("libpartition_map");
|
|
||||||
}
|
|
||||||
} // namespace PartitionMap
|
} // namespace PartitionMap
|
||||||
|
|||||||
86
srclib/libpartition_map/src/Type.cpp
Executable file → Normal file
86
srclib/libpartition_map/src/Type.cpp
Executable file → Normal file
@@ -14,22 +14,20 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <utility>
|
|
||||||
#include <libpartition_map/lib.hpp>
|
#include <libpartition_map/lib.hpp>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace PartitionMap {
|
namespace PartitionMap {
|
||||||
basic_partition_map::iterator::iterator(_entry *p) : ptr(p) {
|
basic_partition_map::iterator::iterator(_entry *p) : ptr(p) {}
|
||||||
}
|
|
||||||
|
|
||||||
auto basic_partition_map::iterator::operator*() const -> std::pair<std::string &, decltype(_entry::props) &> {
|
auto basic_partition_map::iterator::operator*() const
|
||||||
|
-> std::pair<std::string &, decltype(_entry::props) &> {
|
||||||
return {ptr->name, ptr->props};
|
return {ptr->name, ptr->props};
|
||||||
}
|
}
|
||||||
|
|
||||||
_entry *basic_partition_map::iterator::operator->() const {
|
_entry *basic_partition_map::iterator::operator->() const { return ptr; }
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
basic_partition_map::iterator &basic_partition_map::iterator::operator++() {
|
basic_partition_map::iterator &basic_partition_map::iterator::operator++() {
|
||||||
++ptr;
|
++ptr;
|
||||||
@@ -50,35 +48,38 @@ namespace PartitionMap {
|
|||||||
return ptr != other.ptr;
|
return ptr != other.ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
basic_partition_map::constant_iterator::constant_iterator(const _entry *p) : ptr(p) {
|
basic_partition_map::constant_iterator::constant_iterator(const _entry *p)
|
||||||
}
|
: ptr(p) {}
|
||||||
|
|
||||||
auto basic_partition_map::constant_iterator::operator
|
auto basic_partition_map::constant_iterator::operator*() const
|
||||||
*() const -> std::pair<const std::string &, const decltype(_entry::props) &> {
|
-> std::pair<const std::string &, const decltype(_entry::props) &> {
|
||||||
return {ptr->name, ptr->props};
|
return {ptr->name, ptr->props};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const _entry *basic_partition_map::constant_iterator::operator->() const {
|
const _entry *basic_partition_map::constant_iterator::operator->() const {
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
basic_partition_map::constant_iterator &basic_partition_map::constant_iterator::operator++() {
|
basic_partition_map::constant_iterator &
|
||||||
|
basic_partition_map::constant_iterator::operator++() {
|
||||||
++ptr;
|
++ptr;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
basic_partition_map::constant_iterator basic_partition_map::constant_iterator::operator++(int) {
|
basic_partition_map::constant_iterator
|
||||||
|
basic_partition_map::constant_iterator::operator++(int) {
|
||||||
constant_iterator tmp = *this;
|
constant_iterator tmp = *this;
|
||||||
++ptr;
|
++ptr;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool basic_partition_map::constant_iterator::operator==(const constant_iterator &other) const {
|
bool basic_partition_map::constant_iterator::operator==(
|
||||||
|
const constant_iterator &other) const {
|
||||||
return ptr == other.ptr;
|
return ptr == other.ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool basic_partition_map::constant_iterator::operator!=(const constant_iterator &other) const {
|
bool basic_partition_map::constant_iterator::operator!=(
|
||||||
|
const constant_iterator &other) const {
|
||||||
return ptr != other.ptr;
|
return ptr != other.ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +87,8 @@ namespace PartitionMap {
|
|||||||
const size_t new_capacity = _capacity * 2;
|
const size_t new_capacity = _capacity * 2;
|
||||||
auto *new_data = new _entry[new_capacity];
|
auto *new_data = new _entry[new_capacity];
|
||||||
|
|
||||||
for (size_t i = 0; i < _count; i++) new_data[i] = _data[i];
|
for (size_t i = 0; i < _count; i++)
|
||||||
|
new_data[i] = _data[i];
|
||||||
|
|
||||||
delete[] _data;
|
delete[] _data;
|
||||||
_data = new_data;
|
_data = new_data;
|
||||||
@@ -101,13 +103,15 @@ namespace PartitionMap {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
basic_partition_map::basic_partition_map(const std::string &name, const uint64_t size, const bool logical) {
|
basic_partition_map::basic_partition_map(const std::string &name,
|
||||||
|
const uint64_t size,
|
||||||
|
const bool logical) {
|
||||||
_data = new _entry[_capacity];
|
_data = new _entry[_capacity];
|
||||||
insert(name, size, logical);
|
insert(name, size, logical);
|
||||||
}
|
}
|
||||||
|
|
||||||
basic_partition_map::basic_partition_map(const basic_partition_map &other) : _data(new _entry[other._capacity]),
|
basic_partition_map::basic_partition_map(const basic_partition_map &other)
|
||||||
_count(other._count),
|
: _data(new _entry[other._capacity]), _count(other._count),
|
||||||
_capacity(other._capacity) {
|
_capacity(other._capacity) {
|
||||||
std::copy(other._data, other._data + _count, _data);
|
std::copy(other._data, other._data + _count, _data);
|
||||||
}
|
}
|
||||||
@@ -116,17 +120,17 @@ namespace PartitionMap {
|
|||||||
_data = new _entry[_capacity];
|
_data = new _entry[_capacity];
|
||||||
}
|
}
|
||||||
|
|
||||||
basic_partition_map::~basic_partition_map() {
|
basic_partition_map::~basic_partition_map() { delete[] _data; }
|
||||||
delete[] _data;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool basic_partition_map::insert(const std::string &name, const uint64_t size, const bool logical) {
|
bool basic_partition_map::insert(const std::string &name, const uint64_t size,
|
||||||
|
const bool logical) {
|
||||||
if (name == _data[_index_of(name)].name) return false;
|
if (name == _data[_index_of(name)].name) return false;
|
||||||
if (_count == _capacity) _resize_map();
|
if (_count == _capacity) _resize_map();
|
||||||
|
|
||||||
_data[_count++] = {name, {size, logical}};
|
_data[_count++] = {name, {size, logical}};
|
||||||
LOGN(MAP, INFO) << std::boolalpha << "partition " << name << " inserted (size=" << size << ", is_logical=" <<
|
LOGN(MAP, INFO) << std::boolalpha << "partition " << name
|
||||||
logical << ")." << std::endl;
|
<< " inserted (size=" << size << ", is_logical=" << logical
|
||||||
|
<< ")." << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,18 +142,21 @@ namespace PartitionMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint64_t basic_partition_map::get_size(const std::string_view name) const {
|
uint64_t basic_partition_map::get_size(const std::string_view name) const {
|
||||||
if (const int pos = _index_of(name); name == _data[pos].name) return _data[pos].props.size;
|
if (const int pos = _index_of(name); name == _data[pos].name)
|
||||||
|
return _data[pos].props.size;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool basic_partition_map::is_logical(const std::string_view name) const {
|
bool basic_partition_map::is_logical(const std::string_view name) const {
|
||||||
if (const int pos = _index_of(name); name == _data[pos].name) return _data[pos].props.isLogical;
|
if (const int pos = _index_of(name); name == _data[pos].name)
|
||||||
|
return _data[pos].props.isLogical;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
basic_partition_map::_returnable_entry basic_partition_map::get_all(const std::string_view name) const {
|
basic_partition_map::_returnable_entry
|
||||||
|
basic_partition_map::get_all(const std::string_view name) const {
|
||||||
if (const int pos = _index_of(name); name == _data[pos].name)
|
if (const int pos = _index_of(name); name == _data[pos].name)
|
||||||
return _returnable_entry{_data[pos].props.size, _data[pos].props.isLogical};
|
return _returnable_entry{_data[pos].props.size, _data[pos].props.isLogical};
|
||||||
|
|
||||||
@@ -168,9 +175,7 @@ namespace PartitionMap {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t basic_partition_map::size() const {
|
size_t basic_partition_map::size() const { return _count; }
|
||||||
return _count;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool basic_partition_map::empty() const {
|
bool basic_partition_map::empty() const {
|
||||||
if (_count > 0) return false;
|
if (_count > 0) return false;
|
||||||
@@ -185,7 +190,8 @@ namespace PartitionMap {
|
|||||||
_data = new _entry[_capacity];
|
_data = new _entry[_capacity];
|
||||||
}
|
}
|
||||||
|
|
||||||
basic_partition_map &basic_partition_map::operator=(const basic_partition_map &map) {
|
basic_partition_map &
|
||||||
|
basic_partition_map::operator=(const basic_partition_map &map) {
|
||||||
if (this != &map) {
|
if (this != &map) {
|
||||||
delete[] _data;
|
delete[] _data;
|
||||||
|
|
||||||
@@ -199,17 +205,15 @@ namespace PartitionMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool basic_partition_map::operator==(const basic_partition_map &other) const {
|
bool basic_partition_map::operator==(const basic_partition_map &other) const {
|
||||||
if (this->_capacity != other._capacity
|
if (this->_capacity != other._capacity || this->_count != other._count)
|
||||||
|| this->_count != other._count)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (size_t i = 0; i < _count; i++)
|
for (size_t i = 0; i < _count; i++)
|
||||||
if (_data[i].name == other._data[i].name
|
if (_data[i].name == other._data[i].name &&
|
||||||
&& _data[i].props.size == other._data[i].props.size
|
_data[i].props.size == other._data[i].props.size &&
|
||||||
&& _data[i].props.isLogical == other._data[i].props.isLogical)
|
_data[i].props.isLogical == other._data[i].props.isLogical)
|
||||||
continue;
|
continue;
|
||||||
else
|
else return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
30
srclib/libpartition_map/tests/test.cpp
Executable file → Normal file
30
srclib/libpartition_map/tests/test.cpp
Executable file → Normal file
@@ -15,8 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <unistd.h>
|
|
||||||
#include <libpartition_map/lib.hpp>
|
#include <libpartition_map/lib.hpp>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
if (getuid() != 0) return 2;
|
if (getuid() != 0) return 2;
|
||||||
@@ -31,35 +31,39 @@ int main() {
|
|||||||
const auto map = MyMap.getAll();
|
const auto map = MyMap.getAll();
|
||||||
if (map.empty()) throw PartitionMap::Error("getAll() empty");
|
if (map.empty()) throw PartitionMap::Error("getAll() empty");
|
||||||
for (const auto &[name, props] : map) {
|
for (const auto &[name, props] : map) {
|
||||||
std::cout << "Partition: " << name << ", size: "
|
std::cout << "Partition: " << name << ", size: " << props.size
|
||||||
<< props.size << ", logical: "
|
<< ", logical: " << props.isLogical << std::endl;
|
||||||
<< props.isLogical << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto boot = MyMap.get("boot");
|
const auto boot = MyMap.get("boot");
|
||||||
if (!boot) throw PartitionMap::Error("get(\"boot\") returned nullopt");
|
if (!boot) throw PartitionMap::Error("get(\"boot\") returned nullopt");
|
||||||
std::cout << "Name: boot" << ", size: "
|
std::cout << "Name: boot" << ", size: " << boot->first
|
||||||
<< boot->first << ", logical: "
|
<< ", logical: " << boot->second << std::endl;
|
||||||
<< boot->second << std::endl;
|
|
||||||
|
|
||||||
const auto logicals = MyMap.getLogicalPartitionList();
|
const auto logicals = MyMap.getLogicalPartitionList();
|
||||||
if (!logicals) throw PartitionMap::Error("getLogicalPartitionList() returned nullopt");
|
if (!logicals)
|
||||||
|
throw PartitionMap::Error("getLogicalPartitionList() returned nullopt");
|
||||||
std::cout << "Logical partitions: " << std::endl;
|
std::cout << "Logical partitions: " << std::endl;
|
||||||
for (const auto &name : *logicals)
|
for (const auto &name : *logicals)
|
||||||
std::cout << " - " << name << std::endl;
|
std::cout << " - " << name << std::endl;
|
||||||
|
|
||||||
const auto physicals = MyMap.getPhysicalPartitionList();
|
const auto physicals = MyMap.getPhysicalPartitionList();
|
||||||
if (!physicals) throw PartitionMap::Error("getPhysicalPartitionList() returned nullopt");
|
if (!physicals)
|
||||||
|
throw PartitionMap::Error("getPhysicalPartitionList() returned nullopt");
|
||||||
std::cout << "Physical partitions: " << std::endl;
|
std::cout << "Physical partitions: " << std::endl;
|
||||||
for (const auto &name : *physicals)
|
for (const auto &name : *physicals)
|
||||||
std::cout << " - " << name << std::endl;
|
std::cout << " - " << name << std::endl;
|
||||||
|
|
||||||
std::cout << "Boot: " << MyMap.getRealLinkPathOf("boot") << std::endl;
|
std::cout << "Boot: " << MyMap.getRealLinkPathOf("boot") << std::endl;
|
||||||
std::cout << "Boot (realpath): " << MyMap.getRealPathOf("boot") << std::endl;
|
std::cout << "Boot (realpath): " << MyMap.getRealPathOf("boot")
|
||||||
|
<< std::endl;
|
||||||
std::cout << "Search dir: " << MyMap.getCurrentWorkDir() << std::endl;
|
std::cout << "Search dir: " << MyMap.getCurrentWorkDir() << std::endl;
|
||||||
std::cout << "Has partition cache? = " << MyMap.hasPartition("cache") << std::endl;
|
std::cout << "Has partition cache? = " << MyMap.hasPartition("cache")
|
||||||
std::cout << "system partition is logical? = " << MyMap.isLogical("system") << std::endl;
|
<< std::endl;
|
||||||
std::cout << "Size of system partition: " << MyMap.sizeOf("system") << std::endl;
|
std::cout << "system partition is logical? = " << MyMap.isLogical("system")
|
||||||
|
<< std::endl;
|
||||||
|
std::cout << "Size of system partition: " << MyMap.sizeOf("system")
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
MyMap.clear();
|
MyMap.clear();
|
||||||
if (!MyMap.empty()) throw PartitionMap::Error("map cleaned but check fail");
|
if (!MyMap.empty()) throw PartitionMap::Error("map cleaned but check fail");
|
||||||
|
|||||||
Reference in New Issue
Block a user