pmt: apply version 1.7.0 changes

This commit is contained in:
2024-04-09 23:45:38 +03:00
committed by GitHub
parent d3d6bfd244
commit a2aee5c5e8

View File

@@ -1,10 +1,3 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include "include/common.h"
/* By YZBruh */
/*
@@ -23,41 +16,76 @@
* limitations under the License.
*/
extern char *cust_cxt;
extern bool use_cust_cxt;
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <errno.h>
#include <dirent.h>
#include "include/pmt.h"
extern bool pmt_use_cust_cxt;
extern bool pmt_ab;
extern bool pmt_logical;
extern bool pmt_force_mode;
extern char *cust_cxt;
/* list existing partitions */
void listpart() {
if (use_cust_cxt) {
printf("List of classic partitions (%s): \n", cust_cxt);
static char cust_cxt_path[150];
sprintf(cust_cxt_path, "ls %s", cust_cxt);
if (system(cust_cxt_path) != 0) {
error("An error occurred when the partition list appears!\n");
DIR *dir;
struct dirent *entry;
if (pmt_use_cust_cxt) {
dir = opendir(cust_cxt);
if (dir == NULL) {
if (!pmt_force_mode) {
fprintf(stderr, "Could not open: `%s`. Error reason: %s\n", cust_cxt, strerror(errno));
exit(62);
} else {
exit(62);
}
}
} else {
printf("List of classic partitions (/dev/block/by-name): \n");
if (system("ls /dev/block/by-name") != 0) {
error("An error occurred when the classic partition list appears!\n");
dir = opendir("/dev/block/by-name");
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 {
exit(63);
}
}
}
while ((entry = readdir(dir)) != NULL) {
printf("%s\n", entry->d_name);
}
closedir(dir);
if (pmt_logical) {
printf("List of logical partitions (/dev/block/mapper): \n");
if (system("ls /dev/block/mapper") != 0) {
error("An error occurred when the logical partition list appears!\n");
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) {
if (pmt_ab && !pmt_force_mode) {
printf("%sWarning: device using A/B partition style.%s\n", ANSI_YELLOW, ANSI_RESET);
}
if (pmt_logical) {
if (pmt_logical && !pmt_force_mode) {
printf("%sWarning: device using logical partition type.%s\n", ANSI_YELLOW, ANSI_RESET);
}
}
#ifdef __cplusplus
}
#endif
/* end of code */