pmt: initial 2.6.0 update
This commit is contained in:
92
jni/tools.c
92
jni/tools.c
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user