From 8f9c9957875b58ddd0f9dd3fa49b7f8a5ebd52ea Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Thu, 11 May 1995 05:22:54 +0000 Subject: [PATCH] Get the CHUNK_COMPAT_BSD flag right. --- lib/libdisk/chunk.c | 5 ++- lib/libdisk/create_chunk.c | 82 +++++++++++++++------------------- lib/libdisk/tst01.c | 6 +-- release/libdisk/chunk.c | 5 ++- release/libdisk/create_chunk.c | 82 +++++++++++++++------------------- release/libdisk/tst01.c | 6 +-- 6 files changed, 88 insertions(+), 98 deletions(-) diff --git a/lib/libdisk/chunk.c b/lib/libdisk/chunk.c index 54630bed7761..c100927045b7 100644 --- a/lib/libdisk/chunk.c +++ b/lib/libdisk/chunk.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: chunk.c,v 1.10 1995/05/07 01:28:16 jkh Exp $ + * $Id: chunk.c,v 1.11 1995/05/08 02:08:25 phk Exp $ * */ @@ -200,6 +200,8 @@ Add_Chunk(struct disk *d, long offset, u_long size, char *name, chunk_e type, c1->subtype = subtype; return 0; } + if (type == freebsd) + subtype = 0xa5; c1 = 0; if(!c1 && (type == freebsd || type == fat || type == unknown)) c1 = Find_Mother_Chunk(d->chunks,offset,end,extended); @@ -380,6 +382,7 @@ Collapse_Chunk(struct disk *d, struct chunk *c1) } if(c3->type == unused) { c2 = new_chunk(); + if (!c2) err(1,"malloc failed"); *c2 = *c1; c1->next = c2; c1->name = strdup("-"); diff --git a/lib/libdisk/create_chunk.c b/lib/libdisk/create_chunk.c index 4d530f4b27d8..7af521866264 100644 --- a/lib/libdisk/create_chunk.c +++ b/lib/libdisk/create_chunk.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: create_chunk.c,v 1.12 1995/05/08 01:26:47 phk Exp $ + * $Id: create_chunk.c,v 1.13 1995/05/10 05:57:02 phk Exp $ * */ @@ -91,31 +91,17 @@ Fixup_FreeBSD_Names(struct disk *d, struct chunk *c) void Fixup_Extended_Names(struct disk *d, struct chunk *c) { - struct chunk *c1, *c3; - int j; - char *p=0; + struct chunk *c1; + int j=5; for (c1 = c->part; c1 ; c1 = c1->next) { + if (c1->type == unused) continue; + free(c1->name); + c1->name = malloc(12); + if(!c1->name) err(1,"malloc failed"); + sprintf(c1->name,"%ss%d",c->name,j++); if (c1->type == freebsd) Fixup_FreeBSD_Names(d,c1); - if (c1->type == unused) continue; - if (strcmp(c1->name, "X")) continue; - for(j=5;j<=29;j++) { - p = malloc(12); - if(!p) err(1,"malloc failed"); - sprintf(p,"%ss%d",c->name,j); - for(c3 = c->part; c3 ; c3 = c3->next) - if (c3 != c1 && !strcmp(c3->name, p)) - goto match; - free(c1->name); - c1->name = p; - p = 0; - break; - match: - continue; - } - if(p) - free(p); } } @@ -124,32 +110,42 @@ Fixup_Names(struct disk *d) { struct chunk *c1, *c2, *c3; int i,j; - char *p=0; c1 = d->chunks; for(i=1,c2 = c1->part; c2 ; c2 = c2->next) { + c2->flags &= ~CHUNK_BSD_COMPAT; + if (c2->type == unused) + continue; + if (strcmp(c2->name,"X")) + continue; + c2->oname = malloc(12); + if(!c2->oname) err(1,"malloc failed"); + for(j=1;j<=NDOSPART;j++) { + sprintf(c2->oname,"%ss%d",c1->name,j); + for(c3 = c1->part; c3 ; c3 = c3->next) + if (c3 != c2 && !strcmp(c3->name, c2->oname)) + goto match; + free(c2->name); + c2->name = c2->oname; + c2->oname = 0; + break; + match: + continue; + } + if (c2->oname) + free(c2->oname); + } + for(c2 = c1->part; c2 ; c2 = c2->next) { + if (c2->type == freebsd) { + c2->flags |= CHUNK_BSD_COMPAT; + break; + } + } + for(c2 = c1->part; c2 ; c2 = c2->next) { if (c2->type == freebsd) Fixup_FreeBSD_Names(d,c2); if (c2->type == extended) Fixup_Extended_Names(d,c2); - if (c2->type == unused) - continue; - p = malloc(12); - if(!p) err(1,"malloc failed"); - for(j=1;j<=NDOSPART;j++) { - sprintf(p,"%ss%d",c1->name,j); - for(c3 = c1->part; c3 ; c3 = c3->next) - if (c3 != c2 && !strcmp(c3->name, p)) - goto match; - free(c2->name); - c2->name = p; - p = 0; - break; - match: - continue; - } - if(p) - free(p); } } @@ -158,8 +154,6 @@ Create_Chunk(struct disk *d, u_long offset, u_long size, chunk_e type, int subty { int i; - if (type == freebsd) - subtype = 0xa5; i = Add_Chunk(d,offset,size,"X",type,subtype,flags); Fixup_Names(d); return i; @@ -174,8 +168,6 @@ Create_Chunk_DWIM(struct disk *d, struct chunk *parent , u_long size, chunk_e ty if (!parent) parent = d->chunks; - if (type == freebsd) - subtype = 0xa5; for (c1=parent->part; c1 ; c1 = c1->next) { if (c1->type != unused) continue; if (c1->size < size) continue; diff --git a/lib/libdisk/tst01.c b/lib/libdisk/tst01.c index b32253a44521..43a636491b9f 100644 --- a/lib/libdisk/tst01.c +++ b/lib/libdisk/tst01.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: tst01.c,v 1.10 1995/05/04 07:00:56 phk Exp $ + * $Id: tst01.c,v 1.11 1995/05/10 05:57:04 phk Exp $ * */ @@ -171,11 +171,11 @@ main(int argc, char **argv) if (!strcasecmp(*cmds,"dwim") && ncmd == 6) { printf("dwim = %p\n", Create_Chunk_DWIM(d, - (struct chunk *)strtol(cmds[1],0,0)), + (struct chunk *)strtol(cmds[1],0,0), strtol(cmds[2],0,0), strtol(cmds[3],0,0), strtol(cmds[4],0,0), - strtol(cmds[5],0,0) ); + strtol(cmds[5],0,0))); continue; } if (!strcasecmp(*cmds,"delete") && ncmd == 2) { diff --git a/release/libdisk/chunk.c b/release/libdisk/chunk.c index 54630bed7761..c100927045b7 100644 --- a/release/libdisk/chunk.c +++ b/release/libdisk/chunk.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: chunk.c,v 1.10 1995/05/07 01:28:16 jkh Exp $ + * $Id: chunk.c,v 1.11 1995/05/08 02:08:25 phk Exp $ * */ @@ -200,6 +200,8 @@ Add_Chunk(struct disk *d, long offset, u_long size, char *name, chunk_e type, c1->subtype = subtype; return 0; } + if (type == freebsd) + subtype = 0xa5; c1 = 0; if(!c1 && (type == freebsd || type == fat || type == unknown)) c1 = Find_Mother_Chunk(d->chunks,offset,end,extended); @@ -380,6 +382,7 @@ Collapse_Chunk(struct disk *d, struct chunk *c1) } if(c3->type == unused) { c2 = new_chunk(); + if (!c2) err(1,"malloc failed"); *c2 = *c1; c1->next = c2; c1->name = strdup("-"); diff --git a/release/libdisk/create_chunk.c b/release/libdisk/create_chunk.c index 4d530f4b27d8..7af521866264 100644 --- a/release/libdisk/create_chunk.c +++ b/release/libdisk/create_chunk.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: create_chunk.c,v 1.12 1995/05/08 01:26:47 phk Exp $ + * $Id: create_chunk.c,v 1.13 1995/05/10 05:57:02 phk Exp $ * */ @@ -91,31 +91,17 @@ Fixup_FreeBSD_Names(struct disk *d, struct chunk *c) void Fixup_Extended_Names(struct disk *d, struct chunk *c) { - struct chunk *c1, *c3; - int j; - char *p=0; + struct chunk *c1; + int j=5; for (c1 = c->part; c1 ; c1 = c1->next) { + if (c1->type == unused) continue; + free(c1->name); + c1->name = malloc(12); + if(!c1->name) err(1,"malloc failed"); + sprintf(c1->name,"%ss%d",c->name,j++); if (c1->type == freebsd) Fixup_FreeBSD_Names(d,c1); - if (c1->type == unused) continue; - if (strcmp(c1->name, "X")) continue; - for(j=5;j<=29;j++) { - p = malloc(12); - if(!p) err(1,"malloc failed"); - sprintf(p,"%ss%d",c->name,j); - for(c3 = c->part; c3 ; c3 = c3->next) - if (c3 != c1 && !strcmp(c3->name, p)) - goto match; - free(c1->name); - c1->name = p; - p = 0; - break; - match: - continue; - } - if(p) - free(p); } } @@ -124,32 +110,42 @@ Fixup_Names(struct disk *d) { struct chunk *c1, *c2, *c3; int i,j; - char *p=0; c1 = d->chunks; for(i=1,c2 = c1->part; c2 ; c2 = c2->next) { + c2->flags &= ~CHUNK_BSD_COMPAT; + if (c2->type == unused) + continue; + if (strcmp(c2->name,"X")) + continue; + c2->oname = malloc(12); + if(!c2->oname) err(1,"malloc failed"); + for(j=1;j<=NDOSPART;j++) { + sprintf(c2->oname,"%ss%d",c1->name,j); + for(c3 = c1->part; c3 ; c3 = c3->next) + if (c3 != c2 && !strcmp(c3->name, c2->oname)) + goto match; + free(c2->name); + c2->name = c2->oname; + c2->oname = 0; + break; + match: + continue; + } + if (c2->oname) + free(c2->oname); + } + for(c2 = c1->part; c2 ; c2 = c2->next) { + if (c2->type == freebsd) { + c2->flags |= CHUNK_BSD_COMPAT; + break; + } + } + for(c2 = c1->part; c2 ; c2 = c2->next) { if (c2->type == freebsd) Fixup_FreeBSD_Names(d,c2); if (c2->type == extended) Fixup_Extended_Names(d,c2); - if (c2->type == unused) - continue; - p = malloc(12); - if(!p) err(1,"malloc failed"); - for(j=1;j<=NDOSPART;j++) { - sprintf(p,"%ss%d",c1->name,j); - for(c3 = c1->part; c3 ; c3 = c3->next) - if (c3 != c2 && !strcmp(c3->name, p)) - goto match; - free(c2->name); - c2->name = p; - p = 0; - break; - match: - continue; - } - if(p) - free(p); } } @@ -158,8 +154,6 @@ Create_Chunk(struct disk *d, u_long offset, u_long size, chunk_e type, int subty { int i; - if (type == freebsd) - subtype = 0xa5; i = Add_Chunk(d,offset,size,"X",type,subtype,flags); Fixup_Names(d); return i; @@ -174,8 +168,6 @@ Create_Chunk_DWIM(struct disk *d, struct chunk *parent , u_long size, chunk_e ty if (!parent) parent = d->chunks; - if (type == freebsd) - subtype = 0xa5; for (c1=parent->part; c1 ; c1 = c1->next) { if (c1->type != unused) continue; if (c1->size < size) continue; diff --git a/release/libdisk/tst01.c b/release/libdisk/tst01.c index b32253a44521..43a636491b9f 100644 --- a/release/libdisk/tst01.c +++ b/release/libdisk/tst01.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: tst01.c,v 1.10 1995/05/04 07:00:56 phk Exp $ + * $Id: tst01.c,v 1.11 1995/05/10 05:57:04 phk Exp $ * */ @@ -171,11 +171,11 @@ main(int argc, char **argv) if (!strcasecmp(*cmds,"dwim") && ncmd == 6) { printf("dwim = %p\n", Create_Chunk_DWIM(d, - (struct chunk *)strtol(cmds[1],0,0)), + (struct chunk *)strtol(cmds[1],0,0), strtol(cmds[2],0,0), strtol(cmds[3],0,0), strtol(cmds[4],0,0), - strtol(cmds[5],0,0) ); + strtol(cmds[5],0,0))); continue; } if (!strcasecmp(*cmds,"delete") && ncmd == 2) {