Compare commits
69 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| df720bd309 | |||
| f771fb7c68 | |||
| 4bc5235952 | |||
| d4b4c91ff4 | |||
| 6fc38eb01d | |||
| 42e5d132e7 | |||
| 39d1411b11 | |||
| 04d6471c86 | |||
| f7d2f313de | |||
| 49a87b0387 | |||
| 5a104e5b22 | |||
| 055213f2f6 | |||
| 7f270e319c | |||
| 6a035f8f41 | |||
| 1b2dda655a | |||
| 07d63944c1 | |||
| 36b7bcf246 | |||
| cd3f65a145 | |||
| 9dd29f96b8 | |||
| 7254637caf | |||
| 2af00a8028 | |||
| b5790af803 | |||
| 8fe1548796 | |||
| 04d8ccdd81 | |||
| 1a790d1d89 | |||
| 1296e488f1 | |||
| 3fea6c73cc | |||
| cf4b590130 | |||
| 352ef6e68a | |||
| 754ebaade2 | |||
| 8a28a8f1ef | |||
| 086a2dd93d | |||
| 383a1efe55 | |||
| b96977a5fc | |||
| 976c10593c | |||
| d45dd67cbe | |||
| 0fa5a546aa | |||
| 0c487c62fe | |||
| 105d92e0ca | |||
| 850d104a1a | |||
| 6d24fb9eae | |||
| ae8c73c4f5 | |||
| 890d93131c | |||
| a33d4e3f16 | |||
| f344d62d4c | |||
| 40c5b155dc | |||
| 0547e18639 | |||
| f34a47889e | |||
| a9fac9e661 | |||
| e8040de436 | |||
| ff6e82c556 | |||
| 0c7da875b2 | |||
| 41565d221f | |||
| 5ba78d860e | |||
| 181125dfca | |||
| 4464c203fd | |||
| b9e58df98f | |||
| e2f8cf4ca3 | |||
| 07e2249ef1 | |||
| fd970be822 | |||
| 45c964997c | |||
| 31b7f16a29 | |||
| 5f83a4476f | |||
| 5438f5210f | |||
| cb7904cd5a | |||
| 9c570d5b02 | |||
| c9736863fe | |||
| d5ce065e8b | |||
| a4bc9e3834 |
17
CHANGELOG.md
17
CHANGELOG.md
@@ -1,12 +1,9 @@
|
|||||||
#### Version 1.8.0 (code 180):
|
#### Version 1.9.0 (code 190):
|
||||||
- Add formatting support (only ext2/3/4 file systems)
|
- New features have been added to the compilation system. pmt can now be built with two mods. One is normal and the other is debugging.
|
||||||
- new features were added to the building system to create deb (debian) packages
|
- debugging is no longer the default
|
||||||
- Edit some commands that the building system offers. One was removed. Some of them have changed
|
- In flashing and backup, completely C features are used instead of dd. The code is dd based. bought from toybox
|
||||||
- More talent was added to the additional features offered by the building system and a simpler pleasant advance was presented
|
- option trading logic changed
|
||||||
- A more detailed building system was created using separate makefiles
|
- more details
|
||||||
- Light changes on syntax in source code
|
|
||||||
- The source code folder was changed (binary to src)
|
|
||||||
- In packages created during the build no longer, xz is used instead of gzip
|
|
||||||
|
|
||||||
| END OF VERSION 1.8.0 CHANGELOG |
|
| END OF VERSION 1.9.0 CHANGELOG |
|
||||||
|------------------------------------|
|
|------------------------------------|
|
||||||
|
|||||||
8
Makefile
8
Makefile
@@ -14,8 +14,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
include config/vars.mk
|
|
||||||
include config/env.mk
|
include config/env.mk
|
||||||
|
include config/vars.mk
|
||||||
include config/source.mk
|
include config/source.mk
|
||||||
-include config/INS_STAT.mk
|
-include config/INS_STAT.mk
|
||||||
-include config/UNINS_STAT.mk
|
-include config/UNINS_STAT.mk
|
||||||
@@ -37,7 +37,7 @@ all:
|
|||||||
printf " - Generating xz package...\n"; \
|
printf " - Generating xz package...\n"; \
|
||||||
cp $(BINARY_DIR)/pmt $(PACKAGE_DIR) || exit 1; \
|
cp $(BINARY_DIR)/pmt $(PACKAGE_DIR) || exit 1; \
|
||||||
xz $(PACKAGE_DIR)/pmt; \
|
xz $(PACKAGE_DIR)/pmt; \
|
||||||
mv $(PACKAGE_DIR)/pmt.xz $(PACKAGE_DIR)/pmt-$(ARCH)-$(LANG).xz || exit 1; \
|
mv $(PACKAGE_DIR)/pmt.xz $(PACKAGE_DIR)/pmt-$(TARGET_ARCH)-$(LANG).xz || exit 1; \
|
||||||
printf " - Success\n\n"; \
|
printf " - Success\n\n"; \
|
||||||
printf " ------------------------------------ \n";
|
printf " ------------------------------------ \n";
|
||||||
|
|
||||||
@@ -116,9 +116,9 @@ deb:
|
|||||||
printf " - Generating out dir...\n"; \
|
printf " - Generating out dir...\n"; \
|
||||||
mkdir -p $(DEB_DIR); \
|
mkdir -p $(DEB_DIR); \
|
||||||
printf " - Copying files...\n"; \
|
printf " - Copying files...\n"; \
|
||||||
|
cp -r $(DEBUTILS_DIR)/data $(DEBUTILS_DIR)/temp || exit 1; \
|
||||||
rm -f $(DEBTERMUX_USR)/share/man/man1/dummy; \
|
rm -f $(DEBTERMUX_USR)/share/man/man1/dummy; \
|
||||||
rm -f $(DEBTERMUX_USR)/bin/dummy; \
|
rm -f $(DEBTERMUX_USR)/bin/dummy; \
|
||||||
cp -r $(DEBUTILS_DIR)/data $(DEBUTILS_DIR)/temp || exit 1; \
|
|
||||||
mkdir -p $(DEBUTILS_DIR)/temp/DEBIAN; \
|
mkdir -p $(DEBUTILS_DIR)/temp/DEBIAN; \
|
||||||
if [ "$(ARCH)" = "aarch64" ] || [ "$(ARCH)" = "armv8l" ]; then \
|
if [ "$(ARCH)" = "aarch64" ] || [ "$(ARCH)" = "armv8l" ]; then \
|
||||||
printf " - Selected arm-64 package control file.\n"; \
|
printf " - Selected arm-64 package control file.\n"; \
|
||||||
@@ -207,3 +207,5 @@ uninstall:
|
|||||||
else \
|
else \
|
||||||
printf "This function is only available on Termux.\n"; \
|
printf "This function is only available on Termux.\n"; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# end
|
||||||
|
|||||||
19
README.md
19
README.md
@@ -6,7 +6,7 @@ It offers a lot of options. I will place these below. But first let me talk abou
|
|||||||
```
|
```
|
||||||
1. The partition name is obtained (with the -p or --partition argument)
|
1. The partition name is obtained (with the -p or --partition argument)
|
||||||
2. Other arguments (if used) are processed.
|
2. Other arguments (if used) are processed.
|
||||||
3. It is backed up using DD. If the progress is not a problem, it is not given (DD)
|
3. The backup and flashing processes were written according to DD's code. So there is a piece of toybox code
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Presented arguments (options)
|
#### Presented arguments (options)
|
||||||
@@ -41,11 +41,20 @@ Report bugs to <yagizzengin73@gmail.com>
|
|||||||
- Packages are available in publications.
|
- Packages are available in publications.
|
||||||
- İt is mandatory to use the `-b` | `--backup` or `-f` | `--flash` and `-p` | `--partition` argument. After all, a partition name and progress type is required to be progress.
|
- İt is mandatory to use the `-b` | `--backup` or `-f` | `--flash` and `-p` | `--partition` argument. After all, a partition name and progress type is required to be progress.
|
||||||
- If the logical partition flag is not used, a classic partition is tried to be processing by default.
|
- If the logical partition flag is not used, a classic partition is tried to be processing by default.
|
||||||
- [Click to see special version changes](https://github.com/YZBruh/pbt/blob/1.8.0-en/CHANGELOG.md)
|
- [Click to see special version changes](https://github.com/YZBruh/pbt/blob/1.9.0-en/CHANGELOG.md)
|
||||||
- Let me know your suggestions!
|
- Let me know your suggestions!
|
||||||
|
|
||||||
### How is it built?
|
### How is it built?
|
||||||
Even termux is enough to build the pmt. Or you can compile it with linux if you want. NOTE: Use a custom gcc according to the architecture you want to compile.
|
Android NDK is required to build. [Click for usage information](https://developer.android.com/ndk/guides/other_build_systems). [Click for NDK downloads](https://developer.android.com/ndk/downloads).
|
||||||
|
- NOTE 1: The current configuration is configured for compilation with NDK. The configuration was configured according to the NDK guide (I gave the link). You may need to replace it depending on the situation. You just need to set the `CC` variable in the compile command.
|
||||||
|
- NOTE 2: Use NDK 22+
|
||||||
|
- NOTE 3: The current target architecture is aarch64. You can change this in the configuration or by adding it to the compile command. Be careful. While making this current configuration, the following was considered (directory structure):
|
||||||
|
|
||||||
|
```
|
||||||
|
pmt android-ndk other-directories
|
||||||
|
```
|
||||||
|
|
||||||
|
- The directory structure was thought exactly like this. Be careful.
|
||||||
|
|
||||||
If you want to change something, take a look at the configuration. You can change him.
|
If you want to change something, take a look at the configuration. You can change him.
|
||||||
it is located in the `config` folder. His name is `env.mk`. I gave the information in the file. You can ask more.
|
it is located in the `config` folder. His name is `env.mk`. I gave the information in the file. You can ask more.
|
||||||
@@ -55,7 +64,7 @@ To build;
|
|||||||
make
|
make
|
||||||
```
|
```
|
||||||
|
|
||||||
Special `make` commands (pbt offers :) ;
|
Special `make` commands (pmt offers :) ;
|
||||||
```
|
```
|
||||||
------- Partition Manager help -------
|
------- Partition Manager help -------
|
||||||
|
|
||||||
@@ -67,5 +76,3 @@ Special `make` commands (pbt offers :) ;
|
|||||||
make uninstall ==> If you are using termux, it uninstalls the compiled pmt into termux. So it allows you to use it like a normal command.
|
make uninstall ==> If you are using termux, it uninstalls the compiled pmt into termux. So it allows you to use it like a normal command.
|
||||||
make help ==> Display help message
|
make help ==> Display help message
|
||||||
```
|
```
|
||||||
|
|
||||||
I compiled it with termux :D. Why should I bother... I compiled it with `GCC 18.1.4` You can look at the version with the viewing option :)
|
|
||||||
|
|||||||
@@ -22,15 +22,14 @@
|
|||||||
# #
|
# #
|
||||||
#########################################
|
#########################################
|
||||||
|
|
||||||
|
|
||||||
# use custom gcc | true or false
|
|
||||||
USE_CUST_GCC := false
|
|
||||||
|
|
||||||
# custom gcc ext (if used)
|
|
||||||
CUST_GCC :=
|
|
||||||
|
|
||||||
# addionital gcc flags
|
# addionital gcc flags
|
||||||
EXTRA_GCC_FLAGS :=
|
EXTRA_GCC_FLAGS ?=
|
||||||
|
|
||||||
|
# arch config. 32-bit = armv7a | 64-bit = aarch64 | default = aarch64
|
||||||
|
TARGET_BUILD_ARCH ?= aarch64
|
||||||
|
|
||||||
|
# debugging mode (binary)
|
||||||
|
ENABLE_BINARY_DEBUGGING ?= false
|
||||||
|
|
||||||
#########################################
|
#########################################
|
||||||
#########################################
|
#########################################
|
||||||
@@ -43,19 +42,12 @@ EXTRA_GCC_FLAGS :=
|
|||||||
# #
|
# #
|
||||||
#########################################
|
#########################################
|
||||||
|
|
||||||
# gcc setting
|
# gcc flag settings
|
||||||
ifeq ($(USE_CUST_GCC), true)
|
ifeq ($(ENABLE_BINARY_DEBUGGING), true)
|
||||||
CC := $(CUST_GCC)
|
CFLAGS ?= -O3 -g -Wall -Wextra $(EXTRA_GCC_FLAGS)
|
||||||
LD := $(CUST_GCC)
|
else ifeq ($(ENABLE_BINARY_DEBUGGING), false)
|
||||||
else ifeq ($(USE_CUST_GCC), false)
|
CFLAGS ?= -O3 -Wall $(EXTRA_GCC_FLAGS)
|
||||||
CC := gcc
|
|
||||||
LD := gcc
|
|
||||||
else
|
|
||||||
$(error İnvalid custom gcc config flag: $(USE_CUST_GCC))
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# gcc flag settings
|
|
||||||
CFLAGS := -O3 -g -Wall -Wextra $(EXTRA_GCC_FLAGS)
|
|
||||||
|
|
||||||
#########################################
|
#########################################
|
||||||
#########################################
|
#########################################
|
||||||
|
|||||||
23
config/ndk.sh
Normal file
23
config/ndk.sh
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# By YZBruh
|
||||||
|
|
||||||
|
# Copyright 2024 Partition Manager
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
if [ ! -d ../android-ndk ]; then
|
||||||
|
printf "warning; ndk directory not found. And the current configuration may create problems...\n\n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# end of script
|
||||||
@@ -16,14 +16,9 @@
|
|||||||
|
|
||||||
# sources
|
# sources
|
||||||
SRCS := \
|
SRCS := \
|
||||||
$(SOURCE_DIR)/$(TARGET).c \
|
$(wildcard $(SOURCE_DIR)/*.c)
|
||||||
$(SOURCE_DIR)/error.c \
|
|
||||||
$(SOURCE_DIR)/checkers.c \
|
|
||||||
$(SOURCE_DIR)/listpart.c \
|
|
||||||
$(SOURCE_DIR)/flash.c \
|
|
||||||
$(SOURCE_DIR)/backup.c \
|
|
||||||
$(SOURCE_DIR)/format.c \
|
|
||||||
$(SOURCE_DIR)/docs.c
|
|
||||||
|
|
||||||
# only the reason why the resource list is available is that:
|
# only the reason why the resource list is available is that:
|
||||||
# construction of a code was made with a different make sub-process in the old compilation logic. And then the built files were saved. And the main structure was created. But no longer needs it. According to new logic...
|
# construction of a code was made with a different make sub-process in the old compilation logic. And then the built files were saved. And the main structure was created. But no longer needs it. According to new logic...
|
||||||
|
|
||||||
|
# end
|
||||||
|
|||||||
@@ -15,19 +15,45 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
# speficy
|
# speficy
|
||||||
VERSION := 1.8.0
|
VERSION := 1.9.0
|
||||||
VERSION_CODE := 180
|
VERSION_CODE := 190
|
||||||
TARGET := pmt
|
TARGET := pmt
|
||||||
LANG := en
|
LANG := en
|
||||||
|
|
||||||
# device arch info
|
# device arch info
|
||||||
ARCH := $(shell uname -m)
|
ARCH := $(shell uname -m)
|
||||||
|
OS := $(shell uname)
|
||||||
|
|
||||||
# current directory
|
# current directory
|
||||||
CUR_DIR := $(shell pwd)
|
CUR_DIR := $(shell pwd)
|
||||||
|
|
||||||
# others needed important variables
|
# NDK config
|
||||||
SOURCE_DIR := $(CUR_DIR)/src
|
NDK_DIR := $(shell dirname ../android-ndk/file)
|
||||||
|
$(shell chmod 777 $(CUR_DIR)/config/ndk.sh)
|
||||||
|
$(shell $(CUR_DIR)/config/ndk.sh)
|
||||||
|
|
||||||
|
ifeq ($(OS),Darwin)
|
||||||
|
TOOLCHAIN := $(NDK_DIR)/toolchains/llvm/prebuilt/darwin-x86_64
|
||||||
|
else ifeq ($(OS),Linux)
|
||||||
|
TOOLCHAIN := $(NDK_DIR)/toolchains/llvm/prebuilt/linux-x86_64
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(TARGET_BUILD_ARCH),aarch64)
|
||||||
|
TARGET_ARCH := aarch64-linux-android
|
||||||
|
else ifeq ($(TARGET_BUILD_ARCH),armv7a)
|
||||||
|
TARGET_ARCH := armv7a-linux-androideabi
|
||||||
|
endif
|
||||||
|
|
||||||
|
API := 29
|
||||||
|
|
||||||
|
# compiler
|
||||||
|
ifeq "$(origin CC)" "default"
|
||||||
|
undefine CC
|
||||||
|
endif
|
||||||
|
CC ?= $(TOOLCHAIN)/bin/$(TARGET_ARCH)$(API)-clang
|
||||||
|
|
||||||
|
# source config
|
||||||
|
SOURCE_DIR ?= $(CUR_DIR)/src
|
||||||
OUT_DIR := $(CUR_DIR)/out
|
OUT_DIR := $(CUR_DIR)/out
|
||||||
BINARY_DIR := $(OUT_DIR)/binary
|
BINARY_DIR := $(OUT_DIR)/binary
|
||||||
PACKAGE_DIR := $(OUT_DIR)/package
|
PACKAGE_DIR := $(OUT_DIR)/package
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Source: pmt
|
Source: pmt
|
||||||
Package: pmt
|
Package: pmt
|
||||||
Version: 1.8.0
|
Version: 1.9.0
|
||||||
Architecture: arm
|
Architecture: arm
|
||||||
Description: pmt is for reading, writing and formatting partitions of android devices
|
Description: pmt is for reading, writing and formatting partitions of android devices
|
||||||
Section: misc
|
Section: misc
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Source: pmt
|
Source: pmt
|
||||||
Package: pmt
|
Package: pmt
|
||||||
Version: 1.8.0
|
Version: 1.9.0
|
||||||
Architecture: aarch64
|
Architecture: aarch64
|
||||||
Description: pmt is for reading, writing and formatting partitions of android devices
|
Description: pmt is for reading, writing and formatting partitions of android devices
|
||||||
Section: misc
|
Section: misc
|
||||||
|
|||||||
124
src/backup.c
124
src/backup.c
@@ -1,124 +0,0 @@
|
|||||||
/* By YZBruh */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright 2024 Partition Manager
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#include "include/pmt.h"
|
|
||||||
|
|
||||||
extern char *out;
|
|
||||||
extern char *outdir;
|
|
||||||
extern char *cust_cxt;
|
|
||||||
extern bool pmt_use_logical;
|
|
||||||
extern bool pmt_use_cust_cxt;
|
|
||||||
extern bool pmt_force_mode;
|
|
||||||
|
|
||||||
/* backupper func */
|
|
||||||
void backup(char *target_backup_partition, char *backup_partition_style)
|
|
||||||
{
|
|
||||||
static char backupper_path[200];
|
|
||||||
if (strstr(backup_partition_style, "classic") != NULL)
|
|
||||||
{
|
|
||||||
if (pmt_use_cust_cxt)
|
|
||||||
{
|
|
||||||
sprintf(backupper_path, "%s/%s", cust_cxt, target_backup_partition);
|
|
||||||
} else {
|
|
||||||
sprintf(backupper_path, "/dev/block/by-name/%s", target_backup_partition);
|
|
||||||
}
|
|
||||||
} else if (strstr(backup_partition_style, "logical") != NULL)
|
|
||||||
{
|
|
||||||
sprintf(backupper_path, "/dev/block/mapper/%s", target_backup_partition);
|
|
||||||
} else {
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
error("İnvalid partition type!\n", 28);
|
|
||||||
} else {
|
|
||||||
exit(28);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (access(backupper_path, F_OK) == -1)
|
|
||||||
{
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
error("Partition not found!\n", 29);
|
|
||||||
} else {
|
|
||||||
exit(29);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static char backupper_cmd[256];
|
|
||||||
if (outdir != NULL)
|
|
||||||
{
|
|
||||||
if (out != NULL)
|
|
||||||
{
|
|
||||||
sprintf(backupper_cmd, "dd if=%s of=%s/%s.img status=none", backupper_path, outdir, out);
|
|
||||||
} else {
|
|
||||||
sprintf(backupper_cmd, "dd if=%s of=%s/%s.img status=none", backupper_path, outdir, target_backup_partition);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (out != NULL)
|
|
||||||
{
|
|
||||||
sprintf(backupper_cmd, "dd if=%s of=/storage/emulated/0/%s.img status=none", backupper_path, out);
|
|
||||||
} else {
|
|
||||||
sprintf(backupper_cmd, "dd if=%s of=/storage/emulated/0/%s.img status=none", backupper_path, target_backup_partition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (system(backupper_cmd) != 0)
|
|
||||||
{
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
error("Failed!\n", 99);
|
|
||||||
} else {
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (outdir != NULL)
|
|
||||||
{
|
|
||||||
if (out != NULL)
|
|
||||||
{
|
|
||||||
printf("%sSuccess. Output: %s/%s.img%s\n", ANSI_GREEN, outdir, out, ANSI_RESET);
|
|
||||||
} else {
|
|
||||||
printf("%sSuccess. Output: %s/%s.img%s\n", ANSI_GREEN, outdir, target_backup_partition, ANSI_RESET);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (out != NULL)
|
|
||||||
{
|
|
||||||
printf("%sSuccess. Output: /storage/emulated/0/%s.img%s\n", ANSI_GREEN, out, ANSI_RESET);
|
|
||||||
} else {
|
|
||||||
printf("%sSuccess. Output: /storage/emulated/0/%s.img%s\n", ANSI_GREEN, target_backup_partition, ANSI_RESET);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of code */
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/* By YZBruh */
|
/* By YZBruh */
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Copyright 2024 Partition Manager
|
* Copyright 2024 Partition Manager
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -21,11 +21,12 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "include/pmt.h"
|
#include "include/pmt.h"
|
||||||
@@ -39,39 +40,41 @@ extern char *cust_cxt;
|
|||||||
/* check parts */
|
/* check parts */
|
||||||
void check_psf()
|
void check_psf()
|
||||||
{
|
{
|
||||||
|
struct stat abinf;
|
||||||
/* true = ab | false = a */
|
/* true = ab | false = a */
|
||||||
if (pmt_use_cust_cxt)
|
if (pmt_use_cust_cxt)
|
||||||
{
|
{
|
||||||
static char cust_cxt_ck_path[150];
|
static char cust_cxt_ck_path[150];
|
||||||
sprintf(cust_cxt_ck_path, "%s/boot_a", cust_cxt);
|
sprintf(cust_cxt_ck_path, "%s/boot_a", cust_cxt);
|
||||||
if (access(cust_cxt_ck_path, F_OK) != 0)
|
if (stat(cust_cxt_ck_path, &abinf) != 0)
|
||||||
{
|
{
|
||||||
pmt_ab = false;
|
pmt_ab = false;
|
||||||
} else {
|
} else {
|
||||||
pmt_ab = true;
|
pmt_ab = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (access("/dev/block/by-name/boot_a", F_OK) != 0)
|
if (stat("/dev/block/by-name/boot_a", &abinf) != 0)
|
||||||
{
|
{
|
||||||
pmt_ab = false;
|
pmt_ab = false;
|
||||||
} else {
|
} else {
|
||||||
pmt_ab = true;
|
pmt_ab = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct stat logcinf;
|
||||||
/* true = logical | false = classic */
|
/* true = logical | false = classic */
|
||||||
if (pmt_use_cust_cxt)
|
if (pmt_use_cust_cxt)
|
||||||
{
|
{
|
||||||
static char cust_cxt_ckl_path[150];
|
static char cust_cxt_ckl_path[150];
|
||||||
sprintf(cust_cxt_ckl_path, "%s/super", cust_cxt);
|
sprintf(cust_cxt_ckl_path, "%s/super", cust_cxt);
|
||||||
if (access(cust_cxt_ckl_path, F_OK) != 0)
|
if (stat(cust_cxt_ckl_path, &logcinf) != 0)
|
||||||
{
|
{
|
||||||
pmt_logical = false;
|
pmt_logical = false;
|
||||||
} else {
|
} else {
|
||||||
pmt_logical = true;
|
pmt_logical = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (access("/dev/block/by-name/super", F_OK) != 0)
|
if (stat("/dev/block/by-name/super", &logcinf) != 0)
|
||||||
{
|
{
|
||||||
pmt_logical = false;
|
pmt_logical = false;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "include/pmt.h"
|
#include "include/pmt.h"
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
|||||||
94
src/flash.c
94
src/flash.c
@@ -1,94 +0,0 @@
|
|||||||
/* By YZBruh */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright 2024 Partition Manager
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "include/pmt.h"
|
|
||||||
|
|
||||||
extern char *cust_cxt;
|
|
||||||
extern bool pmt_use_cust_cxt;
|
|
||||||
extern bool pmt_force_mode;
|
|
||||||
|
|
||||||
/* flasher func */
|
|
||||||
void flash(char *target_flash_partition, char *target_file, char *flash_partition_style)
|
|
||||||
{
|
|
||||||
static char flasher_path[200];
|
|
||||||
/* determine device block */
|
|
||||||
/* for classic */
|
|
||||||
if (strstr(flash_partition_style, "classic") != NULL)
|
|
||||||
{
|
|
||||||
if (pmt_use_cust_cxt)
|
|
||||||
{
|
|
||||||
sprintf(flasher_path, "%s/%s", cust_cxt, target_flash_partition);
|
|
||||||
} else {
|
|
||||||
sprintf(flasher_path, "/dev/block/by-name/%s", target_flash_partition);
|
|
||||||
}
|
|
||||||
/* for logical */
|
|
||||||
} else if (strstr(flash_partition_style, "logical") != NULL)
|
|
||||||
{
|
|
||||||
sprintf(flasher_path, "/dev/block/mapper/%s", target_flash_partition);
|
|
||||||
} else {
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
error("İnvalid partition type!\n", 30);
|
|
||||||
} else {
|
|
||||||
exit(30);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check partition */
|
|
||||||
if (access(flasher_path, F_OK) == -1)
|
|
||||||
{
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
error("Partition not found!\n", 31);
|
|
||||||
} else {
|
|
||||||
exit(31);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* setting up */
|
|
||||||
static char flasher_cmd[256];
|
|
||||||
sprintf(flasher_cmd, "dd if=%s of=%s status=none", target_file, flasher_path);
|
|
||||||
|
|
||||||
/* start flash */
|
|
||||||
if (system(flasher_cmd) != 0)
|
|
||||||
{
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
error("Failed!\n", 98);
|
|
||||||
} else {
|
|
||||||
exit(98);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of code */
|
|
||||||
107
src/format.c
107
src/format.c
@@ -1,107 +0,0 @@
|
|||||||
/* By YZBruh */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright 2024 Partition Manager
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/statvfs.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "include/pmt.h"
|
|
||||||
|
|
||||||
extern char *format_fs;
|
|
||||||
extern char *cust_cxt;
|
|
||||||
extern bool pmt_use_cust_cxt;
|
|
||||||
extern bool pmt_force_mode;
|
|
||||||
|
|
||||||
void format(char *target_format_partition, char *format_partition_style)
|
|
||||||
{
|
|
||||||
/* generate partition extn */
|
|
||||||
static char ppath[100];
|
|
||||||
if (strstr(format_partition_style, "classic") != NULL)
|
|
||||||
{
|
|
||||||
if (pmt_use_cust_cxt)
|
|
||||||
{
|
|
||||||
sprintf(ppath, "%s/%s", cust_cxt, target_format_partition);
|
|
||||||
} else {
|
|
||||||
sprintf(ppath, "/dev/block/by-name/%s", target_format_partition);
|
|
||||||
}
|
|
||||||
/* for logical */
|
|
||||||
} else if (strstr(format_partition_style, "logical") != NULL)
|
|
||||||
{
|
|
||||||
sprintf(ppath, "/dev/block/mapper/%s", target_format_partition);
|
|
||||||
} else {
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
error("İnvalid partition type!\n", 30);
|
|
||||||
} else {
|
|
||||||
exit(49);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check partition */
|
|
||||||
if (access(ppath, F_OK) == -1)
|
|
||||||
{
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
error("Partition not found!\n", 31);
|
|
||||||
} else {
|
|
||||||
exit(31);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get target partition block size */
|
|
||||||
struct statvfs file_sys_inf;
|
|
||||||
if (statvfs(ppath, &file_sys_inf) != 0)
|
|
||||||
{
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "The partition block size could not be obtained!\n");
|
|
||||||
exit(49);
|
|
||||||
} else {
|
|
||||||
exit(49);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* generate mke2fs command */
|
|
||||||
static char formatter_cmd[200];
|
|
||||||
sprintf(formatter_cmd, "mke2fs -Fq -t %s -b %lu %s", format_fs, file_sys_inf.f_bsize, ppath);
|
|
||||||
|
|
||||||
/* run command */
|
|
||||||
if (system(formatter_cmd) != 0)
|
|
||||||
{
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
error("Formatting failed! There may be a chance that something has been damaged!\n", 71);
|
|
||||||
} else {
|
|
||||||
exit(71);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of code */
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/* By YZBruh */
|
/* By YZBruh */
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Copyright 2024 Partition Manager
|
* Copyright 2024 Partition Manager
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -20,30 +20,18 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* check compiler system */
|
|
||||||
#ifdef _WIN32
|
|
||||||
#error "it can only be compiled in linux or android environment. but current system windows (_WIN32 defined)"
|
|
||||||
#elif ! __linux__ || __android__
|
|
||||||
#error "unknown compiler system founded"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* compiler architecture if arm is not 32-bit or 64-bit, the compilation is stopped */
|
|
||||||
#if ! __SIZEOF_POINTER__ == 4 || ! __SIZEOF_POINTER__ == 8
|
|
||||||
#error "only 32-bit or 64-bit arm compilers can be used"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _PMT_H
|
#ifndef _PMT_H
|
||||||
#define _PMT_H
|
#define _PMT_H
|
||||||
|
|
||||||
/* color definations */
|
/* color definations */
|
||||||
#define ANSI_RED "\033[31m"
|
#define ANSI_RED "\033[31m"
|
||||||
#define ANSI_YELLOW "\033[33m"
|
#define ANSI_YELLOW "\033[33m"
|
||||||
#define ANSI_GREEN "\033[32m"
|
#define ANSI_GREEN "\033[32m"
|
||||||
#define ANSI_RESET "\033[0m"
|
#define ANSI_RESET "\033[0m"
|
||||||
|
|
||||||
/* info */
|
/* info */
|
||||||
#define PMT_VERSION "1.8.0"
|
#define PMT_VERSION "1.9.0"
|
||||||
#define PMT_VERSION_CODE "180"
|
#define PMT_VERSION_CODE "190"
|
||||||
#define PMT_PACKAGE_NAME "Partition Manager"
|
#define PMT_PACKAGE_NAME "Partition Manager"
|
||||||
#define PMT_PACKAGE_LANG "en"
|
#define PMT_PACKAGE_LANG "en"
|
||||||
|
|
||||||
@@ -54,6 +42,7 @@ extern char *cust_cxt;
|
|||||||
extern char *target_partition;
|
extern char *target_partition;
|
||||||
extern char *target_flash_file;
|
extern char *target_flash_file;
|
||||||
extern char *format_fs;
|
extern char *format_fs;
|
||||||
|
extern char *partition_type;
|
||||||
extern bool pmt_use_logical;
|
extern bool pmt_use_logical;
|
||||||
extern bool pmt_use_cust_cxt;
|
extern bool pmt_use_cust_cxt;
|
||||||
extern bool pmt_ab;
|
extern bool pmt_ab;
|
||||||
@@ -68,9 +57,8 @@ void listpart();
|
|||||||
void error(const char *err_msg, uint32_t errcode);
|
void error(const char *err_msg, uint32_t errcode);
|
||||||
void check_psf();
|
void check_psf();
|
||||||
void check_root();
|
void check_root();
|
||||||
void backup(char *target_backup_partition, char *backup_partition_style);
|
void pmt(short progress_code);
|
||||||
void flash(char *target_flash_partition, char *target_file, char *flash_partition_style);
|
void version();
|
||||||
void format(char *target_format_partition, char *format_partition_style);
|
|
||||||
void help();
|
void help();
|
||||||
void licenses();
|
void licenses();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* By YZBruh */
|
/* By YZBruh */
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Copyright 2024 Partition Manager
|
* Copyright 2024 Partition Manager
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -21,11 +21,13 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "include/pmt.h"
|
#include "include/pmt.h"
|
||||||
|
|
||||||
|
|||||||
291
src/pmt.c
291
src/pmt.c
@@ -1,6 +1,6 @@
|
|||||||
/* By YZBruh */
|
/* By YZBruh */
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Copyright 2024 Partition Manager
|
* Copyright 2024 Partition Manager
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -16,11 +16,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* force use C std (if default is C++) */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* include needed libs (headers) */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -29,13 +32,16 @@ extern "C" {
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
/* include custom pmt header */
|
||||||
#include "include/pmt.h"
|
#include "include/pmt.h"
|
||||||
|
|
||||||
|
/* add value to variables that are added globally and are not worth */
|
||||||
char *out = NULL;
|
char *out = NULL;
|
||||||
char *outdir = NULL;
|
char *outdir = NULL;
|
||||||
char *cust_cxt = NULL;
|
char *cust_cxt = NULL;
|
||||||
char *target_partition = NULL;
|
char *target_partition = NULL;
|
||||||
char *target_flash_file = NULL;
|
char *target_flash_file = NULL;
|
||||||
|
char *partition_type = NULL;
|
||||||
char *format_fs = NULL;
|
char *format_fs = NULL;
|
||||||
bool pmt_use_logical = NULL;
|
bool pmt_use_logical = NULL;
|
||||||
bool pmt_use_cust_cxt = NULL;
|
bool pmt_use_cust_cxt = NULL;
|
||||||
@@ -74,19 +80,30 @@ int main(int argc, char *argv[])
|
|||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* boolean statements (only valid in this file) to distinguish. and pointer from a shortcut for the symbol rule */
|
||||||
|
static bool wiew_help = false;
|
||||||
|
static bool wiew_licenses = false;
|
||||||
|
static bool wiew_version = false;
|
||||||
|
static bool list_partitions = false;
|
||||||
|
static bool combo_wiewers = false;
|
||||||
|
static bool use_cust_outdir = false;
|
||||||
static char *opt_symbol = "-";
|
static char *opt_symbol = "-";
|
||||||
static char *common_symbol_rule;
|
static char *common_symbol_rule;
|
||||||
common_symbol_rule = "When entering the attached argument of an option, an argument of another option type cannot be used. In short, the rule is: there can be no '-' at the beginning of the attached argument.\n";
|
common_symbol_rule = "When entering the attached argument of an option, an argument of another option type cannot be used. In short, the rule is: there can be no '-' at the beginning of the attached argument.\n";
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
/* control for each argument */
|
/* control for each argument */
|
||||||
while ((opt = getopt_long(argc, argv, "bF:rp:lo:d:c:DfvL", long_options, NULL)) != -1)
|
while ((opt = getopt_long(argc, argv, "bF:rp:lo:d:c:DfvL", long_options, NULL)) != -1)
|
||||||
{
|
{
|
||||||
/* process arguments */
|
/* process arguments */
|
||||||
switch (opt)
|
switch (opt)
|
||||||
{
|
{
|
||||||
|
/* backup mode */
|
||||||
case 'b':
|
case 'b':
|
||||||
pmt_backup = true;
|
pmt_backup = true;
|
||||||
break;
|
break;
|
||||||
|
/* flash mode */
|
||||||
case 'F':
|
case 'F':
|
||||||
target_flash_file = strdup(optarg);
|
target_flash_file = strdup(optarg);
|
||||||
if (strncmp(target_flash_file, opt_symbol, 1) == 0)
|
if (strncmp(target_flash_file, opt_symbol, 1) == 0)
|
||||||
@@ -99,31 +116,8 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pmt_flash = true;
|
pmt_flash = true;
|
||||||
check_root();
|
|
||||||
check_psf();
|
|
||||||
struct stat flashf_info;
|
|
||||||
if (stat(target_flash_file, &flashf_info) != 0)
|
|
||||||
{
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: %s: %s\n", argv[0], target_flash_file, strerror(errno));
|
|
||||||
exit(15);
|
|
||||||
} else {
|
|
||||||
exit(15);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!S_ISREG(flashf_info.st_mode))
|
|
||||||
{
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: %s: is a not file.\n", argv[0], target_flash_file);
|
|
||||||
exit(16);
|
|
||||||
} else {
|
|
||||||
exit(16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
/* format mode */
|
||||||
case 'r':
|
case 'r':
|
||||||
format_fs = strdup(optarg);
|
format_fs = strdup(optarg);
|
||||||
if (strncmp(format_fs, opt_symbol, 1) == 0)
|
if (strncmp(format_fs, opt_symbol, 1) == 0)
|
||||||
@@ -137,17 +131,8 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pmt_format = true;
|
pmt_format = true;
|
||||||
if (strcmp(format_fs, "ext4") != 0 || strcmp(format_fs, "ext3") != 0 || strcmp(format_fs, "ext2") != 0)
|
|
||||||
{
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: formatter: unsupported filesystem: %s", argv[0], format_fs);
|
|
||||||
exit(41);
|
|
||||||
} else {
|
|
||||||
exit(41);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
/* partition selector option */
|
||||||
case 'p':
|
case 'p':
|
||||||
target_partition = strdup(optarg);
|
target_partition = strdup(optarg);
|
||||||
if (strncmp(target_partition, opt_symbol, 1) == 0)
|
if (strncmp(target_partition, opt_symbol, 1) == 0)
|
||||||
@@ -160,6 +145,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
/* logical partitions option */
|
||||||
case 'l':
|
case 'l':
|
||||||
check_root();
|
check_root();
|
||||||
check_psf();
|
check_psf();
|
||||||
@@ -175,6 +161,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
/* output file option */
|
||||||
case 'o':
|
case 'o':
|
||||||
out = strdup(optarg);
|
out = strdup(optarg);
|
||||||
if (strncmp(out, opt_symbol, 1) == 0)
|
if (strncmp(out, opt_symbol, 1) == 0)
|
||||||
@@ -187,42 +174,12 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
/* output dir option */
|
||||||
case 'd':
|
case 'd':
|
||||||
|
use_cust_outdir = true;
|
||||||
outdir = strdup(optarg);
|
outdir = strdup(optarg);
|
||||||
if (strncmp(outdir, opt_symbol, 1) == 0)
|
|
||||||
{
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
error(common_symbol_rule, 19);
|
|
||||||
} else {
|
|
||||||
exit(19);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
check_root();
|
|
||||||
check_psf();
|
|
||||||
struct stat out_info;
|
|
||||||
if (stat(outdir, &out_info) != 0)
|
|
||||||
{
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: %s: %s\n", argv[0], outdir, strerror(errno));
|
|
||||||
exit(18);
|
|
||||||
} else {
|
|
||||||
exit(18);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!S_ISDIR(out_info.st_mode))
|
|
||||||
{
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: %s: is a not directory.\n", argv[0], outdir);
|
|
||||||
exit(20);
|
|
||||||
} else {
|
|
||||||
exit(20);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
/* context selector option */
|
||||||
case 'c':
|
case 'c':
|
||||||
pmt_use_cust_cxt = true;
|
pmt_use_cust_cxt = true;
|
||||||
cust_cxt = strdup(optarg);
|
cust_cxt = strdup(optarg);
|
||||||
@@ -236,35 +193,47 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
/* partition lister function */
|
||||||
case 'D':
|
case 'D':
|
||||||
check_root();
|
list_partitions = true;
|
||||||
listpart();
|
/* check combo wiewer options and progress */
|
||||||
exit(EXIT_SUCCESS);
|
if (wiew_version || wiew_help || wiew_licenses)
|
||||||
|
{
|
||||||
|
combo_wiewers = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
/* force mode option */
|
||||||
case 'f':
|
case 'f':
|
||||||
pmt_force_mode = true;
|
pmt_force_mode = true;
|
||||||
break;
|
break;
|
||||||
|
/* version info option */
|
||||||
case 'v':
|
case 'v':
|
||||||
printf("Version: %s (code %s)\n", PMT_VERSION, PMT_VERSION_CODE);
|
wiew_version = true;
|
||||||
#ifdef __clang__
|
/* check combo wiewer options and progress */
|
||||||
printf("Compiler: clang %s", __clang_version__);
|
if (list_partitions || wiew_help || wiew_licenses)
|
||||||
#endif
|
{
|
||||||
#ifdef __GNUC__
|
combo_wiewers = true;
|
||||||
printf("(GNUC %d.%d.%d)\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
}
|
||||||
#else
|
|
||||||
printf("\n");
|
|
||||||
#endif
|
|
||||||
printf("See licenses with -L argument.\n");
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
break;
|
break;
|
||||||
|
/* help message opption */
|
||||||
case 0:
|
case 0:
|
||||||
help();
|
wiew_help = true;
|
||||||
exit(EXIT_SUCCESS);
|
/* check combo wiewer options and progress */
|
||||||
|
if (wiew_version || list_partitions || wiew_licenses)
|
||||||
|
{
|
||||||
|
combo_wiewers = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
/* license wiewer option */
|
||||||
case 'L':
|
case 'L':
|
||||||
licenses();
|
wiew_licenses = true;
|
||||||
exit(EXIT_SUCCESS);
|
/* check combo wiewer options and progress */
|
||||||
|
if (wiew_version || wiew_help || list_partitions)
|
||||||
|
{
|
||||||
|
combo_wiewers = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
/* for invalid options */
|
||||||
case '?':
|
case '?':
|
||||||
printf("Try `%s --help' for more information.\n", argv[0]);
|
printf("Try `%s --help' for more information.\n", argv[0]);
|
||||||
exit(43);
|
exit(43);
|
||||||
@@ -275,18 +244,46 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* minor checks */
|
/* stop the program if multiple viewer is used */
|
||||||
if (!pmt_backup && !pmt_flash)
|
if (combo_wiewers)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: Multiple wiewers cannot be used at the same line.\n", argv[0]);
|
||||||
|
exit(81);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* controller to handle viewer */
|
||||||
|
if (wiew_help)
|
||||||
|
{
|
||||||
|
help();
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
} else if (wiew_version)
|
||||||
|
{
|
||||||
|
version();
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
} else if (wiew_licenses)
|
||||||
|
{
|
||||||
|
licenses();
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
} else if (list_partitions)
|
||||||
|
{
|
||||||
|
check_root();
|
||||||
|
listpart();
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* target control is done */
|
||||||
|
if (!pmt_backup && !pmt_flash && !pmt_format)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: missing operand.\nTry `%s --help` for more information.\n", argv[0], argv[0]);
|
fprintf(stderr, "%s: missing operand.\nTry `%s --help` for more information.\n", argv[0], argv[0]);
|
||||||
exit(3);
|
exit(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* prevent multiple mode use */
|
||||||
if (pmt_backup && pmt_flash)
|
if (pmt_backup && pmt_flash)
|
||||||
{
|
{
|
||||||
if (!pmt_force_mode)
|
if (!pmt_force_mode)
|
||||||
{
|
{
|
||||||
error("Backup and flash functions cannot be used in the same command\n", 9);
|
error("Backup and flash functions cannot be used in the same command.\n", 9);
|
||||||
} else {
|
} else {
|
||||||
exit(9);
|
exit(9);
|
||||||
}
|
}
|
||||||
@@ -296,6 +293,81 @@ int main(int argc, char *argv[])
|
|||||||
check_root();
|
check_root();
|
||||||
check_psf();
|
check_psf();
|
||||||
|
|
||||||
|
if (pmt_format)
|
||||||
|
{
|
||||||
|
if (strcmp(format_fs, "ext4") != 0 || strcmp(format_fs, "ext3") != 0 || strcmp(format_fs, "ext2") != 0)
|
||||||
|
{
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: formatter: unsupported filesystem: %s", argv[0], format_fs);
|
||||||
|
exit(41);
|
||||||
|
} else {
|
||||||
|
exit(41);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (use_cust_outdir)
|
||||||
|
{
|
||||||
|
if (strncmp(outdir, opt_symbol, 1) == 0)
|
||||||
|
{
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
error(common_symbol_rule, 19);
|
||||||
|
} else {
|
||||||
|
exit(19);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
struct stat out_info;
|
||||||
|
if (stat(outdir, &out_info) != 0)
|
||||||
|
{
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: cannot stat '%s': %s\n", argv[0], outdir, strerror(errno));
|
||||||
|
exit(18);
|
||||||
|
} else {
|
||||||
|
exit(18);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!S_ISDIR(out_info.st_mode))
|
||||||
|
{
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: %s: is a not directory.\n", argv[0], outdir);
|
||||||
|
exit(20);
|
||||||
|
} else {
|
||||||
|
exit(20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pmt_flash)
|
||||||
|
{
|
||||||
|
struct stat flashf_info;
|
||||||
|
if (stat(target_flash_file, &flashf_info) != 0)
|
||||||
|
{
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: cannot stat '%s': %s\n", argv[0], target_flash_file, strerror(errno));
|
||||||
|
exit(15);
|
||||||
|
} else {
|
||||||
|
exit(15);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!S_ISREG(flashf_info.st_mode))
|
||||||
|
{
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: %s: is a not file.\n", argv[0], target_flash_file);
|
||||||
|
exit(16);
|
||||||
|
} else {
|
||||||
|
exit(16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* custom context checker */
|
/* custom context checker */
|
||||||
if (pmt_use_cust_cxt)
|
if (pmt_use_cust_cxt)
|
||||||
{
|
{
|
||||||
@@ -323,8 +395,9 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
if (strstr(cust_cxt, "/dev") == NULL && !pmt_force_mode)
|
if (strstr(cust_cxt, "/dev") == NULL && !pmt_force_mode)
|
||||||
{
|
{
|
||||||
printf("%sThis custom context is strange...%s\n", ANSI_YELLOW, ANSI_RESET);
|
fprintf(stderr, "%sYou're going through my wave? There's nothing about this /dev. Use force mode if you don't want this error%s\n", ANSI_YELLOW, ANSI_RESET);
|
||||||
}
|
exit(81);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target_partition == NULL)
|
if (target_partition == NULL)
|
||||||
@@ -337,35 +410,25 @@ int main(int argc, char *argv[])
|
|||||||
exit(5);
|
exit(5);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 1 = backup mode
|
||||||
|
*
|
||||||
|
* 2 = flash mode
|
||||||
|
*
|
||||||
|
* 3 = format
|
||||||
|
*/
|
||||||
if (pmt_backup)
|
if (pmt_backup)
|
||||||
{
|
{
|
||||||
if (pmt_use_logical)
|
pmt(1);
|
||||||
{
|
exit(EXIT_SUCCESS);
|
||||||
backup(target_partition, "logical");
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
} else {
|
|
||||||
backup(target_partition, "classic");
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
} else if (pmt_flash)
|
} else if (pmt_flash)
|
||||||
{
|
{
|
||||||
if (pmt_use_logical)
|
pmt(2);
|
||||||
{
|
exit(EXIT_SUCCESS);
|
||||||
flash(target_partition, target_flash_file, "logical");
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
} else {
|
|
||||||
flash(target_partition, target_flash_file, "classic");
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
} else if (pmt_format)
|
} else if (pmt_format)
|
||||||
{
|
{
|
||||||
if (pmt_use_logical) {
|
pmt(3);
|
||||||
format(target_partition, "logical");
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
} else {
|
|
||||||
format(target_partition, "classic");
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "%s: no target (backup or flash).\nTry `%s --help` for more information.\n", argv[0], argv[0]);
|
fprintf(stderr, "%s: no target (backup or flash).\nTry `%s --help` for more information.\n", argv[0], argv[0]);
|
||||||
exit(3);
|
exit(3);
|
||||||
|
|||||||
332
src/tools.c
Normal file
332
src/tools.c
Normal file
@@ -0,0 +1,332 @@
|
|||||||
|
/* By YZBruh */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright 2024 Partition Manager
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/statvfs.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include "include/pmt.h"
|
||||||
|
|
||||||
|
#define BFSIZE 1024
|
||||||
|
|
||||||
|
extern char *out;
|
||||||
|
extern char *outdir;
|
||||||
|
extern char *format_fs;
|
||||||
|
extern char *cust_cxt;
|
||||||
|
extern char *target_partition;
|
||||||
|
extern char *target_flash_file;
|
||||||
|
extern char *partition_type;
|
||||||
|
extern bool pmt_use_logical;
|
||||||
|
extern bool pmt_use_cust_cxt;
|
||||||
|
extern bool pmt_logical;
|
||||||
|
extern bool pmt_flash;
|
||||||
|
extern bool pmt_backup;
|
||||||
|
extern bool pmt_force_mode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* if progress_code is a
|
||||||
|
* 1 = backup mode
|
||||||
|
*
|
||||||
|
* 2 = flash mode
|
||||||
|
*
|
||||||
|
* 3 = format mode
|
||||||
|
*/
|
||||||
|
|
||||||
|
void pmt(short progress_code)
|
||||||
|
{
|
||||||
|
/* required variables */
|
||||||
|
static int srcf, targetf;
|
||||||
|
static char backupper_path[512];
|
||||||
|
static char ppath[100];
|
||||||
|
static char formatter_cmd[200];
|
||||||
|
static char outf[512];
|
||||||
|
static char flasher_path[512];
|
||||||
|
static char buffer[BFSIZE];
|
||||||
|
static ssize_t bytesRead;
|
||||||
|
static unsigned long long bytesCopied = 0;
|
||||||
|
static unsigned long long count = 1024 * 1024 * 1024;
|
||||||
|
|
||||||
|
if (progress_code == 1)
|
||||||
|
{
|
||||||
|
if (!pmt_use_logical)
|
||||||
|
{
|
||||||
|
if (pmt_use_cust_cxt)
|
||||||
|
{
|
||||||
|
sprintf(backupper_path, "%s/%s", cust_cxt, target_partition);
|
||||||
|
} else {
|
||||||
|
sprintf(backupper_path, "/dev/block/by-name/%s", target_partition);
|
||||||
|
}
|
||||||
|
} else if (pmt_use_logical)
|
||||||
|
{
|
||||||
|
sprintf(backupper_path, "/dev/block/mapper/%s", target_partition);
|
||||||
|
} else {
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
error("İnvalid partition type!\n", 28);
|
||||||
|
} else {
|
||||||
|
exit(28);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (access(backupper_path, F_OK) == -1)
|
||||||
|
{
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
error("Partition not found!\n", 29);
|
||||||
|
} else {
|
||||||
|
exit(29);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
srcf = open(backupper_path, O_RDONLY);
|
||||||
|
if (srcf == -1) {
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Couldn't read: %s: %s", backupper_path, strerror(errno));
|
||||||
|
exit(39);
|
||||||
|
} else {
|
||||||
|
exit(39);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* determine output */
|
||||||
|
if (outdir != NULL)
|
||||||
|
{
|
||||||
|
if (out != NULL)
|
||||||
|
{
|
||||||
|
sprintf(outf, "%s/%s.img", outdir, out);
|
||||||
|
} else {
|
||||||
|
sprintf(outf, "%s/%s.img", outdir, target_partition);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (out != NULL)
|
||||||
|
{
|
||||||
|
sprintf(outf, "/storage/emulated/0/%s.img", out);
|
||||||
|
} else {
|
||||||
|
sprintf(outf, "/storage/emulated/0/%s.img", target_partition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
targetf = open(outf, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||||
|
if (targetf == -1) {
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Couldn't generate: %s: %s", outf, strerror(errno));
|
||||||
|
exit(37);
|
||||||
|
} else {
|
||||||
|
exit(37);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* start writing */
|
||||||
|
while ((bytesRead = read(srcf, buffer, BFSIZE)) > 0 && bytesCopied < count)
|
||||||
|
{
|
||||||
|
ssize_t bytesWritten = write(targetf, buffer, bytesRead);
|
||||||
|
if (bytesWritten != bytesRead)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Couldn't write: %s: %s", backupper_path, strerror(errno));
|
||||||
|
close(srcf);
|
||||||
|
close(targetf);
|
||||||
|
exit(81);
|
||||||
|
}
|
||||||
|
|
||||||
|
bytesCopied += bytesWritten;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* close files */
|
||||||
|
close(srcf);
|
||||||
|
close(targetf);
|
||||||
|
|
||||||
|
/* Print the output information by evaluating all situations */
|
||||||
|
if (outdir != NULL)
|
||||||
|
{
|
||||||
|
if (out != NULL)
|
||||||
|
{
|
||||||
|
printf("%sSuccess. Output: %s/%s.img%s\n", ANSI_GREEN, outdir, out, ANSI_RESET);
|
||||||
|
} else {
|
||||||
|
printf("%sSuccess. Output: %s/%s.img%s\n", ANSI_GREEN, outdir, target_partition, ANSI_RESET);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (out != NULL)
|
||||||
|
{
|
||||||
|
printf("%sSuccess. Output: /storage/emulated/0/%s.img%s\n", ANSI_GREEN, out, ANSI_RESET);
|
||||||
|
} else {
|
||||||
|
printf("%sSuccess. Output: /storage/emulated/0/%s.img%s\n", ANSI_GREEN, target_partition, ANSI_RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (progress_code == 2)
|
||||||
|
{
|
||||||
|
/* determine device block */
|
||||||
|
/* for classic */
|
||||||
|
if (!pmt_use_logical)
|
||||||
|
{
|
||||||
|
if (pmt_use_cust_cxt)
|
||||||
|
{
|
||||||
|
sprintf(flasher_path, "%s/%s", cust_cxt, target_partition);
|
||||||
|
} else {
|
||||||
|
sprintf(flasher_path, "/dev/block/by-name/%s", target_partition);
|
||||||
|
}
|
||||||
|
/* for logical */
|
||||||
|
} else if (pmt_use_logical)
|
||||||
|
{
|
||||||
|
sprintf(flasher_path, "/dev/block/mapper/%s", target_partition);
|
||||||
|
} else {
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
error("İnvalid partition type!\n", 30);
|
||||||
|
} else {
|
||||||
|
exit(30);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check partition */
|
||||||
|
if (access(flasher_path, F_OK) == -1)
|
||||||
|
{
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
error("Partition not found!\n", 31);
|
||||||
|
} else {
|
||||||
|
exit(31);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
srcf = open(target_flash_file, O_RDONLY);
|
||||||
|
if (srcf == -1) {
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Couldn't read: %s: %s", target_flash_file, strerror(errno));
|
||||||
|
exit(39);
|
||||||
|
} else {
|
||||||
|
exit(39);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
targetf = open(target_partition, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||||
|
if (targetf == -1) {
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Couldn't read: %s: %s", target_partition, strerror(errno));
|
||||||
|
exit(37);
|
||||||
|
} else {
|
||||||
|
exit(37);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* start writing */
|
||||||
|
while ((bytesRead = read(srcf, buffer, BFSIZE)) > 0 && bytesCopied < count) {
|
||||||
|
ssize_t bytesWritten = write(targetf, buffer, bytesRead);
|
||||||
|
if (bytesWritten != bytesRead) {
|
||||||
|
fprintf(stderr, "Couldn't write: %s: %s", backupper_path, strerror(errno));
|
||||||
|
close(srcf);
|
||||||
|
close(targetf);
|
||||||
|
exit(81);
|
||||||
|
}
|
||||||
|
|
||||||
|
bytesCopied += bytesWritten;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(srcf);
|
||||||
|
close(targetf);
|
||||||
|
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
printf("%sSuccess.%s\n", ANSI_GREEN, ANSI_RESET);
|
||||||
|
}
|
||||||
|
} else if (progress_code == 3)
|
||||||
|
{
|
||||||
|
/* generate partition extn */
|
||||||
|
if (!pmt_use_logical)
|
||||||
|
{
|
||||||
|
if (pmt_use_cust_cxt)
|
||||||
|
{
|
||||||
|
sprintf(ppath, "%s/%s", cust_cxt, target_partition);
|
||||||
|
} else {
|
||||||
|
sprintf(ppath, "/dev/block/by-name/%s", target_partition);
|
||||||
|
}
|
||||||
|
/* for logical */
|
||||||
|
} else if (pmt_use_logical)
|
||||||
|
{
|
||||||
|
sprintf(ppath, "/dev/block/mapper/%s", target_partition);
|
||||||
|
} else {
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
error("İnvalid partition type!\n", 30);
|
||||||
|
} else {
|
||||||
|
exit(49);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check partition */
|
||||||
|
if (access(ppath, F_OK) == -1)
|
||||||
|
{
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
error("Partition not found!\n", 31);
|
||||||
|
} else {
|
||||||
|
exit(31);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get target partition block size */
|
||||||
|
struct statvfs file_sys_inf;
|
||||||
|
if (statvfs(ppath, &file_sys_inf) != 0)
|
||||||
|
{
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "The partition block size could not be obtained!\n");
|
||||||
|
exit(49);
|
||||||
|
} else {
|
||||||
|
exit(49);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* generate mke2fs command */
|
||||||
|
sprintf(formatter_cmd, "mke2fs -Fq -t %s -b %lu %s", format_fs, file_sys_inf.f_bsize, ppath);
|
||||||
|
|
||||||
|
/* run command */
|
||||||
|
if (system(formatter_cmd) != 0)
|
||||||
|
{
|
||||||
|
if (!pmt_force_mode)
|
||||||
|
{
|
||||||
|
error("Formatting failed! There may be a chance that something has been damaged!\n", 71);
|
||||||
|
} else {
|
||||||
|
exit(71);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* end of code */
|
||||||
58
src/versioner.c
Normal file
58
src/versioner.c
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/* By YZBruh */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright 2024 Partition Manager
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "include/pmt.h"
|
||||||
|
|
||||||
|
void version()
|
||||||
|
{
|
||||||
|
printf("Version: %s (code %s) ", PMT_VERSION, PMT_VERSION_CODE);
|
||||||
|
|
||||||
|
#if __SIZEOF_POINTER__ == 4
|
||||||
|
printf("32-bit binary\n");
|
||||||
|
#elif __SIZEOF_POINTER__ == 8
|
||||||
|
printf("64-bit binary\n");
|
||||||
|
#else
|
||||||
|
printf("\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
printf("Compiler: clang %s ", __clang_version__);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
printf("(GNUC %d.%d.%d)\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||||
|
#else
|
||||||
|
printf("\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
printf("See licenses with -L argument.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* end of code */
|
||||||
Reference in New Issue
Block a user