static struct partitions * get_ptbl_from_dtb(struct mmc *mmc) { struct partitions * ptbl = NULL; #ifndef DTB_BIND_KERNEL unsigned char * buffer = NULL; ulong ret, offset; struct virtual_partition *vpart = aml_get_virtual_partition_by_name(MMC_DTB_NAME); /* try get dtb table from ddr, which may exsit while usb burning */ if (NULL == get_partitions()) { /* if failed, try rsv dtb area then. */ buffer = malloc(vpart->size * DTB_COPIES); if (NULL == buffer) { apt_err("Can not alloc enough buffer\n"); goto _err; } offset = _get_inherent_offset(MMC_RESERVED_NAME) + vpart->offset; ret = _mmc_rsv_read(mmc, offset, (vpart->size * DTB_COPIES), buffer); if (ret != (vpart->size * DTB_COPIES)) { apt_err("Can not alloc enough buffer\n"); goto _err1; } /* parse it */ if (get_partition_from_dts(buffer)) { apt_err("get partition table from dts faild\n"); goto _err1; } /* double check part_table(glb) */ if (NULL == get_partitions()) { goto _err1; } apt_info("get partition table from dts successfully\n"); free(buffer); buffer = NULL; } #endif /* asign partition info to *ptbl */ ptbl = get_partitions(); return ptbl; #ifndef DTB_BIND_KERNEL _err1: if (buffer) free(buffer); _err: free (ptbl); return NULL; #endif }
struct pm_partition *get_partition(str *part_name) { struct pm_partition *it; for (it=get_partitions(); it; it=it->next) { if (!str_strcmp(part_name, &it->name)) break; } return it; }
void partition_manager_init() { for(unsigned i = 0; i < (sizeof(struct PARTITION) * MAX_PARTITIONS); i++){ ((char *)&partitions)[i] = 0; } for(int i = 0; i < HDD_MAX_DEVICES; i++){ if(hdd_devices[i].exists){ unsigned char bootSector[512]; int err = hdd_read_sectors((uint16_t *) &bootSector[0], 1, i, 0); if(err != 0) continue;// Abandon Drive! if(!is_mbr(&bootSector[0])){ struct PARTITION p; p.disk = i; p.startSector = 0; p.sectors = hdd_devices[i].sectorCount; p.fileSystem = 0; add_partition(&p); } else { get_partitions(&bootSector[0], i); } } } for(int i = 0; i < MAX_PARTITIONS; i++){ if (partitions[i].present){ unsigned char bootSector[512]; int err = hdd_read_sectors((uint16_t *) &bootSector[0], 1, partitions[i].disk, partitions[i].startSector); if (err == 0){ if(is_fat_boot_sector(&bootSector[0])){ // FAT } else if(is_ext_file_system(&partitions[i])){ // EXT } } } } }
/* * parse a partition parameter of type * <part_name> : attr1=val1; attr2=val2; */ int parse_partition(modparam_t t, void *val) { str type, value, token; char *tok_end; struct pm_partition *el, *it; str decl = {(char*)val, strlen((char *)val)}; if (get_partitions() == NULL) { if (alloc_partitions() == NULL) goto out_memfault; el=get_partitions(); } else { el=pkg_malloc(sizeof(struct pm_partition)); if (el == NULL) goto out_memfault; memset(el, 0, sizeof(struct pm_partition)); for (it=get_partitions(); it->next; it=it->next); it->next = el; } tok_end = q_memchr(decl.s, ':', decl.len); if (tok_end == NULL) goto out_invdef; value.s = decl.s; value.len = tok_end - decl.s; str_trim_spaces_lr(value); el->name = value; decl.len = decl.len - (++tok_end - decl.s); decl.s = tok_end; while (decl.len > 0 && decl.s) { tok_end = q_memchr(decl.s, ';', decl.len); if (tok_end == NULL) break; token.s = decl.s; token.len = tok_end - token.s; tok_end = q_memchr(token.s, '=', token.len); if (tok_end == NULL) break; type.s = token.s; type.len = tok_end - type.s; value.s = tok_end + 1; value.len = (token.s + token.len) - value.s; decl.s += token.len + 1; decl.len -= (token.len + 1); str_trim_spaces_lr(type); str_trim_spaces_lr(value); if (!str_strcmp( &type, &part_db_url)) el->url = value; else if (!str_strcmp( &type, &part_table_name)) el->table = value; else goto out_invdef; } if (el->url.s == NULL) { LM_ERR("you should define an URL for this partition %.*s\n", el->name.len, el->name.s); return -1; } return 0; out_invdef: LM_ERR("invalid partition definition!\n"); return -ERR; out_memfault: LM_ERR("no more memory\n"); return -ERR; }