LeoByteToLBA LeoByteToLBA (function)

LeoByteToLBA, LeoLBAToByte

Converts between LBA and bytes


#include <PR/leo.h>     /* leo.h */

s32 LeoByteToLBA(s32 startlba, u32 nbytes, s32 *lba);

s32 LeoLBAToByte(s32 startlba, u32 nlbas, s32 *bytes);


They convert between a logical block address (LBA) and a physical byte address. The size of one block is different from other blocks for the N64 Disk Drive, so you need to convert back and forth between bytes and LBAs by calling these functions. (See "Hardware Specifications" section of the N64 Disk Drive programming manuals for more details on block size.)

Caution: The LeoByteToLBA and LeoLBAToByte functions make expedient use of Leo Manager's internal variables. As a result, LBA calculations depend on the disk type. If the disk is swapped with another disk of a different type immediately before you call the LeoByteToLBA or LeoLBAToByte function, the resulting LBA size will not be correct for the for the currently inserted disk. You need to exercise caution because a DISK_MAY_HAVE_CHANGED error is not returned by these functions. Therefore, if you use a calculated value for a disk read, write, or seek operation and a DISK_MAY_HAVE_CHANGED error is returned, plan to re-run your code from the LBA-to-byte conversion to make sure you have the correct value. For more detailed information on this, see the "Error-Handling Sequences" section of your N64 Disk Drive programming manuals.

The LeoByteToLBA function converts from a byte size into an LBA size. It calculates the number of LBAs in the nbytes from the start of the block specified by startlba and returns this to the location pointed to by the lbas argument.

The LeoLBAToByte function converts from an LBA size into a byte size. It calculates the number of bytes in the nlbas blocks from the start of the block specified by startlba and returns this to the location pointed to by the bytes argument.

The returned values are:


Leo Manager has not started. The conversion refers to the current disk type that is in use; therefore, make sure these functions are called after starting Leo Manager.


The specified LBA or resulting LBA is out of range.


Normal execution.

See Also

byte2lba, lba2byte, Leo*CreateLeoManager, LeoReadCapacity

Revision History

04/30/1999 Changed Format