LUMIERA.clone/src/backend/mmapings.h
Christian Thaeter c4cbde9853 add a 'bias' to offset mmaped clusters
We will need cluster/page aligned access for certain files (indices),
this files will contain an initial header describing the contents. A bias
is used to step over this header and align the following data.
2010-07-21 04:49:40 +02:00

125 lines
3 KiB
C

/*
mmapings.h - manage ranges of mmaped areas on a filedescriptor
Copyright (C) Lumiera.org
2008, Christian Thaeter <ct@pipapo.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef LUMIERA_MMAPINGS_H
#define LUMIERA_MMAPINGS_H
#include "lib/mutex.h"
#include "lib/llist.h"
typedef struct lumiera_mmapings_struct lumiera_mmapings;
typedef lumiera_mmapings* LumieraMMapings;
#include "backend/filedescriptor.h"
#include "backend/mmap.h"
#include "backend/file.h"
#include <nobug.h>
//NOBUG_DECLARE_FLAG (mmapings);
/**
* @file
* Manage the mmap objects of a file
*
*/
struct lumiera_mmapings_struct
{
/** mmaped ranges are kept in an list sorted by the size of the mmaping, might be improved to a tree someday **/
llist mmaps;
/**
* chunkssize is the smallest granularity which is used for mmapping files, it
* should reflect the intended file usage, that is 'pagesize' for small or non growing
* files and some MB for media files. Must be a 2's exponent of pagesize.
**/
size_t chunksize;
/**
* bias shifts the chunk begin to suppress headers for example
**/
size_t bias;
LumieraFiledescriptor descriptor;
lumiera_mutex lock;
};
/**
* initialize mmapings container
*
*/
LumieraMMapings
lumiera_mmapings_init (LumieraMMapings self, LumieraFile file, size_t chunksize, size_t bias);
/**
* destroy mmapings container and free all resources.
*
*/
LumieraMMapings
lumiera_mmapings_destroy (LumieraMMapings self);
/**
* allocate and initialize new mmapings container
*
*/
LumieraMMapings
lumiera_mmapings_new (LumieraFile file, size_t chunksize, size_t bias);
/**
* destroy and free mmapings container and all its resources
*
*/
void
lumiera_mmapings_delete (LumieraMMapings self);
/**
* acquire a mmap which covers the given range
* @param self mmapings where to search
* @param start begin of the required range
* @param size requested size
* @return MMap object covering the requested range or NULL on error
*/
LumieraMMap
lumiera_mmapings_mmap_acquire (LumieraMMapings self, LumieraFile file, off_t start, size_t size);
/**
* release a previously acquired MMap object
* @param self mmapings to which the map belongs
* @param acquirer holding node
* @param map object to be released
*/
void
lumiera_mmapings_release_mmap (LumieraMMapings self, LumieraMMap map);
#endif
/*
// Local Variables:
// mode: C
// c-file-style: "gnu"
// indent-tabs-mode: nil
// End:
*/