![]() |
![]() |
![]() |
![]() |
Write blocks of data to a file
#include <unistd.h> int writeblock( int fd, size_t blksize, unsigned block, int numblks, const void *buff );
libc
The writeblock() function writes numblks blocks of data to the file associated with the open file descriptor fd, from the buffer pointed to by buff, starting at block number block (blocks are numbered starting at 0). The blksize argument defines the size of a block, in bytes.
This function is useful for direct updating of raw blocks on a block special device (for example, raw disk blocks) but you can also use it for high-speed updating of database files (for example). (The speed gain is through the combined seek/write implicit in this call, and the ability to transfer more than the write() function's limit of INT_MAX bytes at a time.)
If numblks is zero, writeblock() returns zero, and has no other results.
Upon successful completion, the writeblock() function returns the number of blocks actually written to the disk associated with fd. This number is never greater than numblks. The value returned may be less than numblks if one of the following occurs:
If a write error occurs on the first block and one of the sync flags is set, writeblock() returns -1, and sets errno to EIO.
If one of the sync flags is set, writeblock() doesn't return until the blocks are actually transferred to the disk. If neither of the flags is set, writeblock() causes the blocks to be placed in the cache and scheduled for writing as soon as possible, but returns before the write takes place.
![]() |
In the latter instance, it's impossible for the application to know if the write succeeded or not (due to system failures or bad disk blocks). Using the sync flags significantly impacts the performance of writeblock(), but guarantees that the data can be recovered. |
The number of blocks actually written. If an error occurred, it returns -1, sets errno to indicate the error, and doesn't change the contents of the buffer pointed to by buff.
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
![]() |
![]() |
![]() |
![]() |