35 Commits
1.7.0 ... 1.8.0

Author SHA1 Message Date
7cd20acd44 Update README.md 2024-05-05 20:52:56 +03:00
151a520a22 pmt: initial 1.9.0 update 2024-05-05 20:51:53 +03:00
ce017e2cbc pmt: move source in to src 2024-04-25 22:35:32 +03:00
b5daf8a44c pmt: move source in to src 2024-04-25 22:35:01 +03:00
f125ae760c pmt: move source in to src 2024-04-25 22:34:31 +03:00
f68f92ade1 pmt: move source in to src 2024-04-25 22:34:04 +03:00
3a723446cc pmt: move source in to src 2024-04-25 22:33:40 +03:00
1d66a3c21f pmt: move source in to src 2024-04-25 22:32:34 +03:00
13e31df7c6 pmt: move source in to src 2024-04-25 22:31:52 +03:00
4922ed5a35 pmt: move source in to src 2024-04-25 22:31:12 +03:00
3220aace91 pmt: move source in to src 2024-04-25 22:30:40 +03:00
7f85d63088 pmt: initial 1.8.0 update 2024-04-25 22:09:03 +03:00
412b697b9c pmt: initial 1.8.0 update 2024-04-25 22:08:30 +03:00
afc958aeb4 pmt: initial 1.8.0 update 2024-04-25 22:07:45 +03:00
fbd45e0936 pmt: initial 1.8.0 update 2024-04-25 22:07:05 +03:00
0ef8767eb5 pmt: initial 1.8.0 update 2024-04-25 22:06:31 +03:00
9bc871573e pmt: initial 1.8.0 update 2024-04-25 22:05:58 +03:00
adad63bbbd pmt: initial 1.8.0 update 2024-04-25 22:05:12 +03:00
0157c886ae pmt: initial 1.8.0 update 2024-04-25 22:04:33 +03:00
076774d9f4 pmt: initial 1.8.0 update 2024-04-25 22:04:00 +03:00
25642cc6f2 pmt: initial 1.8.0 update 2024-04-25 22:02:58 +03:00
16c8654fa2 pmt: initial 1.8.0 update 2024-04-25 22:02:04 +03:00
1fb592a94f pmt: initial 1.8.0 update 2024-04-25 22:01:14 +03:00
5bb26c9eea pmt: initial 1.8.0 update 2024-04-25 21:59:54 +03:00
540dd4fe35 pmt: initial 1.8.0 update 2024-04-25 21:59:06 +03:00
22ef985925 pmt: initial 1.8.0 update 2024-04-25 21:58:42 +03:00
2e81ab9541 pmt: initial 1.8.0 update 2024-04-25 21:57:50 +03:00
112a2986b5 pmt: initial 1.8.0 update 2024-04-25 21:56:59 +03:00
65fd480ba2 pmt: initial 1.8.0 update 2024-04-25 21:56:37 +03:00
d31bccd8f6 pmt: initial 1.8.0 update 2024-04-25 21:56:05 +03:00
6c574e9536 pmt: initial 1.8.0 update 2024-04-25 21:55:09 +03:00
a4838b24e1 pmt: initial 1.8.0 update 2024-04-25 21:54:10 +03:00
908060219e pmt: initial 1.8.0 update 2024-04-25 21:50:04 +03:00
ac06203a2c pmt: initial 1.8.0 update 2024-04-25 21:49:07 +03:00
56976b2bd0 pmt: initial 1.8.0 update 2024-04-25 21:48:43 +03:00
23 changed files with 627 additions and 204 deletions

View File

@@ -1,9 +1,12 @@
#### Version 1.7.0 (code 170):
- Force mode added
- Compatibility with C++ compilers ensured
- Code integrity fixed
- Exit codes have meanings. Review the code to understand
#### Version 1.8.0 (code 180):
- Add formatting support (only ext2/3/4 file systems)
- new features were added to the building system to create deb (debian) packages
- Edit some commands that the building system offers. One was removed. Some of them have changed
- More talent was added to the additional features offered by the building system and a simpler pleasant advance was presented
- A more detailed building system was created using separate makefiles
- 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.7.0 CHANGELOG |
| END OF VERSION 1.8.0 CHANGELOG |
|------------------------------------|

259
Makefile
View File

@@ -1,6 +1,6 @@
# By YZBruh
# Copyright 2024 YZBruh - Partition Backupper
# 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.
@@ -14,119 +14,196 @@
# See the License for the specific language governing permissions and
# limitations under the License.
include config/vars.mk
include config/env.mk
include config/source.mk
-include config/INS_STAT.mk
-include config/UNINS_STAT.mk
# speficy {version}
VERSION := 1.7.0
VERSION_CODE := 170
SOURCE_DIR := binary
TARGET := pmt
LANG := en
ARCH := $(shell uname -m)
CUR_DIR := $(shell pwd)
# sources
SRCS := $(SOURCE_DIR)/$(TARGET).c
SRCS += $(SOURCE_DIR)/error.c
SRCS += $(SOURCE_DIR)/checkers.c
SRCS += $(SOURCE_DIR)/listpart.c
SRCS += $(SOURCE_DIR)/flash.c
SRCS += $(SOURCE_DIR)/backup.c
SRCS += $(SOURCE_DIR)/docs.c
# objects
OBJS := $(SOURCE_DIR)/$(TARGET).o
OBJS += $(SOURCE_DIR)/error.o
OBJS += $(SOURCE_DIR)/checkers.o
OBJS += $(SOURCE_DIR)/listpart.o
OBJS += $(SOURCE_DIR)/flash.o
OBJS += $(SOURCE_DIR)/backup.o
OBJS += $(SOURCE_DIR)/docs.o
OUT_DIR := $(CUR_DIR)/out
BINARY_DIR := $(OUT_DIR)/binary
PACKAGE_DIR := $(OUT_DIR)/package
# display
# start build (if no custom target)
.PHONY: all
all:
@printf " --- Building Partition Manager --- \n"; \
printf "Version: $(VERSION)\n"; \
printf "Version code: $(VERSION_CODE)\n\n"; \
printf " ------------------------------------- \n\n"; \
printf "Starting build... Please waith.\n"; \
@printf " ---- Building Partition Manager ---- \n\n"; \
printf " - Version: $(VERSION)\n"; \
printf " - Version code: $(VERSION_CODE)\n\n"; \
printf " -------------------------------- \n\n"; \
printf " - Building... Please waith.\n"; \
sleep 2; \
printf "Make running with silent mode...\n"; \
make -s pmt;
# build progress
.PHONY: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS)
@mkdir -p $(OUT_DIR); \
$(CC) $(CFLAGS) -o $(TARGET) $(SRCS) || exit 1; \
mkdir -p $(OUT_DIR); \
mkdir -p $(BINARY_DIR); \
mkdir -p $(PACKAGE_DIR); \
mv pmt $(BINARY_DIR); \
printf "Generating gzip package...\n"; \
cp $(BINARY_DIR)/pmt $(PACKAGE_DIR); \
gzip -f $(PACKAGE_DIR)/pmt; \
mv $(PACKAGE_DIR)/pmt.gz $(PACKAGE_DIR)/pmt-$(ARCH)-$(LANG).gz; \
printf " \n"; \
printf " ------------------------------------- \n";
mv pmt $(BINARY_DIR) || exit 1; \
printf " - Generating xz package...\n"; \
cp $(BINARY_DIR)/pmt $(PACKAGE_DIR) || exit 1; \
xz $(PACKAGE_DIR)/pmt; \
mv $(PACKAGE_DIR)/pmt.xz $(PACKAGE_DIR)/pmt-$(ARCH)-$(LANG).xz || exit 1; \
printf " - Success\n\n"; \
printf " ------------------------------------ \n";
# cleaner functions
.PHONY: clean
clean:
@printf "Cleaning (builded files [.o extended])...\n"; \
sleep 2; \
rm -rf $(OBJS); \
printf "Success\n";
.PHONY: clean-all
clean-all:
@printf "Cleaning (builded files [.o extended] and binary)...\n"; \
sleep 2; \
rm -rf $(OBJS) $(OUT_DIR); \
@printf "Cleaning with rm force mode (builded binary)...\n"; \
sleep 1; \
rm -rf $(OUT_DIR); \
printf "Success\n";
# helper function
.PHONY: help
help:
@printf " --------- Partition Manager help ---------\n"; \
@printf " ------- Partition Manager help -------\n"; \
printf " \n"; \
printf " Commands;\n"; \
printf " make ==> Build Partition Manager\n"; \
printf " make clean ==> Clear files (Builded binaries are not deleted)\n"; \
printf " make clean-all ==> Clear files (Builded binaries are deleted)\n"; \
printf " make install-termux ==> If you are using termux, it installs the compiled pmt into termux. So it allows you to use it like a normal command.\n"; \
printf " make uninstall-termux ==> If you are using termux, it uninstalls the compiled pmt into termux.\n"; \
printf " make help ==> Display help message\n"; \
printf " \n";
printf " make deb ==> Generate deb (debian) package (compatibility => termux)\n"; \
printf " make clean ==> Clear builded binary.\n"; \
printf " make install ==> If you are using termux, it installs the compiled pmt into termux. So it allows you to use it like a normal command.\n"; \
printf " 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.\n"; \
printf " make help ==> Display help message\n\n";
# deb maker
.PHONY: deb
deb:
@printf " --------- Making deb package ---------\n"; \
printf " - Checking all files and directories (only neededs)...\n"; \
if [ ! -d $(DEBUTILS_DIR) ]; then \
printf " - Not found: $(DEBUTILS_DIR) \n"; \
exit 1; \
fi; \
if [ ! -d $(DEBUTILS_DIR)/DEBIAN ]; then \
printf " - Not found: $(DEBUTILS_DIR)/DEBIAN \n"; \
exit 1; \
fi; \
if [ ! -d $(DEBUTILS_DIR)/mandoc ]; then \
printf " - Not found: $(DEBUTILS_DIR)/mandoc \n"; \
exit 1; \
fi; \
if [ ! -d $(DEBUTILS_DIR)/data/data/com.termux ]; then \
printf " - Not found: $(DEBUTILS_DIR)/data/data/com.termux \n"; \
exit 1; \
fi; \
if [ ! -d $(DEBUTILS_DIR)/data/data/com.termux/files/usr ]; then \
printf " - Not found: $(DEBUTILS_DIR)/data/data/com.termux/files/usr \n"; \
exit 1; \
fi; \
if [ ! -d $(DEBUTILS_DIR)/data/data/com.termux/files/usr/bin ]; then \
printf " - Not found: $(DEBUTILS_DIR)/data/data/com.termux/files/usr/bin \n"; \
exit 1; \
fi; \
if [ ! -d $(DEBUTILS_DIR)/data/data/com.termux/files/usr/share/man/man1 ]; then \
printf " - Not found: $(DEBUTILS_DIR)/data/data/com.termux/files/usr/share/man/man1 \n"; \
exit 1; \
fi; \
if [ ! -f $(DEBUTILS_DIR)/mandoc/pmt.1 ]; then \
printf " - Not found: $(DEBUTILS_DIR)/mandoc/pmt.1 \n"; \
exit 1; \
fi; \
if [ ! -f $(DEBUTILS_DIR)/DEBIAN/control_32 ]; then \
printf " - Not found: $(DEBUTILS_DIR)/DEBIAN/control_32 \n"; \
exit 1; \
fi; \
if [ ! -f $(DEBUTILS_DIR)/DEBIAN/control_64 ]; then \
printf " - Not found: $(DEBUTILS_DIR)/DEBIAN/control_64 \n"; \
exit 1; \
fi; \
if [ ! -f $(BINARY_DIR)/pmt ]; then \
printf " - Package not builded! Please build package and try again \n"; \
exit 1; \
fi; \
printf " - Generating template dir...\n"; \
mkdir -p $(DEBUTILS_DIR)/temp; \
printf " - Generating out dir...\n"; \
mkdir -p $(DEB_DIR); \
printf " - Copying files...\n"; \
rm -f $(DEBTERMUX_USR)/share/man/man1/dummy; \
rm -f $(DEBTERMUX_USR)/bin/dummy; \
cp -r $(DEBUTILS_DIR)/data $(DEBUTILS_DIR)/temp || exit 1; \
mkdir -p $(DEBUTILS_DIR)/temp/DEBIAN; \
if [ "$(ARCH)" = "aarch64" ] || [ "$(ARCH)" = "armv8l" ]; then \
printf " - Selected arm-64 package control file.\n"; \
cp $(DEBUTILS_DIR)/DEBIAN/control_64 $(DEBUTILS_DIR)/temp/DEBIAN/control || exit 1; \
elif [ "$(ARCH)" = "aarch32" ] || [ "$(ARCH)" = "armv7l" ]; then \
printf " - Selected arm-32 package control file.\n"; \
cp $(DEBUTILS_DIR)/DEBIAN/control_32 $(DEBUTILS_DIR)/temp/DEBIAN/control || exit 1; \
fi; \
cp $(DEBUTILS_DIR)/mandoc/pmt.1 $(DEBTERMUX_USR)/share/man/man1 || exit 1; \
cp $(BINARY_DIR)/pmt $(DEBTERMUX_USR)/bin || exit 1; \
printf " - Starting dpkg-deb...\n"; \
sleep 2; \
chmod -R 755 *; \
dpkg-deb -b $(DEBUTILS_DIR)/temp $(DEB_DIR)/pmt-$(ARCH)-$(LANG).deb || exit 1; \
rm -r $(DEBUTILS_DIR)/temp || exit 1; \
printf " - Done! Package: $(DEB_DIR)/pmt-$(ARCH)-$(LANG).deb\n"
# installer
.PHONY: install-termux
install-termux:
@if [ -f /data/data/com.termux/files/usr/bin/termux-open ]; then \
printf " ------------------------------------- \n"; \
printf " pmt installer \n"; \
printf " ------------------------------------- \n"; \
cp $(BINARY_DIR)/pmt /data/data/com.termux/files/usr/bin/pmt || exit 1; \
chmod 777 /data/data/com.termux/files/usr/bin/pmt || exit 1; \
printf " \n"; \
printf "Success.\n\n"; \
.PHONY: install
install:
@if [ -f $(TERMUX_BIN)/termux-open ]; then \
printf " ------------ pmt installer ------------ \n"; \
if [ -f $(TERMUX_BIN)/pmt ]; then \
printf " - pmt already installed\n"; \
exit; \
fi; \
if [ ! "$(INSTALL_SUCCESS)" = "true" ] && [ ! "$(INSTALL_SUCCESS)" = "" ]; then \
printf " - Warning: a previously-stayed failed installation process found\n"; \
fi; \
printf " - Checking files...\n"; \
if [ ! -f $(BINARY_DIR)/pmt ]; then \
printf " - Package not builded! Please build package and try again \n"; \
echo "INSTALL_SUCCESS := false" > $(CUR_DIR)/config/INS_STAT.mk; \
exit 1; \
fi; \
printf " - Copying files...\n"; \
if [ "`cp $(BINARY_DIR)/pmt /data/data/com.termux/files/usr/bin/pmt`" = "" ]; then \
printf " - Setting up permissions...\n"; \
else \
echo "INSTALL_SUCCESS := false" > $(CUR_DIR)/config/INS_STAT.mk; \
exit 1; \
fi; \
if [ "`chmod 777 $(TERMUX_BIN)/pmt`" = "" ]; then \
printf " - Saving current status...\n"; \
echo "INSTALL_SUCCESS := true" > $(CUR_DIR)/config/INS_STAT.mk; \
else \
echo "INSTALL_SUCCESS := false" > $(CUR_DIR)/config/INS_STAT.mk; \
exit 1; \
fi; \
printf " - Success.\n\n"; \
echo "INSTALL_SUCCESS := true" > $(CUR_DIR)/config/INS_STAT.mk; \
echo "UNINSTALLED_SUCCESS := " > $(CUR_DIR)/config/UNINS_STAT.mk; \
else \
printf "This function is only available on Termux Android devices using aarch64 (64-bit) and armv7l (32-bit)\n"; \
printf " - This function is only available on Termux.\n"; \
fi
# uninstaller
.PHONY: uninstall-termux
uninstall-termux:
@if [ -f /data/data/com.termux/files/usr/bin/termux-open ]; then \
printf " ------------------------------------- \n"; \
printf " pmt uninstaller \n"; \
printf " ------------------------------------- \n"; \
rm /data/data/com.termux/files/usr/bin/pmt || exit 1; \
printf " \n"; \
printf "Success.\n\n"; \
.PHONY: uninstall
uninstall:
@if [ -f $(TERMUX_BIN)/termux-open ]; then \
printf " ----------- pmt uninstaller ----------- \n"; \
if [ ! -f $(TERMUX_BIN)/pmt ]; then \
printf " - pmt already uninstalled\n"; \
exit; \
fi; \
if [ ! "$(UNINSTALL_SUCCESS)" = "true" ] && [ ! "$(UNINSTALL_SUCCESS)" = "" ]; then \
printf " - Warning: a previously-stayed failed uninstallation process found\n"; \
fi; \
if [ -f $(TERMUX_USR)/share/man/man1/pmt.1 ]; then \
printf " - It was found to be established by pmt's deb pack. It's removed with apt...\n"; \
apt remove -y pmt || exit 1; \
printf " - Success.\n\n"; \
echo "UNINSTALLED_SUCCESS := true" > $(CUR_DIR)/config/UNINS_STAT.mk; \
echo "INSTALL_SUCCESS := " > $(CUR_DIR)/config/INS_STAT.mk; \
else \
printf " - It was found that pmt was manually established (with this makefile or copying). Manually removed...\n"; \
if [ "`rm $(TERMUX_BIN)/pmt`" = "" ]; then \
printf " - Success.\n\n"; \
echo "UNINSTALLED_SUCCESS := true" > $(CUR_DIR)/config/UNINS_STAT.mk; \
echo "INSTALL_SUCCESS := " > $(CUR_DIR)/config/INS_STAT.mk; \
else \
echo "UNINSTALLED_SUCCESS := false" > $(CUR_DIR)/config/UNINS_STAT.mk; \
exit 1; \
fi; \
fi; \
else \
printf "This function is only available on Termux Android devices using aarch64 (64-bit) and armv7l (32-bit)\n"; \
printf "This function is only available on Termux.\n"; \
fi

2
NOTICE
View File

@@ -1,4 +1,4 @@
Copyright 2024 YZBruh - Partition Manager
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.

View File

@@ -1,6 +1,6 @@
## Partition Manager (pmt)
This binary static C library is for manage partitions of android devices.
This binary C is for manage partitions of android devices.
It offers a lot of options. I will place these below. But first let me talk about the operation...
```
@@ -15,6 +15,7 @@ It offers a lot of options. I will place these below. But first let me talk abou
Usage:
-b | --backup backup mode
-F | --flash flash mode
-r | --format format mode (only ext2/3/4 file systems)
-p | --partition name of the partition to be backed up
-l | --logical know that the partition that will be backed up is logical
-o | --out (only backups) the output name of the backed-up partition (default: partition name)
@@ -23,7 +24,7 @@ Usage:
-D | --list list partitions
-f | --force force mode. Output is not produced. Even if it's a mistake. But if the target is not a mode, the error is given. If you want to work stable, it is important to specify this option first.
-v | --version see version
--help see help message
--help see help message
-L | --license see license
Examples:
@@ -40,7 +41,7 @@ Report bugs to <yagizzengin73@gmail.com>
- 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.
- 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.7.0-en/CHANGELOG.md)
- [Click to see special version changes](https://github.com/YZBruh/pbt/blob/1.8.0-en/CHANGELOG.md)
- Let me know your suggestions!
### How is it built?
@@ -56,15 +57,15 @@ make
Special `make` commands (pbt offers :) ;
```
--------- Partition Manager help ---------
------- Partition Manager help -------
Commands;
make ==> Build Partition Manager
make clean ==> Clear files (Builded binaries are not deleted)
make clean-all ==> Clear files (Builded binaries are deleted)
make install-termux ==> If you are using termux, it installs the compiled pmt into termux. So it allows you to use it like a normal command.
make uninstall-termux ==> If you are using termux, it uninstalls the compiled pmt into termux.
make deb ==> Generate deb (debian) package (compatibility => termux)
make clean ==> Clear builded binary.
make install ==> If you are using termux, it installs 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
```
I compiled it with termux :D. Why should I bother... I compiled it with `GCC 18.0.2` You can look at the version with the viewing option :)
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 :)

1
config/INS_STAT.mk Normal file
View File

@@ -0,0 +1 @@
INSTALL_SUCCESS :=

1
config/UNINS_STAT.mk Normal file
View File

@@ -0,0 +1 @@
UNINSTALL_SUCCESS :=

View File

@@ -1,6 +1,6 @@
# By YZBruh
# Copyright 2024 YZBruh - Partition Manager
# 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.
@@ -30,7 +30,7 @@ USE_CUST_GCC := false
CUST_GCC :=
# addionital gcc flags
EXTRA_GCC_FLAGS :=
EXTRA_GCC_FLAGS :=
#########################################
#########################################

29
config/source.mk Normal file
View File

@@ -0,0 +1,29 @@
# By YZBruh
# Copyright 2024 YZBruh - 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.
# sources
SRCS := \
$(SOURCE_DIR)/$(TARGET).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:
# 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...

38
config/vars.mk Normal file
View File

@@ -0,0 +1,38 @@
# 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.
# speficy
VERSION := 1.8.0
VERSION_CODE := 180
TARGET := pmt
LANG := en
# device arch info
ARCH := $(shell uname -m)
# current directory
CUR_DIR := $(shell pwd)
# others needed important variables
SOURCE_DIR := $(CUR_DIR)/src
OUT_DIR := $(CUR_DIR)/out
BINARY_DIR := $(OUT_DIR)/binary
PACKAGE_DIR := $(OUT_DIR)/package
DEB_DIR := $(OUT_DIR)/deb
DEBUTILS_DIR := $(CUR_DIR)/debutils
DEBTERMUX_USR := $(DEBUTILS_DIR)/temp/data/data/com.termux/files/usr
TERMUX_BIN := /data/data/com.termux/files/usr/bin
TERMUX_USR := /data/data/com.termux/files/usr

View File

@@ -0,0 +1,10 @@
Source: pmt
Package: pmt
Version: 1.8.0
Architecture: arm
Description: pmt is for reading, writing and formatting partitions of android devices
Section: misc
Priority: optional
Maintainer: YZBruh <yagizzengin73@gmail.com>
Build-Depends: debhelper (>= 10), clang, make
Standards-Version: 4.5.0

View File

@@ -0,0 +1,10 @@
Source: pmt
Package: pmt
Version: 1.8.0
Architecture: aarch64
Description: pmt is for reading, writing and formatting partitions of android devices
Section: misc
Priority: optional
Maintainer: YZBruh <yagizzengin73@gmail.com>
Build-Depends: debhelper (>= 10), clang, make
Standards-Version: 4.5.0

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1 @@

25
debutils/mandoc/pmt.1 Normal file
View File

@@ -0,0 +1,25 @@
PMT Android Partition Manager 1.8.0
OPTIONS:
-b | --backup backup mode
-F | --flash flash mode
-r | --format format mode (only ext2/3/4 file systems)
-p | --partition name of the partition to be backed up
-l | --logical know that the partition that will be backed up is logical
-o | --out (only backups) the output name of the backed-up partition (default: partition name)
-d | --outdir (only backups) directory where the backup partition will be saved (default: /storage/emulated/0)
-c | --context it is meant to specify a custom /dev context. Only classic partitions (default: /dev/block/by-name)
-D | --list list partitions
-f | --force force mode. Output is not produced. Even if it's a mistake. But if the target is not a mode, the error is given. If you want to work stable, it is important to specify this option first.
-v | --version see version
--help see help message
-L | --license see license
EXAMPLES:
-b --partition boot_a -o boot_slot_a_image -d /sdcard/backup -c /dev/block/platform/bootdevice/by-name
--flash /sdcard/twrp/boot.img -p boot_a -c /dev/block/platform/bootdevice/by-name
-c /dev/block/platform/bootdevice/by-name --list
BUGS:
Report bugs to <yagizzengin73@gmail.com>

View File

@@ -1,7 +1,7 @@
/* By YZBruh */
/*
* Copyright 2024 YZBruh - Partition Manager
* 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.
@@ -26,6 +26,7 @@ extern "C" {
#include <sys/stat.h>
#include <string.h>
#include <stdbool.h>
#include <stddef.h>
#include "include/pmt.h"
@@ -40,24 +41,30 @@ extern bool pmt_force_mode;
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) {
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) {
} else if (strstr(backup_partition_style, "logical") != NULL)
{
sprintf(backupper_path, "/dev/block/mapper/%s", target_backup_partition);
} else {
if (!pmt_force_mode) {
if (!pmt_force_mode)
{
error("İnvalid partition type!\n", 28);
} else {
exit(28);
}
}
if (access(backupper_path, F_OK) == -1) {
if (!pmt_force_mode) {
if (access(backupper_path, F_OK) == -1)
{
if (!pmt_force_mode)
{
error("Partition not found!\n", 29);
} else {
exit(29);
@@ -65,35 +72,43 @@ void backup(char *target_backup_partition, char *backup_partition_style)
}
static char backupper_cmd[256];
if (outdir != NULL) {
if (out != NULL) {
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) {
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) {
if (system(backupper_cmd) != 0)
{
if (!pmt_force_mode)
{
error("Failed!\n", 99);
} else {
exit(EXIT_FAILURE);
}
} else {
if (outdir != NULL) {
if (out != NULL) {
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) {
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);

View File

@@ -1,7 +1,7 @@
/* By YZBruh */
/*
* Copyright 2024 YZBruh - Partition Manager
* 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.
@@ -25,6 +25,7 @@ extern "C" {
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stddef.h>
#include <errno.h>
#include "include/pmt.h"
@@ -39,16 +40,19 @@ extern char *cust_cxt;
void check_psf()
{
/* true = ab | false = a */
if (pmt_use_cust_cxt) {
if (pmt_use_cust_cxt)
{
static char cust_cxt_ck_path[150];
sprintf(cust_cxt_ck_path, "%s/boot_a", cust_cxt);
if (access(cust_cxt_ck_path, F_OK) != 0) {
if (access(cust_cxt_ck_path, F_OK) != 0)
{
pmt_ab = false;
} else {
pmt_ab = true;
}
} else {
if (access("/dev/block/by-name/boot_a", F_OK) != 0) {
if (access("/dev/block/by-name/boot_a", F_OK) != 0)
{
pmt_ab = false;
} else {
pmt_ab = true;
@@ -56,16 +60,19 @@ void check_psf()
}
/* true = logical | false = classic */
if (pmt_use_cust_cxt) {
if (pmt_use_cust_cxt)
{
static char cust_cxt_ckl_path[150];
sprintf(cust_cxt_ckl_path, "%s/super", cust_cxt);
if (access(cust_cxt_ckl_path, F_OK) != 0) {
if (access(cust_cxt_ckl_path, F_OK) != 0)
{
pmt_logical = false;
} else {
pmt_logical = true;
}
} else {
if (access("/dev/block/by-name/super", F_OK) != 0) {
if (access("/dev/block/by-name/super", F_OK) != 0)
{
pmt_logical = false;
} else {
pmt_logical = true;
@@ -77,8 +84,10 @@ void check_psf()
void check_root()
{
/* a quick, easy method to verify root :D */
if (chdir("/dev/block") != 0) {
if (!pmt_force_mode) {
if (chdir("/dev/block") != 0)
{
if (!pmt_force_mode)
{
fprintf(stderr, ANSI_RED "Root privileges could not be detected! Please run this binary with root. Error reason: %s\n" ANSI_RESET, strerror(errno));
exit(27);
} else {

View File

@@ -1,7 +1,7 @@
/* By YZBruh */
/*
* Copyright 2024 YZBruh - Partition Manager
* 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.
@@ -27,7 +27,7 @@ extern "C" {
void licenses()
{
printf("Copyright 2024 YZBruh - Partition Manager\n");
printf("Copyright 2024 Partition Manager\n");
printf("Licensed under the Apache License, Version 2.0 (the \"License\");\n");
printf("you may not use this file except in compliance with the License.\n");
printf("You may obtain a copy of the License at\n\n");
@@ -43,6 +43,7 @@ void help()
printf("Usage: \n");
printf(" -b | --backup backup mode\n");
printf(" -F | --flash flash mode\n");
printf(" -r | --format format mode (only ext2/3/4 file systems)\n");
printf(" -p | --partition name of the partition to be backed up\n");
printf(" -l | --logical know that the partition that will be backed up is logical\n");
printf(" -o | --out (only backups) the output name of the backed-up partition (default: partition name)\n");
@@ -57,7 +58,7 @@ void help()
printf(" -b --partition boot_a -o boot_slot_a_image -d /sdcard/backup -c /dev/block/platform/bootdevice/by-name\n");
printf(" --flash /sdcard/twrp/boot.img -p boot_a -c /dev/block/platform/bootdevice/by-name\n");
printf(" -c /dev/block/platform/bootdevice/by-name --list\n\n");
printf("Report bugs to <xda-@YZBruh>\n");
printf("Report bugs to <yagizzengin73@gmail.com>\n");
}
#ifdef __cplusplus

View File

@@ -1,7 +1,7 @@
/* By YZBruh */
/*
* Copyright 2024 YZBruh - Partition Manager
* 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.

View File

@@ -1,7 +1,7 @@
/* By YZBruh */
/*
* Copyright 2024 YZBruh - Partition Manager
* 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.
@@ -39,17 +39,21 @@ void flash(char *target_flash_partition, char *target_file, char *flash_partitio
static char flasher_path[200];
/* determine device block */
/* for classic */
if (strstr(flash_partition_style, "classic") != NULL) {
if (pmt_use_cust_cxt) {
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) {
} else if (strstr(flash_partition_style, "logical") != NULL)
{
sprintf(flasher_path, "/dev/block/mapper/%s", target_flash_partition);
} else {
if (!pmt_force_mode) {
if (!pmt_force_mode)
{
error("İnvalid partition type!\n", 30);
} else {
exit(30);
@@ -57,8 +61,10 @@ void flash(char *target_flash_partition, char *target_file, char *flash_partitio
}
/* check partition */
if (access(flasher_path, F_OK) == -1) {
if (!pmt_force_mode) {
if (access(flasher_path, F_OK) == -1)
{
if (!pmt_force_mode)
{
error("Partition not found!\n", 31);
} else {
exit(31);
@@ -70,8 +76,10 @@ void flash(char *target_flash_partition, char *target_file, char *flash_partitio
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) {
if (system(flasher_cmd) != 0)
{
if (!pmt_force_mode)
{
error("Failed!\n", 98);
} else {
exit(98);

107
src/format.c Normal file
View File

@@ -0,0 +1,107 @@
/* 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 */

View File

@@ -1,7 +1,7 @@
/* By YZBruh */
/*
* Copyright 2024 YZBruh - Partition Manager
* 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.
@@ -28,12 +28,12 @@ extern "C" {
#endif
/* compiler architecture if arm is not 32-bit or 64-bit, the compilation is stopped */
#if ! defined __arm__ || __aarch64__ || __aarch32__ || __armv8__ || __armv7l__
#if ! __SIZEOF_POINTER__ == 4 || ! __SIZEOF_POINTER__ == 8
#error "only 32-bit or 64-bit arm compilers can be used"
#endif
#ifndef _COMMON_H_
#define _COMMON_H_
#ifndef _PMT_H
#define _PMT_H
/* color definations */
#define ANSI_RED "\033[31m"
@@ -42,8 +42,8 @@ extern "C" {
#define ANSI_RESET "\033[0m"
/* info */
#define PMT_VERSION "1.7.0"
#define PMT_VERSION_CODE "170"
#define PMT_VERSION "1.8.0"
#define PMT_VERSION_CODE "180"
#define PMT_PACKAGE_NAME "Partition Manager"
#define PMT_PACKAGE_LANG "en"
@@ -53,12 +53,14 @@ extern char *outdir;
extern char *cust_cxt;
extern char *target_partition;
extern char *target_flash_file;
extern char *format_fs;
extern bool pmt_use_logical;
extern bool pmt_use_cust_cxt;
extern bool pmt_ab;
extern bool pmt_logical;
extern bool pmt_flash;
extern bool pmt_backup;
extern bool pmt_format;
extern bool pmt_force_mode;
/* function definations */
@@ -68,12 +70,14 @@ void check_psf();
void check_root();
void backup(char *target_backup_partition, char *backup_partition_style);
void flash(char *target_flash_partition, char *target_file, char *flash_partition_style);
void format(char *target_format_partition, char *format_partition_style);
void help();
void licenses();
#endif
#endif /* _PMT_H */
#ifdef __cplusplus
}
#endif
/* end of code */

View File

@@ -1,7 +1,7 @@
/* By YZBruh */
/*
* Copyright 2024 YZBruh - Partition Manager
* 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.
@@ -40,9 +40,11 @@ void listpart() {
DIR *dir;
struct dirent *entry;
if (pmt_use_cust_cxt) {
if (pmt_use_cust_cxt)
{
dir = opendir(cust_cxt);
if (dir == NULL) {
if (dir == NULL)
{
if (!pmt_force_mode) {
fprintf(stderr, "Could not open: `%s`. Error reason: %s\n", cust_cxt, strerror(errno));
exit(62);
@@ -52,8 +54,10 @@ void listpart() {
}
} else {
dir = opendir("/dev/block/by-name");
if (dir == NULL) {
if (!pmt_force_mode) {
if (dir == NULL)
{
if (!pmt_force_mode)
{
fprintf(stderr, "Could not open: `/dev/block/by-name`. Error reason: %s\n", strerror(errno));
exit(63);
} else {
@@ -68,18 +72,22 @@ void listpart() {
closedir(dir);
if (pmt_logical) {
if (pmt_logical)
{
printf("List of logical partitions (/dev/block/mapper): \n");
if (system("ls /dev/block/mapper") != 0 && !pmt_force_mode) {
if (system("ls /dev/block/mapper") != 0 && !pmt_force_mode)
{
error("An error occurred when the logical partition list appears!\n", 64);
}
}
if (pmt_ab && !pmt_force_mode) {
if (pmt_ab && !pmt_force_mode)
{
printf("%sWarning: device using A/B partition style.%s\n", ANSI_YELLOW, ANSI_RESET);
}
if (pmt_logical && !pmt_force_mode) {
if (pmt_logical && !pmt_force_mode)
{
printf("%sWarning: device using logical partition type.%s\n", ANSI_YELLOW, ANSI_RESET);
}
}

View File

@@ -1,7 +1,7 @@
/* By YZBruh */
/*
* Copyright 2024 YZBruh - Partition Manager
* 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.
@@ -36,20 +36,23 @@ char *outdir = NULL;
char *cust_cxt = NULL;
char *target_partition = NULL;
char *target_flash_file = NULL;
char *format_fs = NULL;
bool pmt_use_logical = NULL;
bool pmt_use_cust_cxt = NULL;
bool pmt_ab = false;
bool pmt_logical = false;
bool pmt_flash = false;
bool pmt_backup = false;
bool pmt_format = false;
bool pmt_force_mode = false;
/* classic main function (C binary here xd) */
int main(int argc, char *argv[])
{
/* check argument total */
if (argc < 2) {
fprintf(stderr, "%s: missing operand\nTry `%s --help` for more information.\n", argv[0], argv[0]);
if (argc < 2)
{
fprintf(stderr, "%s: missing operand\nTry `%s --help' for more information.\n", argv[0], argv[0]);
exit(44);
}
@@ -57,6 +60,7 @@ int main(int argc, char *argv[])
struct option long_options[] = {
{"backup", no_argument, 0, 'b'},
{"flash", required_argument, 0, 'F'},
{"format", required_argument, 0, 'r'},
{"partition", required_argument, 0, 'p'},
{"logical", no_argument, 0, 'l'},
{"out", required_argument, 0, 'o'},
@@ -75,16 +79,20 @@ int main(int argc, char *argv[])
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;
/* control for each argument */
while ((opt = getopt_long(argc, argv, "bF:p: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 */
switch (opt) {
switch (opt)
{
case 'b':
pmt_backup = true;
break;
case 'F':
target_flash_file = strdup(optarg);
if (strncmp(target_flash_file, opt_symbol, 1) == 0) {
if (!pmt_force_mode) {
if (strncmp(target_flash_file, opt_symbol, 1) == 0)
{
if (!pmt_force_mode)
{
error(common_symbol_rule, 19);
} else {
exit(19);
@@ -94,16 +102,20 @@ int main(int argc, char *argv[])
check_root();
check_psf();
struct stat flashf_info;
if (stat(target_flash_file, &flashf_info) != 0) {
if (!pmt_force_mode) {
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) {
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 {
@@ -112,10 +124,36 @@ int main(int argc, char *argv[])
}
}
break;
case 'r':
format_fs = strdup(optarg);
if (strncmp(format_fs, opt_symbol, 1) == 0)
{
if (!pmt_force_mode)
{
fprintf(stderr, "%s", common_symbol_rule);
exit(71);
} else {
exit(71);
}
}
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;
case 'p':
target_partition = strdup(optarg);
if (strncmp(target_partition, opt_symbol, 1) == 0) {
if (!pmt_force_mode) {
if (strncmp(target_partition, opt_symbol, 1) == 0)
{
if (!pmt_force_mode)
{
error(common_symbol_rule, 19);
} else {
exit(19);
@@ -125,10 +163,12 @@ int main(int argc, char *argv[])
case 'l':
check_root();
check_psf();
if (pmt_logical) {
if (pmt_logical)
{
pmt_use_logical = true;
} else {
if (!pmt_force_mode) {
if (!pmt_force_mode)
{
error("This device does not have logical partitions!\n", 17);
} else {
exit(17);
@@ -137,8 +177,10 @@ int main(int argc, char *argv[])
break;
case 'o':
out = strdup(optarg);
if (strncmp(out, opt_symbol, 1) == 0) {
if (!pmt_force_mode) {
if (strncmp(out, opt_symbol, 1) == 0)
{
if (!pmt_force_mode)
{
error(common_symbol_rule, 19);
} else {
exit(19);
@@ -147,8 +189,10 @@ int main(int argc, char *argv[])
break;
case 'd':
outdir = strdup(optarg);
if (strncmp(outdir, opt_symbol, 1) == 0) {
if (!pmt_force_mode) {
if (strncmp(outdir, opt_symbol, 1) == 0)
{
if (!pmt_force_mode)
{
error(common_symbol_rule, 19);
} else {
exit(19);
@@ -157,16 +201,20 @@ int main(int argc, char *argv[])
check_root();
check_psf();
struct stat out_info;
if (stat(outdir, &out_info) != 0) {
if (!pmt_force_mode) {
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) {
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 {
@@ -178,8 +226,10 @@ int main(int argc, char *argv[])
case 'c':
pmt_use_cust_cxt = true;
cust_cxt = strdup(optarg);
if (strncmp(cust_cxt, opt_symbol, 1) == 0) {
if (!pmt_force_mode) {
if (strncmp(cust_cxt, opt_symbol, 1) == 0)
{
if (!pmt_force_mode)
{
error(common_symbol_rule, 19);
} else {
exit(19);
@@ -220,19 +270,22 @@ int main(int argc, char *argv[])
exit(43);
break;
default:
printf("Usage: %s [-b | --backup] [-f | --flash FILE] [-p | --partition PARTITION] [-l | --logical] [-o | --out OUTNAME] [-d | --outdir OUTDIR] [-c | --context] [-D | --list] [-v | --version] [--help] [-L | --license]\n", argv[0]);
printf("Usage: %s [-b | --backup] [-f | --flash FILE] [-r | --format FS_TYPE] [-p | --partition PARTITION] [-l | --logical] [-o | --out OUTNAME] [-d | --outdir OUTDIR] [-c | --context] [-D | --list] [-v | --version] [--help] [-L | --license]\n", argv[0]);
exit(44);
}
}
/* minor checks */
if (!pmt_backup && !pmt_flash) {
if (!pmt_backup && !pmt_flash)
{
fprintf(stderr, "%s: missing operand.\nTry `%s --help` for more information.\n", argv[0], argv[0]);
exit(3);
}
if (pmt_backup && pmt_flash) {
if (!pmt_force_mode) {
if (pmt_backup && pmt_flash)
{
if (!pmt_force_mode)
{
error("Backup and flash functions cannot be used in the same command\n", 9);
} else {
exit(9);
@@ -244,11 +297,15 @@ int main(int argc, char *argv[])
check_psf();
/* custom context checker */
if (pmt_use_cust_cxt) {
if (pmt_use_cust_cxt)
{
struct stat cxtinfo;
if (stat(cust_cxt, &cxtinfo) == 0) {
if (!S_ISREG(cxtinfo.st_mode)) {
if (!pmt_force_mode) {
if (stat(cust_cxt, &cxtinfo) == 0)
{
if (!S_ISREG(cxtinfo.st_mode))
{
if (!pmt_force_mode)
{
fprintf(stderr, "%s: %s: is a not directory.\n", argv[0], cust_cxt);
exit(8);
} else {
@@ -256,42 +313,59 @@ int main(int argc, char *argv[])
}
}
} else {
if (!pmt_force_mode) {
if (!pmt_force_mode)
{
fprintf(stderr, "%s: %s: %s\n", argv[0], cust_cxt, strerror(errno));
exit(6);
} else {
exit(6);
}
}
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);
}
}
if (target_partition == NULL) {
if (!pmt_force_mode) {
if (target_partition == NULL)
{
if (!pmt_force_mode)
{
fprintf(stderr, "%s: required partition name.\nTry `%s --help' for more information.\n", argv[0], argv[0]);
exit(5);
} else {
exit(5);
}
} else {
if (pmt_backup) {
if (pmt_use_logical) {
if (pmt_backup)
{
if (pmt_use_logical)
{
backup(target_partition, "logical");
exit(EXIT_SUCCESS);
} else {
backup(target_partition, "classic");
exit(EXIT_SUCCESS);
}
} else if (pmt_flash) {
if (pmt_use_logical) {
} else if (pmt_flash)
{
if (pmt_use_logical)
{
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)
{
if (pmt_use_logical) {
format(target_partition, "logical");
exit(EXIT_SUCCESS);
} else {
format(target_partition, "classic");
exit(EXIT_SUCCESS);
}
} else {
fprintf(stderr, "%s: no target (backup or flash).\nTry `%s --help` for more information.\n", argv[0], argv[0]);
exit(3);