blob: c64b7e7694d2c7eee50909b4d1022af849962408 [file] [log] [blame]
Theodore Ts'o19c78dc1997-04-29 16:17:09 +00001/*
2 * irel_ma.c
Theodore Ts'oefc6f622008-08-27 23:07:54 -04003 *
Theodore Ts'o19c78dc1997-04-29 16:17:09 +00004 * Copyright (C) 1996, 1997 Theodore Ts'o.
5 *
6 * %Begin-Header%
Theodore Ts'o543547a2010-05-17 21:31:56 -04007 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
Theodore Ts'o19c78dc1997-04-29 16:17:09 +00009 * %End-Header%
10 */
11
Theodore Ts'od1154eb2011-09-18 17:34:37 -040012#include "config.h"
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000013#include <fcntl.h>
14#include <stdio.h>
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000015#include <string.h>
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +000016#if HAVE_UNISTD_H
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000017#include <unistd.h>
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +000018#endif
19#if HAVE_ERRNO_H
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000020#include <errno.h>
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +000021#endif
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000022
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +000023#include "ext2_fs.h"
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000024#include "ext2fs.h"
25#include "irel.h"
26
Theodore Ts'o31dbecd2001-01-11 04:54:39 +000027static errcode_t ima_put(ext2_irel irel, ext2_ino_t old,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000028 struct ext2_inode_relocate_entry *ent);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +000029static errcode_t ima_get(ext2_irel irel, ext2_ino_t old,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000030 struct ext2_inode_relocate_entry *ent);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +000031static errcode_t ima_get_by_orig(ext2_irel irel, ext2_ino_t orig, ext2_ino_t *old,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000032 struct ext2_inode_relocate_entry *ent);
33static errcode_t ima_start_iter(ext2_irel irel);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +000034static errcode_t ima_next(ext2_irel irel, ext2_ino_t *old,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000035 struct ext2_inode_relocate_entry *ent);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +000036static errcode_t ima_add_ref(ext2_irel irel, ext2_ino_t ino,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000037 struct ext2_inode_reference *ref);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +000038static errcode_t ima_start_iter_ref(ext2_irel irel, ext2_ino_t ino);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000039static errcode_t ima_next_ref(ext2_irel irel, struct ext2_inode_reference *ref);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +000040static errcode_t ima_move(ext2_irel irel, ext2_ino_t old, ext2_ino_t new);
41static errcode_t ima_delete(ext2_irel irel, ext2_ino_t old);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000042static errcode_t ima_free(ext2_irel irel);
43
44/*
45 * This data structure stores the array of inode references; there is
46 * a structure for each inode.
47 */
48struct inode_reference_entry {
49 __u16 num;
50 struct ext2_inode_reference *refs;
51};
52
53struct irel_ma {
54 __u32 magic;
Theodore Ts'o31dbecd2001-01-11 04:54:39 +000055 ext2_ino_t max_inode;
56 ext2_ino_t ref_current;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000057 int ref_iter;
Theodore Ts'o31dbecd2001-01-11 04:54:39 +000058 ext2_ino_t *orig_map;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000059 struct ext2_inode_relocate_entry *entries;
60 struct inode_reference_entry *ref_entries;
61};
62
Theodore Ts'o31dbecd2001-01-11 04:54:39 +000063errcode_t ext2fs_irel_memarray_create(char *name, ext2_ino_t max_inode,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000064 ext2_irel *new_irel)
65{
66 ext2_irel irel = 0;
67 errcode_t retval;
68 struct irel_ma *ma = 0;
69 size_t size;
70
71 *new_irel = 0;
72
73 /*
74 * Allocate memory structures
75 */
Theodore Ts'o7b4e4531997-10-26 03:41:24 +000076 retval = ext2fs_get_mem(sizeof(struct ext2_inode_relocation_table),
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -040077 &irel);
Theodore Ts'o7b4e4531997-10-26 03:41:24 +000078 if (retval)
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000079 goto errout;
80 memset(irel, 0, sizeof(struct ext2_inode_relocation_table));
Theodore Ts'oefc6f622008-08-27 23:07:54 -040081
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -040082 retval = ext2fs_get_mem(strlen(name)+1, &irel->name);
Theodore Ts'o7b4e4531997-10-26 03:41:24 +000083 if (retval)
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000084 goto errout;
85 strcpy(irel->name, name);
Theodore Ts'oefc6f622008-08-27 23:07:54 -040086
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -040087 retval = ext2fs_get_mem(sizeof(struct irel_ma), &ma);
Theodore Ts'o7b4e4531997-10-26 03:41:24 +000088 if (retval)
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000089 goto errout;
90 memset(ma, 0, sizeof(struct irel_ma));
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +000091 irel->priv_data = ma;
Theodore Ts'oefc6f622008-08-27 23:07:54 -040092
Theodore Ts'o31dbecd2001-01-11 04:54:39 +000093 size = (size_t) (sizeof(ext2_ino_t) * (max_inode+1));
Theodore Ts'oee010792007-11-09 19:01:06 -050094 retval = ext2fs_get_array(max_inode+1, sizeof(ext2_ino_t),
95 &ma->orig_map);
Theodore Ts'o7b4e4531997-10-26 03:41:24 +000096 if (retval)
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000097 goto errout;
98 memset(ma->orig_map, 0, size);
99
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000100 size = (size_t) (sizeof(struct ext2_inode_relocate_entry) *
101 (max_inode+1));
Theodore Ts'oee010792007-11-09 19:01:06 -0500102 retval = ext2fs_get_array((max_inode+1,
103 sizeof(struct ext2_inode_relocate_entry), &ma->entries);
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000104 if (retval)
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000105 goto errout;
106 memset(ma->entries, 0, size);
107
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000108 size = (size_t) (sizeof(struct inode_reference_entry) *
109 (max_inode+1));
Theodore Ts'oee010792007-11-09 19:01:06 -0500110 retval = ext2fs_get_mem(max_inode+1,
111 sizeof(struct inode_reference_entry), &ma->ref_entries);
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000112 if (retval)
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000113 goto errout;
114 memset(ma->ref_entries, 0, size);
115 ma->max_inode = max_inode;
116
117 /*
118 * Fill in the irel data structure
119 */
120 irel->put = ima_put;
121 irel->get = ima_get;
122 irel->get_by_orig = ima_get_by_orig;
123 irel->start_iter = ima_start_iter;
124 irel->next = ima_next;
125 irel->add_ref = ima_add_ref;
126 irel->start_iter_ref = ima_start_iter_ref;
127 irel->next_ref = ima_next_ref;
128 irel->move = ima_move;
129 irel->delete = ima_delete;
130 irel->free = ima_free;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400131
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000132 *new_irel = irel;
133 return 0;
134
135errout:
136 ima_free(irel);
137 return retval;
138}
139
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000140static errcode_t ima_put(ext2_irel irel, ext2_ino_t old,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000141 struct ext2_inode_relocate_entry *ent)
142{
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000143 struct inode_reference_entry *ref_ent;
144 struct irel_ma *ma;
145 errcode_t retval;
Theodore Ts'o76f875d1998-04-27 01:41:13 +0000146 size_t size, old_size;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000147
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000148 ma = irel->priv_data;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000149 if (old > ma->max_inode)
Theodore Ts'o1f0b6c11997-10-31 06:07:47 +0000150 return EXT2_ET_INVALID_ARGUMENT;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000151
152 /*
153 * Force the orig field to the correct value; the application
154 * program shouldn't be messing with this field.
155 */
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000156 if (ma->entries[(unsigned) old].new == 0)
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000157 ent->orig = old;
158 else
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000159 ent->orig = ma->entries[(unsigned) old].orig;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400160
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000161 /*
162 * If max_refs has changed, reallocate the refs array
163 */
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000164 ref_ent = ma->ref_entries + (unsigned) old;
165 if (ref_ent->refs && ent->max_refs !=
166 ma->entries[(unsigned) old].max_refs) {
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000167 size = (sizeof(struct ext2_inode_reference) * ent->max_refs);
Theodore Ts'o76f875d1998-04-27 01:41:13 +0000168 old_size = (sizeof(struct ext2_inode_reference) *
169 ma->entries[(unsigned) old].max_refs);
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400170 retval = ext2fs_resize_mem(old_size, size, &ref_ent->refs);
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000171 if (retval)
172 return retval;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000173 }
174
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000175 ma->entries[(unsigned) old] = *ent;
176 ma->orig_map[(unsigned) ent->orig] = old;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000177 return 0;
178}
179
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000180static errcode_t ima_get(ext2_irel irel, ext2_ino_t old,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000181 struct ext2_inode_relocate_entry *ent)
182{
183 struct irel_ma *ma;
184
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000185 ma = irel->priv_data;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000186 if (old > ma->max_inode)
Theodore Ts'o1f0b6c11997-10-31 06:07:47 +0000187 return EXT2_ET_INVALID_ARGUMENT;
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000188 if (ma->entries[(unsigned) old].new == 0)
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000189 return ENOENT;
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000190 *ent = ma->entries[(unsigned) old];
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000191 return 0;
192}
193
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000194static errcode_t ima_get_by_orig(ext2_irel irel, ext2_ino_t orig, ext2_ino_t *old,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000195 struct ext2_inode_relocate_entry *ent)
196{
197 struct irel_ma *ma;
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000198 ext2_ino_t ino;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000199
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000200 ma = irel->priv_data;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000201 if (orig > ma->max_inode)
Theodore Ts'o1f0b6c11997-10-31 06:07:47 +0000202 return EXT2_ET_INVALID_ARGUMENT;
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000203 ino = ma->orig_map[(unsigned) orig];
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000204 if (ino == 0)
205 return ENOENT;
206 *old = ino;
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000207 *ent = ma->entries[(unsigned) ino];
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000208 return 0;
209}
210
211static errcode_t ima_start_iter(ext2_irel irel)
212{
213 irel->current = 0;
214 return 0;
215}
216
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000217static errcode_t ima_next(ext2_irel irel, ext2_ino_t *old,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000218 struct ext2_inode_relocate_entry *ent)
219{
220 struct irel_ma *ma;
221
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000222 ma = irel->priv_data;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000223 while (++irel->current < ma->max_inode) {
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000224 if (ma->entries[(unsigned) irel->current].new == 0)
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000225 continue;
226 *old = irel->current;
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000227 *ent = ma->entries[(unsigned) irel->current];
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000228 return 0;
229 }
230 *old = 0;
231 return 0;
232}
233
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000234static errcode_t ima_add_ref(ext2_irel irel, ext2_ino_t ino,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000235 struct ext2_inode_reference *ref)
236{
237 struct irel_ma *ma;
238 size_t size;
239 struct inode_reference_entry *ref_ent;
240 struct ext2_inode_relocate_entry *ent;
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000241 errcode_t retval;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000242
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000243 ma = irel->priv_data;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000244 if (ino > ma->max_inode)
Theodore Ts'o1f0b6c11997-10-31 06:07:47 +0000245 return EXT2_ET_INVALID_ARGUMENT;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000246
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000247 ref_ent = ma->ref_entries + (unsigned) ino;
248 ent = ma->entries + (unsigned) ino;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400249
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000250 /*
251 * If the inode reference array doesn't exist, create it.
252 */
253 if (ref_ent->refs == 0) {
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400254 size = (size_t) ((sizeof(struct ext2_inode_reference) *
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000255 ent->max_refs));
Theodore Ts'oee010792007-11-09 19:01:06 -0500256 retval = ext2fs_get_array(ent->max_refs,
257 sizeof(struct ext2_inode_reference), &ref_ent->refs);
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000258 if (retval)
259 return retval;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000260 memset(ref_ent->refs, 0, size);
261 ref_ent->num = 0;
262 }
263
264 if (ref_ent->num >= ent->max_refs)
Theodore Ts'o1f0b6c11997-10-31 06:07:47 +0000265 return EXT2_ET_TOO_MANY_REFS;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000266
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000267 ref_ent->refs[(unsigned) ref_ent->num++] = *ref;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000268 return 0;
269}
270
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000271static errcode_t ima_start_iter_ref(ext2_irel irel, ext2_ino_t ino)
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000272{
273 struct irel_ma *ma;
274
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000275 ma = irel->priv_data;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000276 if (ino > ma->max_inode)
Theodore Ts'o1f0b6c11997-10-31 06:07:47 +0000277 return EXT2_ET_INVALID_ARGUMENT;
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000278 if (ma->entries[(unsigned) ino].new == 0)
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000279 return ENOENT;
280 ma->ref_current = ino;
281 ma->ref_iter = 0;
282 return 0;
283}
284
285static errcode_t ima_next_ref(ext2_irel irel,
286 struct ext2_inode_reference *ref)
287{
288 struct irel_ma *ma;
289 struct inode_reference_entry *ref_ent;
290
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000291 ma = irel->priv_data;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400292
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000293 ref_ent = ma->ref_entries + ma->ref_current;
294
295 if ((ref_ent->refs == NULL) ||
296 (ma->ref_iter >= ref_ent->num)) {
297 ref->block = 0;
298 ref->offset = 0;
299 return 0;
300 }
301 *ref = ref_ent->refs[ma->ref_iter++];
302 return 0;
303}
304
305
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000306static errcode_t ima_move(ext2_irel irel, ext2_ino_t old, ext2_ino_t new)
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000307{
308 struct irel_ma *ma;
309
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000310 ma = irel->priv_data;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000311 if ((old > ma->max_inode) || (new > ma->max_inode))
Theodore Ts'o1f0b6c11997-10-31 06:07:47 +0000312 return EXT2_ET_INVALID_ARGUMENT;
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000313 if (ma->entries[(unsigned) old].new == 0)
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000314 return ENOENT;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400315
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000316 ma->entries[(unsigned) new] = ma->entries[(unsigned) old];
317 if (ma->ref_entries[(unsigned) new].refs)
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400318 ext2fs_free_mem(&ma->ref_entries[(unsigned) new].refs);
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000319 ma->ref_entries[(unsigned) new] = ma->ref_entries[(unsigned) old];
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400320
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000321 ma->entries[(unsigned) old].new = 0;
322 ma->ref_entries[(unsigned) old].num = 0;
323 ma->ref_entries[(unsigned) old].refs = 0;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000324
325 ma->orig_map[ma->entries[new].orig] = new;
326 return 0;
327}
328
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000329static errcode_t ima_delete(ext2_irel irel, ext2_ino_t old)
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000330{
331 struct irel_ma *ma;
332
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000333 ma = irel->priv_data;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000334 if (old > ma->max_inode)
Theodore Ts'o1f0b6c11997-10-31 06:07:47 +0000335 return EXT2_ET_INVALID_ARGUMENT;
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000336 if (ma->entries[(unsigned) old].new == 0)
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000337 return ENOENT;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400338
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000339 ma->entries[old].new = 0;
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000340 if (ma->ref_entries[(unsigned) old].refs)
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400341 ext2fs_free_mem(&ma->ref_entries[(unsigned) old].refs);
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000342 ma->orig_map[ma->entries[(unsigned) old].orig] = 0;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400343
Theodore Ts'o1c27cac1997-08-14 17:20:42 +0000344 ma->ref_entries[(unsigned) old].num = 0;
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000345 ma->ref_entries[(unsigned) old].refs = 0;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000346 return 0;
347}
348
349static errcode_t ima_free(ext2_irel irel)
350{
351 struct irel_ma *ma;
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000352 ext2_ino_t ino;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000353
354 if (!irel)
355 return 0;
356
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000357 ma = irel->priv_data;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000358
359 if (ma) {
360 if (ma->orig_map)
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400361 ext2fs_free_mem(&ma->orig_map);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000362 if (ma->entries)
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400363 ext2fs_free_mem(&ma->entries);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000364 if (ma->ref_entries) {
365 for (ino = 0; ino <= ma->max_inode; ino++) {
Theodore Ts'o3cb6c501997-08-11 20:29:22 +0000366 if (ma->ref_entries[(unsigned) ino].refs)
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400367 ext2fs_free_mem(&ma->ref_entries[(unsigned) ino].refs);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000368 }
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400369 ext2fs_free_mem(&ma->ref_entries);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000370 }
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400371 ext2fs_free_mem(&ma);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000372 }
373 if (irel->name)
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400374 ext2fs_free_mem(&irel->name);
375 ext2fs_free_mem(&irel);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000376 return 0;
377}