#include #include #include #include #include #include #define HRWIDTH 72 static void _hrule(void) { static char buf[HRWIDTH + 1] = ""; if (!buf[0]) { memset(buf, '=', HRWIDTH); buf[HRWIDTH] = '\0'; } puts(buf); } static void _debug_disk(struct disk *dp) { putchar('\n'); Debug_Disk(dp); putchar('\n'); } static void _try_create_chunk(struct disk *dp, struct chunk *cp) { int rc; printf("Trying to create 'freebsd' partition inside %s\n", cp->name); if ((rc = Create_Chunk(dp, cp->offset, cp->size, part, 165, CHUNK_IS_ROOT))) { puts("Cannot create chunk"); printf("Died on line %d somewhere in libdisk(3).\n", rc); } } int main(int ac, char *av[]) { char *prog; struct disk *dp; char ps[32 + 1]; struct chunk *cp; prog = strrchr(av[0], '/'); prog = (prog) ? prog + 1: av[0]; if (ac != 2) { printf("Usage: %s \n", prog); return EX_USAGE; } if (!(dp = Open_Disk(av[1]))) err(1, "Cannot open disk %s", av[1]); _debug_disk(dp); _hrule(); snprintf(ps, 32 + 1, "%ss1", av[1]); if (!dp->chunks || !dp->chunks->part || strcmp(dp->chunks->part->name, ps)) { puts("No first slice."); return 1; } cp = dp->chunks->part; _try_create_chunk(dp, cp); _debug_disk(dp); _hrule(); puts("Changing slice type to 'freebsd'"); cp->type = freebsd; cp->subtype = 165; _debug_disk(dp); _hrule(); _try_create_chunk(dp, cp); _debug_disk(dp); return 0; }