int write_mbr_partition_table(void) { printf("write mbr partition \n"); emmc_part_device_init(); //write pmbr struct disk_info *device_disk_info; if (!(device_disk_info = load_diskconfig())) { printf("Errors encountered while loading disk partation\n"); return 1; } /* First, partition the drive */ if (apply_disk_config(device_disk_info)) printf("write partition list success\n"); return 1; }
int main(int argc, char *argv[]) { struct disk_info *dinfo; if (argc < 2) { LOGE("usage: %s <conf file>", argv[0]); return 1; } if (!(dinfo = load_diskconfig(argv[1], NULL))) return 1; dump_disk_config(dinfo); return 0; }
void setup_disk_information(char *disk_layout_location) { char *disk_force; /* Read the preos.fstab, which is used to for filesystem * meta-data and also the sd card device node */ load_volume_table(); /* * If all device nodes exist and disk_force set to no in * config file, skip to load/write partition table */ disk_force = tboot_config_get(DISK_FORCE_KEY); if (!disk_force) { pr_error("Invalid tboot config disk_force.\n"); tboot_config_set(DISK_FORCE_KEY, "yes"); } if (!check_devnodes() && !strcasecmp(disk_force, "no")) { pr_debug("bypass load disk config\n"); return; } /* Read disk_layout.conf, which provides physical partition * layout information */ pr_debug("Reading disk layout from %s\n", disk_layout_location); disk_info = load_diskconfig(disk_layout_location, NULL); if (!disk_info) { pr_error("Disk layout unreadable.\n"); die(); } process_disk_config(disk_info); dump_disk_config(disk_info); /* Set up the partition table */ if (apply_disk_config(disk_info, 0)) { pr_error("Couldn't apply disk configuration.\n"); die(); } }
static int parse_args(int argc, char *argv[], struct disk_info **dinfo, int *test, int *verbose) { char *layout_conf = NULL; char *img_file = NULL; struct stat64 filestat; int x; while ((x = getopt (argc, argv, "vthl:i:")) != EOF) { switch (x) { case 'h': return usage(); case 'l': layout_conf = optarg; break; case 't': *test = 1; break; case 'i': img_file = optarg; break; case 'v': *verbose = 1; break; default: fprintf(stderr, "Unknown argument: %c\n", (char)optopt); return usage(); } } if (!img_file || !layout_conf) { fprintf(stderr, "Image filename and configuration file are required\n"); return usage(); } /* we'll need to parse the command line later for partition-file * mappings, so make sure there's at least something there */ if (optind >= argc) { fprintf(stderr, "Must provide partition -> file mappings\n"); return usage(); } if (stat64(img_file, &filestat)) { perror("Cannot stat image file"); return 1; } /* make sure we don't screw up and write to a block device on the host * and wedge things. I just don't trust myself. */ if (!S_ISREG(filestat.st_mode)) { fprintf(stderr, "This program should only be used on regular files."); return 1; } /* load the disk layout file */ if (!(*dinfo = load_diskconfig(layout_conf, img_file))) { fprintf(stderr, "Errors encountered while loading disk conf file %s", layout_conf); return 1; } /* parse the filename->partition mappings from the command line and patch * up a loaded config file's partition table entries to have * length == filesize */ x = 0; while (optind < argc) { char *pair = argv[optind++]; char *part_name; struct part_info *pinfo; struct stat64 tmp_stat; if (x >= MAX_NUM_PARTS) { fprintf(stderr, "Error: Too many partitions specified (%d)!\n", x); return 1; } if (!(part_name = strsep(&pair, "=")) || !pair || !(*pair)) { fprintf(stderr, "Error parsing partition mappings\n"); return usage(); } if (!(pinfo = find_part(*dinfo, part_name))) { fprintf(stderr, "Partition '%s' not found.\n", part_name); return 1; } /* here pair points to the filename (after the '=') */ part_file_map[x].pinfo = pinfo; part_file_map[x++].filename = pair; if (stat64(pair, &tmp_stat) < 0) { fprintf(stderr, "Could not stat file: %s\n", pair); return 1; } pinfo->len_kb = (tmp_stat.st_size + 1023) >> 10; } return 0; }