1.1 --- a/libe2access/lib/src/image.c Sun Nov 28 22:18:33 2021 +0100
1.2 +++ b/libe2access/lib/src/image.c Tue Dec 28 01:37:59 2021 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Filesystem access functions.
1.6 *
1.7 - * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2019, 2021 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -20,7 +20,6 @@
1.13 */
1.14
1.15 #include <string.h>
1.16 -#include <sys/stat.h>
1.17
1.18 #include <ext2fs/ext2fs.h>
1.19
1.20 @@ -186,6 +185,47 @@
1.21 return ext2fs_read_inode(fs, ino, inode);
1.22 }
1.23
1.24 +/* List a directory in the filesystem image. */
1.25 +
1.26 +errcode_t image_list_dir(ext2_filsys fs, const char *path,
1.27 + int (*proc)(struct ext2_dir_entry *, int, int, char *,
1.28 + void *),
1.29 + void *data)
1.30 +{
1.31 + const char *path_orig = path;
1.32 + char *buf;
1.33 + ext2_ino_t ino;
1.34 + errcode_t retval;
1.35 +
1.36 + retval = ext2fs_get_mem(fs->blocksize, &buf);
1.37 + if (retval)
1.38 + return retval;
1.39 +
1.40 + /* Locate the object and test whether it is a directory. */
1.41 +
1.42 + retval = image_find_path(fs, &path, &ino);
1.43 + if (retval)
1.44 + {
1.45 + ext2fs_free_mem(&buf);
1.46 + return retval;
1.47 + }
1.48 +
1.49 + if (!_image_isdir(fs, ino))
1.50 + return 1;
1.51 +
1.52 + /* List the directory contents. */
1.53 +
1.54 + retval = ext2fs_dir_iterate(fs, ino, 0, buf, proc, data);
1.55 + if (retval)
1.56 + {
1.57 + ext2fs_free_mem(&buf);
1.58 + return retval;
1.59 + }
1.60 +
1.61 + ext2fs_free_mem(&buf);
1.62 + return 0;
1.63 +}
1.64 +
1.65 /* Make a directory in the given directory in the filesystem image having the
1.66 given name and metadata. */
1.67