plugins/streaming/streaming.c
/* Write data to the stream. */
Write data to the stream.
Write data to the stream .
static int
streaming_pwrite (void *handle, const void *buf,
                  uint32_t count, uint64_t offset)
{
  size_t n;
  ssize_t r;
  if (errorstate) {
    nbdkit_error ("unrecoverable error state");
    errno = EIO;
    return -1;
  }
  if (offset < highestwrite) {
    nbdkit_error ("client tried to seek backwards and write: "
                  "the streaming plugin does not currently support this");
    errorstate = 1;
    errno = EIO;
    return -1;
  }
  if (offset > highestwrite) {
    int64_t size = offset - highestwrite;
    char buf[4096];
    memset (buf, 0, sizeof buf);
    while (size > 0) {
      n = size > sizeof buf ? sizeof buf : size;
      r = write (fd, buf, n);
      if (r == -1) {
        nbdkit_error ("write: %m");
        errorstate = 1;
        return -1;
      }
      highestwrite += r;
      size -= r;
    }
  }
  while (count > 0) {
    r = write (fd, buf, count);
    if (r == -1) {
      nbdkit_error ("write: %m");
      errorstate = 1;
      return -1;
    }
    buf += r;
    highestwrite += r;
    count -= r;
  }
  return 0;
}
static int streaming_pwrite ( void * handle , const void * buf , uint32_t count , uint64_t offset ) { size_t n ; ssize_t r ; if ( errorstate ) { nbdkit_error ( " " ) ; errno = EIO ; return -1 ; } if ( offset < highestwrite ) { nbdkit_error ( " " " " ) ; errorstate = 1 ; errno = EIO ; return -1 ; } if ( offset > highestwrite ) { int64_t size = offset - highestwrite ; char buf [ 4096 ] ; memset ( buf , 0 , sizeof buf ) ; while ( size > 0 ) { n = size > sizeof buf ? sizeof buf : size ; r = write ( fd , buf , n ) ; if ( r == -1 ) { nbdkit_error ( " " ) ; errorstate = 1 ; return -1 ; } highestwrite += r ; size -= r ; } } while ( count > 0 ) { r = write ( fd , buf , count ) ; if ( r == -1 ) { nbdkit_error ( " " ) ; errorstate = 1 ; return -1 ; } buf += r ; highestwrite += r ; count -= r ; } return 0 ; }
Write data to the stream.
Write data to the stream .
/* Need to write some zeroes. */ /* Write the data. */