4 * Copyright (C) 1996, 1997 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
23 #include <linux/ext2_fs.h>
28 static errcode_t bma_put(ext2_brel brel, blk_t old,
29 struct ext2_block_relocate_entry *ent);
30 static errcode_t bma_get(ext2_brel brel, blk_t old,
31 struct ext2_block_relocate_entry *ent);
32 static errcode_t bma_start_iter(ext2_brel brel);
33 static errcode_t bma_next(ext2_brel brel, blk_t *old,
34 struct ext2_block_relocate_entry *ent);
35 static errcode_t bma_move(ext2_brel brel, blk_t old, blk_t new);
36 static errcode_t bma_delete(ext2_brel brel, blk_t old);
37 static errcode_t bma_free(ext2_brel brel);
42 struct ext2_block_relocate_entry *entries;
45 errcode_t ext2fs_brel_memarray_create(char *name, blk_t max_block,
50 struct brel_ma *ma = 0;
56 * Allocate memory structures
59 brel = malloc(sizeof(struct ext2_block_relocation_table));
62 memset(brel, 0, sizeof(struct ext2_block_relocation_table));
64 brel->name = malloc(strlen(name)+1);
67 strcpy(brel->name, name);
69 ma = malloc(sizeof(struct brel_ma));
72 memset(ma, 0, sizeof(struct brel_ma));
75 size = sizeof(struct ext2_block_relocate_entry) * (max_block+1);
76 ma->entries = malloc(size);
79 memset(ma->entries, 0, size);
80 ma->max_block = max_block;
83 * Fill in the brel data structure
87 brel->start_iter = bma_start_iter;
88 brel->next = bma_next;
89 brel->move = bma_move;
90 brel->delete = bma_delete;
91 brel->free = bma_free;
101 static errcode_t bma_put(ext2_brel brel, blk_t old,
102 struct ext2_block_relocate_entry *ent)
107 if (old > ma->max_block)
109 ma->entries[old] = *ent;
113 static errcode_t bma_get(ext2_brel brel, blk_t old,
114 struct ext2_block_relocate_entry *ent)
119 if (old > ma->max_block)
121 if (ma->entries[old].new == 0)
123 *ent = ma->entries[old];
127 static errcode_t bma_start_iter(ext2_brel brel)
133 static errcode_t bma_next(ext2_brel brel, blk_t *old,
134 struct ext2_block_relocate_entry *ent)
139 while (++brel->current < ma->max_block) {
140 if (ma->entries[brel->current].new == 0)
142 *old = brel->current;
143 *ent = ma->entries[brel->current];
150 static errcode_t bma_move(ext2_brel brel, blk_t old, blk_t new)
155 if ((old > ma->max_block) || (new > ma->max_block))
157 if (ma->entries[old].new == 0)
159 ma->entries[new] = ma->entries[old];
160 ma->entries[old].new = 0;
164 static errcode_t bma_delete(ext2_brel brel, blk_t old)
169 if (old > ma->max_block)
171 if (ma->entries[old].new == 0)
173 ma->entries[old].new = 0;
177 static errcode_t bma_free(ext2_brel brel)