libext2fs: Add ext2fs_dblist_get_last() and ext2fs_dblist_drop_last()

Add two new functions which allows the caller to examine the last
directory block entry added to the list, and to drop if it necessary.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
bitmap-optimize
Theodore Ts'o 2008-03-13 00:34:16 -04:00
parent d45edec0fb
commit 52b1dd5e49
3 changed files with 32 additions and 0 deletions

View File

@ -259,3 +259,29 @@ int ext2fs_dblist_count(ext2_dblist dblist)
{
return (int) dblist->count;
}
errcode_t ext2fs_dblist_get_last(ext2_dblist dblist,
struct ext2_db_entry **entry)
{
errcode_t retval;
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)
{
EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
if (dblist->count == 0)
return EXT2_ET_DBLIST_EMPTY;
dblist->count--;
return 0;
}

View File

@ -326,5 +326,8 @@ ec EXT2_ET_TDB_ERR_NOEXIST,
ec EXT2_ET_TDB_ERR_RDONLY,
"TDB: Write not permitted"
ec EXT2_ET_DBLIST_EMPTY,
"Ext2fs directory block list is empty"
end

View File

@ -652,6 +652,9 @@ extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
ext2_dblist *dest);
extern int ext2fs_dblist_count(ext2_dblist dblist);
extern errcode_t ext2fs_dblist_get_last(ext2_dblist dblist,
struct ext2_db_entry **entry);
extern errcode_t ext2fs_dblist_drop_last(ext2_dblist dblist);
/* dblist_dir.c */
extern errcode_t