4 * Copyright (C) 1996, 1997 Theodore Ts'o.
6 * TODO: rewrite to not use a direct array!!! (Fortunately this
7 * module isn't really used yet.)
10 * This file may be redistributed under the terms of the GNU Public
26 #include <linux/ext2_fs.h>
31 static errcode_t bma_put(ext2_brel brel, blk_t old,
32 struct ext2_block_relocate_entry *ent);
33 static errcode_t bma_get(ext2_brel brel, blk_t old,
34 struct ext2_block_relocate_entry *ent);
35 static errcode_t bma_start_iter(ext2_brel brel);
36 static errcode_t bma_next(ext2_brel brel, blk_t *old,
37 struct ext2_block_relocate_entry *ent);
38 static errcode_t bma_move(ext2_brel brel, blk_t old, blk_t new);
39 static errcode_t bma_delete(ext2_brel brel, blk_t old);
40 static errcode_t bma_free(ext2_brel brel);
45 struct ext2_block_relocate_entry *entries;
48 errcode_t ext2fs_brel_memarray_create(char *name, blk_t max_block,
53 struct brel_ma *ma = 0;
59 * Allocate memory structures
61 retval = EXT2_NO_MEMORY;
62 brel = malloc(sizeof(struct ext2_block_relocation_table));
65 memset(brel, 0, sizeof(struct ext2_block_relocation_table));
67 brel->name = malloc(strlen(name)+1);
70 strcpy(brel->name, name);
72 ma = malloc(sizeof(struct brel_ma));
75 memset(ma, 0, sizeof(struct brel_ma));
78 size = (size_t) (sizeof(struct ext2_block_relocate_entry) *
80 ma->entries = malloc(size);
83 memset(ma->entries, 0, size);
84 ma->max_block = max_block;
87 * Fill in the brel data structure
91 brel->start_iter = bma_start_iter;
92 brel->next = bma_next;
93 brel->move = bma_move;
94 brel->delete = bma_delete;
95 brel->free = bma_free;
105 static errcode_t bma_put(ext2_brel brel, blk_t old,
106 struct ext2_block_relocate_entry *ent)
111 if (old > ma->max_block)
112 return EXT2_INVALID_ARGUMENT;
113 ma->entries[(unsigned)old] = *ent;
117 static errcode_t bma_get(ext2_brel brel, blk_t old,
118 struct ext2_block_relocate_entry *ent)
123 if (old > ma->max_block)
124 return EXT2_INVALID_ARGUMENT;
125 if (ma->entries[(unsigned)old].new == 0)
127 *ent = ma->entries[old];
131 static errcode_t bma_start_iter(ext2_brel brel)
137 static errcode_t bma_next(ext2_brel brel, blk_t *old,
138 struct ext2_block_relocate_entry *ent)
143 while (++brel->current < ma->max_block) {
144 if (ma->entries[(unsigned)brel->current].new == 0)
146 *old = brel->current;
147 *ent = ma->entries[(unsigned)brel->current];
154 static errcode_t bma_move(ext2_brel brel, blk_t old, blk_t new)
159 if ((old > ma->max_block) || (new > ma->max_block))
160 return EXT2_INVALID_ARGUMENT;
161 if (ma->entries[(unsigned)old].new == 0)
163 ma->entries[(unsigned)new] = ma->entries[old];
164 ma->entries[(unsigned)old].new = 0;
168 static errcode_t bma_delete(ext2_brel brel, blk_t old)
173 if (old > ma->max_block)
174 return EXT2_INVALID_ARGUMENT;
175 if (ma->entries[(unsigned)old].new == 0)
177 ma->entries[(unsigned)old].new = 0;
181 static errcode_t bma_free(ext2_brel brel)