src/storage/blobfs/compression/zstd-seekable-blob.cc
// ZSTD Seekable Format API function for `ZSTD_seekable_customFile`.
ZSTD Seekable Format API function for `ZSTD_seekable_customFile`.
ZSTD Seekable Format API function for ` ZSTD_seekable_customFile ` .
int ZSTDSeek(void* void_ptr_zstd_seekable_file, long long byte_offset, int origin) {
  ZX_DEBUG_ASSERT(void_ptr_zstd_seekable_file);
  auto* file = static_cast<ZSTDSeekableFile*>(void_ptr_zstd_seekable_file);
  if (file->status != ZX_OK) {
    return -1;
  }
  unsigned long long new_byte_offset = file->byte_offset;
  switch (origin) {
    case SEEK_SET:
      if (byte_offset < 0) {
        FS_TRACE_ERROR("[blobfs][zstd-seekable] Seek absolute underflow: offset=%lld\n",
                       byte_offset);
        file->status = ZX_ERR_OUT_OF_RANGE;
        return -1;
      }
      new_byte_offset = byte_offset;
      break;
    case SEEK_CUR:
      if (byte_offset < 0 && file->byte_offset + byte_offset >= file->byte_offset) {
        FS_TRACE_ERROR(
            "[blobfs][zstd-seekable] Seek from current position underflow: current=%llu "
            "offset=%lld\n",
            file->byte_offset, byte_offset);
        file->status = ZX_ERR_OUT_OF_RANGE;
        return -1;
      }
      new_byte_offset = file->byte_offset + byte_offset;
      break;
    case SEEK_END:
      if (byte_offset < 0 && file->num_bytes + byte_offset >= file->num_bytes) {
        FS_TRACE_ERROR("[blobfs][zstd-seekable] Seek from end underflow: end=%llu offset=%lld\n",
                       file->num_bytes, byte_offset);
        file->status = ZX_ERR_OUT_OF_RANGE;
        return -1;
      }
      new_byte_offset = file->num_bytes + byte_offset;
      break;
    default:
      FS_TRACE_ERROR("[blobfs][zstd-seekable] Invalid seek origin enum value: %d\n", origin);
      return -1;
  }
  if (new_byte_offset > file->num_bytes) {
    FS_TRACE_ERROR("[blobfs][zstd-seekable] Seek passed end of file: end=%llu offset=%lld\n",
                   file->num_bytes, new_byte_offset);
    file->status = ZX_ERR_OUT_OF_RANGE;
    return -1;
  }
  file->byte_offset = new_byte_offset;
  return 0;
}
int ZSTDSeek ( void * void_ptr_zstd_seekable_file , long long byte_offset , int origin ) { ZX_DEBUG_ASSERT ( void_ptr_zstd_seekable_file ) ; auto * file = static_cast < ZSTDSeekableFile * > ( void_ptr_zstd_seekable_file ) ; if ( file -> status != ZX_OK ) { return -1 ; } unsigned long long new_byte_offset = file -> byte_offset ; switch ( origin ) { case SEEK_SET : if ( byte_offset < 0 ) { FS_TRACE_ERROR ( " \n " , byte_offset ) ; file -> status = ZX_ERR_OUT_OF_RANGE ; return -1 ; } new_byte_offset = byte_offset ; break ; case SEEK_CUR : if ( byte_offset < 0 && file -> byte_offset + byte_offset >= file -> byte_offset ) { FS_TRACE_ERROR ( " " " \n " , file -> byte_offset , byte_offset ) ; file -> status = ZX_ERR_OUT_OF_RANGE ; return -1 ; } new_byte_offset = file -> byte_offset + byte_offset ; break ; case SEEK_END : if ( byte_offset < 0 && file -> num_bytes + byte_offset >= file -> num_bytes ) { FS_TRACE_ERROR ( " \n " , file -> num_bytes , byte_offset ) ; file -> status = ZX_ERR_OUT_OF_RANGE ; return -1 ; } new_byte_offset = file -> num_bytes + byte_offset ; break ; default : FS_TRACE_ERROR ( " \n " , origin ) ; return -1 ; } if ( new_byte_offset > file -> num_bytes ) { FS_TRACE_ERROR ( " \n " , file -> num_bytes , new_byte_offset ) ; file -> status = ZX_ERR_OUT_OF_RANGE ; return -1 ; } file -> byte_offset = new_byte_offset ; return 0 ; }
ZSTD Seekable Format API function for `ZSTD_seekable_customFile`.
ZSTD Seekable Format API function for ` ZSTD_seekable_customFile ` .
// Give up if any file operation has ever failed. // Absolute offset: // Set position in ZSTD archive to |byte_offset|. // Relative-to-current offset: // Set position in ZSTD archive to |file->byte_offset + byte_offset|. // Relative-to-end offset: // Set position in ZSTD archive to |file->num_bytes + byte_offset|. // New offset must not go passed end of file.