#include "dm-verity-debug.h"

#include <linux/module.h>
#include <linux/reboot.h>

#include <linux/ctype.h>

#define DM_MSG_PREFIX           "verity"

#define DM_VERITY_ENV_LENGTH        42
#define DM_VERITY_ENV_VAR_NAME      "DM_VERITY_ERR_BLOCK_NR"

#define DM_VERITY_DEFAULT_PREFETCH_SIZE 262144

#define DM_VERITY_MAX_CORRUPTED_ERRS    100

struct blks_info* b_info = 0;

int empty_b_info(void){
    return (b_info) ? 0 : 1;
}

struct blks_info * create_b_info(void){
    b_info = kzalloc(sizeof(struct blks_info),GFP_KERNEL);
    return b_info;
}

void free_b_info(void){
    if(empty_b_info())
        return;
    kfree(b_info);
}

/* get */
long long get_total_blks(void){
    if(!empty_b_info())
        return atomic64_read(&b_info->total_blks);
    return 0;
}

long long get_skipped_blks(void){
    if(!empty_b_info())
        return atomic64_read(&b_info->skipped_blks);
    return 0;
}

long long get_fec_correct_blks(void){
    if(!empty_b_info())
        return atomic64_read(&b_info->fec_correct_blks);
    return 0;
}

long long get_corrupted_blks(void){
    if(!empty_b_info())
        return atomic64_read(&b_info->corrupted_blks);
    return 0;
}

long long get_prev_total_blks(void){
    if(!empty_b_info())
        return atomic64_read(&b_info->prev_total_blks);
    return 0;
}
int get_fec_off_cnt(void){
    if(!empty_b_info())
        return atomic_read(&b_info->fec_off_cnt);
    return 0;
}

int get_dmv_ctr_cnt(void){
    if(!empty_b_info())
        return atomic_read(&b_info->dmv_ctr_cnt);
    return 0;
}

void add_dmv_ctr_entry(char* dev_name){
    int idx = get_dmv_ctr_cnt();

    if(!empty_b_info() && idx < MAX_DEV_LIST){
        snprintf(b_info->dmv_ctr_list[idx],MAX_DEV_NAME,"%s",dev_name);
        atomic_inc(&b_info->dmv_ctr_cnt);
    }
}

struct blks_info * get_b_info(char* dev_name){
    pr_err("dm-verity-debug : dev_name = %s\n",dev_name);

    if(empty_b_info()) {
        b_info = create_b_info();
        add_dmv_ctr_entry(dev_name);
    }
    else{
        pr_info("dm-verity-debug : b_info already exists\n");
        add_dmv_ctr_entry(dev_name);
        return b_info;
    }

    if(!b_info){
        pr_err("dm-verity-debug : Can't get b_info !\n");
        return 0;
    }

    pr_info("dm-verity-debug : get b_info successfully\n");
    return b_info;
}


/* set */
void set_prev_total_blks(long long val){
    if(!empty_b_info())
        atomic64_set(&b_info->prev_total_blks, val);
}
/* add */
void add_total_blks(long long val){
    if(!empty_b_info())
        atomic64_add(val, &b_info->total_blks);
}
void add_skipped_blks(void){
    if(!empty_b_info())
        atomic64_inc(&b_info->skipped_blks);
}
void add_fec_correct_blks(void){
    if(!empty_b_info())
        atomic64_inc(&b_info->fec_correct_blks);
}
void add_corrupted_blks(void){
    if(!empty_b_info())
        atomic64_inc(&b_info->corrupted_blks);
}
void add_fc_blks_entry(sector_t cur_blk, char* dev_name){
    if(empty_b_info()){
        pr_err("dm-verity-debug : b_info is empty !\n");
        return;
    }

    b_info->fc_blks_list[b_info->list_idx] = cur_blk;
    snprintf(b_info->dev_name[b_info->list_idx],MAX_DEV_NAME,"%s",dev_name);

    b_info->list_idx = (b_info->list_idx + 1) % MAX_FC_BLKS_LIST;
}
void add_fec_off_cnt(char* dev_name){
    if(!empty_b_info()){
        int idx = get_fec_off_cnt();

        if(idx < MAX_DEV_LIST){
            snprintf(b_info->fec_off_list[idx],MAX_DEV_NAME,"%s",dev_name);
            atomic_inc(&b_info->fec_off_cnt);
        }
    }
}

void print_blks_cnt(char* dev_name){
    int i,foc = get_fec_off_cnt();
    if(empty_b_info()){
        return;
    }

    pr_err("dev_name = %s,total_blks = %llu,skipped_blks = %llu,corrupted_blks = %llu,fec_correct_blks = %llu",dev_name,get_total_blks(),get_skipped_blks(),get_corrupted_blks(),get_fec_correct_blks());

    if(foc > 0){
        pr_err("fec_off_cnt = %d",foc);
        for(i = 0 ; i < foc; i++)
            pr_err("fec_off_dev = %s ",b_info->fec_off_list[i]);
    }
}

void print_fc_blks_list(void){
    int i = 0;

    if(empty_b_info()){
        return;
    }
    if(get_fec_correct_blks() == 0)
        return;

    pr_err("\n====== FC_BLKS_LIST START ======\n");

    if ((long long) MAX_FC_BLKS_LIST <= get_fec_correct_blks()){
        pr_err("%s %llu",b_info->dev_name[b_info->list_idx],(unsigned long long)b_info->fc_blks_list[b_info->list_idx]);
        i = (b_info->list_idx + 1) % MAX_FC_BLKS_LIST;
    }


    for( ; i != b_info->list_idx; i = (i + 1) % MAX_FC_BLKS_LIST)
        pr_err("%s %llu",b_info->dev_name[i],(unsigned long long)b_info->fc_blks_list[i]);

    pr_err("====== FC_BLKS_LIST END ======\n");
}

void print_dmv_ctr_list(void){
    int i = 0, ctr_cnt = get_dmv_ctr_cnt();

    if(empty_b_info()){
        return;
    }

    pr_err("\n====== DMV_CTR_LIST START ======\n");

    for( ; i < ctr_cnt; i++)
        pr_err("%s",b_info->dmv_ctr_list[i]);

    pr_err("====== DMV_CTR_LIST END ======\n");
}

static void print_block_data(unsigned long long blocknr, unsigned char *data_to_dump,
                            int start, int len)
{
    int i, j;
    int bh_offset = (start / 16) * 16;
    char row_data[17] = { 0, };
    char row_hex[50] = { 0, };
    char ch;

    if (blocknr == 0) {
        pr_err("printing Hash dump %dbyte, hash_to_dump 0x%p\n", len, (void *)data_to_dump);
    } else {
        pr_err("dm-verity corrupted, printing data in hex\n");
        pr_err(" dump block# : %llu, start offset(byte) : %d\n"
                , blocknr, start);
        pr_err(" length(byte) : %d, data_to_dump 0x%p\n"
                , len, (void *)data_to_dump);
        pr_err("-------------------------------------------------\n");
    }
    for (i = 0; i < (len + 15) / 16; i++) {
        for (j = 0; j < 16; j++) {
            ch = *(data_to_dump + bh_offset + j);
            if (start <= bh_offset + j
                    && start + len > bh_offset + j) {

                if (isascii(ch) && isprint(ch))
                    sprintf(row_data + j, "%c", ch);
                else
                    sprintf(row_data + j, ".");

                sprintf(row_hex + (j * 3), "%2.2x ", ch);
            } else {
                sprintf(row_data + j, " ");
                sprintf(row_hex + (j * 3), "-- ");
            }
        }

        pr_err("0x%4.4x : %s | %s\n"
                , bh_offset, row_hex, row_data);
        bh_offset += 16;
    }
    pr_err("---------------------------------------------------\n");
}

int verity_handle_err_hex_debug(struct dm_verity *v, enum verity_block_type type,
        unsigned long long block, struct dm_verity_io *io, struct bvec_iter *iter)
{
    char verity_env[DM_VERITY_ENV_LENGTH];
    char *envp[] = { verity_env, NULL };
    const char *type_str = "";
    struct dm_buffer *buf;
    struct mapped_device *md = dm_table_get_md(v->ti->table);
    struct bio *bio = dm_bio_from_per_bio_data(io, v->ti->per_io_data_size);
    struct bio_vec bv;
    u8 *data;
    u8 *page;

    int i;
    char hex_str[65] = {0, };
    /* Corruption should be visible in device status in all modes */
    v->hash_failed = 1;

    if (ignore_fs_panic) {
        DMERR("%s: Don't trigger a panic during cleanup for shutdown. Skipping %s",
                v->data_dev->name, __func__);
        return 0;
    }

    if (v->corrupted_errs >= DM_VERITY_MAX_CORRUPTED_ERRS)
        goto out;

    v->corrupted_errs++;

    switch (type) {
        case DM_VERITY_BLOCK_TYPE_DATA:
            type_str = "data";
            break;
        case DM_VERITY_BLOCK_TYPE_METADATA:
            type_str = "metadata";
            break;
        default:
            BUG();
    }

    if(empty_b_info()) {
        pr_err("dm-verity-debug : b_info is empty !\n");
    } else {
        print_dmv_ctr_list();
        print_blks_cnt(v->data_dev->name);
        print_fc_blks_list();
    }

    DMERR("%s: %s block %llu is corrupted", v->data_dev->name, type_str, block);

    for(i=0 ; i < v->salt_size; i++){
        sprintf(hex_str + (i * 2), "%02x", *(v->salt + i));
    }
    DMERR("dm-verity salt: %s", hex_str);

    if (!(strcmp(type_str, "metadata"))) {
        data = dm_bufio_read(v->bufio, block, &buf);
        print_block_data(0, (unsigned char *)(verity_io_real_digest(v, io)), 0, v->digest_size);
        print_block_data(0, (unsigned char *)(verity_io_want_digest(v, io)), 0, v->digest_size);
        print_block_data((unsigned long long)block, (unsigned char *)data, 0, PAGE_SIZE);
    } else if (!(strcmp(type_str, "data"))) {
        bv = bio_iter_iovec(bio, *iter);
        page = kmap_atomic(bv.bv_page);
        print_block_data(0, (unsigned char *)(verity_io_real_digest(v, io)), 0, v->digest_size);
        print_block_data(0, (unsigned char *)(verity_io_want_digest(v, io)), 0, v->digest_size);
        print_block_data((unsigned long long)block, (unsigned char *)page, 0, PAGE_SIZE);
        kunmap_atomic(page);
    } else {
        DMERR("%s: %s block : Unknown block type", v->data_dev->name, type_str);
    }

    panic("dmv corrupt");

    if (v->corrupted_errs == DM_VERITY_MAX_CORRUPTED_ERRS)
        DMERR("%s: reached maximum errors", v->data_dev->name);

    snprintf(verity_env, DM_VERITY_ENV_LENGTH, "%s=%d,%llu",
        DM_VERITY_ENV_VAR_NAME, type, block);

    kobject_uevent_env(&disk_to_dev(dm_disk(md))->kobj, KOBJ_CHANGE, envp);

out:
    if (v->mode == DM_VERITY_MODE_LOGGING)
        return 0;

    if (v->mode == DM_VERITY_MODE_RESTART) {
#ifdef CONFIG_DM_VERITY_AVB
        dm_verity_avb_error_handler();
#endif
        kernel_restart("dm-verity device corrupted");
    }

    return 1;
}
