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%
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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);
|
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++) {
|
|
|
|
if (fs->group_desc[i].bg_used_dirs_count > 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
|
|
|
|
num_dirs += fs->group_desc[i].bg_used_dirs_count;
|
|
|
|
}
|
|
|
|
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
|
|
|
*/
|
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
|
|
|
static errcode_t make_dblist(ext2_filsys fs, ext2_ino_t size, ext2_ino_t count,
|
1997-04-30 01:26:48 +04:00
|
|
|
struct ext2_db_entry *list,
|
|
|
|
ext2_dblist *ret_dblist)
|
1997-04-29 20:15:03 +04:00
|
|
|
{
|
|
|
|
ext2_dblist dblist;
|
|
|
|
errcode_t retval;
|
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)
|
|
|
|
return retval;
|
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 {
|
|
|
|
retval = ext2fs_get_num_dirs(fs, &dblist->size);
|
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
1997-06-09 18:51:29 +04:00
|
|
|
dblist->size = (dblist->size * 2) + 12;
|
1997-04-30 01:26:48 +04:00
|
|
|
}
|
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
|
|
|
len = (size_t) sizeof(struct ext2_db_entry) * dblist->size;
|
1997-04-30 01:26:48 +04:00
|
|
|
dblist->count = count;
|
2007-11-10 03:01:06 +03:00
|
|
|
retval = ext2fs_get_array(dblist->size, sizeof(struct ext2_db_entry),
|
|
|
|
&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
|
|
|
|
*/
|
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_add_dir_block(ext2_dblist dblist, ext2_ino_t ino, blk_t blk,
|
1997-04-29 20:15:03 +04:00
|
|
|
int blockcnt)
|
|
|
|
{
|
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
|
|
|
struct ext2_db_entry *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) {
|
1998-04-27 05:41:13 +04:00
|
|
|
old_size = dblist->size * sizeof(struct ext2_db_entry);
|
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 *
|
1997-10-26 06:41:24 +03:00
|
|
|
sizeof(struct ext2_db_entry),
|
2003-08-01 17:41:07 +04:00
|
|
|
&dblist->list);
|
1997-10-26 06:41:24 +03:00
|
|
|
if (retval) {
|
1997-04-29 20:15:03 +04:00
|
|
|
dblist->size -= 100;
|
1997-10-26 06:41:24 +03:00
|
|
|
return retval;
|
1997-04-29 20:15:03 +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
|
|
|
new_entry = dblist->list + ( (int) dblist->count++);
|
|
|
|
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
|
|
|
|
*/
|
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_set_dir_block(ext2_dblist dblist, ext2_ino_t ino, blk_t blk,
|
1997-04-29 21:48:10 +04:00
|
|
|
int blockcnt)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2002-08-31 10:32:41 +04:00
|
|
|
void ext2fs_dblist_sort(ext2_dblist dblist,
|
|
|
|
EXT2_QSORT_TYPE (*sortfunc)(const void *,
|
|
|
|
const void *))
|
|
|
|
{
|
|
|
|
if (!sortfunc)
|
|
|
|
sortfunc = dir_block_cmp;
|
|
|
|
qsort(dblist->list, (size_t) dblist->count,
|
|
|
|
sizeof(struct ext2_db_entry), sortfunc);
|
|
|
|
dblist->sorted = 1;
|
|
|
|
}
|
|
|
|
|
1997-04-29 20:15:03 +04:00
|
|
|
/*
|
|
|
|
* This function iterates over the directory block list
|
|
|
|
*/
|
|
|
|
errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
|
|
|
|
int (*func)(ext2_filsys fs,
|
|
|
|
struct ext2_db_entry *db_info,
|
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
|
|
|
void *priv_data),
|
|
|
|
void *priv_data)
|
1997-04-29 20:15:03 +04:00
|
|
|
{
|
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 i;
|
|
|
|
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)
|
|
|
|
ext2fs_dblist_sort(dblist, 0);
|
1997-04-29 20:15:03 +04:00
|
|
|
for (i=0; i < dblist->count; i++) {
|
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
|
|
|
ret = (*func)(dblist->fs, &dblist->list[(int)i], priv_data);
|
1997-04-29 20:15:03 +04:00
|
|
|
if (ret & DBLIST_ABORT)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-04-30 21:35:59 +04:00
|
|
|
static EXT2_QSORT_TYPE dir_block_cmp(const void *a, const void *b)
|
1997-04-29 20:15:03 +04:00
|
|
|
{
|
|
|
|
const struct ext2_db_entry *db_a =
|
|
|
|
(const struct ext2_db_entry *) a;
|
|
|
|
const struct ext2_db_entry *db_b =
|
|
|
|
(const struct ext2_db_entry *) b;
|
|
|
|
|
|
|
|
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
|
|
|
|
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->blockcnt - db_b->blockcnt);
|
1997-04-29 20:15:03 +04:00
|
|
|
}
|
|
|
|
|
1997-06-17 07:55:00 +04:00
|
|
|
int ext2fs_dblist_count(ext2_dblist dblist)
|
|
|
|
{
|
|
|
|
return (int) dblist->count;
|
|
|
|
}
|
2008-03-13 07:34:16 +03:00
|
|
|
|
2008-08-28 07:07:54 +04:00
|
|
|
errcode_t ext2fs_dblist_get_last(ext2_dblist dblist,
|
2008-03-13 07:34:16 +03:00
|
|
|
struct ext2_db_entry **entry)
|
|
|
|
{
|
|
|
|
EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
|
|
|
|
|
|
|
|
if (dblist->count == 0)
|
|
|
|
return EXT2_ET_DBLIST_EMPTY;
|
|
|
|
|
|
|
|
if (entry)
|
|
|
|
*entry = dblist->list + ( (int) dblist->count-1);
|
|
|
|
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;
|
|
|
|
}
|