From: Michael Vrable Date: Fri, 13 Nov 2009 23:12:45 +0000 (-0800) Subject: New BlueSky interface for implementing readdir. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=bc90f29d0c20f85e77761dbf2c43aec96848af36;p=bluesky.git New BlueSky interface for implementing readdir. --- diff --git a/bluesky/bluesky.h b/bluesky/bluesky.h index fc30075..9808434 100644 --- a/bluesky/bluesky.h +++ b/bluesky/bluesky.h @@ -210,6 +210,7 @@ void bluesky_insert_inode(BlueSkyFS *fs, BlueSkyInode *inode); void bluesky_dirent_destroy(gpointer dirent); uint64_t bluesky_directory_lookup(BlueSkyInode *inode, gchar *name); uint64_t bluesky_directory_ilookup(BlueSkyInode *inode, gchar *name); +BlueSkyDirent *bluesky_directory_read(BlueSkyInode *dir, uint32_t cookie); gboolean bluesky_directory_insert(BlueSkyInode *dir, const gchar *name, uint64_t inum); void bluesky_directory_dump(BlueSkyInode *dir); diff --git a/bluesky/dir.c b/bluesky/dir.c index 44729b4..f279eb6 100644 --- a/bluesky/dir.c +++ b/bluesky/dir.c @@ -67,6 +67,22 @@ uint64_t bluesky_directory_ilookup(BlueSkyInode *inode, gchar *name) return d->inum; } +/* Iterate through a directory listing. This returns one directory entry at a + * time, finding the first entry with a directory cookie value larger than the + * supplied one. Use a cookie of 0 to start reading from the start of a + * directory. */ +BlueSkyDirent *bluesky_directory_read(BlueSkyInode *dir, uint32_t cookie) +{ + BlueSkyDirent start = {NULL, NULL, cookie, 0}; + GSequenceIter *i = g_sequence_search(dir->dirents, &start, + bluesky_dirent_compare, NULL); + + if (g_sequence_iter_is_end(i)) + return NULL; + else + return g_sequence_get(i); +} + /* Insert a new entry into a directory. Should be called with the inode lock * already held. */ gboolean bluesky_directory_insert(BlueSkyInode *dir,