master_ops.c revision 8e56767d5805b843712c67bce2d732cc722f154b
/*
* 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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/kobj_lex.h>
#define masterfile "/boot/solaris/devicedb/master"
/* Maximum size of a master line */
static char *one_master_line;
static int one_master_line_cur_index = 0, one_master_line_max = 0;
struct master_line {
char *column[10];
char *text; /* to be kmem alloc'd */
int line_size;
};
static int mf_column = 0;
static int incore_master_table_line_count = 0;
#define MASTER_OPS_DEBUG_PRINT_INCORE 0x0001
#define MASTER_OPS_DEBUG_PROCESS 0x0002
#define MASTER_OPS_DEBUG_LOOKUP 0x0004
#define MASTER_OPS_DEBUG_CID_FOUND 0x2000
static long master_ops_debug = 0x0;
#define EOL 0xA
static void
int i;
for (i = 0; i < incore_master_table_line_count; i++) {
printf("1)%s, 2)%s, 3)%s, 4)%s, 5)%s, 6)%s, ",
}
}
printf("\n");
i++;
break;
}
}
printf("There are %d lines\n", i);
}
}
/*
* parses one_master_line[] from index pointed by one_master_line_cur_index
* returns the following tokens
* POUND -- if a comment line
* NEWLINE -- if an empty line
* NAME -- return a string from one_master_line separated by " or blank
* EOL -- End of line
*/
static int
master_lex(char *val) {
char *cp;
int ch;
int token;
/* skip leading blanks */
;
val = 0;
return (EOL);
}
switch (ch) {
case '#':
break;
case '\n':
case '\r':
break;
case '"':
cp--;
!= '"') && (one_master_line_cur_index <=
}
break;
default:
}
break;
}
*cp = '\0';
return (token);
}
/*
* one_master_line_max -- size of data in one_master_line[]
* one_master_line_cur_index -- reset to zero
*/
static int
int ch;
one_master_line_max = 0;
one_master_line_cur_index = 0; /* used by master_lex() */
if (ch == -1) {
if (one_master_line_max == 0) {
one_master_line[0] = 0;
return (EOF);
} else {
return (one_master_line_max);
}
}
if (one_master_line_max >= MASTER_LINE_MAX) {
}
}
return (one_master_line_max);
}
/*
* skip a line
*/
static void
char ch;
;
}
/*
* return NULL if no bar found
* if bar found, return pointer after the bar
* plus, change character '|' (bar) to null as a delimiter
*/
static char *
return (NULL);
}
target++;
}
if (*target == '|') {
*target = 0;
return (++target);
}
return (NULL);
}
/*
* If column 0 has | (bars) as device separators, we need make (dup)
* more lines for each device.
*/
static void
dup_devices() {
char *token;
int i;
return;
}
sizeof (struct master_line), KM_SLEEP);
for (i = 0; i < 10; i++) {
}
}
}
/*
* sets master_ops_debug flag from propertyu passed by the boot
*/
static void
{
char *prop;
long flags;
long data;
master_ops_debug = (unsigned long)data;
"master_ops_debug");
}
}
}
/*
*/
void
char tokbuf[MASTER_LINE_MAX];
int token;
int done = 0;
int line_begin;
int x = 0;
int total_line_processed = 0;
return;
}
mf_column = 0;
while (!done) {
if (mf_column == 0) {
x = master_get_a_line(file);
if (x == EOF) { /* end of file */
done = 1;
continue;
}
if (x == 0) { /* blank line */
continue;
}
}
switch (token) {
case POUND: /* ignore comment line */
if (master_ops_debug & MASTER_OPS_DEBUG_PROCESS) {
printf("master_ops: # found skip this line\n");
}
mf_column = 0;
break;
case NAME: /* found actual string, parse and keep it */
if (mf_column == 0) {
if (incore_master_tail == NULL) {
/* very 1st line */
incore_master_tail = (struct
sizeof (struct master_line),
KM_SLEEP);
incore_master_head->text = (char *)
KM_SLEEP);
} else {
incore_master_tail->next = (struct
sizeof (struct master_line),
KM_SLEEP);
incore_master_tail->text = (char *)
KM_SLEEP);
}
line_begin = 0;
}
mf_column = 0;
break;
}
tokbuf);
if (master_ops_debug & MASTER_OPS_DEBUG_PROCESS) {
printf("master_ops: line=%d column[%x] found:"\
" \"%s\"\n",
}
mf_column++;
break;
case EOF: /* end of file */
if (master_ops_debug & MASTER_OPS_DEBUG_PROCESS) {
printf("master_ops: EOF found. We're done.\n");
}
done = 1;
break;
case EOL: /* end of line */
if (master_ops_debug & MASTER_OPS_DEBUG_PROCESS) {
printf("master_ops: EOL found.\n");
}
mf_column = 0;
one_master_line_max = 0;
dup_devices();
break;
default: /* something went wrong */
"parsing master file: %s", tokbuf);
}
}
if (master_ops_debug & MASTER_OPS_DEBUG_PROCESS) {
printf("master_ops: incore line count: %d\n",
printf("master_ops: total line processed: %d\n",
}
}
/*
* Loop and free all per line master data, including line text
*/
void
free_master_data() {
int i;
for (i = 0; i < incore_master_table_line_count; i++) {
}
break; /* we're done */
}
}
if (one_master_line) {
}
}
/*
* To match pnpid with master table entries
* returns 0 if no matching device found in master file
* 1 if a matching device is in master file
* devname -- device node name
* description -- device description string
* properties -- device attributes (e.g. compatibility="kb8042")
* (could be NULL)
*/
int
char **properties)
{
/*
* Caller will pass us a null pointer if _CID not present
*/
return (0);
if (master_ops_debug & MASTER_OPS_DEBUG_LOOKUP) {
}
KM_SLEEP);
KM_SLEEP);
} else
*properties = NULL;
if (master_ops_debug & MASTER_OPS_DEBUG_LOOKUP) {
printf("FOUND. dev node name: \"%s\"\n",
*devname);
if (*properties != NULL) {
printf(" properties: \"%s\"\n",
*properties);
} else {
printf("\n");
}
}
return (1);
}
}
/* XXX: for the devices not found, they should go to used resources?? */
if (master_ops_debug & MASTER_OPS_DEBUG_LOOKUP) {
printf("NOT FOUND!!!\n");
}
return (0);
}
/*
* master_file_lookups() -- processes multiple pnp IDs (CIDs)
* return 1 if a PNP id is matched
* else return 0
*/
int
char **properties, int pnpid_size)
{
return (0);
}
if (ret == 1) {
}
return (ret); /* a CID is found */
}
}
return (0);
}