File: bitmap.h

package info (click to toggle)
ocfs2-tools 1.8.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 6,232 kB
  • sloc: ansic: 86,865; sh: 5,781; python: 2,380; makefile: 1,305
file content (142 lines) | stat: -rw-r--r-- 4,974 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* -*- mode: c; c-basic-offset: 8; -*-
 * vim: noexpandtab sw=8 ts=8 sts=0:
 *
 * bitmap.h
 *
 * Structures for allocation bitmaps for the OCFS2 userspace library.
 *
 * Copyright (C) 2004 Oracle.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License, version 2,  as published by the Free Software Foundation.
 * 
 * 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., 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301 USA.
 *
 * Authors: Joel Becker
 */

#ifndef _BITMAP_H
#define _BITMAP_H

#include "ocfs2/kernel-rbtree.h"


struct ocfs2_bitmap_region {
	struct rb_node br_node;
	uint64_t br_start_bit;		/* Bit offset. */
	int br_bitmap_start;		/* bit start in br_bitmap. */
	int br_valid_bits;		/* bit length valid in br_bitmap. */
	int br_total_bits;		/* set_bit() and friends can't
					   handle bitmaps larger than
					   int offsets */
	size_t br_bytes;
	int br_set_bits;
	uint8_t *br_bitmap;
	void *br_private;
};

struct ocfs2_bitmap_operations {
	errcode_t (*set_bit)(ocfs2_bitmap *bitmap, uint64_t bit,
			     int *oldval);
	errcode_t (*clear_bit)(ocfs2_bitmap *bitmap, uint64_t bit,
			       int *oldval);
	errcode_t (*test_bit)(ocfs2_bitmap *bitmap, uint64_t bit,
			      int *val);
	errcode_t (*find_next_set)(ocfs2_bitmap *bitmap,
				   uint64_t start, 
				   uint64_t *found);
	errcode_t (*find_next_clear)(ocfs2_bitmap *bitmap,
				     uint64_t start, 
				     uint64_t *found);
	int (*merge_region)(ocfs2_bitmap *bitmap,
			    struct ocfs2_bitmap_region *prev,
			    struct ocfs2_bitmap_region *next);
	errcode_t (*read_bitmap)(ocfs2_bitmap *bitmap);
	errcode_t (*write_bitmap)(ocfs2_bitmap *bitmap);
	void (*destroy_notify)(ocfs2_bitmap *bitmap);
	void (*bit_change_notify)(ocfs2_bitmap *bitmap,
				  struct ocfs2_bitmap_region *br,
				  uint64_t bitno,
				  int new_val);
	errcode_t (*alloc_range)(ocfs2_bitmap *bitmap, uint64_t min_len,
				 uint64_t len, uint64_t *first_bit,
				 uint64_t *bits_found);
	errcode_t (*clear_range)(ocfs2_bitmap *bitmap, uint64_t len, 
				 uint64_t first_bit);
};

struct _ocfs2_bitmap {
	ocfs2_filesys *b_fs;
	uint64_t b_set_bits;
	uint64_t b_total_bits;
	char *b_description;
	struct ocfs2_bitmap_operations *b_ops;
	struct rb_root b_regions;
	void *b_private;
};


errcode_t ocfs2_bitmap_new(ocfs2_filesys *fs,
			   uint64_t total_bits,
			   const char *description,
			   struct ocfs2_bitmap_operations *ops,
			   void *private_data,
			   ocfs2_bitmap **ret_bitmap);
errcode_t ocfs2_bitmap_alloc_region(ocfs2_bitmap *bitmap,
				    uint64_t start_bit,
				    int bitmap_start,
				    int total_bits,
				    struct ocfs2_bitmap_region **ret_br);
void ocfs2_bitmap_free_region(struct ocfs2_bitmap_region *br);
errcode_t ocfs2_bitmap_realloc_region(ocfs2_bitmap *bitmap,
				      struct ocfs2_bitmap_region *br,
				      int total_bits);
errcode_t ocfs2_bitmap_insert_region(ocfs2_bitmap *bitmap,
				     struct ocfs2_bitmap_region *br);
typedef errcode_t (*ocfs2_bitmap_foreach_func)(struct ocfs2_bitmap_region *br,
					       void *private_data);
errcode_t ocfs2_bitmap_foreach_region(ocfs2_bitmap *bitmap,
				      ocfs2_bitmap_foreach_func func,
				      void *private_data);
errcode_t ocfs2_bitmap_set_generic(ocfs2_bitmap *bitmap,
				   uint64_t bitno, int *oldval);
errcode_t ocfs2_bitmap_clear_generic(ocfs2_bitmap *bitmap,
				     uint64_t bitno, int *oldval);
errcode_t ocfs2_bitmap_test_generic(ocfs2_bitmap *bitmap,
				    uint64_t bitno, int *val);
errcode_t ocfs2_bitmap_find_next_set_generic(ocfs2_bitmap *bitmap,
					     uint64_t start,
					     uint64_t *found);
errcode_t ocfs2_bitmap_find_next_clear_generic(ocfs2_bitmap *bitmap,
					       uint64_t start,
					       uint64_t *found);
errcode_t ocfs2_bitmap_alloc_range_generic(ocfs2_bitmap *bitmap,
					   uint64_t min_len,
					   uint64_t len,
					   uint64_t *first_bit,
					   uint64_t *bits_found);
errcode_t ocfs2_bitmap_clear_range_generic(ocfs2_bitmap *bitmap,
					   uint64_t len,
					   uint64_t first_bit);
errcode_t ocfs2_bitmap_set_holes(ocfs2_bitmap *bitmap,
				 uint64_t bitno, int *oldval);
errcode_t ocfs2_bitmap_clear_holes(ocfs2_bitmap *bitmap,
				   uint64_t bitno, int *oldval);
errcode_t ocfs2_bitmap_test_holes(ocfs2_bitmap *bitmap,
				  uint64_t bitno, int *val);
errcode_t ocfs2_bitmap_find_next_set_holes(ocfs2_bitmap *bitmap,
					   uint64_t start,
					   uint64_t *found);
errcode_t ocfs2_bitmap_find_next_clear_holes(ocfs2_bitmap *bitmap,
					     uint64_t start,
					     uint64_t *found);
#endif  /* _BITMAP_H */