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