7.3 Synchronous Functions


Synchronous functions are those whose processing is performed within the calling thread. No values are returned from the function until processing is finished.

The following functions are specific examples.


7.3.1 Converting between Byte Number and LBA Number

LeoByteToLBA( )function

#include <PR/leo.h>

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

startlba LBA
nbytes number of bytes
lbas calculation result

Converts byte number to LBA number. The function returns as lbas the number of LBAs in the area extending nbytes from the beginning of the block specified by startlba.

LeoLBAToByte( )function

#include <PR/leo.h>

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

startlba LBA
nlbas number of blocks
bytes calculation result

Converts LBA number to byte number. The function returns as bytes the number of bytes in the area extending nlbas blocks from the beginning of the block specified by startlba.

The meanings of the return values in both cases are the same as with asynchronous functions, with 0 returned when the leo manager has been started and -1 returned if it has not been started. Checking the return values is usually unnecessary.

Because LBA calculations depend on the disk type, LeoByteToLBA() and LeoLBAToByte() tempororily uses the local variables of leo manager. This means that if the disk is replaced by another disk immediately before this command is issued, the LBA number obtained will differ from that of the inserted disk. Be particularly careful to ensure that a DISK_MAY_HAVE_CHANGED error is not returned with this command. Please design the program so that if disk operations such as reading, writing, or seeking are performed based on values calculated with these functions and the commands for those operations return a DISK_MAY_HAVE_CHANGED error, the program is re-executed from the LBA-Byte conversion. For specific processing sequences, please see "Chapter 10, Error-Handling Sequences."


7.3.2 Checking the Writable and Readable Area

LeoReadCapacity ( )function

#include <PR/leo.h>

typedef struct

{

u32 startLBA;

u32 endLBA;

u32 nbytes;

} LEOCapacity;

s32 LeoReadCapacity(LEOCapacity *cap, s32 dir);

cap information on the readable/writable area
dir OS_READ reading information
OS_WRITE writing information

If this function is called with OS_READ inserted for dir, the initial LBA of the readable area is returned for cap->startLBA, the final LBA of the readable area is returned for cap->endLBA, and total number of readable bytes is returned for cap->nbytes. These values are the same regardless of the type of disk inserted: startLBA=0, endLBA=4291, nbytes=64458560.

If this function is called with OS_WRITE inserted for dir, the initial LBA of the writable area is returned for cap->startLBA, the final LBA of the writable area is returned for cap->endLBA, and total number of writable bytes is returned for cap->nbytes. The return values vary according to the disk type. As with LeoByteToLBA() and LeoLBAToByte( ), locally recorded variables are used to store the type of disk inserted. For a precautionary note on this subject, please see Section 7.3.1, Converting Between Byte Number and LBA" Number.

The meanings of the return values in both cases are the same as with asynchronous functions, with 0 returned when the leo manager has been started and -1 returned if it has not been started. Checking the return values is usually unnecessary.


7.3.3 Checking the Hardware and Software Versionsu

LeoInquiry ( )function

#include <PR/leo.h>

typedef struct

{

u8 drive; /* version of hw */

u8 driver; /* version of sw */

u8 deviceType; /* dev type, always 00 */

u8 ndevices; /* # of devices, always 01 */

} LEOVersion;

s32 LeoInquiry(LEOVersion *ver);

ver version information

Returns the version numbers of the hardware and software(libraries) of the currently connected 64DD. With commercial drives, the lower 4 bits of the hardware version number represent the number 3; with development drives, the lower 4 bits represent 4. As of May 1998, the version number of the latest development drive hardware was 0x14. The drive with a version number of 0x4 is the previous version. When LEO_MOTOR_BRAKE is specified in LeoSpdlMotor, this version responds in the same manner as when LEO_MOTOR_SLEEP is specified. Software version numbers are as shown in the following table.

Library Number
Versions prior to 2.0H 0
2.0H 1
PatchN64dd_082297(NW version)
PatchPC_083197(PC version)
2
2.0I or later See the release notes

The meanings of the return values in both cases are the same as with asynchronous functions, with 0 returned when the leo manager has been started and -1 returned if it has not been started. Checking the return values is usually unnecessary.