| Mac OS X header: | CoreServices/CoreServices.h |
| Mac OS 9 header: | Files.h |
| Reading, Writing, and Closing Files Functions | |
| FSRead | Reads any number of bytes from an open file. |
| FSReadFork | Reads data from an open fork. |
| FSWrite | Writes any number of bytes to an open file. |
| PBReadForkSync | Reads data from an open fork. |
| FSClose | Closes an open file. |
| PBReadForkAsync | Reads data from an open fork. |
| FSWriteFork | Writes data to an open fork. |
| PBWriteForkSync | Writes data to an open fork. |
| PBWriteForkAsync | Writes data to an open fork. |
| FSCloseFork | Closes an open fork. |
| PBCloseForkSync | Closes an open fork. |
| PBCloseForkAsync | Closes an open fork. |
FSRead |
| Carbon status: | Supported |
Reads any number of bytes from an open file.
OSErr FSRead (
SInt16 refNum,
SInt32 *count,
void *buffPtr
);
The file reference number of the open file from which to read.
On input, a pointer to the number of bytes to read; on output, a pointer to the number of bytes actually read.
A pointer to the data buffer into which the data will be read. This buffer is allocated by your application and must be at least as large as the count parameter.
A result code.
Because the read operation begins at the current mark, you might want to set the mark first by calling the
The low-level functions PBReadSync and PBReadAsync let you set the mark without having to call SetFPos. Furthermore, if you want to read data in newline mode, you must use PBReadSync or PBReadAsync instead of FSRead. For a description of the PBReadSync and PBReadAsync functions, see the Device Manager Reference.
If you wish to read from named forks other than the data or resource forks, or from files larger than 2GB, you must use the
Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 8.1 or later.
FSReadFork |
| Carbon status: | Supported |
Reads data from an open fork.
OSErr FSReadFork (
SInt16 forkRefNum,
UInt16 positionMode,
SInt64 positionOffset,
ByteCount requestCount,
void *buffer,
ByteCount actualCount
);
The reference number of the fork to read from. You should have previously opened this fork using the
A constant specifying the base location within the fork for the start of the read. See
The caller can also use this parameter to hint to the File Manager whether the data being read should or should not be cached. Caching reads appropriately can be important in ensuring that your program access files efficiently.
If you add the forceReadMask constant to the value you pass in this parameter, this tells the File Manager to force the data to be read directly from the disk. This is different from adding the noCacheMask constant since forceReadMask tells the File Manager to flush the appropriate part of the cache first, then ignore any data already in the cache. However, data that is read may be placed in the cache for future reads. The forceReadMask constant is also passed to the device driver, indicating that the driver should avoid reading from any device caches.
See
The offset from the base location for the start of the read.
The number of bytes to read.
A pointer to the buffer where the data will be returned.
On return, a pointer to the number of bytes actually read. The value pointed to by the actualCount parameter should be equal to the value in the requestCount parameter unless there was an error during the read operation.
This parameter is optional; if you dont want this information returned, set actualCount to NULL.
A result code. If there are fewer than requestCount bytes from the specified position to the logical end-of-file, then all of those bytes are read, and eofErr is returned.
FSReadFork reads data starting at the position specified by the positionMode and positionOffset parameters. The function reads up to requestCount bytes into the buffer pointed to by the buffer parameter and sets the forks current position to the byte immediately after the last byte read (that is, the initial position plus actualCount).
To verify that data previously written has been correctly transferred to disk, read it back in using the forceReadMask constant in the positionMode parameter and compare it with the data you previously wrote.
When reading data from a fork, it is important to pay attention to that way that your program accesses the fork, because this can have a significant performance impact. For best results, you should use an I/O size of at least 4KB and block align your read requests. On Mac OS X, you should align your requests to 4KB boundaries; on the traditional Mac OS, byte-alignments beyond 512-bytes are irrelevant, but 4KB aligned requests will perform well on current and future versions.
Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 9 or later.
FSWrite |
| Carbon status: | Supported |
Writes any number of bytes to an open file.
OSErr FSWrite (
SInt16 refNum,
SInt32 *count,
const void *buffPtr
);
The file reference number of the open file to which to write.
On input, a pointer to the number of bytes to write to the file; on output, a pointer to the number of bytes actually written.
A pointer to the data buffer containing the data to write.
A result code.
The FSWrite function takes the specified number of bytes from the data buffer and attempts to write them to the file. Because the write operation begins at the current mark, you might want to set the mark first by calling the
If the write operation completes successfully, FSWrite moves the file mark to the byte following the last byte written and returns noErr. If you try to write past the logical end-of-file, FSWrite moves the logical end-of-file. If you try to write past the physical end-of-file, FSWrite adds one or more clumps to the file and moves the physical end-of-file accordingly.
The low-level functions PBWriteSync and PBWriteAsync let you set the mark without having to call SetFPos. For a description of the PBWriteSync and PBWriteAsync functions, see the Device Manager Reference.
If you wish to write to named forks other than the data or resource forks, or grow files larger than 2GB, you must use the
Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 8.1 or later.
PBReadForkSync |
| Carbon status: | Supported |
Reads data from an open fork.
OSErr PBReadForkSync (
FSForkIOParam *paramBlock
);
A pointer to a fork I/O parameter block. See
A result code. If there are fewer than requestCount bytes from the specified position to the logical end-of-file, then all of those bytes are read, and eofErr is returned.
The relevant fields of the parameter block are:
On input, the reference number of the fork to read from. You should have previously opened this fork using the
On input, a constant specifying the base location within the fork for the start of the read. See
The caller can also use this parameter to hint to the File Manager whether the data being read should or should not be cached. Caching reads appropriately can be important in ensuring that your program access files efficiently.
If you add the forceReadMask constant to the value you pass in this parameter, this tells the File Manager to force the data to be read directly from the disk. This is different from adding the noCacheMask constant since forceReadMask tells the File Manager to flush the appropriate part of the cache first, then ignore any data already in the cache. However, data that is read may be placed in the cache for future reads. The forceReadMask constant is also passed to the device driver, indicating that the driver should avoid reading from any device caches.
See
On input, the offset from the base location for the start of the read.
On input, the number of bytes to read. The value that you pass in this field should be greater than zero.
A pointer to the buffer where the data will be returned.
On output, the number of bytes actually read. The value in this field should be equal to the value in the requestCount field unless there was an error during the read operation.
PBReadForkSync reads data starting at the position specified by the positionMode and positionOffset fields. The function reads up to requestCount bytes into the buffer pointed to by the buffer field and sets the forks current position to the byte immediately after the last byte read (that is, the initial position plus actualCount).
To verify that data previously written has been correctly transferred to disk, read it back in using the forceReadMask constant in the positionMode field and compare it with the data you previously wrote.
When reading data from a fork, it is important to pay attention to that way that your program accesses the fork, because this can have a significant performance impact. For best results, you should use an I/O size of at least 4KB and block align your read requests. On Mac OS X, you should align your requests to 4KB boundaries; on the traditional Mac OS, byte-alignments beyond 512-bytes are irrelevant, but 4KB aligned requests will perform well on current and future versions.
Note that on Mac OS 8 and 9, it is possible to call PBReadForkSync with a value of 0 in the requestCount field; however, this behavior is not supported on Mac OS X. On OS X, PBReadForkSync returns a paramErr error if the value in the requestCount field is 0
Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 9 or later.
FSClose |
| Carbon status: | Supported |
Closes an open file.
OSErr FSClose (
SInt16 refNum
);
The file reference number of the open file.
A result code.
The FSClose function removes the access path for the specified file and writes the contents of the volume buffer to the volume.
The FSClose function calls the PBFlushFileSync function internally to write the files bytes onto the volume. To ensure that the files catalog entry is updated, you should call
Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 8.1 or later.
Make sure that you do not call FSClose with a file reference number of a file that has already been closed. Attempting to close the same file twice may result in loss of data on a volume.
PBReadForkAsync |
| Carbon status: | Supported |
Reads data from an open fork.
void PBReadForkAsync (
FSForkIOParam *paramBlock
);
A pointer to a fork I/O parameter block. See
The relevant fields of the parameter block are:
On input, a pointer to a completion routine. For more information on completion routines, see
On output, the result code of the function. If there are fewer than requestCount bytes from the specified position to the logical end-of-file, then all of those bytes are read, and eofErr is returned.
On input, the reference number of the fork to read from. You should have previously opened this fork using the
On input, a constant specifying the base location within the fork for the start of the read. See
The caller can also use this parameter to hint to the File Manager whether the data being read should or should not be cached. Caching reads appropriately can be important in ensuring that your program access files efficiently.
If you add the forceReadMask constant to the value you pass in this parameter, this tells the File Manager to force the data to be read directly from the disk. This is different from adding the noCacheMask constant since forceReadMask tells the File Manager to flush the appropriate part of the cache first, then ignore any data already in the cache. However, data that is read may be placed in the cache for future reads. The forceReadMask constant is also passed to the device driver, indicating that the driver should avoid reading from any device caches.
See
On input, the offset from the base location for the start of the read.
On input, the number of bytes to read. The value that you pass in this field should be greater than zero.
A pointer to the buffer where the data will be returned.
On output, the number of bytes actually read. The value in this field should be equal to the value in the requestCount field unless there was an error during the read operation.
PBReadForkAsync reads data starting at the position specified by the positionMode and positionOffset fields. The function reads up to requestCount bytes into the buffer pointed to by the buffer field and sets the forks current position to the byte immediately after the last byte read (that is, the initial position plus actualCount).
To verify that data previously written has been correctly transferred to disk, read it back in using the forceReadMask constant in the positionMode field and compare it with the data you previously wrote.
When reading data from a fork, it is important to pay attention to that way that your program accesses the fork, because this can have a significant performance impact. For best results, you should use an I/O size of at least 4KB and block align your read requests. On Mac OS X, you should align your requests to 4KB boundaries; on the traditional Mac OS, byte-alignments beyond 512-bytes are irrelevant, but 4KB aligned requests will perform well on current and future versions.
Note that on Mac OS 8 and 9, it is possible to call PBReadForkAsync with a value of 0 in the requestCount field; however, this behavior is not supported on Mac OS X. On OS X, PBReadForkAsync returns a paramErr error if the value in the requestCount field is 0.
Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 9 or later.
FSWriteFork |
| Carbon status: | Supported |
Writes data to an open fork.
OSErr FSWriteFork (
SInt16 forkRefNum,
UInt16 positionMode,
SInt64 positionOffset,
ByteCount requestCount,
const void *buffer,
ByteCount actualCount
);
The reference number of the fork to which to write. You should have previously opened the fork using the
A constant specifying the base location within the fork for the start of the write. See
The caller can also use this parameter to hint to the File Manager whether the data being written should or should not be cached. See
The offset from the base location for the start of the write.
The number of bytes to write.
A pointer to a buffer containing the data to write.
On return, a pointer to the number of bytes actually written. The value pointed to by the actualCount parameter will be equal to the value in the requestCount parameter unless there was an error during the write operation.
This parameter is optional; if you dont want this information, set actualCount to NULL.
A result code. If there is not enough space on the volume to write requestCount bytes, then dskFulErr is returned.
FSWriteFork writes data starting at the position specified by the positionMode and positionOffset parameters. The function attempts to write requestCount bytes from the buffer pointed at by the buffer parameter and sets the forks current position to the byte immediately after the last byte written (that is, the initial position plus actualCount).
When writing data to a fork, it is important to pay attention to that way that your program accesses the fork, because this can have a significant performance impact. For best results, you should use an I/O size of at least 4KB and block align your write requests. On Mac OS X, you should align your requests to 4KB boundaries; on the traditional Mac OS, byte-alignments beyond 512-bytes are irrelevant, but 4KB aligned requests will perform well on current and future versions.
Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 9 or later.
PBWriteForkSync |
| Carbon status: | Supported |
Writes data to an open fork.
OSErr PBWriteForkSync (
FSForkIOParam *paramBlock
);
A pointer to a fork I/O parameter block. See
A result code. If there is not enough space on the volume to write requestCount bytes, then dskFulErr is returned.
The relevant fields of the parameter block are:
On output, the result code of the function. If there is not enough space on the volume to write requestCount bytes, then dskFulErr is returned.
On input, the reference number of the fork to which to write. You should have previously opened the fork using the
On input, a constant specifying the base location within the fork for the start of the write. See
The caller can also use this parameter to hint to the File Manager whether the data being written should or should not be cached. See
On input, the offset from the base location for the start of the write.
On input, the number of bytes to write.
A pointer to a buffer containing the data to write.
On output, the number of bytes actually written. The value in the actualCount field will be equal to the value in the requestCount field unless there was an error during the write operation.
PBWriteForkSync writes data starting at the position specified by the positionMode and positionOffset fields. The function attempts to write requestCount bytes from the buffer pointed to by the buffer field and sets the forks current position to the byte immediately after the last byte written (that is, the initial position plus actualCount).
When writing data to a fork, it is important to pay attention to that way that your program accesses the fork, because this can have a significant performance impact. For best results, you should use an I/O size of at least 4KB and block align your write requests. On Mac OS X, you should align your requests to 4KB boundaries; on the traditional Mac OS, byte-alignments beyond 512-bytes are irrelevant, but 4KB aligned requests will perform well on current and future versions.
Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 9 or later.
PBWriteForkAsync |
| Carbon status: | Supported |
Writes data to an open fork.
void PBWriteForkAsync (
FSForkIOParam *paramBlock
);
A pointer to a fork I/O parameter block. See
The relevant fields of the parameter block are:
On input, a pointer to a completion routine. For more information on completion routines, see
On output, the result code of the function. If there is not enough space on the volume to write requestCount bytes, then dskFulErr is returned.
On input, the reference number of the fork to which to write. You should have previously opened the fork using the
On input, a constant specifying the base location within the fork for the start of the write. See
The caller can also use this parameter to hint to the File Manager whether the data being written should or should not be cached. See
On input, the offset from the base location for the start of the write.
On input, the number of bytes to write.
A pointer to a buffer containing the data to write.
On output, the number of bytes actually written. The value in the actualCount field will be equal to the value in the requestCount field unless there was an error during the write operation.
PBWriteForkAsync writes data starting at the position specified by the positionMode and positionOffset fields. The function attempts to write requestCount bytes from the buffer pointed to by the buffer field and sets the forks current position to the byte immediately after the last byte written (that is, the initial position plus actualCount).
When writing data to a fork, it is important to pay attention to that way that your program accesses the fork, because this can have a significant performance impact. For best results, you should use an I/O size of at least 4KB and block align your write requests. On Mac OS X, you should align your requests to 4KB boundaries; on the traditional Mac OS, byte-alignments beyond 512-bytes are irrelevant, but 4KB aligned requests will perform well on current and future versions.
Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 9 or later.
FSCloseFork |
| Carbon status: | Supported |
Closes an open fork.
OSErr FSCloseFork (
SInt16 forkRefNum
);
The reference number of the fork to close. After the call to this function, the reference number in this parameter is invalid.
A result code.
The FSCloseFork function causes all data written to the fork to be written to disk, in the same manner as the
Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 9 or later.
PBCloseForkSync |
| Carbon status: | Supported |
Closes an open fork.
OSErr PBCloseForkSync (
FSForkIOParam *paramBlock
);
A pointer to a fork I/O parameter block. See
A result code.
The relevant field of the parameter block is:
On input, the reference number of the fork to close. After the call to this function, the reference number in this parameter is invalid.
The PBCloseForkSync function causes all data written to the fork to be written to disk, in the same manner as the
Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 9 or later.
PBCloseForkAsync |
| Carbon status: | Supported |
Closes an open fork.
void PBCloseForkAsync (
FSForkIOParam *paramBlock
);
A pointer to a fork I/O parameter block. See
The relevant fields of the parameter block are:
On input, a pointer to a completion routine. For more information on completion routines, see
On output, the result code of the function.
On input, the reference number of the fork to close. After the call to this function, the reference number in this parameter is invalid.
The PBCloseForkAsync function causes all data written to the fork to be written to disk, in the same manner as the
Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 9 or later.
© 2001 Apple Computer, Inc. (Last Updated July 17, 2001)