* ========== Copyright Header Begin ==========================================
* Hypervisor Software File: finddropin.c
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* - Do no alter or remove copyright notices
* - Redistribution and use of this software in source and binary forms, with
* or without modification, are permitted provided that the following
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of Sun Microsystems, Inc. or the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
* MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
* OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
* FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or maintenance of
* ========== Copyright Header End ============================================
* id: @(#)finddropin.c 1.1 03/04/01
* copyright: Copyright 2000, 2003 Sun Microsystems, Inc. All Rights Reserved
* copyright: Use is subject to license terms.
extract_string(dropin_data_t
*data
)
int32_t len
= data
->size
+1;
strncpy(str
, (caddr_t
)data
->data
, data
->size
);
do_lempel_ziv(uchar_t
*src
, int32_t len
, int32_t dlen
, int32_t verbose
)
dbuf
= (uchar_t
*)malloc(dlen
);
di_bail("Malloc Failed");
nlen
= di_decomp(src
, len
, dbuf
);
printf("Decompress: %d/%d bytes, [%d], ratio %2.2f:1\n",
len
, dlen
, nlen
, (((float)dlen
)/((float)len
)));
data
= (uchar_t
*)malloc(dlen
);
di_bail("Malloc Failed");
memcpy(data
, dbuf
, dlen
);
di_getdata(obmd_t
*src
, int32_t verbose
, dropin_data_t
*rdata
)
uint32_t *dptr
= (uint32_t *)((caddr_t
)src
+ OBMD_HDR
);
uchar_t
*data
= (uchar_t
*)dptr
;
int32_t dlen
= src
->size
;
compresshdr
*chdr
= (compresshdr
*) dptr
;
if ((chdr
->magic
== COMP_MAGIC
) && (src
->size
== chdr
->comp_size
)) {
int32_t clen
= chdr
->comp_size
;
int32_t type
= chdr
->type
;
dlen
= chdr
->decomp_size
;
printf("[COMP: %x,%x]\n", clen
, dlen
);
data
= do_lempel_ziv(data
+sizeof (compresshdr
),
clen
, dlen
, (verbose
-1));
printf("Unknown compression type: %d\n", type
);
if (dptr
[0] == OBME_MAGIC
) {
rdata
->data
+= sizeof (obme_t
);
rdata
->size
-= sizeof (obme_t
);
return (strncmp((caddr_t
)src
, "OBMD", 4) == 0);
uchar_t
*bdata
= ((uchar_t
*)src
)+OBMD_HDR
;
int32_t *data
= (int32_t *)bdata
;
return (di_isdropin(src
) && (data
[0] == OBME_MAGIC
));
di_iterate(caddr_t name
, obmd_t
*src
, int32_t size
, int32_t verbose
,
printf("di_iterate: '%s'\n", name
);
* Iterate through the chunk looking for dropins
while ((found
== NULL
) && (bytes
< size
) && (num_found
<= instance
)) {
if (!di_isdropin(src
)) break;
printf("..di: '%s' [%d]\n", src
->name
, src
->size
);
printf("instance = %i\n", instance
);
if (strcmp(name
, src
->name
) == 0) {
if (instance
== num_found
)
dlen
= src
->size
+ OBMD_HDR
;
dlen
= src
->size
+ OBMD_HDR
;
di_finddropin(caddr_t name
, obmd_t
*src
, int32_t filesize
,
int32_t verbose
, int32_t instance
)
dropin_data_t dropin_data
;
if (verbose
> 0) printf("x");
di_getdata(src
, (verbose
-1), &dropin_data
);
src
= (obmd_t
*)dropin_data
.data
;
printf("<empty filename>\n");
printf("<Not a dropin>\n");
printf("<no more bytes>\n");
container
= strdup(name
);
dir
= slash
= strchr(container
, '/');
printf("Path: %s [%x]\n", name
, size
);
while ((++i
<= instance
) && (src
!= NULL
)) {
data
= di_iterate(container
, src
, filesize
, (verbose
-1), 1);
next
+= (src
->size
+ OBMD_HDR
);
printf("Dropin: '%s', [%d]\n", data
->name
, data
->size
);
di_getdata(data
, (verbose
-1), &dropin_data
);
new = (obmd_t
*)dropin_data
.data
;
new_size
= dropin_data
.size
;
printf("Descending into: %s [%d]\n",
data
= di_finddropin(dir
, new, new_size
,