[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH v5 1/6] filesystem_walk: fixed root inode listing



With the current implementation, the root inode of the given partition
is ignored.

The root inode is now reported. Its name will be a single dot '.'
reproducing the TSK API.

Signed-off-by: Matteo Cafasso <noxdafox gmail com>
---
 daemon/tsk.c         | 22 +++++++++++++++++++---
 generator/actions.ml |  5 ++---
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/daemon/tsk.c b/daemon/tsk.c
index dd368d7..9884472 100644
--- a/daemon/tsk.c
+++ b/daemon/tsk.c
@@ -49,6 +49,7 @@ static int file_flags (TSK_FS_FILE *fsfile);
 static void file_metadata (TSK_FS_META *, guestfs_int_tsk_dirent *);
 static int send_dirent_info (guestfs_int_tsk_dirent *);
 static void reply_with_tsk_error (const char *);
+static int entry_is_dot(TSK_FS_FILE *);
 
 int
 do_internal_filesystem_walk (const mountable_t *mountable)
@@ -113,9 +114,7 @@ fswalk_callback (TSK_FS_FILE *fsfile, const char *path, void *data)
   CLEANUP_FREE char *fname = NULL;
   struct guestfs_int_tsk_dirent dirent;
 
-  /* Ignore ./ and ../ */
-  ret = TSK_FS_ISDOT (fsfile->name->name);
-  if (ret != 0)
+  if (entry_is_dot (fsfile))
     return TSK_WALK_CONT;
 
   /* Build the full relative path of the entry */
@@ -271,6 +270,23 @@ reply_with_tsk_error (const char *funcname)
     reply_with_error ("%s: unknown error", funcname);
 }
 
+/* Check whether the entry is dot and is not Root.
+ * Return 1 if it is dot, 0 otherwise or if it is the Root entry.
+ */
+static int
+entry_is_dot (TSK_FS_FILE *fsfile)
+{
+  if (TSK_FS_ISDOT (fsfile->name->name)) {
+    if (fsfile->fs_info->root_inum == fsfile->name->meta_addr &&  /* Root */
+        STREQ(fsfile->name->name, "."))  /* Avoid '..' 'bin/..' 'etc/..' */
+      return 0;
+    else
+      return 1;
+  }
+
+  return 0;
+}
+
 int
 optgroup_libtsk_available (void)
 {
diff --git a/generator/actions.ml b/generator/actions.ml
index eccef00..0698b4f 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -3566,9 +3566,8 @@ and directories stored within.
 
 It is not necessary to mount the disk partition to run this command.
 
-All entries in the filesystem are returned, excluding C<.> and
-C<..>. This function can list deleted or unaccessible files.
-The entries are I<not> sorted.
+All entries in the filesystem are returned. This function can list deleted
+or unaccessible files. The entries are I<not> sorted.
 
 The C<tsk_dirent> structure contains the following fields.
 
-- 
2.9.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]