android框架_5.recovery的流程中文件分析_012

 

一、bootable/recovery/common.h文件,有如下定义:

#ifndef RECOVERY_COMMON_H
#define RECOVERY_COMMON_H

#include <stdio.h>
#include <stdarg.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

// TODO: restore ui_print for LOGE
#define LOGE(...) fprintf(stdout, "E:" __VA_ARGS__)
#define LOGW(...) fprintf(stdout, "W:" __VA_ARGS__)
#define LOGI(...) fprintf(stdout, "I:" __VA_ARGS__)

#if 0
#define LOGV(...) fprintf(stdout, "V:" __VA_ARGS__)
#define LOGD(...) fprintf(stdout, "D:" __VA_ARGS__)
#else
#define LOGV(...) do {} while (0)
#define LOGD(...) do {} while (0)
#endif

#define STRINGIFY(x) #x
#define EXPAND(x) STRINGIFY(x)

1、都是定义的宏;

 

typedef struct {
    const char* mount_point;  // eg. "/cache".  must live in the root directory.

    const char* fs_type;      // "yaffs2" or "ext4" or "vfat"

    const char* device;       // MTD partition name if fs_type == "yaffs"
                              // block device if fs_type == "ext4" or "vfat"

    const char* device2;      // alternative device to try if fs_type
                              // == "ext4" or "vfat" and mounting
                              // 'device' fails

    long long length;         // (ext4 partition only) when
                              // formatting, size to use for the
                              // partition.  0 or negative number
                              // means to format all but the last
                              // (that much).
} Volume;

2、定义一个结构体,名为Volume,有挂载点,文件类型,设备, 设备2,长度;//typedef struct fstab_rec Volume;

 

// fopen a file, mounting volumes and making parent dirs as necessary.
FILE* fopen_path(const char *path, const char *mode);

void ui_print(const char* format, ...);


bool is_support_gpt(void);

3、打开一个路径文件,和ui的打印,以及是否支持gpt

#define PRELOADER_PART "/dev/block/mmcblk0boot0"
#define BOOT_PART      "/dev/block/platform/mtk-msdc.0/by-name/boot"
#define CACHE_PART     "/dev/block/platform/mtk-msdc.0/by-name/cache"
#define FAT_PART       "/dev/block/platform/mtk-msdc.0/by-name/intsd"
#define SYSTEM_PART    "/dev/block/platform/mtk-msdc.0/by-name/system"
#define DATA_PART      "/dev/block/platform/mtk-msdc.0/by-name/userdata"
#define MISC_PART      "/dev/block/platform/mtk-msdc.0/by-name/para"
#define RECOVERY_PART  "/dev/block/platform/mtk-msdc.0/by-name/recovery"
#define CUSTOM_PART    "/dev/block/platform/mtk-msdc.0/by-name/custom"
#define VENDOR_PART    "/dev/block/platform/mtk-msdc.0/by-name/vendor"
#define LOGO_PART      "/dev/block/platform/mtk-msdc.0/by-name/logo"
#define LK_PART        "/dev/block/platform/mtk-msdc.0/by-name/lk"
#define TEE1_PART      "/dev/block/platform/mtk-msdc.0/by-name/tee1"
#define TEE2_PART      "/dev/block/platform/mtk-msdc.0/by-name/tee2"
#define PERSIST_PART   "/dev/block/platform/mtk-msdc.0/by-name/persist"
#define NVDATA_PART    "/dev/block/platform/mtk-msdc.0/by-name/nvdata"

static inline bool support_gpt(void) {\
    int fd = open(MISC_PART, O_RDONLY);\
    if (fd == -1) {\
        return false;\
    } else {\
        close(fd);\
        return true;\
    }\
}

4、这个上面也都是定义的宏,供其他文件调用的;

 

二、分析bootable/recovery/roots.cpp文件;

1、这里有很多引用的.h文件;

#if defined(CACHE_MERGE_SUPPORT)
#include <dirent.h>
#include "backup_restore.h"

static int need_clear_cache = 0;
static const char *DATA_CACHE_ROOT = "/data/.cache";

#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
static int remove_dir(const char *dirname)
{
    DIR *dir;
    struct dirent *entry;
    char path[PATH_MAX];

    dir = opendir(dirname);
    if (dir == NULL) {
        LOGE("opendir %s failed\n", dirname);
        return -1;
    }

    while ((entry = readdir(dir)) != NULL) {
        if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) {
            snprintf(path, (size_t) PATH_MAX, "%s/%s", dirname, entry->d_name);
            if (entry->d_type == DT_DIR) {
                remove_dir(path);
            } else {
                // delete file
                unlink(path);
            }
        }
    }
    closedir(dir);

    // now we can delete the empty dir
    rmdir(dirname);
    return 0;
}
#endif

2、这个删除目录的方法,涉及到很多的内容需要学习的,比如很多的DIR结构体,opendir方法怎么打开文件夹的,来看下这个DIR结构体:

struct __dirstream
{
void *__fd; /* `struct hurd_fd' pointer for descriptor.   */
char *__data; /* Directory block.   */
int __entry_data; /* Entry number `__data' corresponds to.   */
char *__ptr; /* Current pointer into the block.   */
int __entry_ptr; /* Entry number `__ptr' corresponds to.   */
size_t __allocation; /* Space allocated for the block.   */
size_t __size; /* Total valid data in the block.   */
__libc_lock_define (, __lock) /* Mutex lock for this structure.   */
};
typedef struct __dirstream DIR;

3、就是这样定义的一个DIR,还有一个dirent结构体:

struct dirent
{
   long d_ino; /* inode number 索引节点号 */
   off_t d_off; /* offset to this dirent 在目录文件中的偏移 */
   unsigned short d_reclen; /* length of this d_name 文件名长 */
   unsigned char d_type; /* the type of d_name 文件类型 */
   char d_name [NAME_MAX+1]; /* file name (null-terminated) 文件名,最长255字符 */
}

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值