tnf_writer.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1994, by Sun Microsytems, Inc.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#ifndef DEBUG
#define NDEBUG 1
#endif
#ifdef _KERNEL
#include <sys/tnf_writer.h>
#include "tnf_types.h"
#include "tnf_trace.h"
#else /* _KERNEL */
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "tnf_types.h"
#include <tnf_trace.h>
#endif /* _KERNEL */
/*
* Defines
*/
#ifdef _KERNEL
#else
#endif
/*
* Local functions
*/
/*
* TNF tag version 1
*/
sizeof (tnf_tag_version_t),
sizeof (tnf_tag_data_t)
};
/*
* Pure abstract types
*/
/*
* Scalar types
*/
static tnf_tag_data_t **std_scalar_properties[] = {
0};
/*
* Array types
*/
static tnf_tag_data_t **array_properties[] = {
0
};
static tnf_tag_data_t **std_array_properties[] = {
0
};
/* Exported */
/* Exported */
tnf_tag_data_t **tnf_array_slots[] = {
0
};
/*
* Derived types
*/
static tnf_tag_data_t **derived_properties[] = {
0
};
/* Exported */
#if defined(_LP64)
#else
#endif /* defined(_LP64) */
/*
* Struct types
*/
static tnf_tag_data_t **no_properties[] = { 0 };
static tnf_tag_data_t **no_slots[] = { 0 };
static tnf_tag_data_t **std_struct_properties[] = {
0};
/* Exported */
/*
* File header - CAUTION - has to be in sync with com.h
*/
static char *file_header_slot_names[] = {
/* XXX add writer-specific opaque slots here for reader */
0};
static tnf_tag_data_t **file_header_slots[] = {
/* XXX add writer-specific opaque slots here for reader */
0};
/* size of tnf_file_header has the size of the magic number subtracted */
sizeof (tnf_buf_file_header_t) - sizeof (tnf_uint32_t));
/*
* Block header - CAUTION - has to be in sync with com.h
*/
static char *block_header_slot_names[] = {
"A_lock", /* XXX */
"B_lock", /* XXX */
"next_block", /* XXX */
0};
static tnf_tag_data_t **block_header_slots[] = {
0};
sizeof (tnf_block_header_t));
/*
* Metatypes
*/
static tnf_tag_data_t **type_properties[] = {
0};
/* Exported */
static tnf_tag_data_t **type_slots[] = {
0};
static tnf_tag_data_t **array_type_slots[] = {
0};
static tnf_tag_data_t **derived_type_slots[] = {
0};
static tnf_tag_data_t **scalar_type_slots[] = {
0};
static tnf_tag_data_t **struct_type_slots[] = {
0};
/*
* Generic tnf reference - does checking on whether destination is
* a permanent block or not
*/
#ifdef _KERNEL
/*ARGSUSED0*/
{
unsigned int offset_shift =
/* LINTED pointer cast may result in improper alignment */
/* reference to a permanent block */
/* LINTED ast from 64-bit integer to 32-bit integer */
return (TNF_REF32_MAKE_PERMANENT(offset_delta));
} else {
/* reference to a reclaimable block */
/* LINTED ast from 64-bit integer to 32-bit integer */
return (TNF_REF32_MAKE_RECLAIMABLE(result));
}
}
#else
/*ARGSUSED0*/
{
unsigned int offset_shift =
/* LINTED pointer cast may result in improper alignment */
/* reference to a permanent block */
/* LINTED ast from 64-bit integer to 32-bit integer */
return (TNF_REF32_MAKE_PERMANENT(offset_delta));
} else {
/* reference to a reclaimable block */
/* LINTED ast from 64-bit integer to 32-bit integer */
return (TNF_REF32_MAKE_RECLAIMABLE(result));
}
}
#endif
/*
* Tag descriptors
*/
/*
* Write instances of tnf_type
*/
{
enum tnf_alloc_mode saved_mode;
/* LINTED assignment of 32-bit integer to 8-bit integer */
/* LINTED assignment of 32-bit integer to 8-bit integer */
}
/*
* Write instances of tnf_scalar_type
*/
{
enum tnf_alloc_mode saved_mode;
/* LINTED assignment of 32-bit integer to 8-bit integer */
/* LINTED assignment of 32-bit integer to 8-bit integer */
/* LINTED assignment of 64-bit integer to 32-bit integer */
/* LINTED assignment of 32-bit integer to 8-bit integer */
}
/*
* Write instances of tnf_derived_type
*/
{
enum tnf_alloc_mode saved_mode;
/* LINTED assignment of 32-bit integer to 8-bit integer */
/* LINTED assignment of 32-bit integer to 8-bit integer */
}
/*
* Write instances of tnf_struct_type (except root)
*/
{
enum tnf_alloc_mode saved_mode;
/* LINTED assignment of 32-bit integer to 8-bit integer */
/* LINTED assignment of 64-bit integer to 32-bit integer */
/* LINTED assignment of 32-bit integer to 8-bit integer */
}
/*
* Write instances of tnf_array_type
*/
{
enum tnf_alloc_mode saved_mode;
/* LINTED assignment of 32-bit integer to 8-bit integer */
/* LINTED assignment of 64-bit integer to 32-bit integer */
/* LINTED assignment of 32-bit integer to 8-bit integer */
}
/*
* Write the root metatype, and some critical bootstrap types
*/
static tnf_record_p
{
enum tnf_alloc_mode saved_mode;
/* LINTED assignment of 32-bit integer to 8-bit integer */
/*
* update the root forwarding pointer to point to this root
* CAUTION: Do this before anything else...
*/
#ifdef _KERNEL
/* LINTED pointer cast may result in improper alignment */
#else
/* LINTED pointer cast may result in improper alignment */
if (fw_p) {
(tnf_record_p) fw_p);
}
#endif
#ifdef _KERNEL
/* LINTED constant truncated by assignment */
#else
#endif
/* LINTED assignment of 64-bit integer to 32-bit integer */
/*
* Write some additional bootstrap types
*/
{
static tnf_tag_data_t *bootstrap_types[] = {
0};
}
}
/*
* fix for circularity in filling in file header tag and block
* header tag. REMIND: should also fix tag_index of
* file_header.
*/
#ifdef _KERNEL
/* LINTED pointer cast may result in improper alignment */
(tnf_record_p)fw_p);
/* LINTED pointer cast may result in improper alignment */
(tnf_record_p)fw_p);
#else
/* LINTED pointer cast may result in improper alignment */
if (fw_p) {
(tnf_record_p)fw_p);
}
/* LINTED pointer cast may result in improper alignment */
if (fw_p) {
(tnf_record_p) fw_p);
}
#endif
/* LINTED assignment of 32-bit integer to 8-bit integer */
}
/*
* Data encoders
*/
/*
* Strings and derivatives
*/
{
if (!string)
return ((tnf_reference_t)TNF_NULL);
if (string_size > TNF_STRING_LIMIT)
/* Allocate space for terminating NUL as well */
/* LINTED assignment of 64-bit integer to 32-bit integer */
#ifdef _KERNEL
#else
#endif
/* NUL-terminate */
}
/*
* Array of strings and derivatives
*/
{
char **tmp;
if (!strings)
return ((tnf_reference_t)TNF_NULL);
record_size = sizeof (*bufhdr);
while (*tmp++)
record_size += sizeof (tnf_string_t);
/* LINTED assignment of 64-bit integer to 32-bit integer */
/* LINTED pointer cast may result in improper alignment */
while (*tmp) {
tmp++;
ref_p++;
}
}
/*
* Type record as generic (not tag) reference
*/
{
if (aux_tag_data)
if (!aux_tag_data->tag_index)
/* tnf_derived has derived_base == TNF_NULL */
if (!tag_data_p)
return ((tnf_reference_t)TNF_NULL);
tag_data = *tag_data_p;
}
/*
* Array of type records as generic (not tag) references
*/
{
tnf_tag_data_t ***tmp;
if (!tag_data_array)
return ((tnf_reference_t)TNF_NULL);
record_size = sizeof (*bufhdr);
while (*tmp++)
record_size += sizeof (tnf_reference_t);
/* LINTED assignment of 64-bit integer to 32-bit integer */
/* LINTED pointer cast may result in improper alignment */
while (*tmp) {
TNF_NULL);
tmp++;
ref_p++;
}
}
/*
* Array of properties (type records)
*/
{
if (!tag_data_array)
return ((tnf_reference_t)TNF_NULL);
}
#ifdef _KERNEL
/*
* Initialize all core tag pointers defined in this file.
* CAUTION: tnf_tag_core_init is a function for kernel compilation.
*/
void
tnf_tag_core_init(void)
{
#endif
#ifdef _KERNEL
/* Snap exported properties */
}
#else /* _KERNEL */
#endif /* _KERNEL */