Important: The information in this document is obsolete and should not be used for new development.
PBWrite
You can use thePBWritefunction to write data from a data buffer to an open driver.
pascal OSErr PBWrite(ParmBlkPtr paramBlock, Boolean async);
paramBlock- A pointer to an
IOParamstructure of the Device Manager parameter block.async- A Boolean value that indicates whether the request is asynchronous.
--> ioCompletion ProcPtr A pointer to a completion routine. <-- ioResult OSErr The device driver's result code. --> ioVRefNum short The drive number. --> ioRefNum short The driver reference number. --> ioBuffer Ptr A pointer to a data buffer. --> ioReqCount long The requested number of bytes to write. <-- ioActCount long The actual number of bytes written. --> ioPosMode short The positioning mode. <--> ioPosOffset long The positioning offset. DESCRIPTION
ThePBWritefunction attempts to write the number of bytes indicated by theioReqCountfield from the data buffer pointed to by theioBufferfield to the device driver specified by theioRefNumfield. After the transfer is complete, theioActCountfield indicates the number of bytes actually written.For block devices such as disk drivers, the
PBWritefunction allows you to specify a drive number in theioVRefNumfield and specify a positioning mode and offset in theioPosModeandioPosOffsetfields. Bits 0 and 1 of theioPosMode field indicate where an operation should begin relative to the physical beginning of the
block-formatted medium. You can use the following constants to test or set the value of these bits:
enum { /* positioning modes */ fsAtMark = 0, /* at current position */ fsFromStart = 1, /* offset from beginning */ fsFromMark = 3 /* offset from current position */ };TheioPosOffsetfield specifies the positive or negative byte offset where the data is to be written, relative to the positioning mode. The offset must be a multiple of 512. TheioPosOffsetfield is ignored whenioPosModeis set tofsAtMark.After the transfer is complete, the
ioPosOffsetfield indicates the new current position of a block device.SPECIAL CONSIDERATIONS
Do not call thePBWritefunction synchronously at interrupt time. Synchronous requests at interrupt time may block other pending I/O requests and cause the Device Manager to loop indefinitely while it waits for the device driver to complete the interrupted requests.ASSEMBLY-LANGUAGE INFORMATION
The trap macro for thePBWritefunction is_Write(0xA003). Set bit 10 of the trap word to execute this function asynchronously. Set bit 9 to execute it immediately.You must set up register A0 with the address of the parameter block. When
_Writereturns, register D0 contains the result code. Register D0 is the only register affected by this function.
Registers on entry A0 Address of the parameter block
Registers on exit D0 Result code RESULT CODES
noErr 0 No error writErr -20 Driver does not respond to write requests badUnitErr -21 Driver reference number does not match unit table unitEmptyErr -22 Driver reference number specifies a nilhandle in unit tableabortErr -27 Request aborted by KillIOnotOpenErr -28 Driver not open SEE ALSO
For information about the high-level function for writing to device drivers, see the description of theFSWritefunction on page 1-72. For an example of how to write to a device driver using thePBWritefunction, see Listing 1-4 on page 1-22.