1997-04-29 20:15:03 +04:00
|
|
|
/*
|
|
|
|
* dblist.c -- directory block list functions
|
2008-08-28 07:07:54 +04:00
|
|
|
*
|
1997-04-29 20:15:03 +04:00
|
|
|
* Copyright 1997 by Theodore Ts'o
|
2008-08-28 07:07:54 +04:00
|
|
|
*
|
1997-04-29 20:15:03 +04:00
|
|
|
* %Begin-Header%
|
2010-05-18 05:31:56 +04:00
|
|
|
* This file may be redistributed under the terms of the GNU Library
|
|
|
|
* General Public License, version 2.
|
1997-04-29 20:15:03 +04:00
|
|
|
* %End-Header%
|
|
|
|
*/
|
|
|
|
|
2011-09-19 01:34:37 +04:00
|
|
|
#include "config.h"
|
1997-04-29 20:15:03 +04:00
|
|
|
#include <stdio.h>
|
1997-08-11 03:07:40 +04:00
|
|
|
#if HAVE_UNISTD_H
|
1997-04-29 20:15:03 +04:00
|
|
|
#include <unistd.h>
|
1997-08-11 03:07:40 +04:00
|
|
|
#endif
|
1997-04-29 20:15:03 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
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:15:03 +04:00
|
|
|
#include "ext2fsP.h"
|
|
|
|
|
1998-04-30 21:35:59 +04:00
|
|
|
static EXT2_QSORT_TYPE dir_block_cmp(const void *a, const void *b);
|
2010-06-13 18:00:00 +04:00
|
|
|
static EXT2_QSORT_TYPE dir_block_cmp2(const void *a, const void *b);
|
|
|
|
static EXT2_QSORT_TYPE (*sortfunc32)(const void *a, const void *b);
|
1997-04-29 20:15:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the number of directories in the filesystem as reported by
|
|
|
|
* the group descriptors. Of course, the group descriptors could be
|
|
|
|
* wrong!
|
|
|
|
*/
|
Many files:
alloc.c, bb_inode.c, bitmaps.c, bitops.h, block.c, bmap.c, bmove.c,
brel.h, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c,
expanddir.c, ext2fs.h, ext2fsP.h, fileio.c, finddev.c, get_pathname.c,
icount.c, inode.c, irel.h, irel_ma.c, ismounted.c, link.c, lookup.c,
mkdir.c, mkjournal.c, namei.c, newdir.c, read_bb_file.c, test_io.c,
tst_iscan.c, unix_io.c, unlink.c: Change use of ino_t to ext2_ino_t,
to protect applications that attempt to compile
-D_FILE_OFFSET_BITS=64, since this inexplicably changes ino_t(!?). So
we use ext2_ino_t to avoid an unexpected ABI change.
2001-01-11 07:54:39 +03:00
|
|
|
errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs)
|
1997-04-29 20:15:03 +04:00
|
|
|
{
|
1998-09-03 05:22:57 +04:00
|
|
|
dgrp_t i;
|
Many files:
alloc.c, bb_inode.c, bitmaps.c, bitops.h, block.c, bmap.c, bmove.c,
brel.h, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c,
expanddir.c, ext2fs.h, ext2fsP.h, fileio.c, finddev.c, get_pathname.c,
icount.c, inode.c, irel.h, irel_ma.c, ismounted.c, link.c, lookup.c,
mkdir.c, mkjournal.c, namei.c, newdir.c, read_bb_file.c, test_io.c,
tst_iscan.c, unix_io.c, unlink.c: Change use of ino_t to ext2_ino_t,
to protect applications that attempt to compile
-D_FILE_OFFSET_BITS=64, since this inexplicably changes ino_t(!?). So
we use ext2_ino_t to avoid an unexpected ABI change.
2001-01-11 07:54:39 +03:00
|
|
|
ext2_ino_t num_dirs, max_dirs;
|
1997-04-29 20:15:03 +04:00
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-29 20:15:03 +04:00
|
|
|
num_dirs = 0;
|
1998-02-21 08:01:19 +03:00
|
|
|
max_dirs = fs->super->s_inodes_per_group;
|
Many files:
dblist.c (ext2fs_get_num_dirs): Make ext2fs_get_num_dirs more paranoid
about validating the directory counts from the block group
information.
all files: Don't include stdlib.h anymore; include it in ext2_fs.h,
since that file requires stdlib.h
ChangeLog, Makefile.in, dirinfo.c:
dirinfo.c (e2fsck_add_dir_info): Use ext2fs_get_num_dirs instead of
e2fsck_get_num_dirs, which has been removed.
Makefile.in (PROGS): Remove @EXTRA_PROGS@, since we don't want to
compile and install flushb.
ChangeLog, configure.in:
Remove @EXTRA_PROGS@, since we aren't using it in 2fsck/Makefile.in anymore
ChangeLog, Makefile.in:
Install debugfs in /sbin, instead of /usr/sbin.
libext2fs.texinfo:
Update version string to be 1.12
Makefile.in:
Fix bug in find script which made the exclusion list, where a '-' was
missing from an -name option.
1997-12-01 21:24:10 +03:00
|
|
|
for (i = 0; i < fs->group_desc_count; i++) {
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 04:43:47 +03:00
|
|
|
if (ext2fs_bg_used_dirs_count(fs, i) > max_dirs)
|
1998-02-21 08:01:19 +03:00
|
|
|
num_dirs += max_dirs / 8;
|
Many files:
dblist.c (ext2fs_get_num_dirs): Make ext2fs_get_num_dirs more paranoid
about validating the directory counts from the block group
information.
all files: Don't include stdlib.h anymore; include it in ext2_fs.h,
since that file requires stdlib.h
ChangeLog, Makefile.in, dirinfo.c:
dirinfo.c (e2fsck_add_dir_info): Use ext2fs_get_num_dirs instead of
e2fsck_get_num_dirs, which has been removed.
Makefile.in (PROGS): Remove @EXTRA_PROGS@, since we don't want to
compile and install flushb.
ChangeLog, configure.in:
Remove @EXTRA_PROGS@, since we aren't using it in 2fsck/Makefile.in anymore
ChangeLog, Makefile.in:
Install debugfs in /sbin, instead of /usr/sbin.
libext2fs.texinfo:
Update version string to be 1.12
Makefile.in:
Fix bug in find script which made the exclusion list, where a '-' was
missing from an -name option.
1997-12-01 21:24:10 +03:00
|
|
|
else
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 04:43:47 +03:00
|
|
|
num_dirs += ext2fs_bg_used_dirs_count(fs, i);
|
Many files:
dblist.c (ext2fs_get_num_dirs): Make ext2fs_get_num_dirs more paranoid
about validating the directory counts from the block group
information.
all files: Don't include stdlib.h anymore; include it in ext2_fs.h,
since that file requires stdlib.h
ChangeLog, Makefile.in, dirinfo.c:
dirinfo.c (e2fsck_add_dir_info): Use ext2fs_get_num_dirs instead of
e2fsck_get_num_dirs, which has been removed.
Makefile.in (PROGS): Remove @EXTRA_PROGS@, since we don't want to
compile and install flushb.
ChangeLog, configure.in:
Remove @EXTRA_PROGS@, since we aren't using it in 2fsck/Makefile.in anymore
ChangeLog, Makefile.in:
Install debugfs in /sbin, instead of /usr/sbin.
libext2fs.texinfo:
Update version string to be 1.12
Makefile.in:
Fix bug in find script which made the exclusion list, where a '-' was
missing from an -name option.
1997-12-01 21:24:10 +03:00
|
|
|
}
|
|
|
|
if (num_dirs > fs->super->s_inodes_count)
|
|
|
|
num_dirs = fs->super->s_inodes_count;
|
1997-04-29 20:15:03 +04:00
|
|
|
|
|
|
|
*ret_num_dirs = num_dirs;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-04-30 01:26:48 +04:00
|
|
|
* helper function for making a new directory block list (for
|
|
|
|
* initialize and copy).
|
1997-04-29 20:15:03 +04:00
|
|
|
*/
|
2010-06-13 18:00:00 +04:00
|
|
|
static errcode_t make_dblist(ext2_filsys fs, ext2_ino_t size,
|
|
|
|
ext2_ino_t count,
|
|
|
|
struct ext2_db_entry2 *list,
|
1997-04-30 01:26:48 +04:00
|
|
|
ext2_dblist *ret_dblist)
|
1997-04-29 20:15:03 +04:00
|
|
|
{
|
|
|
|
ext2_dblist dblist;
|
|
|
|
errcode_t retval;
|
2010-06-13 18:00:00 +04:00
|
|
|
ext2_ino_t num_dirs;
|
1997-04-30 01:26:48 +04:00
|
|
|
size_t len;
|
1997-04-29 20:15:03 +04:00
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
|
|
|
|
|
|
|
|
if ((ret_dblist == 0) && fs->dblist &&
|
|
|
|
(fs->dblist->magic == EXT2_ET_MAGIC_DBLIST))
|
|
|
|
return 0;
|
|
|
|
|
2003-08-01 17:41:07 +04:00
|
|
|
retval = ext2fs_get_mem(sizeof(struct ext2_struct_dblist), &dblist);
|
1997-10-26 06:41:24 +03:00
|
|
|
if (retval)
|
2011-09-17 00:49:28 +04:00
|
|
|
goto cleanup;
|
1997-04-29 20:15:03 +04:00
|
|
|
memset(dblist, 0, sizeof(struct ext2_struct_dblist));
|
|
|
|
|
|
|
|
dblist->magic = EXT2_ET_MAGIC_DBLIST;
|
|
|
|
dblist->fs = fs;
|
1997-04-30 01:26:48 +04:00
|
|
|
if (size)
|
|
|
|
dblist->size = size;
|
|
|
|
else {
|
2010-06-13 18:00:00 +04:00
|
|
|
retval = ext2fs_get_num_dirs(fs, &num_dirs);
|
1997-04-30 01:26:48 +04:00
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
2010-06-13 18:00:00 +04:00
|
|
|
dblist->size = (num_dirs * 2) + 12;
|
1997-04-30 01:26:48 +04:00
|
|
|
}
|
2010-06-13 18:00:00 +04:00
|
|
|
len = (size_t) sizeof(struct ext2_db_entry2) * dblist->size;
|
1997-04-30 01:26:48 +04:00
|
|
|
dblist->count = count;
|
2010-06-13 18:00:00 +04:00
|
|
|
retval = ext2fs_get_array(dblist->size, sizeof(struct ext2_db_entry2),
|
2007-11-10 03:01:06 +03:00
|
|
|
&dblist->list);
|
1997-10-26 06:41:24 +03:00
|
|
|
if (retval)
|
1997-04-29 20:15:03 +04:00
|
|
|
goto cleanup;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-30 01:26:48 +04:00
|
|
|
if (list)
|
|
|
|
memcpy(dblist->list, list, len);
|
1997-04-29 20:15:03 +04:00
|
|
|
else
|
1997-04-30 01:26:48 +04:00
|
|
|
memset(dblist->list, 0, len);
|
1998-09-03 05:22:57 +04:00
|
|
|
if (ret_dblist)
|
|
|
|
*ret_dblist = dblist;
|
|
|
|
else
|
|
|
|
fs->dblist = dblist;
|
1997-04-29 20:15:03 +04:00
|
|
|
return 0;
|
|
|
|
cleanup:
|
|
|
|
if (dblist)
|
2003-08-01 17:41:07 +04:00
|
|
|
ext2fs_free_mem(&dblist);
|
1997-04-29 20:15:03 +04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
1997-04-30 01:26:48 +04:00
|
|
|
/*
|
|
|
|
* Initialize a directory block list
|
|
|
|
*/
|
|
|
|
errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist)
|
|
|
|
{
|
|
|
|
ext2_dblist dblist;
|
|
|
|
errcode_t retval;
|
|
|
|
|
|
|
|
retval = make_dblist(fs, 0, 0, 0, &dblist);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
dblist->sorted = 1;
|
|
|
|
if (ret_dblist)
|
|
|
|
*ret_dblist = dblist;
|
|
|
|
else
|
|
|
|
fs->dblist = dblist;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy a directory block list
|
|
|
|
*/
|
|
|
|
errcode_t ext2fs_copy_dblist(ext2_dblist src, ext2_dblist *dest)
|
|
|
|
{
|
|
|
|
ext2_dblist dblist;
|
|
|
|
errcode_t retval;
|
|
|
|
|
|
|
|
retval = make_dblist(src->fs, src->size, src->count, src->list,
|
|
|
|
&dblist);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
dblist->sorted = src->sorted;
|
|
|
|
*dest = dblist;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-04-29 20:15:03 +04:00
|
|
|
/*
|
|
|
|
* Close a directory block list
|
|
|
|
*
|
|
|
|
* (moved to closefs.c)
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a directory block to the directory block list
|
|
|
|
*/
|
2010-06-13 18:00:00 +04:00
|
|
|
errcode_t ext2fs_add_dir_block2(ext2_dblist dblist, ext2_ino_t ino,
|
|
|
|
blk64_t blk, e2_blkcnt_t blockcnt)
|
1997-04-29 20:15:03 +04:00
|
|
|
{
|
2010-06-13 18:00:00 +04:00
|
|
|
struct ext2_db_entry2 *new_entry;
|
1997-10-26 06:41:24 +03:00
|
|
|
errcode_t retval;
|
1998-04-27 05:41:13 +04:00
|
|
|
unsigned long old_size;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-29 20:15:03 +04:00
|
|
|
EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
|
|
|
|
|
|
|
|
if (dblist->count >= dblist->size) {
|
2010-06-13 18:00:00 +04:00
|
|
|
old_size = dblist->size * sizeof(struct ext2_db_entry2);
|
2008-08-24 07:17:17 +04:00
|
|
|
dblist->size += dblist->size > 200 ? dblist->size / 2 : 100;
|
1998-04-27 05:41:13 +04:00
|
|
|
retval = ext2fs_resize_mem(old_size, (size_t) dblist->size *
|
2010-06-13 18:00:00 +04:00
|
|
|
sizeof(struct ext2_db_entry2),
|
2003-08-01 17:41:07 +04:00
|
|
|
&dblist->list);
|
1997-10-26 06:41:24 +03:00
|
|
|
if (retval) {
|
2011-06-11 20:54:50 +04:00
|
|
|
dblist->size = old_size / sizeof(struct ext2_db_entry2);
|
1997-10-26 06:41:24 +03:00
|
|
|
return retval;
|
1997-04-29 20:15:03 +04:00
|
|
|
}
|
|
|
|
}
|
2010-06-13 18:00:00 +04:00
|
|
|
new_entry = dblist->list + ( dblist->count++);
|
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
|
|
|
new_entry->blk = blk;
|
|
|
|
new_entry->ino = ino;
|
|
|
|
new_entry->blockcnt = blockcnt;
|
1997-04-29 20:15:03 +04:00
|
|
|
|
|
|
|
dblist->sorted = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-04-29 21:48:10 +04:00
|
|
|
/*
|
|
|
|
* Change the directory block to the directory block list
|
|
|
|
*/
|
2010-06-13 18:00:00 +04:00
|
|
|
errcode_t ext2fs_set_dir_block2(ext2_dblist dblist, ext2_ino_t ino,
|
|
|
|
blk64_t blk, e2_blkcnt_t blockcnt)
|
1997-04-29 21:48:10 +04:00
|
|
|
{
|
1998-09-03 05:22:57 +04:00
|
|
|
dgrp_t i;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-29 21:48:10 +04:00
|
|
|
EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
|
|
|
|
|
|
|
|
for (i=0; i < dblist->count; i++) {
|
|
|
|
if ((dblist->list[i].ino != ino) ||
|
|
|
|
(dblist->list[i].blockcnt != blockcnt))
|
|
|
|
continue;
|
|
|
|
dblist->list[i].blk = blk;
|
|
|
|
dblist->sorted = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
1997-10-31 09:07:47 +03:00
|
|
|
return EXT2_ET_DB_NOT_FOUND;
|
1997-04-29 21:48:10 +04:00
|
|
|
}
|
|
|
|
|
2010-06-13 18:00:00 +04:00
|
|
|
void ext2fs_dblist_sort2(ext2_dblist dblist,
|
|
|
|
EXT2_QSORT_TYPE (*sortfunc)(const void *,
|
|
|
|
const void *))
|
2002-08-31 10:32:41 +04:00
|
|
|
{
|
|
|
|
if (!sortfunc)
|
2010-06-13 18:00:00 +04:00
|
|
|
sortfunc = dir_block_cmp2;
|
2002-08-31 10:32:41 +04:00
|
|
|
qsort(dblist->list, (size_t) dblist->count,
|
2010-06-13 18:00:00 +04:00
|
|
|
sizeof(struct ext2_db_entry2), sortfunc);
|
2002-08-31 10:32:41 +04:00
|
|
|
dblist->sorted = 1;
|
|
|
|
}
|
|
|
|
|
1997-04-29 20:15:03 +04:00
|
|
|
/*
|
|
|
|
* This function iterates over the directory block list
|
|
|
|
*/
|
2010-06-13 18:00:00 +04:00
|
|
|
errcode_t ext2fs_dblist_iterate2(ext2_dblist dblist,
|
|
|
|
int (*func)(ext2_filsys fs,
|
|
|
|
struct ext2_db_entry2 *db_info,
|
|
|
|
void *priv_data),
|
|
|
|
void *priv_data)
|
1997-04-29 20:15:03 +04:00
|
|
|
{
|
2010-06-13 18:00:00 +04:00
|
|
|
unsigned long long i;
|
Many files:
alloc.c, bb_inode.c, bitmaps.c, bitops.h, block.c, bmap.c, bmove.c,
brel.h, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c,
expanddir.c, ext2fs.h, ext2fsP.h, fileio.c, finddev.c, get_pathname.c,
icount.c, inode.c, irel.h, irel_ma.c, ismounted.c, link.c, lookup.c,
mkdir.c, mkjournal.c, namei.c, newdir.c, read_bb_file.c, test_io.c,
tst_iscan.c, unix_io.c, unlink.c: Change use of ino_t to ext2_ino_t,
to protect applications that attempt to compile
-D_FILE_OFFSET_BITS=64, since this inexplicably changes ino_t(!?). So
we use ext2_ino_t to avoid an unexpected ABI change.
2001-01-11 07:54:39 +03:00
|
|
|
int ret;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-29 20:15:03 +04:00
|
|
|
EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
|
|
|
|
|
2002-08-31 10:32:41 +04:00
|
|
|
if (!dblist->sorted)
|
2010-06-13 18:00:00 +04:00
|
|
|
ext2fs_dblist_sort2(dblist, 0);
|
1997-04-29 20:15:03 +04:00
|
|
|
for (i=0; i < dblist->count; i++) {
|
2010-06-13 18:00:00 +04:00
|
|
|
ret = (*func)(dblist->fs, &dblist->list[i], priv_data);
|
1997-04-29 20:15:03 +04:00
|
|
|
if (ret & DBLIST_ABORT)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-13 18:00:00 +04:00
|
|
|
static EXT2_QSORT_TYPE dir_block_cmp2(const void *a, const void *b)
|
1997-04-29 20:15:03 +04:00
|
|
|
{
|
2010-06-13 18:00:00 +04:00
|
|
|
const struct ext2_db_entry2 *db_a =
|
|
|
|
(const struct ext2_db_entry2 *) a;
|
|
|
|
const struct ext2_db_entry2 *db_b =
|
|
|
|
(const struct ext2_db_entry2 *) b;
|
1997-04-29 20:15:03 +04:00
|
|
|
|
|
|
|
if (db_a->blk != db_b->blk)
|
Many files:
dosio.c: New file to do DOS/BIOS disk accesses.
namei.c (open_namei): Make pathlen be of type size_t.
llseek.c: Always #include stdlib.h since it's need to define
size_t.
io.h: Use errcode_t for magic numbers.
icount.c (get_icount_el), dupfs.c (ext2fs_dup_handle), dblist.c
(dir_block_cmp): Use size_t where appropriate.
read_bb.c (ext2fs_read_bb_inode), cmp_bitmaps.c
(ext2fs_compare_inode_bitmap): Use blk_t, ino_t and size_t
where appropriate.
closefs.c (ext2fs_flush): Use dgrp_t instead of int where
appropriate.
openfs.c (ext2fs_open), check_desc.c (ext2fs_check_desc): Use blk_t
instead of int where appropriate.
rw_bitmaps.c (read_bitmaps), irel_ma.c, inode.c (ext2fs_write_inode),
initialize.c (ext2fs_initialize): brel_ma.c: Fix to make be
16-bit safe.
link.c (ext2fs_link), unlink.c (ext2fs_unlink), lookup.c (lookup_proc),
ismounted.c (ext2fs_check_if_mounted), block.c (xlate_func):
Add #pragma argsused for Turbo C.
1997-08-12 00:29:22 +04:00
|
|
|
return (int) (db_a->blk - db_b->blk);
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-29 20:15:03 +04:00
|
|
|
if (db_a->ino != db_b->ino)
|
Many files:
dosio.c: New file to do DOS/BIOS disk accesses.
namei.c (open_namei): Make pathlen be of type size_t.
llseek.c: Always #include stdlib.h since it's need to define
size_t.
io.h: Use errcode_t for magic numbers.
icount.c (get_icount_el), dupfs.c (ext2fs_dup_handle), dblist.c
(dir_block_cmp): Use size_t where appropriate.
read_bb.c (ext2fs_read_bb_inode), cmp_bitmaps.c
(ext2fs_compare_inode_bitmap): Use blk_t, ino_t and size_t
where appropriate.
closefs.c (ext2fs_flush): Use dgrp_t instead of int where
appropriate.
openfs.c (ext2fs_open), check_desc.c (ext2fs_check_desc): Use blk_t
instead of int where appropriate.
rw_bitmaps.c (read_bitmaps), irel_ma.c, inode.c (ext2fs_write_inode),
initialize.c (ext2fs_initialize): brel_ma.c: Fix to make be
16-bit safe.
link.c (ext2fs_link), unlink.c (ext2fs_unlink), lookup.c (lookup_proc),
ismounted.c (ext2fs_check_if_mounted), block.c (xlate_func):
Add #pragma argsused for Turbo C.
1997-08-12 00:29:22 +04:00
|
|
|
return (int) (db_a->ino - db_b->ino);
|
1997-04-29 20:15:03 +04:00
|
|
|
|
2010-06-13 18:00:00 +04:00
|
|
|
return (db_a->blockcnt - db_b->blockcnt);
|
1997-04-29 20:15:03 +04:00
|
|
|
}
|
|
|
|
|
2010-06-13 18:00:00 +04:00
|
|
|
blk64_t ext2fs_dblist_count2(ext2_dblist dblist)
|
1997-06-17 07:55:00 +04:00
|
|
|
{
|
2010-06-13 18:00:00 +04:00
|
|
|
return dblist->count;
|
1997-06-17 07:55:00 +04:00
|
|
|
}
|
2008-03-13 07:34:16 +03:00
|
|
|
|
2010-06-13 18:00:00 +04:00
|
|
|
errcode_t ext2fs_dblist_get_last2(ext2_dblist dblist,
|
|
|
|
struct ext2_db_entry2 **entry)
|
2008-03-13 07:34:16 +03:00
|
|
|
{
|
|
|
|
EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
|
|
|
|
|
|
|
|
if (dblist->count == 0)
|
|
|
|
return EXT2_ET_DBLIST_EMPTY;
|
|
|
|
|
|
|
|
if (entry)
|
2010-06-13 18:00:00 +04:00
|
|
|
*entry = dblist->list + ( dblist->count-1);
|
2008-03-13 07:34:16 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
errcode_t ext2fs_dblist_drop_last(ext2_dblist dblist)
|
2008-08-28 07:07:54 +04:00
|
|
|
{
|
2008-03-13 07:34:16 +03:00
|
|
|
EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
|
|
|
|
|
|
|
|
if (dblist->count == 0)
|
|
|
|
return EXT2_ET_DBLIST_EMPTY;
|
|
|
|
|
|
|
|
dblist->count--;
|
|
|
|
return 0;
|
|
|
|
}
|
2010-06-13 18:00:00 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Legacy 32-bit versions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a directory block to the directory block list
|
|
|
|
*/
|
|
|
|
errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino, blk_t blk,
|
|
|
|
int blockcnt)
|
|
|
|
{
|
|
|
|
return ext2fs_add_dir_block2(dblist, ino, blk, blockcnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Change the directory block to the directory block list
|
|
|
|
*/
|
|
|
|
errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino, blk_t blk,
|
|
|
|
int blockcnt)
|
|
|
|
{
|
|
|
|
return ext2fs_set_dir_block2(dblist, ino, blk, blockcnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ext2fs_dblist_sort(ext2_dblist dblist,
|
|
|
|
EXT2_QSORT_TYPE (*sortfunc)(const void *,
|
|
|
|
const void *))
|
|
|
|
{
|
|
|
|
if (sortfunc) {
|
|
|
|
sortfunc32 = sortfunc;
|
|
|
|
sortfunc = dir_block_cmp;
|
|
|
|
} else
|
|
|
|
sortfunc = dir_block_cmp2;
|
|
|
|
qsort(dblist->list, (size_t) dblist->count,
|
|
|
|
sizeof(struct ext2_db_entry2), sortfunc);
|
|
|
|
dblist->sorted = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function iterates over the directory block list
|
|
|
|
*/
|
|
|
|
struct iterate_passthrough {
|
|
|
|
int (*func)(ext2_filsys fs,
|
|
|
|
struct ext2_db_entry *db_info,
|
|
|
|
void *priv_data);
|
|
|
|
void *priv_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int passthrough_func(ext2_filsys fs,
|
|
|
|
struct ext2_db_entry2 *db_info,
|
|
|
|
void *priv_data)
|
|
|
|
{
|
|
|
|
struct iterate_passthrough *p = priv_data;
|
|
|
|
struct ext2_db_entry db;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
db.ino = db_info->ino;
|
|
|
|
db.blk = (blk_t) db_info->blk;
|
|
|
|
db.blockcnt = (int) db_info->blockcnt;
|
|
|
|
ret = (p->func)(fs, &db, p->priv_data);
|
|
|
|
db_info->ino = db.ino;
|
|
|
|
db_info->blk = db.blk;
|
|
|
|
db_info->blockcnt = db.blockcnt;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
|
|
|
|
int (*func)(ext2_filsys fs,
|
|
|
|
struct ext2_db_entry *db_info,
|
|
|
|
void *priv_data),
|
|
|
|
void *priv_data)
|
|
|
|
{
|
|
|
|
struct iterate_passthrough pass;
|
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
|
|
|
|
pass.func = func;
|
|
|
|
pass.priv_data = priv_data;
|
|
|
|
|
|
|
|
return ext2fs_dblist_iterate2(dblist, passthrough_func, &pass);
|
|
|
|
}
|
|
|
|
|
|
|
|
static EXT2_QSORT_TYPE dir_block_cmp(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const struct ext2_db_entry2 *db_a =
|
|
|
|
(const struct ext2_db_entry2 *) a;
|
|
|
|
const struct ext2_db_entry2 *db_b =
|
|
|
|
(const struct ext2_db_entry2 *) b;
|
|
|
|
|
|
|
|
struct ext2_db_entry a32, b32;
|
|
|
|
|
|
|
|
a32.ino = db_a->ino; a32.blk = db_a->blk;
|
|
|
|
a32.blockcnt = db_a->blockcnt;
|
|
|
|
|
|
|
|
b32.ino = db_b->ino; b32.blk = db_b->blk;
|
|
|
|
b32.blockcnt = db_b->blockcnt;
|
|
|
|
|
|
|
|
return sortfunc32(&a32, &b32);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ext2fs_dblist_count(ext2_dblist dblist)
|
|
|
|
{
|
|
|
|
return dblist->count;
|
|
|
|
}
|
|
|
|
|
|
|
|
errcode_t ext2fs_dblist_get_last(ext2_dblist dblist,
|
|
|
|
struct ext2_db_entry **entry)
|
|
|
|
{
|
|
|
|
EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
|
|
|
|
static struct ext2_db_entry ret_entry;
|
|
|
|
struct ext2_db_entry2 *last;
|
|
|
|
|
|
|
|
if (dblist->count == 0)
|
|
|
|
return EXT2_ET_DBLIST_EMPTY;
|
|
|
|
|
|
|
|
if (!entry)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
last = dblist->list + dblist->count -1;
|
|
|
|
|
|
|
|
ret_entry.ino = last->ino;
|
|
|
|
ret_entry.blk = last->blk;
|
|
|
|
ret_entry.blockcnt = last->blockcnt;
|
|
|
|
*entry = &ret_entry;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|