00001 /* 00002 * Copyright 2008, 2009 Alexandros Frantzis, Michael Iatrou 00003 * 00004 * This file is part of libbls. 00005 * 00006 * libbls is free software: you can redistribute it and/or modify it under the 00007 * terms of the GNU Lesser General Public License as published by the Free Software 00008 * Foundation, either version 3 of the License, or (at your option) any later 00009 * version. 00010 * 00011 * libbls is distributed in the hope that it will be useful, but WITHOUT ANY 00012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00013 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00014 * details. 00015 * 00016 * You should have received a copy of the GNU General Public License along with 00017 * libbls. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 /** 00021 * @file segment.h 00022 * 00023 * Segment 00024 */ 00025 #ifndef _SEGMENT_H 00026 #define _SEGMENT_H 00027 00028 #include <sys/types.h> 00029 00030 /** 00031 * @defgroup segment Segment 00032 * 00033 * A segment holds information about a continuous part of a data object. 00034 * 00035 * By default, when a segment becomes associated with a data object, the 00036 * segment is not responsible for managing the data object's memory. This 00037 * kind of memory management can be achieved be specifying the data_usage_func 00038 * when creating the segment or changing its data association. The function 00039 * is called whenever the segment is created or freed and updates the data 00040 * object's usage count. 00041 * 00042 * @{ 00043 */ 00044 00045 /** 00046 * Opaque type for segment ADT. 00047 */ 00048 typedef struct segment segment_t; 00049 00050 /** 00051 * Function called to change the usage count of some data. 00052 * 00053 * @param data the data whose usage count is being changed 00054 * @param change the change in the usage count or 0 to reset the count 00055 * 00056 * @return the operation error code 00057 */ 00058 typedef int (*segment_data_usage_func)(void *data, int change); 00059 00060 int segment_new(segment_t **seg, void *data, off_t start, off_t size, 00061 segment_data_usage_func data_usage_func); 00062 00063 int segment_copy(segment_t *seg, segment_t **seg_copy); 00064 00065 int segment_free(segment_t *seg); 00066 00067 int segment_clear(segment_t *seg); 00068 00069 int segment_split(segment_t *seg, segment_t **seg1, off_t split_index); 00070 00071 int segment_merge(segment_t *seg, segment_t *seg1); 00072 00073 int segment_get_data(segment_t *seg, void **data); 00074 00075 int segment_get_start(segment_t *seg, off_t *start); 00076 00077 int segment_get_size(segment_t *seg, off_t *size); 00078 00079 int segment_set_data(segment_t *seg, void *data, 00080 segment_data_usage_func data_usage_func); 00081 00082 int segment_set_range(segment_t *seg, off_t start, off_t size); 00083 00084 /** @} */ 00085 00086 #endif /* _SEGMENT_H */