Add the private void *pointer to the chunks, and the functions to manage it.
Make the reassignment of partition names less bogus.
This commit is contained in:
parent
455d2a327b
commit
3a333cad85
@ -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.4 1995/04/30 06:09:24 phk Exp $
|
||||
* $Id: chunk.c,v 1.5 1995/05/01 21:30:22 jkh Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -79,6 +79,8 @@ Free_Chunk(struct chunk *c1)
|
||||
{
|
||||
/* XXX remove all chunks which "ref" us */
|
||||
if(!c1) return;
|
||||
if(c1->private && c1->private_free)
|
||||
(*c1->private_free)(c1->private);
|
||||
if(c1->part)
|
||||
Free_Chunk(c1->part);
|
||||
if(c1->next)
|
||||
@ -96,6 +98,8 @@ Clone_Chunk(struct chunk *c1)
|
||||
c2 = new_chunk();
|
||||
if (!c2) err(1,"malloc failed");
|
||||
*c2 = *c1;
|
||||
if (c1->private && c1->private_clone)
|
||||
c2->private_clone(c2->private);
|
||||
c2->name = strdup(c2->name);
|
||||
c2->next = Clone_Chunk(c2->next);
|
||||
c2->part = Clone_Chunk(c2->part);
|
||||
@ -109,13 +113,12 @@ Insert_Chunk(struct chunk *c2, u_long offset, u_long size, char *name, chunk_e t
|
||||
|
||||
ct = new_chunk();
|
||||
if (!ct) err(1,"malloc failed");
|
||||
memset(ct,0,sizeof *ct);
|
||||
ct->offset = offset;
|
||||
ct->size = size;
|
||||
ct->end = offset + size - 1;
|
||||
ct->type = type;
|
||||
ct->name = strdup(name);
|
||||
ct->next = 0;
|
||||
ct->part = 0;
|
||||
ct->subtype = subtype;
|
||||
ct->flags = flags;
|
||||
|
||||
|
@ -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.6 1995/05/01 04:05:24 phk Exp $
|
||||
* $Id: create_chunk.c,v 1.7 1995/05/03 06:30:50 phk Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -30,8 +30,12 @@ Fixup_FreeBSD_Names(struct disk *d, struct chunk *c)
|
||||
if (!strcmp(c->name, "X")) return;
|
||||
|
||||
/* reset all names to "X" */
|
||||
for (c1 = c->part; c1 ; c1 = c1->next)
|
||||
for (c1 = c->part; c1 ; c1 = c1->next) {
|
||||
c1->oname = c1->name;
|
||||
c1->name = malloc(12);
|
||||
if(!c1->name) err(1,"Malloc failed");
|
||||
strcpy(c1->name,"X");
|
||||
}
|
||||
|
||||
/* Allocate the first swap-partition we find */
|
||||
for (c1 = c->part; c1 ; c1 = c1->next) {
|
||||
@ -51,6 +55,15 @@ Fixup_FreeBSD_Names(struct disk *d, struct chunk *c)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Try to give them the same as they had before */
|
||||
for (c1 = c->part; c1 ; c1 = c1->next) {
|
||||
for(c3 = c->part; c3 ; c3 = c3->next)
|
||||
if (c1 != c3 && !strcmp(c3->name, c1->oname)) {
|
||||
strcpy(c1->name,c1->oname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate the rest sequentially */
|
||||
for (c1 = c->part; c1 ; c1 = c1->next) {
|
||||
const char order[] = "defghab";
|
||||
@ -69,6 +82,10 @@ Fixup_FreeBSD_Names(struct disk *d, struct chunk *c)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (c1 = c->part; c1 ; c1 = c1->next) {
|
||||
free(c1->oname);
|
||||
c1->oname = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: disk.c,v 1.13 1995/05/03 06:30:55 phk Exp $
|
||||
* $Id: disk.c,v 1.14 1995/05/03 17:37:58 jkh Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -186,7 +186,7 @@ Int_Open_Disk(char *name, u_long size)
|
||||
dl.d_partitions[j].p_size,
|
||||
pname,part,
|
||||
dl.d_partitions[j].p_fstype,
|
||||
j == 0 ? CHUNK_IS_ROOT : 0) && j != 3)
|
||||
0) && j != 3)
|
||||
warn(
|
||||
"Failed to add chunk for partition %c [%lu,%lu]",
|
||||
j + 'a',dl.d_partitions[j].p_offset,
|
||||
|
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: libdisk.h,v 1.9 1995/05/03 06:30:57 phk Exp $
|
||||
* $Id: libdisk.h,v 1.10 1995/05/03 17:37:59 jkh Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -40,6 +40,10 @@ struct chunk {
|
||||
u_long size;
|
||||
u_long end;
|
||||
char *name;
|
||||
char *oname;
|
||||
/* Used during Fixup_Names() to avoid renaming more than
|
||||
* absolutely needed.
|
||||
*/
|
||||
chunk_e type;
|
||||
int subtype;
|
||||
u_long flags;
|
||||
@ -54,6 +58,15 @@ struct chunk {
|
||||
# define CHUNK_ALIGN 8
|
||||
# define CHUNK_IS_ROOT 16
|
||||
/* This 'part' is a rootfs, allocate 'a' */
|
||||
|
||||
void (*private_free)(void*);
|
||||
void *(*private_clone)(void*);
|
||||
void *private;
|
||||
/* For data private to the application, and the management
|
||||
* thereof. If the functions are not provided, no storage
|
||||
* management is done, Cloning will just copy the pointer
|
||||
* and freeing will just forget it.
|
||||
*/
|
||||
};
|
||||
|
||||
struct disk *
|
||||
|
@ -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.4 1995/04/30 06:09:24 phk Exp $
|
||||
* $Id: chunk.c,v 1.5 1995/05/01 21:30:22 jkh Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -79,6 +79,8 @@ Free_Chunk(struct chunk *c1)
|
||||
{
|
||||
/* XXX remove all chunks which "ref" us */
|
||||
if(!c1) return;
|
||||
if(c1->private && c1->private_free)
|
||||
(*c1->private_free)(c1->private);
|
||||
if(c1->part)
|
||||
Free_Chunk(c1->part);
|
||||
if(c1->next)
|
||||
@ -96,6 +98,8 @@ Clone_Chunk(struct chunk *c1)
|
||||
c2 = new_chunk();
|
||||
if (!c2) err(1,"malloc failed");
|
||||
*c2 = *c1;
|
||||
if (c1->private && c1->private_clone)
|
||||
c2->private_clone(c2->private);
|
||||
c2->name = strdup(c2->name);
|
||||
c2->next = Clone_Chunk(c2->next);
|
||||
c2->part = Clone_Chunk(c2->part);
|
||||
@ -109,13 +113,12 @@ Insert_Chunk(struct chunk *c2, u_long offset, u_long size, char *name, chunk_e t
|
||||
|
||||
ct = new_chunk();
|
||||
if (!ct) err(1,"malloc failed");
|
||||
memset(ct,0,sizeof *ct);
|
||||
ct->offset = offset;
|
||||
ct->size = size;
|
||||
ct->end = offset + size - 1;
|
||||
ct->type = type;
|
||||
ct->name = strdup(name);
|
||||
ct->next = 0;
|
||||
ct->part = 0;
|
||||
ct->subtype = subtype;
|
||||
ct->flags = flags;
|
||||
|
||||
|
@ -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.6 1995/05/01 04:05:24 phk Exp $
|
||||
* $Id: create_chunk.c,v 1.7 1995/05/03 06:30:50 phk Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -30,8 +30,12 @@ Fixup_FreeBSD_Names(struct disk *d, struct chunk *c)
|
||||
if (!strcmp(c->name, "X")) return;
|
||||
|
||||
/* reset all names to "X" */
|
||||
for (c1 = c->part; c1 ; c1 = c1->next)
|
||||
for (c1 = c->part; c1 ; c1 = c1->next) {
|
||||
c1->oname = c1->name;
|
||||
c1->name = malloc(12);
|
||||
if(!c1->name) err(1,"Malloc failed");
|
||||
strcpy(c1->name,"X");
|
||||
}
|
||||
|
||||
/* Allocate the first swap-partition we find */
|
||||
for (c1 = c->part; c1 ; c1 = c1->next) {
|
||||
@ -51,6 +55,15 @@ Fixup_FreeBSD_Names(struct disk *d, struct chunk *c)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Try to give them the same as they had before */
|
||||
for (c1 = c->part; c1 ; c1 = c1->next) {
|
||||
for(c3 = c->part; c3 ; c3 = c3->next)
|
||||
if (c1 != c3 && !strcmp(c3->name, c1->oname)) {
|
||||
strcpy(c1->name,c1->oname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate the rest sequentially */
|
||||
for (c1 = c->part; c1 ; c1 = c1->next) {
|
||||
const char order[] = "defghab";
|
||||
@ -69,6 +82,10 @@ Fixup_FreeBSD_Names(struct disk *d, struct chunk *c)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (c1 = c->part; c1 ; c1 = c1->next) {
|
||||
free(c1->oname);
|
||||
c1->oname = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: disk.c,v 1.13 1995/05/03 06:30:55 phk Exp $
|
||||
* $Id: disk.c,v 1.14 1995/05/03 17:37:58 jkh Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -186,7 +186,7 @@ Int_Open_Disk(char *name, u_long size)
|
||||
dl.d_partitions[j].p_size,
|
||||
pname,part,
|
||||
dl.d_partitions[j].p_fstype,
|
||||
j == 0 ? CHUNK_IS_ROOT : 0) && j != 3)
|
||||
0) && j != 3)
|
||||
warn(
|
||||
"Failed to add chunk for partition %c [%lu,%lu]",
|
||||
j + 'a',dl.d_partitions[j].p_offset,
|
||||
|
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: libdisk.h,v 1.9 1995/05/03 06:30:57 phk Exp $
|
||||
* $Id: libdisk.h,v 1.10 1995/05/03 17:37:59 jkh Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -40,6 +40,10 @@ struct chunk {
|
||||
u_long size;
|
||||
u_long end;
|
||||
char *name;
|
||||
char *oname;
|
||||
/* Used during Fixup_Names() to avoid renaming more than
|
||||
* absolutely needed.
|
||||
*/
|
||||
chunk_e type;
|
||||
int subtype;
|
||||
u_long flags;
|
||||
@ -54,6 +58,15 @@ struct chunk {
|
||||
# define CHUNK_ALIGN 8
|
||||
# define CHUNK_IS_ROOT 16
|
||||
/* This 'part' is a rootfs, allocate 'a' */
|
||||
|
||||
void (*private_free)(void*);
|
||||
void *(*private_clone)(void*);
|
||||
void *private;
|
||||
/* For data private to the application, and the management
|
||||
* thereof. If the functions are not provided, no storage
|
||||
* management is done, Cloning will just copy the pointer
|
||||
* and freeing will just forget it.
|
||||
*/
|
||||
};
|
||||
|
||||
struct disk *
|
||||
|
Loading…
x
Reference in New Issue
Block a user