/*static char *SCCSID = "@(#)misc.c	6.2 91/01/14";*/
#define SCCSID "@(#)misc.c	6.2 91/01/14"
/*
 *	IBM/Microsoft Confidential
 *
 *	Copyright (c) IBM Corporation 1987, 1989
 *	Copyright (c) Microsoft Corporation 1987, 1989
 *
 *	All Rights Reserved
 *
 */

/*
 *  MISC.C
 *
 *    DESCRIPTION
 *    
 *      Miscellaneous functions which don't fit elsewhere.
 *
 *
 *    FUNCTIONS DEFINED
 *
 *      lb_offset ()    -   Offset of logical block within sector.
 *      lb_to_ls ()     -   Returns the logical sector containing a logical
 *                              block.
 *
 *  REVISION HISTORY (in reverse chronological order)
 *  -----------------------------------------------------------------------
 *  7/19/90     Brian Andrew    Fixed lb_to_ls to correctly handle case
 *                              where logical block is not logical sector.
 *                              MSBUG oso1314.
 *
 *  8/10/89     Brian Andrew    Included code from MSCDEX
 *
 *  8/4/89      Brian Andrew    Initial Blank Template
 *
 *
 *  TO DO
 *  -------------------------------------------------------------------------
 */


#define INCL_DOSERRORS
#define INCL_NOPMAPI

#include <os2.h>
#include <fsd.h>

#include "cdfs.h"
#include "sem.h"
#include "path.h"
#include "vol.h"
#include "file.h"
#include "buffer.h"
#include "mem.h"
#include "heap.h"
#include "message.h"

#ifdef STATS_H
#include "stats.h"
#endif

#include "fsdata.h"
#include "pr_misc.h"

#ifdef DEBUG
#include "pr_debug.h"
#endif


/* lb_offset() -
**
** DESCRIPTION
**  Calculates the offset of a logical block within the logical sector
**  We know that lbsize is always less than or equal to the 
**  logical sector size which is 2048 for CDROM's. Therefore,
**  it's either 512, 1024, or 2048.
**
** RETURNS
**  Returns the offset of the lbn in number of bytes.
*/
USHORT lb_offset(lbn, lbsize)
ULONG       lbn;
USHORT      lbsize;
{

	if (lbsize < SECTOR_SIZE)
		return(((USHORT) lbn & (lbsize == 512 ? 3 : 1)) * lbsize);
	else
		return(0);

} /* end lb_offset */

/* lb_to_ls() -
**
** DESCRIPTION
**  Converts a logical block address to a logical sector
**  address. Logical block size is always less than or equal
**  to the logical sector size.
**
** RETURNS
**  4-byte logical sector address
*/
LONG lb_to_ls(lbn, lbsize)
ULONG       lbn;
USHORT      lbsize;
{
	return  (lbsize == SECTOR_SIZE ? lbn : ((lbn * lbsize) / SECTOR_SIZE));

} /* end lb_to_ls */


