e2fsprogs/lib/ext2fs/irel_ma.c

374 lines
9.0 KiB
C
Raw Normal View History

1997-04-29 20:17:09 +04:00
/*
* irel_ma.c
*
* Copyright (C) 1996, 1997 Theodore Ts'o.
*
* %Begin-Header%
* This file may be redistributed under the terms of the GNU Public
* License.
* %End-Header%
*/
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#if HAVE_UNISTD_H
1997-04-29 20:17:09 +04:00
#include <unistd.h>
#endif
#if HAVE_ERRNO_H
1997-04-29 20:17:09 +04:00
#include <errno.h>
#endif
1997-04-29 20:17:09 +04:00
Many files: inode.c (ext2fs_open_inode_scan): Initialize the group variables so that we don't need to call get_next_blockgroup() the first time around. Saves a bit of time, and prevents us from needing to assign -1 to current_group (which is an unsigned value). icount.c (insert_icount_el): Cast the estimated number of inodes from a float to an ino_t. alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c, bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c, check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c, ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c, icount.c, initialize.c, inline.c, inode.c, irel_ma.c, ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c, newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c, rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c, tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c, version.c: If EXT2_FLAT_INCLUDES is defined, then assume all of the ext2-specific header files are in a flat directory. block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast all assignments from void * to be compatible with C++. closefs.c (ext2fs_flush): Add a call to io_channel_flush() to make sure the contents of the disk are flushed to disk. dblist.c (ext2fs_add_dir_block): Change new to be new_entry to avoid C++ namespace clash. bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to avoid C++ namespace clash. ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c, irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c, ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c, unlink.c: Change private to be priv_data (to avoid C++ namespace clash)
1998-01-19 17:47:53 +03:00
#include "ext2_fs.h"
1997-04-29 20:17:09 +04:00
#include "ext2fs.h"
#include "irel.h"
static errcode_t ima_put(ext2_irel irel, ext2_ino_t old,
1997-04-29 20:17:09 +04:00
struct ext2_inode_relocate_entry *ent);
static errcode_t ima_get(ext2_irel irel, ext2_ino_t old,
1997-04-29 20:17:09 +04:00
struct ext2_inode_relocate_entry *ent);
static errcode_t ima_get_by_orig(ext2_irel irel, ext2_ino_t orig, ext2_ino_t *old,
1997-04-29 20:17:09 +04:00
struct ext2_inode_relocate_entry *ent);
static errcode_t ima_start_iter(ext2_irel irel);
static errcode_t ima_next(ext2_irel irel, ext2_ino_t *old,
1997-04-29 20:17:09 +04:00
struct ext2_inode_relocate_entry *ent);
static errcode_t ima_add_ref(ext2_irel irel, ext2_ino_t ino,
1997-04-29 20:17:09 +04:00
struct ext2_inode_reference *ref);
static errcode_t ima_start_iter_ref(ext2_irel irel, ext2_ino_t ino);
1997-04-29 20:17:09 +04:00
static errcode_t ima_next_ref(ext2_irel irel, struct ext2_inode_reference *ref);
static errcode_t ima_move(ext2_irel irel, ext2_ino_t old, ext2_ino_t new);
static errcode_t ima_delete(ext2_irel irel, ext2_ino_t old);
1997-04-29 20:17:09 +04:00
static errcode_t ima_free(ext2_irel irel);
/*
* This data structure stores the array of inode references; there is
* a structure for each inode.
*/
struct inode_reference_entry {
__u16 num;
struct ext2_inode_reference *refs;
};
struct irel_ma {
__u32 magic;
ext2_ino_t max_inode;
ext2_ino_t ref_current;
1997-04-29 20:17:09 +04:00
int ref_iter;
ext2_ino_t *orig_map;
1997-04-29 20:17:09 +04:00
struct ext2_inode_relocate_entry *entries;
struct inode_reference_entry *ref_entries;
};
errcode_t ext2fs_irel_memarray_create(char *name, ext2_ino_t max_inode,
1997-04-29 20:17:09 +04:00
ext2_irel *new_irel)
{
ext2_irel irel = 0;
errcode_t retval;
struct irel_ma *ma = 0;
size_t size;
*new_irel = 0;
/*
* Allocate memory structures
*/
retval = ext2fs_get_mem(sizeof(struct ext2_inode_relocation_table),
(void **) &irel);
if (retval)
1997-04-29 20:17:09 +04:00
goto errout;
memset(irel, 0, sizeof(struct ext2_inode_relocation_table));
retval = ext2fs_get_mem(strlen(name)+1, (void **) &irel->name);
if (retval)
1997-04-29 20:17:09 +04:00
goto errout;
strcpy(irel->name, name);
retval = ext2fs_get_mem(sizeof(struct irel_ma), (void **) &ma);
if (retval)
1997-04-29 20:17:09 +04:00
goto errout;
memset(ma, 0, sizeof(struct irel_ma));
Many files: inode.c (ext2fs_open_inode_scan): Initialize the group variables so that we don't need to call get_next_blockgroup() the first time around. Saves a bit of time, and prevents us from needing to assign -1 to current_group (which is an unsigned value). icount.c (insert_icount_el): Cast the estimated number of inodes from a float to an ino_t. alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c, bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c, check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c, ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c, icount.c, initialize.c, inline.c, inode.c, irel_ma.c, ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c, newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c, rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c, tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c, version.c: If EXT2_FLAT_INCLUDES is defined, then assume all of the ext2-specific header files are in a flat directory. block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast all assignments from void * to be compatible with C++. closefs.c (ext2fs_flush): Add a call to io_channel_flush() to make sure the contents of the disk are flushed to disk. dblist.c (ext2fs_add_dir_block): Change new to be new_entry to avoid C++ namespace clash. bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to avoid C++ namespace clash. ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c, irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c, ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c, unlink.c: Change private to be priv_data (to avoid C++ namespace clash)
1998-01-19 17:47:53 +03:00
irel->priv_data = ma;
1997-04-29 20:17:09 +04:00
size = (size_t) (sizeof(ext2_ino_t) * (max_inode+1));
retval = ext2fs_get_mem(size, (void **) &ma->orig_map);
if (retval)
1997-04-29 20:17:09 +04:00
goto errout;
memset(ma->orig_map, 0, size);
size = (size_t) (sizeof(struct ext2_inode_relocate_entry) *
(max_inode+1));
retval = ext2fs_get_mem(size, (void **) &ma->entries);
if (retval)
1997-04-29 20:17:09 +04:00
goto errout;
memset(ma->entries, 0, size);
size = (size_t) (sizeof(struct inode_reference_entry) *
(max_inode+1));
retval = ext2fs_get_mem(size, (void **) &ma->ref_entries);
if (retval)
1997-04-29 20:17:09 +04:00
goto errout;
memset(ma->ref_entries, 0, size);
ma->max_inode = max_inode;
/*
* Fill in the irel data structure
*/
irel->put = ima_put;
irel->get = ima_get;
irel->get_by_orig = ima_get_by_orig;
irel->start_iter = ima_start_iter;
irel->next = ima_next;
irel->add_ref = ima_add_ref;
irel->start_iter_ref = ima_start_iter_ref;
irel->next_ref = ima_next_ref;
irel->move = ima_move;
irel->delete = ima_delete;
irel->free = ima_free;
*new_irel = irel;
return 0;
errout:
ima_free(irel);
return retval;
}
static errcode_t ima_put(ext2_irel irel, ext2_ino_t old,
1997-04-29 20:17:09 +04:00
struct ext2_inode_relocate_entry *ent)
{
struct inode_reference_entry *ref_ent;
struct irel_ma *ma;
errcode_t retval;
size_t size, old_size;
1997-04-29 20:17:09 +04:00
Many files: inode.c (ext2fs_open_inode_scan): Initialize the group variables so that we don't need to call get_next_blockgroup() the first time around. Saves a bit of time, and prevents us from needing to assign -1 to current_group (which is an unsigned value). icount.c (insert_icount_el): Cast the estimated number of inodes from a float to an ino_t. alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c, bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c, check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c, ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c, icount.c, initialize.c, inline.c, inode.c, irel_ma.c, ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c, newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c, rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c, tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c, version.c: If EXT2_FLAT_INCLUDES is defined, then assume all of the ext2-specific header files are in a flat directory. block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast all assignments from void * to be compatible with C++. closefs.c (ext2fs_flush): Add a call to io_channel_flush() to make sure the contents of the disk are flushed to disk. dblist.c (ext2fs_add_dir_block): Change new to be new_entry to avoid C++ namespace clash. bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to avoid C++ namespace clash. ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c, irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c, ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c, unlink.c: Change private to be priv_data (to avoid C++ namespace clash)
1998-01-19 17:47:53 +03:00
ma = irel->priv_data;
1997-04-29 20:17:09 +04:00
if (old > ma->max_inode)
return EXT2_ET_INVALID_ARGUMENT;
1997-04-29 20:17:09 +04:00
/*
* Force the orig field to the correct value; the application
* program shouldn't be messing with this field.
*/
if (ma->entries[(unsigned) old].new == 0)
1997-04-29 20:17:09 +04:00
ent->orig = old;
else
ent->orig = ma->entries[(unsigned) old].orig;
1997-04-29 20:17:09 +04:00
/*
* If max_refs has changed, reallocate the refs array
*/
ref_ent = ma->ref_entries + (unsigned) old;
if (ref_ent->refs && ent->max_refs !=
ma->entries[(unsigned) old].max_refs) {
1997-04-29 20:17:09 +04:00
size = (sizeof(struct ext2_inode_reference) * ent->max_refs);
old_size = (sizeof(struct ext2_inode_reference) *
ma->entries[(unsigned) old].max_refs);
retval = ext2fs_resize_mem(old_size, size,
(void **) &ref_ent->refs);
if (retval)
return retval;
1997-04-29 20:17:09 +04:00
}
ma->entries[(unsigned) old] = *ent;
ma->orig_map[(unsigned) ent->orig] = old;
1997-04-29 20:17:09 +04:00
return 0;
}
static errcode_t ima_get(ext2_irel irel, ext2_ino_t old,
1997-04-29 20:17:09 +04:00
struct ext2_inode_relocate_entry *ent)
{
struct irel_ma *ma;
Many files: inode.c (ext2fs_open_inode_scan): Initialize the group variables so that we don't need to call get_next_blockgroup() the first time around. Saves a bit of time, and prevents us from needing to assign -1 to current_group (which is an unsigned value). icount.c (insert_icount_el): Cast the estimated number of inodes from a float to an ino_t. alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c, bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c, check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c, ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c, icount.c, initialize.c, inline.c, inode.c, irel_ma.c, ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c, newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c, rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c, tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c, version.c: If EXT2_FLAT_INCLUDES is defined, then assume all of the ext2-specific header files are in a flat directory. block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast all assignments from void * to be compatible with C++. closefs.c (ext2fs_flush): Add a call to io_channel_flush() to make sure the contents of the disk are flushed to disk. dblist.c (ext2fs_add_dir_block): Change new to be new_entry to avoid C++ namespace clash. bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to avoid C++ namespace clash. ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c, irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c, ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c, unlink.c: Change private to be priv_data (to avoid C++ namespace clash)
1998-01-19 17:47:53 +03:00
ma = irel->priv_data;
1997-04-29 20:17:09 +04:00
if (old > ma->max_inode)
return EXT2_ET_INVALID_ARGUMENT;
if (ma->entries[(unsigned) old].new == 0)
1997-04-29 20:17:09 +04:00
return ENOENT;
*ent = ma->entries[(unsigned) old];
1997-04-29 20:17:09 +04:00
return 0;
}
static errcode_t ima_get_by_orig(ext2_irel irel, ext2_ino_t orig, ext2_ino_t *old,
1997-04-29 20:17:09 +04:00
struct ext2_inode_relocate_entry *ent)
{
struct irel_ma *ma;
ext2_ino_t ino;
1997-04-29 20:17:09 +04:00
Many files: inode.c (ext2fs_open_inode_scan): Initialize the group variables so that we don't need to call get_next_blockgroup() the first time around. Saves a bit of time, and prevents us from needing to assign -1 to current_group (which is an unsigned value). icount.c (insert_icount_el): Cast the estimated number of inodes from a float to an ino_t. alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c, bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c, check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c, ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c, icount.c, initialize.c, inline.c, inode.c, irel_ma.c, ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c, newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c, rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c, tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c, version.c: If EXT2_FLAT_INCLUDES is defined, then assume all of the ext2-specific header files are in a flat directory. block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast all assignments from void * to be compatible with C++. closefs.c (ext2fs_flush): Add a call to io_channel_flush() to make sure the contents of the disk are flushed to disk. dblist.c (ext2fs_add_dir_block): Change new to be new_entry to avoid C++ namespace clash. bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to avoid C++ namespace clash. ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c, irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c, ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c, unlink.c: Change private to be priv_data (to avoid C++ namespace clash)
1998-01-19 17:47:53 +03:00
ma = irel->priv_data;
1997-04-29 20:17:09 +04:00
if (orig > ma->max_inode)
return EXT2_ET_INVALID_ARGUMENT;
ino = ma->orig_map[(unsigned) orig];
1997-04-29 20:17:09 +04:00
if (ino == 0)
return ENOENT;
*old = ino;
*ent = ma->entries[(unsigned) ino];
1997-04-29 20:17:09 +04:00
return 0;
}
static errcode_t ima_start_iter(ext2_irel irel)
{
irel->current = 0;
return 0;
}
static errcode_t ima_next(ext2_irel irel, ext2_ino_t *old,
1997-04-29 20:17:09 +04:00
struct ext2_inode_relocate_entry *ent)
{
struct irel_ma *ma;
Many files: inode.c (ext2fs_open_inode_scan): Initialize the group variables so that we don't need to call get_next_blockgroup() the first time around. Saves a bit of time, and prevents us from needing to assign -1 to current_group (which is an unsigned value). icount.c (insert_icount_el): Cast the estimated number of inodes from a float to an ino_t. alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c, bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c, check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c, ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c, icount.c, initialize.c, inline.c, inode.c, irel_ma.c, ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c, newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c, rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c, tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c, version.c: If EXT2_FLAT_INCLUDES is defined, then assume all of the ext2-specific header files are in a flat directory. block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast all assignments from void * to be compatible with C++. closefs.c (ext2fs_flush): Add a call to io_channel_flush() to make sure the contents of the disk are flushed to disk. dblist.c (ext2fs_add_dir_block): Change new to be new_entry to avoid C++ namespace clash. bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to avoid C++ namespace clash. ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c, irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c, ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c, unlink.c: Change private to be priv_data (to avoid C++ namespace clash)
1998-01-19 17:47:53 +03:00
ma = irel->priv_data;
1997-04-29 20:17:09 +04:00
while (++irel->current < ma->max_inode) {
if (ma->entries[(unsigned) irel->current].new == 0)
1997-04-29 20:17:09 +04:00
continue;
*old = irel->current;
*ent = ma->entries[(unsigned) irel->current];
1997-04-29 20:17:09 +04:00
return 0;
}
*old = 0;
return 0;
}
static errcode_t ima_add_ref(ext2_irel irel, ext2_ino_t ino,
1997-04-29 20:17:09 +04:00
struct ext2_inode_reference *ref)
{
struct irel_ma *ma;
size_t size;
struct inode_reference_entry *ref_ent;
struct ext2_inode_relocate_entry *ent;
errcode_t retval;
1997-04-29 20:17:09 +04:00
Many files: inode.c (ext2fs_open_inode_scan): Initialize the group variables so that we don't need to call get_next_blockgroup() the first time around. Saves a bit of time, and prevents us from needing to assign -1 to current_group (which is an unsigned value). icount.c (insert_icount_el): Cast the estimated number of inodes from a float to an ino_t. alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c, bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c, check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c, ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c, icount.c, initialize.c, inline.c, inode.c, irel_ma.c, ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c, newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c, rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c, tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c, version.c: If EXT2_FLAT_INCLUDES is defined, then assume all of the ext2-specific header files are in a flat directory. block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast all assignments from void * to be compatible with C++. closefs.c (ext2fs_flush): Add a call to io_channel_flush() to make sure the contents of the disk are flushed to disk. dblist.c (ext2fs_add_dir_block): Change new to be new_entry to avoid C++ namespace clash. bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to avoid C++ namespace clash. ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c, irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c, ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c, unlink.c: Change private to be priv_data (to avoid C++ namespace clash)
1998-01-19 17:47:53 +03:00
ma = irel->priv_data;
1997-04-29 20:17:09 +04:00
if (ino > ma->max_inode)
return EXT2_ET_INVALID_ARGUMENT;
1997-04-29 20:17:09 +04:00
ref_ent = ma->ref_entries + (unsigned) ino;
ent = ma->entries + (unsigned) ino;
1997-04-29 20:17:09 +04:00
/*
* If the inode reference array doesn't exist, create it.
*/
if (ref_ent->refs == 0) {
size = (size_t) ((sizeof(struct ext2_inode_reference) *
ent->max_refs));
retval = ext2fs_get_mem(size, (void **) &ref_ent->refs);
if (retval)
return retval;
1997-04-29 20:17:09 +04:00
memset(ref_ent->refs, 0, size);
ref_ent->num = 0;
}
if (ref_ent->num >= ent->max_refs)
return EXT2_ET_TOO_MANY_REFS;
1997-04-29 20:17:09 +04:00
ref_ent->refs[(unsigned) ref_ent->num++] = *ref;
1997-04-29 20:17:09 +04:00
return 0;
}
static errcode_t ima_start_iter_ref(ext2_irel irel, ext2_ino_t ino)
1997-04-29 20:17:09 +04:00
{
struct irel_ma *ma;
Many files: inode.c (ext2fs_open_inode_scan): Initialize the group variables so that we don't need to call get_next_blockgroup() the first time around. Saves a bit of time, and prevents us from needing to assign -1 to current_group (which is an unsigned value). icount.c (insert_icount_el): Cast the estimated number of inodes from a float to an ino_t. alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c, bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c, check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c, ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c, icount.c, initialize.c, inline.c, inode.c, irel_ma.c, ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c, newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c, rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c, tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c, version.c: If EXT2_FLAT_INCLUDES is defined, then assume all of the ext2-specific header files are in a flat directory. block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast all assignments from void * to be compatible with C++. closefs.c (ext2fs_flush): Add a call to io_channel_flush() to make sure the contents of the disk are flushed to disk. dblist.c (ext2fs_add_dir_block): Change new to be new_entry to avoid C++ namespace clash. bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to avoid C++ namespace clash. ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c, irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c, ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c, unlink.c: Change private to be priv_data (to avoid C++ namespace clash)
1998-01-19 17:47:53 +03:00
ma = irel->priv_data;
1997-04-29 20:17:09 +04:00
if (ino > ma->max_inode)
return EXT2_ET_INVALID_ARGUMENT;
if (ma->entries[(unsigned) ino].new == 0)
1997-04-29 20:17:09 +04:00
return ENOENT;
ma->ref_current = ino;
ma->ref_iter = 0;
return 0;
}
static errcode_t ima_next_ref(ext2_irel irel,
struct ext2_inode_reference *ref)
{
struct irel_ma *ma;
struct inode_reference_entry *ref_ent;
Many files: inode.c (ext2fs_open_inode_scan): Initialize the group variables so that we don't need to call get_next_blockgroup() the first time around. Saves a bit of time, and prevents us from needing to assign -1 to current_group (which is an unsigned value). icount.c (insert_icount_el): Cast the estimated number of inodes from a float to an ino_t. alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c, bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c, check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c, ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c, icount.c, initialize.c, inline.c, inode.c, irel_ma.c, ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c, newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c, rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c, tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c, version.c: If EXT2_FLAT_INCLUDES is defined, then assume all of the ext2-specific header files are in a flat directory. block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast all assignments from void * to be compatible with C++. closefs.c (ext2fs_flush): Add a call to io_channel_flush() to make sure the contents of the disk are flushed to disk. dblist.c (ext2fs_add_dir_block): Change new to be new_entry to avoid C++ namespace clash. bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to avoid C++ namespace clash. ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c, irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c, ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c, unlink.c: Change private to be priv_data (to avoid C++ namespace clash)
1998-01-19 17:47:53 +03:00
ma = irel->priv_data;
1997-04-29 20:17:09 +04:00
ref_ent = ma->ref_entries + ma->ref_current;
if ((ref_ent->refs == NULL) ||
(ma->ref_iter >= ref_ent->num)) {
ref->block = 0;
ref->offset = 0;
return 0;
}
*ref = ref_ent->refs[ma->ref_iter++];
return 0;
}
static errcode_t ima_move(ext2_irel irel, ext2_ino_t old, ext2_ino_t new)
1997-04-29 20:17:09 +04:00
{
struct irel_ma *ma;
Many files: inode.c (ext2fs_open_inode_scan): Initialize the group variables so that we don't need to call get_next_blockgroup() the first time around. Saves a bit of time, and prevents us from needing to assign -1 to current_group (which is an unsigned value). icount.c (insert_icount_el): Cast the estimated number of inodes from a float to an ino_t. alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c, bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c, check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c, ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c, icount.c, initialize.c, inline.c, inode.c, irel_ma.c, ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c, newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c, rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c, tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c, version.c: If EXT2_FLAT_INCLUDES is defined, then assume all of the ext2-specific header files are in a flat directory. block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast all assignments from void * to be compatible with C++. closefs.c (ext2fs_flush): Add a call to io_channel_flush() to make sure the contents of the disk are flushed to disk. dblist.c (ext2fs_add_dir_block): Change new to be new_entry to avoid C++ namespace clash. bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to avoid C++ namespace clash. ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c, irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c, ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c, unlink.c: Change private to be priv_data (to avoid C++ namespace clash)
1998-01-19 17:47:53 +03:00
ma = irel->priv_data;
1997-04-29 20:17:09 +04:00
if ((old > ma->max_inode) || (new > ma->max_inode))
return EXT2_ET_INVALID_ARGUMENT;
if (ma->entries[(unsigned) old].new == 0)
1997-04-29 20:17:09 +04:00
return ENOENT;
ma->entries[(unsigned) new] = ma->entries[(unsigned) old];
if (ma->ref_entries[(unsigned) new].refs)
ext2fs_free_mem((void **) &ma->ref_entries[(unsigned) new].refs);
ma->ref_entries[(unsigned) new] = ma->ref_entries[(unsigned) old];
1997-04-29 20:17:09 +04:00
ma->entries[(unsigned) old].new = 0;
ma->ref_entries[(unsigned) old].num = 0;
ma->ref_entries[(unsigned) old].refs = 0;
1997-04-29 20:17:09 +04:00
ma->orig_map[ma->entries[new].orig] = new;
return 0;
}
static errcode_t ima_delete(ext2_irel irel, ext2_ino_t old)
1997-04-29 20:17:09 +04:00
{
struct irel_ma *ma;
Many files: inode.c (ext2fs_open_inode_scan): Initialize the group variables so that we don't need to call get_next_blockgroup() the first time around. Saves a bit of time, and prevents us from needing to assign -1 to current_group (which is an unsigned value). icount.c (insert_icount_el): Cast the estimated number of inodes from a float to an ino_t. alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c, bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c, check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c, ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c, icount.c, initialize.c, inline.c, inode.c, irel_ma.c, ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c, newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c, rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c, tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c, version.c: If EXT2_FLAT_INCLUDES is defined, then assume all of the ext2-specific header files are in a flat directory. block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast all assignments from void * to be compatible with C++. closefs.c (ext2fs_flush): Add a call to io_channel_flush() to make sure the contents of the disk are flushed to disk. dblist.c (ext2fs_add_dir_block): Change new to be new_entry to avoid C++ namespace clash. bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to avoid C++ namespace clash. ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c, irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c, ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c, unlink.c: Change private to be priv_data (to avoid C++ namespace clash)
1998-01-19 17:47:53 +03:00
ma = irel->priv_data;
1997-04-29 20:17:09 +04:00
if (old > ma->max_inode)
return EXT2_ET_INVALID_ARGUMENT;
if (ma->entries[(unsigned) old].new == 0)
1997-04-29 20:17:09 +04:00
return ENOENT;
ma->entries[old].new = 0;
if (ma->ref_entries[(unsigned) old].refs)
ext2fs_free_mem((void **) &ma->ref_entries[(unsigned) old].refs);
ma->orig_map[ma->entries[(unsigned) old].orig] = 0;
1997-04-29 20:17:09 +04:00
ma->ref_entries[(unsigned) old].num = 0;
ma->ref_entries[(unsigned) old].refs = 0;
1997-04-29 20:17:09 +04:00
return 0;
}
static errcode_t ima_free(ext2_irel irel)
{
struct irel_ma *ma;
ext2_ino_t ino;
1997-04-29 20:17:09 +04:00
if (!irel)
return 0;
Many files: inode.c (ext2fs_open_inode_scan): Initialize the group variables so that we don't need to call get_next_blockgroup() the first time around. Saves a bit of time, and prevents us from needing to assign -1 to current_group (which is an unsigned value). icount.c (insert_icount_el): Cast the estimated number of inodes from a float to an ino_t. alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c, bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c, check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c, ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c, icount.c, initialize.c, inline.c, inode.c, irel_ma.c, ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c, newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c, rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c, tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c, version.c: If EXT2_FLAT_INCLUDES is defined, then assume all of the ext2-specific header files are in a flat directory. block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast all assignments from void * to be compatible with C++. closefs.c (ext2fs_flush): Add a call to io_channel_flush() to make sure the contents of the disk are flushed to disk. dblist.c (ext2fs_add_dir_block): Change new to be new_entry to avoid C++ namespace clash. bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to avoid C++ namespace clash. ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c, irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c, ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c, unlink.c: Change private to be priv_data (to avoid C++ namespace clash)
1998-01-19 17:47:53 +03:00
ma = irel->priv_data;
1997-04-29 20:17:09 +04:00
if (ma) {
if (ma->orig_map)
ext2fs_free_mem((void **) &ma->orig_map);
1997-04-29 20:17:09 +04:00
if (ma->entries)
ext2fs_free_mem((void **) &ma->entries);
1997-04-29 20:17:09 +04:00
if (ma->ref_entries) {
for (ino = 0; ino <= ma->max_inode; ino++) {
if (ma->ref_entries[(unsigned) ino].refs)
ext2fs_free_mem((void **) &ma->ref_entries[(unsigned) ino].refs);
1997-04-29 20:17:09 +04:00
}
ext2fs_free_mem((void **) &ma->ref_entries);
1997-04-29 20:17:09 +04:00
}
ext2fs_free_mem((void **) &ma);
1997-04-29 20:17:09 +04:00
}
if (irel->name)
ext2fs_free_mem((void **) &irel->name);
ext2fs_free_mem((void **) &irel);
1997-04-29 20:17:09 +04:00
return 0;
}