FreeBSD/usr.sbin/dumpcis/readcis.c
/*
 *	Read one tuple list from the card.
 */
Read one tuple list from the card.
Read one tuple list from the card .
static struct tuple_list *
read_one_tuplelist(int fd, int flags, off_t offs)
{
	struct tuple *tp, *last_tp = 0;
	struct tuple_list *tl;
	struct tuple_info *tinfo;
	int     total = 0;
	unsigned char code, length;
	for (tl = tlist; tl; tl = tl->next)
		if (tl->offs == offs && tl->flags == (flags & MDF_ATTR))
			return (0);
	tl = xmalloc(sizeof(*tl));
	tl->offs = offs;
	tl->flags = flags & MDF_ATTR;
	ioctl(fd, PIOCRWFLAG, &flags);
	lseek(fd, offs, SEEK_SET);
	do {
		if (read(fd, &code, 1) != 1) {
			warn("CIS code read");
			break;
		}
		total++;
		if (code == CIS_NULL)
			continue;
		tp = xmalloc(sizeof(*tp));
		tp->code = code;
		if (code == CIS_END)
			length = 0;
		else {
			if (read(fd, &length, 1) != 1) {
				warn("CIS len read");
				break;
			}
			total++;
		}
		tp->length = length;
#ifdef	DEBUG
		printf("Tuple code = 0x%x, len = %d\n", code, length);
#endif
		if (length == 0xFF) {
			length = tp->length = 0;
			code = CIS_END;
		}
		if (length != 0) {
			total += length;
			tp->data = xmalloc(length);
			if (read(fd, tp->data, length) != length) {
				warn("CIS read");
				break;
			}
		}
		tinfo = get_tuple_info(code);
		if (tinfo != NULL && (tinfo->length != 255 && tinfo->length > length)) {
			printf("code %s (%d) ignored\n", tuple_name(code), code);
			tp->code = CIS_NULL;
		}
		if (tl->tuples == NULL)
			tl->tuples = tp;
		else
			last_tp->next = tp;
		last_tp = tp;
	} while (code != CIS_END && total < 1024);
	return (tl);
}
static struct tuple_list * read_one_tuplelist ( int fd , int flags , off_t offs ) { struct tuple * tp , * last_tp = 0 ; struct tuple_list * tl ; struct tuple_info * tinfo ; int total = 0 ; unsigned char code , length ; for ( tl = tlist ; tl ; tl = tl -> next ) if ( tl -> offs == offs && tl -> flags == ( flags & MDF_ATTR ) ) return ( 0 ) ; tl = xmalloc ( sizeof ( * tl ) ) ; tl -> offs = offs ; tl -> flags = flags & MDF_ATTR ; ioctl ( fd , PIOCRWFLAG , & flags ) ; lseek ( fd , offs , SEEK_SET ) ; do { if ( read ( fd , & code , 1 ) != 1 ) { warn ( " " ) ; break ; } total ++ ; if ( code == CIS_NULL ) continue ; tp = xmalloc ( sizeof ( * tp ) ) ; tp -> code = code ; if ( code == CIS_END ) length = 0 ; else { if ( read ( fd , & length , 1 ) != 1 ) { warn ( " " ) ; break ; } total ++ ; } tp -> length = length ; #ifdef DEBUG printf ( " \n " , code , length ) ; #endif if ( length == 0xFF ) { length = tp -> length = 0 ; code = CIS_END ; } if ( length != 0 ) { total += length ; tp -> data = xmalloc ( length ) ; if ( read ( fd , tp -> data , length ) != length ) { warn ( " " ) ; break ; } } tinfo = get_tuple_info ( code ) ; if ( tinfo != NULL && ( tinfo -> length != 255 && tinfo -> length > length ) ) { printf ( " \n " , tuple_name ( code ) , code ) ; tp -> code = CIS_NULL ; } if ( tl -> tuples == NULL ) tl -> tuples = tp ; else last_tp -> next = tp ; last_tp = tp ; } while ( code != CIS_END && total < 1024 ) ; return ( tl ) ; }
Read one tuple list from the card.
Read one tuple list from the card .
/* Check to see if this memory has already been scanned. */ /*
		 * Check the tuple, and ignore it if it isn't in the table
		 * or the length is illegal.
		 */