1
/* MDB Tools - A library for reading MS Access database file
2
* Copyright (C) 2000 Brian Bruns
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public
15
* License along with this library; if not, write to the
16
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
27
mdb_map_find_next0(MdbHandle *mdb, unsigned char *map, unsigned int map_sz, guint32 start_pg)
29
guint32 pgnum, i, usage_bitlen;
30
unsigned char *usage_bitmap;
32
pgnum = mdb_get_int32(map, 1);
33
usage_bitmap = map + 5;
34
usage_bitlen = (map_sz - 5) * 8;
36
i = (start_pg >= pgnum) ? start_pg-pgnum+1 : 0;
37
for (; i<usage_bitlen; i++) {
38
if (usage_bitmap[i/8] & (1 << (i%8))) {
42
/* didn't find anything */
46
mdb_map_find_next1(MdbHandle *mdb, unsigned char *map, unsigned int map_sz, guint32 start_pg)
48
guint32 map_ind, max_map_pgs, offset, usage_bitlen;
51
* start_pg will tell us where to (re)start the scan
52
* for the next data page. each usage_map entry points to a
53
* 0x05 page which bitmaps (mdb->fmt->pg_size - 4) * 8 pages.
55
* map_ind gives us the starting usage_map entry
56
* offset gives us a page offset into the bitmap
58
usage_bitlen = (mdb->fmt->pg_size - 4) * 8;
59
max_map_pgs = (map_sz - 1) / 4;
60
map_ind = (start_pg + 1) / usage_bitlen;
61
offset = (start_pg + 1) % usage_bitlen;
63
for (; map_ind<max_map_pgs; map_ind++) {
64
unsigned char *usage_bitmap;
67
if (!(map_pg = mdb_get_int32(map, (map_ind*4)+1))) {
70
if(mdb_read_alt_pg(mdb, map_pg) != mdb->fmt->pg_size) {
71
fprintf(stderr, "Oops! didn't get a full page at %d\n", map_pg);
75
usage_bitmap = mdb->alt_pg_buf + 4;
76
for (i=offset; i<usage_bitlen; i++) {
77
if (usage_bitmap[i/8] & (1 << (i%8))) {
78
return map_ind*usage_bitlen + i;
83
/* didn't find anything */
87
mdb_map_find_next(MdbHandle *mdb, unsigned char *map, unsigned int map_sz, guint32 start_pg)
90
return mdb_map_find_next0(mdb, map, map_sz, start_pg);
91
} else if (map[0] == 1) {
92
return mdb_map_find_next1(mdb, map, map_sz, start_pg);
95
fprintf(stderr, "Warning: unrecognized usage map type: %d\n", map[0]);
99
mdb_alloc_page(MdbTableDef *table)
101
printf("Allocating new page\n");
105
mdb_map_find_next_freepage(MdbTableDef *table, int row_size)
107
MdbCatalogEntry *entry = table->entry;
108
MdbHandle *mdb = entry->mdb;
114
pgnum = mdb_map_find_next(mdb,
115
table->free_usage_map,
116
table->freemap_sz, cur_pg);
119
/* allocate new page */
120
pgnum = mdb_alloc_page(table);
125
mdb_read_pg(mdb, pgnum);
126
free_space = mdb_pg_get_freespace(mdb);
128
} while (free_space < row_size);