lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #include <stdio.h>
|
| 2 | #include <stdlib.h>
|
| 3 | #include <assert.h>
|
| 4 | #include <string.h>
|
| 5 | #include "fs_check.h"
|
| 6 | #include "pub_debug_info.h"
|
| 7 |
|
| 8 | extern int mount_fs_partition(struct mtd_fs *p_fs);
|
| 9 | extern int mtd_erase_partition(const char* partition_name);
|
| 10 | extern int mtd_write_partition(const char* partition_name, const char* image_file);
|
| 11 | extern int unmount_fs_partition(struct mtd_fs *p_fs);
|
| 12 | extern int check_userdata_is_normal();
|
| 13 | extern char *g_path_prefix;
|
| 14 |
|
| 15 | static struct mtd_fs fs_array[] = {
|
| 16 | #ifdef USE_UBIFS
|
| 17 | #ifdef CONFIG_SYSTEM_CAP
|
| 18 | {
|
| 19 | .patition_name="capuserdata",
|
| 20 | .mtd_index=-1,
|
| 21 | .mount_point="/mnt/userdata",
|
| 22 | .image_file="/etc_ro/ap_capuserdata.img",
|
| 23 | .fs_type="ubifs",
|
| 24 | .mount_opt="",
|
| 25 | .sh_cmd=NULL
|
| 26 | },
|
| 27 | #else
|
| 28 | {
|
| 29 | .patition_name="userdata",
|
| 30 | .mtd_index=-1,
|
| 31 | .mount_point="/mnt/userdata",
|
| 32 | .image_file="/etc_ro/ap_userdata.img",
|
| 33 | .fs_type="ubifs",
|
| 34 | .mount_opt="",
|
| 35 | .sh_cmd=NULL
|
| 36 | },
|
| 37 | #endif
|
| 38 | #else
|
| 39 | #ifdef CONFIG_SYSTEM_CAP
|
| 40 | {
|
| 41 | .patition_name="capuserdata",
|
| 42 | .mtd_index=-1,
|
| 43 | .mount_point="/mnt/userdata",
|
| 44 | .image_file="/etc_ro/ap_capuserdata.img",
|
| 45 | .fs_type="jffs2",
|
| 46 | .mount_opt="",
|
| 47 | .sh_cmd=NULL
|
| 48 | },
|
| 49 | #else
|
| 50 | {
|
| 51 | .patition_name="userdata",
|
| 52 | .mtd_index=-1,
|
| 53 | .mount_point="/mnt/userdata",
|
| 54 | .image_file="/etc_ro/ap_userdata.img",
|
| 55 | .fs_type="jffs2",
|
| 56 | .mount_opt="",
|
| 57 | .sh_cmd=NULL
|
| 58 | },
|
| 59 | #endif
|
| 60 | #endif
|
| 61 | #ifndef CONFIG_SYSTEM_CAP
|
| 62 | {
|
| 63 | .patition_name="nvrofs",
|
| 64 | .mtd_index=-1,
|
| 65 | .mount_point="/mnt/nvrofs",
|
| 66 | .image_file=NULL,
|
| 67 | .fs_type="jffs2",
|
| 68 | .mount_opt="-o ro",
|
| 69 | .sh_cmd=NULL
|
| 70 | }
|
| 71 | #endif
|
| 72 | };
|
| 73 |
|
| 74 | int main(int argc, char *argv[]) {
|
| 75 |
|
| 76 | int i;
|
| 77 | int ret;
|
| 78 | int result;
|
| 79 | int fs_cnt = sizeof(fs_array)/sizeof(fs_array[0]);
|
| 80 |
|
| 81 | //recovery版本文件系统挂载
|
| 82 | if (0 == strcmp(argv[1], "recovery"))
|
| 83 | {
|
| 84 | g_path_prefix = "/recovery";
|
| 85 | for(i = 0; i < fs_cnt; i++) {
|
| 86 | printf("fs_check mount_fs_partition begin\n");
|
| 87 | sc_debug_info_record(MODULE_ID_AP_FS_CHECK, "fs_check mount_fs_partition begin\n");
|
| 88 | ret = mount_fs_partition(&fs_array[i]);
|
| 89 | printf("fs_check mount_fs_partition mount result %d\n",ret);
|
| 90 | sc_debug_info_record(MODULE_ID_AP_FS_CHECK, "fs_check mount_fs_partition mount result %d\n", ret);
|
| 91 | }
|
| 92 | return 0;
|
| 93 | }
|
| 94 |
|
| 95 | //normal版本文件系统挂载
|
| 96 | for(i = 0; i < fs_cnt; i++) {
|
| 97 | printf("fs_check mount_fs_partition begin\n");
|
| 98 | ret = mount_fs_partition(&fs_array[i]);
|
| 99 | if(ret)
|
| 100 | {
|
| 101 | unmount_fs_partition(&fs_array[i]);
|
| 102 | mtd_erase_partition(fs_array[i].patition_name);
|
| 103 | printf("fs_check mtd_erase %s\n", fs_array[i].patition_name);
|
| 104 | sc_debug_info_record(MODULE_ID_AP_FS_CHECK, "fs_check mtd_erase %s\n", fs_array[i].patition_name);
|
| 105 | ret = mtd_write_partition(fs_array[i].patition_name, fs_array[i].image_file);
|
| 106 | printf("fs_check mtd_write %s ret = %d\n", fs_array[i].patition_name, ret);
|
| 107 | sc_debug_info_record(MODULE_ID_AP_FS_CHECK, "fs_check mtd_write %s ret = %d\n", fs_array[i].patition_name, ret);
|
| 108 | ret = mount_fs_partition(&fs_array[i]);
|
| 109 | if(ret)
|
| 110 | assert(0);
|
| 111 | }
|
| 112 | #ifndef CONFIG_SYSTEM_CAP
|
| 113 | else
|
| 114 | {
|
| 115 | //挂载成功后检查文件是否被破坏,如果破坏则恢复
|
| 116 | if ((0 == strcmp(fs_array[i].patition_name, "userdata")))
|
| 117 | {
|
| 118 | result = check_userdata_is_normal();
|
| 119 | }
|
| 120 | else
|
| 121 | {
|
| 122 | result = 0;
|
| 123 | }
|
| 124 | if(result)
|
| 125 | {
|
| 126 | unmount_fs_partition(&fs_array[i]);
|
| 127 | //printf("fs_check mount %s fail\n", fs_array[i].patition_name);
|
| 128 | mtd_erase_partition(fs_array[i].patition_name);
|
| 129 | printf("fs_check mtd_erase %s\n", fs_array[i].patition_name);
|
| 130 | sc_debug_info_record(MODULE_ID_AP_FS_CHECK, "fs_check mtd_erase %s\n", fs_array[i].patition_name);
|
| 131 | ret = mtd_write_partition(fs_array[i].patition_name, fs_array[i].image_file);
|
| 132 | printf("fs_check mtd_write %s ret = %d\n", fs_array[i].patition_name, ret);
|
| 133 | sc_debug_info_record(MODULE_ID_AP_FS_CHECK, "fs_check mtd_write %s ret = %d\n", fs_array[i].patition_name, ret);
|
| 134 | ret = mount_fs_partition(&fs_array[i]);
|
| 135 | if(ret)
|
| 136 | assert(0);
|
| 137 | }
|
| 138 | }
|
| 139 | #endif
|
| 140 | printf("fs_check mount %s success!\n", fs_array[i].patition_name);
|
| 141 | sc_debug_info_record(MODULE_ID_AP_FS_CHECK, "fs_check mount %s success!\n", fs_array[i].patition_name);
|
| 142 | }
|
| 143 |
|
| 144 | return 0;
|
| 145 | }
|
| 146 |
|
| 147 |
|