Blame source/uds/bufferedReader.h

Packit Service 310c69
/*
Packit Service 310c69
 * Copyright (c) 2020 Red Hat, Inc.
Packit Service 310c69
 *
Packit Service 310c69
 * This program is free software; you can redistribute it and/or
Packit Service 310c69
 * modify it under the terms of the GNU General Public License
Packit Service 310c69
 * as published by the Free Software Foundation; either version 2
Packit Service 310c69
 * of the License, or (at your option) any later version.
Packit Service 310c69
 * 
Packit Service 310c69
 * This program is distributed in the hope that it will be useful,
Packit Service 310c69
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 310c69
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 310c69
 * GNU General Public License for more details.
Packit Service 310c69
 * 
Packit Service 310c69
 * You should have received a copy of the GNU General Public License
Packit Service 310c69
 * along with this program; if not, write to the Free Software
Packit Service 310c69
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service 310c69
 * 02110-1301, USA. 
Packit Service 310c69
 *
Packit Service 310c69
 * $Id: //eng/uds-releases/jasper/src/uds/bufferedReader.h#3 $
Packit Service 310c69
 */
Packit Service 310c69
Packit Service 310c69
#ifndef BUFFERED_READER_H
Packit Service 310c69
#define BUFFERED_READER_H 1
Packit Service 310c69
Packit Service 310c69
#include "common.h"
Packit Service 310c69
Packit Service 310c69
#ifdef __KERNEL__
Packit Service 310c69
struct dm_bufio_client;
Packit Service 310c69
struct ioFactory;
Packit Service 310c69
#else
Packit Service 310c69
struct ioRegion;
Packit Service 310c69
#endif
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * The buffered reader allows efficient IO for IORegions, which may be
Packit Service 310c69
 * file- or block-based. The internal buffer always reads aligned data
Packit Service 310c69
 * from the underlying region.
Packit Service 310c69
 **/
Packit Service 310c69
typedef struct bufferedReader BufferedReader;
Packit Service 310c69
Packit Service 310c69
#ifdef __KERNEL__
Packit Service 310c69
/**
Packit Service 310c69
 * Make a new buffered reader.
Packit Service 310c69
 *
Packit Service 310c69
 * @param factory     The IOFactory creating the buffered reader.
Packit Service 310c69
 * @param client      The dm_bufio_client to read from.
Packit Service 310c69
 * @param blockLimit  The number of blocks that may be read.
Packit Service 310c69
 * @param readerPtr   The pointer to hold the newly allocated buffered reader
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or error code.
Packit Service 310c69
 **/
Packit Service 310c69
int makeBufferedReader(struct ioFactory        *factory,
Packit Service 310c69
                       struct dm_bufio_client  *client,
Packit Service 310c69
                       sector_t                 blockLimit,
Packit Service 310c69
                       BufferedReader         **readerPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
#else
Packit Service 310c69
/**
Packit Service 310c69
 * Make a new buffered reader.
Packit Service 310c69
 *
Packit Service 310c69
 * @param region     An IORegion to read from.
Packit Service 310c69
 * @param readerPtr  The pointer to hold the newly allocated buffered reader.
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or error code.
Packit Service 310c69
 **/
Packit Service 310c69
int makeBufferedReader(struct ioRegion *region, BufferedReader **readerPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
#endif
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Free a buffered reader.
Packit Service 310c69
 *
Packit Service 310c69
 * @param reader        The buffered reader
Packit Service 310c69
 **/
Packit Service 310c69
void freeBufferedReader(BufferedReader *reader);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Retrieve data from a buffered reader, reading from the region when needed.
Packit Service 310c69
 *
Packit Service 310c69
 * @param reader        The buffered reader
Packit Service 310c69
 * @param data          The buffer to read data into
Packit Service 310c69
 * @param length        The length of the data to read
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code.
Packit Service 310c69
 **/
Packit Service 310c69
int readFromBufferedReader(BufferedReader *reader, void *data, size_t length)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Verify that the data currently in the buffer matches the required value.
Packit Service 310c69
 *
Packit Service 310c69
 * @param reader        The buffered reader.
Packit Service 310c69
 * @param value         The value that must match the buffer contents.
Packit Service 310c69
 * @param length        The length of the value that must match.
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code, specifically UDS_CORRUPT_FILE
Packit Service 310c69
 *         if the required value fails to match.
Packit Service 310c69
 *
Packit Service 310c69
 * @note If the value matches, the matching contents are consumed. However,
Packit Service 310c69
 *       if the match fails, any buffer contents are left as is.
Packit Service 310c69
 **/
Packit Service 310c69
int verifyBufferedData(BufferedReader *reader,
Packit Service 310c69
                       const void     *value,
Packit Service 310c69
                       size_t          length)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
#endif // BUFFERED_READER_H