Whamcloud - gitweb
libext2fs: Add ext2fs_dblist_get_last() and ext2fs_dblist_drop_last()
authorTheodore Ts'o <tytso@mit.edu>
Thu, 13 Mar 2008 04:34:16 +0000 (00:34 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 13 Mar 2008 04:34:16 +0000 (00:34 -0400)
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>
lib/ext2fs/dblist.c
lib/ext2fs/ext2_err.et.in
lib/ext2fs/ext2fs.h

index 21b36aa..3bf63a0 100644 (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;
+}
index eda4bb4..7451242 100644 (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
 
index 0b2c321..d098961 100644 (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