Blame uds/ioFactory.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/ioFactory.h#7 $
Packit Service 310c69
 */
Packit Service 310c69
Packit Service 310c69
#ifndef IO_FACTORY_H
Packit Service 310c69
#define IO_FACTORY_H
Packit Service 310c69
Packit Service 310c69
#include "bufferedReader.h"
Packit Service 310c69
#include "bufferedWriter.h"
Packit Service 310c69
#ifdef __KERNEL__
Packit Service 310c69
#include <linux/dm-bufio.h>
Packit Service 310c69
#else
Packit Service 310c69
#include "fileUtils.h"
Packit Service 310c69
#include "ioRegion.h"
Packit Service 310c69
#endif
Packit Service 310c69
Packit Service 310c69
/*
Packit Service 310c69
 * An IOFactory object is responsible for controlling access to index storage.
Packit Service 310c69
 * The index is a contiguous range of blocks on a block device or within a
Packit Service 310c69
 * file.
Packit Service 310c69
 *
Packit Service 310c69
 * The IOFactory holds the open device or file and is responsible for closing
Packit Service 310c69
 * it.  The IOFactory has methods to make IORegions that are used to access
Packit Service 310c69
 * sections of the index.
Packit Service 310c69
 */
Packit Service 310c69
typedef struct ioFactory IOFactory;
Packit Service 310c69
Packit Service 310c69
/*
Packit Service 310c69
 * Define the UDS block size as 4K.  Historically, we wrote the volume file in
Packit Service 310c69
 * large blocks, but wrote all the other index data into byte streams stored in
Packit Service 310c69
 * files.  When we converted to writing an index into a block device, we
Packit Service 310c69
 * changed to writing the byte streams into page sized blocks.  Now that we
Packit Service 310c69
 * support multiple architectures, we write into 4K blocks on all platforms.
Packit Service 310c69
 *
Packit Service 310c69
 * XXX We must convert all the rogue 4K constants to use UDS_BLOCK_SIZE.
Packit Service 310c69
 */
Packit Service 310c69
enum { UDS_BLOCK_SIZE = 4096 };
Packit Service 310c69
Packit Service 310c69
#ifdef __KERNEL__
Packit Service 310c69
/**
Packit Service 310c69
 * Create an IOFactory.  The IOFactory is returned with a reference count of 1.
Packit Service 310c69
 *
Packit Service 310c69
 * @param path        The path to the block device or file that contains the
Packit Service 310c69
 *                    block stream
Packit Service 310c69
 * @param factoryPtr  The IOFactory is returned here
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code
Packit Service 310c69
 **/
Packit Service 310c69
int makeIOFactory(const char *path, IOFactory **factoryPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
#else
Packit Service 310c69
/**
Packit Service 310c69
 * Create an IOFactory.  The IOFactory is returned with a reference count of 1.
Packit Service 310c69
 *
Packit Service 310c69
 * @param path        The path to the block device or file that contains the
Packit Service 310c69
 *                    block stream
Packit Service 310c69
 * @param access      The requested access kind.
Packit Service 310c69
 * @param factoryPtr  The IOFactory is returned here
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code
Packit Service 310c69
 **/
Packit Service 310c69
int makeIOFactory(const char  *path,
Packit Service 310c69
                  FileAccess   access,
Packit Service 310c69
                  IOFactory  **factoryPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
#endif
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get another reference to an IOFactory, incrementing its reference count.
Packit Service 310c69
 *
Packit Service 310c69
 * @param factory  The IOFactory
Packit Service 310c69
 **/
Packit Service 310c69
void getIOFactory(IOFactory *factory);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Free a reference to an IOFactory.  If the reference count drops to zero,
Packit Service 310c69
 * free the IOFactory and release all its resources.
Packit Service 310c69
 *
Packit Service 310c69
 * @param factory  The IOFactory
Packit Service 310c69
 **/
Packit Service 310c69
void putIOFactory(IOFactory *factory);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get the maximum potential size of the device or file.  For a device, this is
Packit Service 310c69
 * the actual size of the device.  For a file, this is the largest file that we
Packit Service 310c69
 * can possibly write.
Packit Service 310c69
 *
Packit Service 310c69
 * @param factory  The IOFactory
Packit Service 310c69
 *
Packit Service 310c69
 * @return the writable size (in bytes)
Packit Service 310c69
 **/
Packit Service 310c69
size_t getWritableSize(IOFactory *factory) __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
#ifdef __KERNEL__
Packit Service 310c69
/**
Packit Service 310c69
 * Create a struct dm_bufio_client for a region of the index.
Packit Service 310c69
 *
Packit Service 310c69
 * @param factory          The IOFactory
Packit Service 310c69
 * @param offset           The byte offset to the region within the index
Packit Service 310c69
 * @param size             The size of a block, in bytes
Packit Service 310c69
 * @param reservedBuffers  The number of buffers that can be reserved
Packit Service 310c69
 * @param clientPtr        The struct dm_bufio_client is returned here
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code
Packit Service 310c69
 **/
Packit Service 310c69
int makeBufio(IOFactory               *factory,
Packit Service 310c69
              off_t                    offset,
Packit Service 310c69
              size_t                   blockSize,
Packit Service 310c69
              unsigned int             reservedBuffers,
Packit Service 310c69
              struct dm_bufio_client **clientPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
#else
Packit Service 310c69
/**
Packit Service 310c69
 * Create an IORegion for a region of the index.
Packit Service 310c69
 *
Packit Service 310c69
 * @param factory    The IOFactory
Packit Service 310c69
 * @param offset     The byte offset to the region within the index
Packit Service 310c69
 * @param size       The size in bytes of the region
Packit Service 310c69
 * @param regionPtr  The IORegion is returned here
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code
Packit Service 310c69
 **/
Packit Service 310c69
int makeIORegion(IOFactory  *factory,
Packit Service 310c69
                 off_t       offset,
Packit Service 310c69
                 size_t      size,
Packit Service 310c69
                 IORegion  **regionPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
#endif
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Create a BufferedReader for a region of the index.
Packit Service 310c69
 *
Packit Service 310c69
 * @param factory    The IOFactory
Packit Service 310c69
 * @param offset     The byte offset to the region within the index
Packit Service 310c69
 * @param size       The size in bytes of the region
Packit Service 310c69
 * @param regionPtr  The IORegion is returned here
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code
Packit Service 310c69
 **/
Packit Service 310c69
int openBufferedReader(IOFactory       *factory,
Packit Service 310c69
                       off_t            offset,
Packit Service 310c69
                       size_t           size,
Packit Service 310c69
                       BufferedReader **readerPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Create a BufferedWriter for a region of the index.
Packit Service 310c69
 *
Packit Service 310c69
 * @param factory    The IOFactory
Packit Service 310c69
 * @param offset     The byte offset to the region within the index
Packit Service 310c69
 * @param size       The size in bytes of the region
Packit Service 310c69
 * @param regionPtr  The IORegion is returned here
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code
Packit Service 310c69
 **/
Packit Service 310c69
int openBufferedWriter(IOFactory       *factory,
Packit Service 310c69
                       off_t            offset,
Packit Service 310c69
                       size_t           size,
Packit Service 310c69
                       BufferedWriter **writerPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
#endif // IO_FACTORY_H