rem: && entries[i].adr == 0x01)
add: TRACE(("%s: WARNING: session %d, point %d not a data track point\n", kModuleDebugName, entries[i].session, entries[i].point)); } if (entries[i].adr == 0x01)
context: cdrom_session_get_nth_info(int deviceFD, int32 index, off_t deviceSize,                   int32 blockSize, struct session_info *sessionInfo){	status_t error = sessionInfo && index >= 0 ? B_OK : B_BAD_VALUE;	uchar data[2048];	int32 session = index+1;	//	bool found_track = false;//	bool found_start = false;//	bool found_end = false;	off_t start_lba = 0;	off_t end_lba = 0;	TRACE(("%s: get_nth_info(%d, %ld, %lld, %ld, %p)\n", kModuleDebugName,		   deviceFD, index, deviceSize, blockSize, sessionInfo));	// Attempt to read the table of contents, first in lba mode, then in msf mode	if (!error) {		error = read_table_of_contents(deviceFD, 1, data, 2048, false);	}		if (error) {		TRACE(("%s: lba read_toc failed, trying msf instead\n", kModuleDebugName));		error = read_table_of_contents(deviceFD, 1, data, 2048, true);	}			// Interpret the data returned, if successful	if (!error) {		cdrom_table_of_contents_header *header;		cdrom_full_table_of_contents_entry *entries;		int i, count;		header = (cdrom_table_of_contents_header*)data;		entries = (cdrom_full_table_of_contents_entry*)(data+4);		header->length = B_BENDIAN_TO_HOST_INT16(header->length);				count = (header->length-2) / sizeof(cdrom_full_table_of_contents_entry);				// Check for a valid session index		if (session < 1 || session > 99)			error = B_ENTRY_NOT_FOUND;				// Extract the data of interest		if (!error) {						uint32 current_session = 0;		// The number given the current session			uint32 current_toc_session = 0;	// The number given the current "session"			uint first_track = 0;			// Track # of first track in "session"			uint last_track = 0;			// Track # of last track in "session"			off_t lead_out_lba;				// The address of the end of the current "session"			enum {				cdromStart,				cdromFoundFirstTrack,				cdromFoundLastTrack,				cdromFoundLeadOut,				cdromNeedEndLBA,				cdromFinished,				cdromError,			} state = cdromStart;						for (i = 0; i < count && state != cdromError && state != cdromFinished; i++) {				// We're only interested in positional info for data tracks				if ((entries[i].control == 0x04 || entries[i].control == 0x06)				    	// 0x04 == data track, digital copy prohibited						// 0x06 == data track, digital copy allowed				    && entries[i].adr == 0x01)						// 0x01 == positional information				{					switch (entries[i].point) {						// first track number (in pmin)						case 0xa0:								if (entries[i].session == current_toc_session+1) {								current_toc_session++;								first_track = entries[i].pminutes;								state = cdromFoundFirstTrack;							} else {								// something screwy								state = cdromError;								TRACE(("%s: Point 0xA0 found in state %d\n",								       kModuleDebugName, state));							}							break;						// last track number (in pmin)						case 0xa1:								if (entries[i].session == current_toc_session							    && state == cdromFoundFirstTrack)							{								last_track = entries[i].pminutes;								state = cdromFoundLastTrack;							} else {								// something screwy								state = cdromError;								TRACE(("%s: Point 0xA1 found in state %d\n",								       kModuleDebugName, state));							}							break;						// start position of lead-out (in pmsf)						case 0xa2:							if (entries[i].session == current_toc_session							    && state == cdromFoundLastTrack)							{								lead_out_lba = msf_to_lba(make_msf_address(								                          entries[i].pminutes,								                          entries[i].pseconds,								                          entries[i].pframes));								state = cdromFoundLeadOut;							} else {								// something screwy								state = cdromError;								TRACE(("%s: Point 0xA2 found in state %d\n",								       kModuleDebugName, state));							}						            							break;														default:							// start position of track (in pmsf)							if (1 <= entries[i].point && entries[i].point <= 99									// valid track number							    && entries[i].session == current_toc_session)							{								switch (state) {									case cdromFoundLeadOut:										current_session++;										if ((int)current_session == session) {											// This is the session we're interested in											start_lba = msf_to_lba(make_msf_address(											                       entries[i].pminutes,										                           entries[i].pseconds,										                           entries[i].pframes));											if (entries[i].point == last_track) {												// Hooray! This the last track in the "session", so												// we already know the end_lba												end_lba = lead_out_lba;												state = cdromFinished;											} else {												// Damn, we have to look up the start of the next												// track still...												state = cdromNeedEndLBA;											}										}										break;																			case cdromNeedEndLBA:										end_lba = msf_to_lba(make_msf_address(										                     entries[i].pminutes,									                         entries[i].pseconds,									                         entries[i].pframes));										state = cdromFinished;										break;																			default:										// something screwy										state = cdromError;										TRACE(("%s: Session of interest found in state %d\n",										       kModuleDebugName, state));										break;								}															} else {								// something screwy								state = cdromError;								if (entries[i].session == current_toc_session) {									TRACE(("%s: New session encountered with track information; "									       " session == %d, previous session == %d, track == %d\n",									       kModuleDebugName, entries[i].session, current_toc_session,									       entries[i].point));								} else {									TRACE(("%s: Invalid track encountered: %d\n", kModuleDebugName,										   entries[i].point));								}							}						            							break;					}				}			}									if (state == cdromFinished) {				TRACE(("%s: found session #%ld info\n", kModuleDebugName, session));				sessionInfo->offset = start_lba * blockSize;				sessionInfo->size = (end_lba - start_lba) * blockSize;				sessionInfo->logical_block_size = blockSize;				sessionInfo->index = index;				sessionInfo->flags = B_DATA_SESSION;	// possibly B_AUDIO_SESSION for audio tracks?			} else {				TRACE(("%s: error reading table of contents, ended up in state %d\n",				       kModuleDebugName, state));				error = B_ENTRY_NOT_FOUND;			}		}	}		if (error)			TRACE(("%s: get_nth error 0x%lx\n", kModuleDebugName, error));			return error;}