pmt: initial 2.6.0 update

This commit is contained in:
2024-07-28 23:01:21 +03:00
parent 36efab6eb3
commit 5b00b0bfe3
27 changed files with 706 additions and 677 deletions

View File

@@ -26,121 +26,149 @@ ifeq ($(INC_OLDENV),true)
include $(BUILD)/config/oldenv.mk
endif
# make objects. Usage $(call make_obj,<SRCFILE>)
define make_obj
$(eval OBJ := $(1:.c=.o))
$(call m_stat,CC,`basename $(SOURCE_DIR)`/`basename $(OBJ)`,n)
$(CC) $(CFLAGS) -c "$1" || exit 1;
$(hide)printf "\n"
endef
INCLUDE_DIR := $(realpath ../include)
PMT_INCDIR := $(INCLUDE_DIR)/pmt
# make executable file with using static libraries and objects. Usage: $(call make_executable)
define make_executable
printf " - Making executable file...\n"; \
printf " LD $(TARGET)"; \
$(CC) $(CFLAGS) -L$(SOURCE_DIR) \
$(foreach s_obj_b, \
$(shell basename -a $(STATICLIB_OBJS)), \
$(eval s_obj_t_b = $(s_obj_b:.o=)) \
$(shell echo -lpmt_$(s_obj_t_b)) \
) \
-o $(TARGET) $(OBJS_EXEC) || exit 1;
endef
# the presence of all source files that are on this list will be checked
SRCS_REQ := \
place-holder/debugging.c \
place-holder/help.c \
place-holder/get_stat.c \
place-holder/lang_tools.c \
place-holder/languages.c \
place-holder/partitiontool.c \
place-holder/pmt.c \
place-holder/root.c \
place-holder/tools.c \
place-holder/versioning.c
# make static library. Usage $(call make_staticlib,<LIBRARY_NAME>,<OBJECT(S)>)
define make_staticlib
echo -n " AR $1"; \
$(AR) rcs "$1" "$2" || exit 1; \
echo;
endef
# objects to be used when executable file is created
OBJS_EXEC := \
$(SOURCE_DIR)/$(TARGET).o \
$(SOURCE_DIR)/help.o \
$(SOURCE_DIR)/versioning.o \
$(SOURCE_DIR)/get_stat.o \
$(SOURCE_DIR)/tools.o \
$(SOURCE_DIR)/lang_tools.o \
$(SOURCE_DIR)/languages.o
# controls the presence of source file. usage: $(call check_cfile,<SOURCE_FILE>)
define check_cfile
# the first argument is taken and controlled by the file with -f option
printf " CHK $(SOURCE_DIRNAME)/`basename $1`\n"; \
if [ ! -f $1 ]; then \
printf " ==> Couldn't found required source file: $(SOURCE_DIRNAME)/`basename $1`\n"; \
if [ -d "$(TEMP_DIR)" ]; then \
rm -rf $(TEMP_DIR); \
fi; \
exit 1; \
fi;
endef
HEADERS_REQ := \
$(PMT_INCDIR)/pmt/deprecates.h \
$(PMT_INCDIR)/pmt/help_msgs.h \
$(PMT_INCDIR)/pmt/pmt.h \
$(PMT_INCDIR)/pmt/stringkeys.h \
$(PMT_INCDIR)/pmt/versioning.h
# controls the presence of header file. usage: $(call check_hfile,<SOURCE_FILE>)
define check_hfile
# the first argument is taken and controlled by the file with -f option
printf " CHK include/pmt/`basename $1`\n"; \
if [ ! -f $1 ]; then \
printf " ==> Couldn't found required header file: include/pmt/`basename $1`\n"; \
if [ -d "$(TEMP_DIR)" ]; then \
rm -rf $(TEMP_DIR); \
fi; \
exit 1; \
fi;
PROGRESS_LIST := \
welcome \
$(SRCS_REQ) \
$(HEADERS_REQ) \
pr_obj \
$(OBJS) \
make_outdirs \
$(STATIC_LIBS) \
make_executable \
end_progress
define check_hf
@ [ ! -f "$1" ] \
&& $(E_NS) " ==> Couldn't found required header file: include/pmt/`basename $1`" \
&& exit 1
endef
# all target for building
all:
$(hide)rm -f $(BUILD)/config/oldenv.mk
$(hide)printf " ---- Partition Manager Builder ---- \n\n"
$(hide)printf " - Version: $(VERSION)\n"
$(hide)printf " - Version code: $(VERSION_CODE)\n\n"
$(hide)printf " -------------------------------- \n\n"
$(hide)if [ -f $(SOURCE_DIR)/debugging.o ]; then \
printf " - Please clean up before you build it.\n\n"; \
printf " ----------------------------------- \n"; \
all: $(PROGRESS_LIST)
welcome:
@ rm -f $(BUILD)/config/oldenv.mk
@ echo " ---- Partition Manager Builder ---- " \
&& $(E_NS)
$(E) " - Version: $(VERSION)"
$(E) " - Version code: $(VERSION_CODE)" \
&& $(E_NS)
$(E) " -------------------------------- " \
&& $(E_NS)
@ if [ -f $(SOURCE_DIR)/debugging.o ]; then \
$(E_NS) " - Please clean up before you build it." && echo; \
$(E_NS) " ----------------------------------- "; \
exit 1; \
fi
$(hide)printf " - Checking required source files...\n"
$(hide)sleep 1
$(foreach src_cf, \
$(SRCS_REQ), \
$(call check_cfile,$(src_cf)) \
)
$(foreach src_hf, \
$(HEADERS_REQ), \
$(call check_hfile,$(src_hf)) \
)
$(hide)printf " - Building objects...\n"
$(hide)sleep 2
$(foreach csrc, \
$(SRCS), \
$(call make_obj,$(csrc)) \
)
$(foreach reqdir,$(IN_OUT_DIR),$(call mdir,$(reqdir)))
$(hide)printf " - Making static libraries...\n"
$(foreach s_obj, \
$(shell basename -a $(STATICLIB_OBJS)), \
$(eval s_obj_t = $(s_obj:.o=.a)) \
$(call make_staticlib,libpmt_$(s_obj_t),$(s_obj)) \
)
$(hide)sleep 1
$(call make_executable)
$(hide)sleep 1
$(hide)abort_build() { \
if [ -d "$(PACKAGE_DIR)" ]; then \
rm -rf "$(PACKAGE_DIR)"; \
fi; \
if [ -d "$(BINARY_DIR)" ]; then \
rm -rf "$(BINARY_DIR)"; \
fi; \
if [ -d "$(STATICLIB_DIR)" ]; then \
rm -rf "$(STATICLIB_DIR)"; \
fi; \
$(E) " - Checking required source files..."
@ sleep 1
pr_obj:
$(E) " - Building objects..."
make_outdirs:
@ rm -rf $(IN_OUT_DIR)
@ mkdir $(BINARY_DIR)
@ mkdir $(PACKAGE_DIR)
@ mkdir $(STATICLIB_DIR)
place-holder/%.c:
$(E) " CHK $(SOURCE_DIRNAME)/`basename $@`"
@ if [ ! -f "$(SOURCE_DIR)/`basename $@`" ]; then \
$(E_NS) " ==> Couldn't found required source file: $(SOURCE_DIRNAME)/`basename $@`"; \
exit 1; \
fi
$(PMT_INCDIR)/%.h:
$(E) " CHK include/pmt/`basename $@`"
@ if [ ! -f "$(INCLUDE_DIR)/pmt/`basename $@`" ]; then \
$(E_NS) " ==> Couldn't found required header file: include/pmt/`basename $@`"; \
exit 1; \
fi
$(SOURCE_DIR)/%.o: $(SOURCE_DIR)/%.c
$(E) " CC $(SOURCE_DIRNAME)/`basename $@`"
@ $(CC) $(CFLAGS) -c "$<" || exit 1
$(eval GEN_OBJS_MSG = )
lib$(TARGET)_root.a:
$(E) " - Making static libraries..."
$(E) " AR $@"
@ $(AR) rcs "$@" "$(SOURCE_DIR)/root.o" || exit 1
lib$(TARGET)_debugging.a:
$(E) " AR $@"
@ $(AR) rcs "$@" "$(SOURCE_DIR)/debugging.o"
lib$(TARGET)_listpart.a:
$(E) " AR $@"
@ $(AR) rcs "$@" "$(SOURCE_DIR)/listpart.o"
lib$(TARGET)_partitiontool.a:
$(E) " AR $@"
@ $(AR) rcs "$@" "$(SOURCE_DIR)/partitiontool.o"
@ sleep 1
make_executable:
$(E) " - Making executable file..."
$(E) " LD $(TARGET)"
@ $(CC) $(CFLAGS) -L$(SOURCE_DIR) -l$(TARGET)_root -l$(TARGET)_debugging -l$(TARGET)_listpart -l$(TARGET)_partitiontool -o $(TARGET) $(OBJS_EXEC) || exit 1
@ sleep 1
end_progress:
@ abort_build() { \
[ -d "$(PACKAGE_DIR)" ] \
&& rm -rf "$(PACKAGE_DIR)"; \
[ -d "$(BINARY_DIR)" ] \
&& rm -rf "$(BINARY_DIR)"; \
[ -d "$(STATICLIB_DIR)" ] \
&& rm -rf "$(STATICLIB_DIR)"; \
exit 1; \
}; \
mv $(TARGET) $(BINARY_DIR) || abort_build; \
mv *.a $(STATICLIB_DIR) || abort_build; \
printf "\n - Generating package...\n"; \
$(E_NS) " - Generating package..."; \
cp $(BINARY_DIR)/$(TARGET) $(PACKAGE_DIR) || abort_build; \
printf " XZ $(OUT_DIRNAME)/package/$(TARGET)-`date +%Y%m%d`.xz"
$(E_NS) " XZ $(OUT_DIRNAME)/package/$(TARGET)-`date +%Y%m%d`.xz"
xz $(PACKAGE_DIR)/$(TARGET) || abort_build; \
sleep 1; \
mv $(PACKAGE_DIR)/$(TARGET).xz $(PACKAGE_DIR)/$(TARGET)-`date +%Y%m%d`.xz || abort_build; \
printf "\n - Success"; \
sleep 1; \
printf "\n\n ----------------------------------- \n"
mv $(PACKAGE_DIR)/$(TARGET).xz $(PACKAGE_DIR)/$(TARGET)-`date +%Y%m%d`.xz || abort_build
$(E) " - Success" && $(E_NS)
@ sleep 1
$(E) " ----------------------------------- "
.PHONY: clean
clean:

View File

@@ -27,8 +27,6 @@ extern "C" {
void debug(LogLevel status, const char* _Nullable fmt, ...)
{
if (fmt == NULL) exit(1);
va_list args;
va_start(args, fmt);

View File

@@ -21,10 +21,11 @@ extern "C" {
#endif
#define INC_MAIN_LIBS
#define HELP
#include <pmt/pmt.h>
#include <pmt/stringkeys.h>
#include <pmt/docs.h>
#include <pmt/help_msgs.h>
extern char* bin_name;
extern char* curr_lang;

View File

@@ -54,7 +54,7 @@ langctrl(const char* _Nonnull lang_)
int loadlang(void)
{
static char lang_fpr[10] = "en";
static char lang_fpr[3] = "en";
langconf = NULL;
if (get_stat(TERMUX_PMT_MANDOC, "file") == 0)

View File

@@ -86,30 +86,22 @@ list(const char* operation, const char* target_dir)
/* list existing partitions */
int listpart(void)
{
static char acc_cxt[350];
if (pmt_use_cust_cxt)
sprintf(acc_cxt, "%s", cust_cxt);
else
sprintf(acc_cxt, "%s", CUR_DEV_CNTX);
if (list("access", acc_cxt) != 0)
{
if (list("access", cust_cxt) != 0)
{
if (!pmt_force_mode)
LOGE("%s: `%s': %s\n", current->not_open, cust_cxt, strerror(errno));
else
return 1;
}
if (!pmt_force_mode)
LOGE("%s: `%s': %s\n", current->not_open, acc_cxt, strerror(errno));
else
list("print", cust_cxt);
return 1;
}
else
{
if (list("access", CUR_DEV_CNTX) != 0)
{
if (!pmt_force_mode)
LOGE("%s: `%s': %s\n", current->not_open, CUR_DEV_CNTX, strerror(errno));
else
return 1;
}
else
list("print", CUR_DEV_CNTX);
}
list("print", acc_cxt);
if (pmt_logical)
{

View File

@@ -29,7 +29,9 @@ extern "C" {
#include <pmt/pmt.h>
#include <pmt/stringkeys.h>
#include <pmt/deprecates.h>
#include <pmt/docs.h>
#include <pmt/help_msgs.h>
#define opt_symbol "-"
/* add value to variables that are added globally and are not worth */
char* out = NULL;
@@ -51,7 +53,6 @@ bool pmt_force_mode = false;
bool pmt_inst_on_termux = false;
/* variable for use in control of '-' expression */
static const char* opt_symbol = "-";
static char common_symbol_rule[350];
#if !defined(__clang__)

View File

@@ -29,6 +29,8 @@ extern "C" {
#include <pmt/pmt.h>
#include <pmt/stringkeys.h>
#define count (1024 * 1024 * 1024)
/**
* it is meant to calculate the size of the quickly given file.
* its purpose is for rapid processing
@@ -79,38 +81,35 @@ int pmt(unsigned short progress_code)
{
/* required variables */
static int srcf, targetf;
static char backupper_path[512];
static char ppath[100];
static char acc_part_path[512];
static char formatter_cmd[200];
static char outf[512];
static char flasher_path[512];
static char buffer[BFSIZE];
static ssize_t readed_data;
static unsigned long long copied_data = 0;
static unsigned long long count = 1024 * 1024 * 1024;
if (pmt_use_logical)
sprintf(acc_part_path, "/dev/block/mapper/%s", target_partition);
else
{
if (pmt_use_cust_cxt)
sprintf(acc_part_path, "%s/%s", cust_cxt, target_partition);
else
sprintf(acc_part_path, "/dev/block/by-name/%s", target_partition);
}
search_partition(acc_part_path);
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
sprintf(backupper_path, "/dev/block/mapper/%s", target_partition);
search_partition(backupper_path);
if (calc_flsz(backupper_path) != -1)
LOGD("%s: %.2f\n", current->part_disk_sz, calc_flsz(backupper_path));
if (calc_flsz(acc_part_path) != -1)
LOGD("%s: %.2fM\n", current->part_disk_sz, calc_flsz(acc_part_path));
else
LOGW("%s\n", current->part_disk_sz_fail);
srcf = open(backupper_path, O_RDONLY);
srcf = open(acc_part_path, O_RDONLY);
if (srcf == -1)
LOGE("%s: %s: %s\n", current->not_read, backupper_path, strerror(errno));
LOGE("%s: %s: %s\n", current->not_read, acc_part_path, strerror(errno));
/* determine output */
if (strcmp(out, target_partition) == 0)
@@ -133,7 +132,7 @@ int pmt(unsigned short progress_code)
{
if (get_stat(outf, "file") == 0)
remove(outf);
LOGF("%s: %s: %s\n", current->not_write, backupper_path, strerror(errno));
LOGF("%s: %s: %s\n", current->not_write, acc_part_path, strerror(errno));
}
copied_data += writed_data;
@@ -147,35 +146,19 @@ int pmt(unsigned short progress_code)
}
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
sprintf(flasher_path, "/dev/block/mapper/%s", target_partition);
/* check partition */
search_partition(flasher_path);
if (calc_flsz(target_flash_file) != -1)
LOGD("%s: %.2f\n", current->flash_file_sz, calc_flsz(target_flash_file));
LOGD("%s: %.2fM\n", current->flash_file_sz, calc_flsz(target_flash_file));
else
LOGW("%s\n", current->flash_file_sz_fail);
if (calc_flsz(flasher_path) != -1)
LOGD("%s: %.2f\n", current->part_disk_sz, calc_flsz(flasher_path));
if (calc_flsz(acc_part_path) != -1)
LOGD("%s: %.2fM\n", current->part_disk_sz, calc_flsz(acc_part_path));
else
LOGW("%s\n", current->part_disk_sz_fail);
if (calc_flsz(target_flash_file) != -1 && calc_flsz(flasher_path) != -1)
if (calc_flsz(target_flash_file) != -1 && calc_flsz(acc_part_path) != -1)
{
if (calc_flsz(target_flash_file) > calc_flsz(flasher_path))
if (calc_flsz(target_flash_file) > calc_flsz(acc_part_path))
LOGE("%s\n", current->ffile_more_part);
}
@@ -183,16 +166,16 @@ int pmt(unsigned short progress_code)
if (srcf == -1)
LOGF("%s: %s: %s\n", current->not_read, target_flash_file, strerror(errno));
targetf = open(target_partition, O_WRONLY | O_CREAT | O_TRUNC, 0660);
targetf = open(acc_part_path, O_WRONLY | O_CREAT | O_TRUNC, 0660);
if (targetf == -1)
LOGF("%s: %s: %s\n", current->not_read, target_partition, strerror(errno));
LOGF("%s: %s: %s\n", current->not_read, acc_part_path, strerror(errno));
/* start writing */
while ((readed_data = read(srcf, buffer, BFSIZE)) > 0 && copied_data < count)
{
ssize_t writed_data = write(targetf, buffer, readed_data);
if (writed_data != readed_data)
LOGF("%s: %s: %s\n", current->not_write, backupper_path, strerror(errno));
LOGF("%s: %s: %s\n", current->not_write, acc_part_path, strerror(errno));
copied_data += writed_data;
}
@@ -204,28 +187,13 @@ int pmt(unsigned short progress_code)
}
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
sprintf(ppath, "/dev/block/mapper/%s", target_partition);
/* check partition */
search_partition(ppath);
/* get target partition block size */
struct statvfs file_sys_inf;
if (statvfs(ppath, &file_sys_inf) != 0)
if (statvfs(acc_part_path, &file_sys_inf) != 0)
LOGE("%s\n", current->cannot_get_bsz);
/* generate mke2fs command */
sprintf(formatter_cmd, "mke2fs -Fq -t %s -b %lu %s", format_fs, file_sys_inf.f_bsize, ppath);
sprintf(formatter_cmd, "mke2fs -Fq -t %s -b %lu %s", format_fs, file_sys_inf.f_bsize, acc_part_path);
/* run command */
if (system(formatter_cmd) != 0)

View File

@@ -21,6 +21,7 @@ extern "C" {
#endif
#define INC_MAIN_LIBS
#define VERSIONING
#include <pmt/pmt.h>
#include <pmt/stringkeys.h>
@@ -40,7 +41,7 @@ void version(void)
#if defined(__clang__) && !defined(__NDK_BUILD)
LOGD("%s: clang %d.%d.%d\n", current->compiler_str, __clang_major__, __clang_minor__, __clang_patchlevel__);
#elif defined(__clang__) && defined(__NDK_BUILD)
#elif defined(__NDK_BUILD)
LOGD("%s\n", __NDK_CC_VERSION__);
#endif
}